Skip to content

Commit 332e811

Browse files
committed
cross platform windows fix
1 parent 8f17475 commit 332e811

File tree

173 files changed

+379
-313
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

173 files changed

+379
-313
lines changed

CMakeLists.txt

+7-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ SET(BENCHMARK_FORCE_WERROR OFF CACHE INTERNAL "")
4343
SET(BENCHMARK_ENABLE_WERROR ON CACHE INTERNAL "")
4444
SET(BENCHMARK_USE_BUNDLED_GTEST CACHE INTERNAL "")
4545

46-
add_subdirectory(benchmark)
4746

4847
##############################
4948
### Project ###
@@ -54,6 +53,9 @@ enable_testing()
5453
include("CPack")
5554
include(CTest)
5655
set(CMAKE_DEBUG_POSTFIX "-d")
56+
set(CXX_STANDARD 20)
57+
58+
add_subdirectory(benchmark)
5759

5860
##############################
5961
### Globals ###
@@ -63,9 +65,12 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
6365
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
6466
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
6567
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-variable -Wno-unused-parameter -Wno-comment -Wno-unused-function -Wno-deprecated-this-capture")
66-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-implicit-int-float-conversion")
68+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-implicit-int-float-conversion -Wno-reserved-macro-identifier -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-old-style-cast -Wno-sign-conversion -Wshadow-field-in-constructor -Wno-language-extension-token")
6769

6870
set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib")
71+
set(EXEEXT ${CMAKE_EXECUTABLE_SUFFIX})
72+
set(LIBEXT ${CMAKE_STATIC_LIBRARY_SUFFIX})
73+
set(SHAREDEXT ${CMAKE_SHARED_LIBRARY_SUFFIX})
6974

7075
set_tests_properties(${noArgsTests} PROPERTIES TIMEOUT 10)
7176
include(macros.cmake)

build.py

+20-10
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ def build_rlc(
4747
build_type: str,
4848
llvm_install_dir,
4949
clang_path: str,
50-
python_path: str
50+
python_path: str,
51+
is_windows: bool,
5152
):
5253
assert_run_program(
5354
execution_dir,
@@ -61,8 +62,8 @@ def build_rlc(
6162
"-DMLIR_DIR={}/lib/cmake/mlir".format(llvm_install_dir),
6263
"-DLLVM_DIR={}/lib/cmake/llvm".format(llvm_install_dir),
6364
"-DClang_DIR={}/lib/cmake/clang".format(llvm_install_dir),
64-
f"-DCMAKE_C_COMPILER={path.abspath(clang_path)}",
65-
f"-DCMAKE_CXX_COMPILER={path.abspath(clang_path)}++",
65+
f"-DCMAKE_C_COMPILER={path.abspath(clang_path)}{".exe" is_windows ""}",
66+
f"-DCMAKE_CXX_COMPILER={path.abspath(clang_path)}++{".exe" is_windows ""}",
6667
"-DBUILD_SHARED_LIBS={}".format("ON" if build_shared else "OFF"),
6768
"-DCMAKE_BUILD_WITH_INSTALL_RPATH={}".format("OFF" if build_shared else "ON"),
6869
"-DHAVE_STD_REGEX=ON",
@@ -93,9 +94,9 @@ def build_llvm(
9394
"-DLLVM_ENABLE_PROJECTS=clang;clang-tools-extra;mlir;compiler-rt;lld;",
9495
"-DLLVM_USE_LINKER=lld" if use_lld else "",
9596
"-DCMAKE_EXPORT_COMPILE_COMMANDS=True",
96-
"-DLLVM_ENABLE_RUNTIMES=libcxx;libunwind",
9797
f"-DCMAKE_C_COMPILER={clang}",
9898
f"-DCMAKE_CXX_COMPILER={clang_plus_plus}",
99+
"-DLLVM_ENABLE_RUNTIMES=libcxx",
99100
"-G",
100101
"Ninja",
101102
"-DBUILD_SHARED_LIBS={}".format("ON" if build_shared else "OFF"),
@@ -131,6 +132,11 @@ def main():
131132
help="does not build debug llvm",
132133
action="store_true",
133134
)
135+
parser.add_argument(
136+
"--no-debug-rlc",
137+
help="does not build debug llvm",
138+
action="store_true",
139+
)
134140
parser.add_argument(
135141
"--dry-run",
136142
help="only prints the command that would be executing",
@@ -250,8 +256,11 @@ def main():
250256
else:
251257
build_shared = args.rlc_shared
252258

259+
is_windows = os.name == "nt"
260+
253261
# build debug
254-
build_rlc(
262+
if not args.no_debug_rlc:
263+
build_rlc(
255264
execution_dir=rlc_build_dir,
256265
cmake_path=cmake,
257266
rlc_source_dir=rlc_dir,
@@ -260,9 +269,10 @@ def main():
260269
build_type="Debug",
261270
llvm_install_dir=llvm_dir,
262271
clang_path=f"{llvm_install_release_dir}/bin/clang",
263-
python_path=python
264-
)
265-
install(execution_dir=rlc_build_dir, ninja_path=ninja, run_tests=True)
272+
python_path=python,
273+
is_windows=is_windows,
274+
)
275+
install(execution_dir=rlc_build_dir, ninja_path=ninja, run_tests=True)
266276

267277
build_rlc(
268278
execution_dir=rlc_release_dir,
@@ -273,8 +283,8 @@ def main():
273283
build_type="Release",
274284
llvm_install_dir=llvm_install_release_dir,
275285
clang_path=f"{llvm_install_release_dir}/bin/clang",
276-
python_path=python
277-
286+
python_path=python,
287+
is_windows=is_windows,
278288
)
279289
install(execution_dir=rlc_release_dir, ninja_path=ninja, run_tests=True)
280290

environment.bat

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
..\.venv\Scripts\activate.bat
2+
@set LIBPATH=%LIBPATH%;C:\Users\mofio\Documents\rlc-infrastructure\llvm-install-release\lib
3+
@set PATH=%PATH%;C:\Users\mofio\Documents\rlc-infrastructure\llvm-install-release\bin

googletest

Submodule googletest updated 162 files

lib/backend/src/BackEnd.cpp

+55-14
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ limitations under the License.
3333
#include "llvm/Pass.h"
3434
#include "llvm/PassRegistry.h"
3535
#include "llvm/Passes/PassBuilder.h"
36+
#include "llvm/Passes/PassPlugin.h"
3637
#include "llvm/Support/CommandLine.h"
3738
#include "llvm/Support/Error.h"
3839
#include "llvm/Support/FileSystem.h"
@@ -108,11 +109,25 @@ static void addFuzzerInstrumentationPass(llvm::ModulePassManager &MPM)
108109
MPM.addPass(SanitizerCoveragePass(opts));
109110
}
110111

112+
class AddWindowsDLLExportPass: public PassInfoMixin<AddWindowsDLLExportPass>
113+
{
114+
public:
115+
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
116+
{
117+
if (F.getName().starts_with("rl__") or F.getName().starts_with("rl_m__"))
118+
return PreservedAnalyses::none();
119+
120+
F.setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass);
121+
return PreservedAnalyses::none();
122+
};
123+
};
124+
111125
static void runOptimizer(
112126
llvm::Module &M,
113127
bool optimize,
114128
bool emitSanitizerInstrumentation,
115-
bool linkAgainsFuzzer)
129+
bool linkAgainsFuzzer,
130+
bool targetIsWindows)
116131
{
117132
// Create the analysis managers.
118133
LoopAnalysisManager LAM;
@@ -139,10 +154,12 @@ static void runOptimizer(
139154
{
140155
ModulePassManager passManager;
141156
FunctionPassManager functionPassManager;
157+
if (targetIsWindows)
158+
functionPassManager.addPass(AddWindowsDLLExportPass());
142159
functionPassManager.addPass(llvm::PromotePass());
143160
passManager.addPass(
144161
createModuleToFunctionPassAdaptor(std::move(functionPassManager)));
145-
if (emitSanitizerInstrumentation)
162+
if (emitSanitizerInstrumentation and not targetIsWindows)
146163
addFuzzerInstrumentationPass(passManager);
147164
passManager.run(M, MAM);
148165

@@ -163,7 +180,9 @@ static void runOptimizer(
163180
{
164181
ModulePassManager MPM =
165182
PB.buildO0DefaultPipeline(OptimizationLevel::O0, true);
166-
if (emitSanitizerInstrumentation)
183+
if (targetIsWindows)
184+
MPM.addPass(createModuleToFunctionPassAdaptor(AddWindowsDLLExportPass()));
185+
if (emitSanitizerInstrumentation and not targetIsWindows)
167186
addFuzzerInstrumentationPass(MPM);
168187
MPM.run(M, MAM);
169188
}
@@ -380,22 +399,37 @@ static int linkLibraries(
380399
argSource.push_back("-fuse-ld=lld");
381400
argSource.push_back("-Wl,-subsystem:console");
382401
}
383-
argSource.push_back("-o");
384-
argSource.push_back(outputFile.str());
385-
if (not info.isMacOS())
402+
else if (not info.isMacOS())
386403
argSource.push_back("-lm");
404+
405+
argSource.push_back("-o");
387406
if (shared)
388407
{
389-
argSource.push_back("--shared");
390-
if (not info.isWindows())
408+
if (info.isWindows())
409+
{
410+
argSource.push_back(outputFile.str() + ".dll");
411+
}
412+
else
413+
{
414+
argSource.push_back(outputFile.str());
391415
argSource.push_back("-fPIE");
416+
}
417+
argSource.push_back("--shared");
392418
}
393419
else
394420
{
395-
if (not info.isWindows())
421+
if (info.isWindows())
422+
{
423+
argSource.push_back(outputFile.str() + ".exe");
424+
}
425+
else
426+
{
427+
argSource.push_back(outputFile.str());
396428
argSource.push_back("-no-pie");
429+
}
397430
}
398-
if (emitSanitizerInstrumentation or linkAgainstFuzzer)
431+
if ((emitSanitizerInstrumentation or linkAgainstFuzzer) and
432+
not info.isWindows())
399433
{
400434
std::string arg("-fsanitize=");
401435
if (emitSanitizerInstrumentation)
@@ -405,11 +439,13 @@ static int linkLibraries(
405439
if (linkAgainstFuzzer)
406440
arg += "fuzzer";
407441
argSource.push_back(arg);
442+
if (info.isWindows())
443+
{
444+
argSource.push_back("-Wl,/NODEFAULTLIB:libcmt");
445+
argSource.push_back("-Wl,-defaultlib:msvcrt");
446+
}
408447
}
409448

410-
for (auto rpathEntry : rpaths)
411-
argSource.push_back("-Wl,-rpath," + rpathEntry);
412-
413449
for (auto extraObject : extraObjectFiles)
414450
argSource.push_back(extraObject);
415451

@@ -441,7 +477,12 @@ namespace mlir::rlc
441477
assert(Module);
442478
Module->setTargetTriple(llvm::sys::getDefaultTargetTriple());
443479

444-
runOptimizer(*Module, targetInfo->optimize(), emitSanitizer, emitFuzzer);
480+
runOptimizer(
481+
*Module,
482+
targetInfo->optimize(),
483+
emitSanitizer,
484+
emitFuzzer,
485+
targetInfo->isWindows());
445486

446487
if (dumpIR)
447488
{

lib/conversions/src/RLCToPython.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ namespace mlir::python
646646
auto lib = builder.create<mlir::rlc::python::CTypesLoad>(
647647
getOperation().getLoc(),
648648
mlir::rlc::python::CDLLType::get(&getContext()),
649-
"lib.so");
649+
target_is_windows ? "lib.dll" : "lib.so");
650650
mlir::ConversionTarget target(getContext());
651651

652652
mlir::TypeConverter ctypesConverter;

lib/dialect/test/src/DialectTest.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16+
#include "any"
1617
#include "gtest/gtest.h"
1718

1819
#include "rlc/dialect/ActionArgumentAnalysis.hpp"

lib/driver/src/Driver.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ namespace mlir::rlc
8787
{
8888
manager.addPass(mlir::rlc::createSortTypeDeclarationsPass());
8989
manager.addPass(mlir::python::createRLCTypesToPythonTypesPass());
90-
manager.addPass(mlir::python::createRLCToPythonPass());
90+
manager.addPass(
91+
mlir::python::createRLCToPythonPass({ targetInfo->isWindows() }));
9192
if (request == Request::dumpPythonAST)
9293
manager.addPass(mlir::rlc::createPrintIRPass({ OS, hidePosition }));
9394
else

lib/parser/src/Lexer.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,11 @@ Token Lexer::nextWithoutTrailingConsume()
618618
indentStack.pop_back();
619619
return Token::Deindent;
620620
}
621+
while (deindentToEmit != 0)
622+
{
623+
deindentToEmit--;
624+
return Token::Deindent;
625+
}
621626
return Token::End;
622627
}
623628

lib/parser/test/src/LexerTester.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16+
#include "any"
1617
#include "gtest/gtest.h"
1718

1819
#include "rlc/parser/Lexer.hpp"

lib/python/src/Operations.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -336,12 +336,13 @@ mlir::LogicalResult mlir::rlc::python::CTypesLoad::emit(
336336
llvm::raw_ostream& OS, SerializationContext& context)
337337
{
338338
OS << "from ctypes import *\n";
339+
OS << "import os\n";
339340
OS << "from typing import overload\n";
340341
OS << "from pathlib import Path\n";
341342
OS << "import builtins\n";
342343
OS << "from collections import defaultdict\n\n";
343-
OS << "lib = CDLL(Path(__file__).resolve().parent / \"" << getLibName()
344-
<< "\")\n";
344+
OS << "lib = CDLL(os.path.join(Path(__file__).resolve().parent, \"" << getLibName()
345+
<< "\"))\n";
345346
context.registerValue(getResult(), "lib");
346347

347348
OS << "actions = defaultdict(list)\n";

lib/python/src/Passes.td

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ include "mlir/Rewrite/PassUtil.td"
33

44
def RLCToPythonPass: Pass<"rlc-to-python", "mlir::ModuleOp"> {
55
let summary = "convert rlc to python";
6+
let options = [
7+
Option<"target_is_windows", "target is windows", "bool", /*default=*/"false",
8+
"true if the target is windows">
9+
];
610
}
711

812
def RLCTypesToPythonTypesPass: Pass<"rlc-types-to-python-types", "mlir::ModuleOp"> {

lib/runtime/include/rlc/runtime/Runtime.h

+20-13
Original file line numberDiff line numberDiff line change
@@ -18,45 +18,52 @@ limitations under the License.
1818
#include <stdbool.h>
1919
#include <stdint.h>
2020

21+
#ifdef _WIN32
22+
# define EXPORT __declspec(dllexport)
23+
#else
24+
# define EXPORT
25+
#endif
26+
2127
typedef struct String String;
2228

2329
// fun init(String self)
24-
void rl_m_init__String(String* self);
30+
EXPORT void rl_m_init__String(String* self);
2531

2632
// fun get(String self, Int index)
27-
void rl_m_get__String_int64_t_r_int8_tRef(
33+
EXPORT void rl_m_get__String_int64_t_r_int8_tRef(
2834
int8_t** out, String* self, int64_t* index);
2935

3036
// fun append(String self, StringLiteral l)
31-
void rl_m_append__String_strlit(String* self, char** to_append);
37+
EXPORT void rl_m_append__String_strlit(String* self, char** to_append);
3238

3339
// fun append(String self, Int to_append)
34-
void rl_append_to_string__int64_t_String(int64_t* member, String* out);
40+
EXPORT void rl_append_to_string__int64_t_String(int64_t* member, String* out);
3541
// fun append(String self, Byte to_append)
36-
void rl_append_to_string__int8_t_String(int8_t* member, String* out);
42+
EXPORT void rl_append_to_string__int8_t_String(int8_t* member, String* out);
3743
// fun append(String self, Float to_append)
38-
void rl_append_to_string__double_String(double* member, String* out);
44+
EXPORT void rl_append_to_string__double_String(double* member, String* out);
3945

4046
// fun print(String self)
41-
void rl_print__String(String* s);
47+
EXPORT void rl_print__String(String* s);
4248
// fun print(StringLiteral self)
43-
void rl_print_string__strlit(char** s);
49+
EXPORT void rl_print_string__strlit(char** s);
4450

4551
// fun parse_string(Int result, String buffer, Int index) -> Bool
46-
void rl_parse_string__int64_t_String_int64_t_r_bool(
52+
EXPORT void rl_parse_string__int64_t_String_int64_t_r_bool(
4753
bool* return_value, int64_t* result, String* buffer, int64_t* current);
4854

4955
// fun parse_string(Float result, String buffer, Int index) -> Bool
50-
void rl_parse_string__double_String_int64_t_r_bool(
56+
EXPORT void rl_parse_string__double_String_int64_t_r_bool(
5157
bool* return_value, double* result, String* buffer, int64_t* current);
5258

5359
// fun parse_string(Byte result, String buffer, Int index) -> Bool
54-
void rl_parse_string__int8_t_String_int64_t_r_bool(
60+
EXPORT void rl_parse_string__int8_t_String_int64_t_r_bool(
5561
bool* return_value, int8_t* result, String* buffer, int64_t* current);
5662

5763
// fun parse_string(Byte result, String buffer, Int index) -> Bool
58-
void rl_is_alphanumeric__int8_t_r_bool(bool* return_value, int8_t* input_char);
64+
EXPORT void rl_is_alphanumeric__int8_t_r_bool(
65+
bool* return_value, int8_t* input_char);
5966

6067
// fun load_file(String file_path, String out) -> Bool
61-
void rl_load_file__String_r_String(
68+
EXPORT void rl_load_file__String_r_String(
6269
int8_t* result, String* file_name, String* out);

0 commit comments

Comments
 (0)