Skip to content

Commit 50d54d9

Browse files
committed
fix windows build issues
1 parent 979795b commit 50d54d9

File tree

8 files changed

+64
-28
lines changed

8 files changed

+64
-28
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ SET(gtest_disable_pthreads OFF CACHE INTERNAL "")
1414
SET(gtest_hide_internal_symbols OFF CACHE INTERNAL "")
1515
SET(gtest_force_shared_crt OFF CACHE INTERNAL "")
1616
SET(GTEST_HAS_ABSL OFF CACHE INTERNAL "")
17+
SET(GTEST_HAS_RTTI OFF CACHE INTERNAL "")
18+
SET(GTEST_INTERNAL_HAS_ANY OFF CACHE INTERNAL "")
19+
SET(GTEST_LINKED_AS_SHARED_LIBRARY OFF CACHE INTERNAL "")
20+
SET(gtest_force_shared_crt ON CACHE INTERNAL "")
1721

1822
add_subdirectory(googletest)
1923
#set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=undefined -fsanitize=memory -fsanitize-ignorelist=/home/massimo/Documents/example_rlc/rlc-infrastructure/rlc-debug/ignorelist.txt -fsanitize-recover=all")
@@ -71,6 +75,7 @@ list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
7175
include(AddLLVM)
7276

7377
find_package(MLIR REQUIRED CONFIG)
78+
set(EXEEXT ${CMAKE_EXECUTABLE_SUFFIX})
7479

7580
##############################
7681
### Subfolders ###

build.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ def build_llvm(
8989
"-DLLVM_INSTALL_UTILS=True",
9090
"-DCMAKE_BUILD_TYPE={}".format(build_type),
9191
"-DCMAKE_INSTALL_PREFIX={}".format(install_dir),
92-
"-DLLVM_ENABLE_PROJECTS=clang;clang-tools-extra;mlir;compiler-rt;",
92+
"-DLLVM_ENABLE_PROJECTS=clang;clang-tools-extra;mlir;compiler-rt;lld;",
9393
"-DLLVM_USE_LINKER=lld" if use_lld else "",
9494
"-DCMAKE_EXPORT_COMPILE_COMMANDS=True",
95-
"-DLLVM_ENABLE_RUNTIMES=libcxx;libcxxabi;libunwind",
95+
"-DLLVM_ENABLE_RUNTIMES=libcxx;libunwind",
9696
f"-DCMAKE_C_COMPILER={clang}",
9797
f"-DCMAKE_CXX_COMPILER={clang_plus_plus}",
9898
"-G",

lib/backend/include/rlc/backend/BackEnd.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ namespace mlir::rlc
3535
bool optimize() const;
3636
bool isShared() const;
3737
bool isMacOS() const;
38+
bool isWindows() const;
3839
const llvm::DataLayout& getDataLayout() const;
3940

4041
TargetInfo(TargetInfo&& other): pimpl(other.pimpl)

lib/backend/src/BackEnd.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,11 @@ bool mlir::rlc::TargetInfo::isMacOS() const
226226
return pimpl->triple.isOSDarwin();
227227
}
228228

229+
bool mlir::rlc::TargetInfo::isWindows() const
230+
{
231+
return pimpl->triple.isOSWindows();
232+
}
233+
229234
const llvm::DataLayout &mlir::rlc::TargetInfo::getDataLayout() const
230235
{
231236
return *pimpl->datalayout;
@@ -276,7 +281,7 @@ static int linkLibraries(
276281
bool linkAgainstFuzzer,
277282
const std::vector<std::string> &extraObjectFiles,
278283
const std::vector<std::string> &rpaths,
279-
bool macOS)
284+
const mlir::rlc::TargetInfo &info)
280285
{
281286
auto failedToFindClang = false;
282287
auto maybeRealPath =
@@ -296,18 +301,25 @@ static int linkLibraries(
296301
llvm::SmallVector<std::string, 4> argSource;
297302
argSource.push_back("clang");
298303
argSource.push_back(library.getFilename().str());
304+
if (info.isWindows())
305+
{
306+
argSource.push_back("-fuse-ld=lld");
307+
argSource.push_back("-Wl,-subsystem:console");
308+
}
299309
argSource.push_back("-o");
300310
argSource.push_back(outputFile.str());
301-
if (not macOS)
311+
if (not info.isMacOS())
302312
argSource.push_back("-lm");
303313
if (shared)
304314
{
305315
argSource.push_back("--shared");
306-
argSource.push_back("-fPIE");
316+
if (not info.isWindows())
317+
argSource.push_back("-fPIE");
307318
}
308319
else
309320
{
310-
argSource.push_back("-no-pie");
321+
if (not info.isWindows())
322+
argSource.push_back("-no-pie");
311323
}
312324
if (emitSanitizerInstrumentation or linkAgainstFuzzer)
313325
{
@@ -382,6 +394,7 @@ namespace mlir::rlc
382394
}
383395

384396
compile(*targetInfo, std::move(Module), library.os());
397+
library.os().close();
385398

386399
if (compileOnly)
387400
{
@@ -398,7 +411,7 @@ namespace mlir::rlc
398411
emitFuzzer,
399412
*extraObjectFiles,
400413
*rpaths,
401-
targetInfo->isMacOS()) != 0)
414+
*targetInfo) != 0)
402415
signalPassFailure();
403416
}
404417
};

lib/dialect/src/Conversion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1499,7 +1499,7 @@ class FunctionRewriter
14991499
if (not op.isDeclaration() and op.getType().getResults().size() == 1 and
15001500
not op.getType().getResults().front().isa<mlir::rlc::VoidType>())
15011501
newF.getBody().front().insertArgument(
1502-
size_t(0), op.getType().getResults().front(), op.getLoc());
1502+
unsigned(0), op.getType().getResults().front(), op.getLoc());
15031503

15041504
rewriter.eraseOp(op);
15051505

stdlib/action.rl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import serialization.to_byte_vector
1919
import serialization.print
2020
import bounded_arg
2121
import math.numeric
22+
import algorithms.equal
2223

2324
trait<FrameType, ActionType> ApplicableTo:
2425
fun apply(ActionType action, FrameType frame)
@@ -97,6 +98,7 @@ fun<FrameType, AllActionsVariant> gen_python_methods(FrameType state, AllActions
9798
from_byte_vector(x, serialized)
9899
parse_action_optimized(x, serialized, 0)
99100
enumerate(x).size()
101+
equal(variant, variant)
100102
let v : Vector<Float>
101103
to_observation_tensor(state, 0, v)
102104
print(variant)

stdlib/algorithms/equal.rl

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,34 @@
1-
trait<T> Comparable
2-
fun custom_equal(T lhs, T rhs) -> Bool
1+
trait<T> Comparable:
2+
fun custom_equal(T lhs, T rhs) -> Bool
33

44
fun custom_equal(Int lhs, Int rhs) -> Bool:
5-
return lhs == rhs
5+
return lhs == rhs
66

77
fun custom_equal(Bool lhs, Bool rhs) -> Bool:
8-
return lhs == rhs
8+
return lhs == rhs
99

1010
fun custom_equal(Byte lhs, Byte rhs) -> Bool:
11-
return lhs == rhs
11+
return lhs == rhs
1212

1313
fun custom_equal(Float lhs, Float rhs) -> Bool:
14-
return lhs == rhs
14+
return lhs == rhs
1515

16-
fun<T, Int X> custom_equal(T[X] lhs, T[X] rhs):
17-
let counter = 0
18-
while counter < X:
19-
if !(lhs == rhs):
20-
return false
21-
counter = counter + 1
22-
return true
16+
fun<T, Int X> custom_equal(T[X] lhs, T[X] rhs) -> Bool:
17+
let counter = 0
18+
while counter < X:
19+
if !equal(lhs, rhs):
20+
return false
21+
counter = counter + 1
22+
return true
2323

2424
# to implement
25-
fun<T> equal(T lhs, T rhs):
26-
if lhs is Comparable:
27-
if rhs is Comparable:
28-
return custom_equal(lhs, rhs)
29-
for field of lhs
25+
fun<T> equal(T lhs, T rhs) -> Bool:
26+
if lhs is Comparable:
27+
if rhs is Comparable:
28+
return custom_equal(lhs, rhs)
29+
for field, field2 of lhs, rhs:
30+
using T2 = type(field)
31+
if field2 is T2:
32+
if !equal(field, field2):
33+
return false
34+
return true

tool/rlc/src/Main.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ limitations under the License.
2626
#include "llvm/Support/MemoryBuffer.h"
2727
#include "llvm/Support/Path.h"
2828
#include "llvm/Support/Process.h"
29+
#include "llvm/Support/Path.h"
2930
#include "llvm/Support/Program.h"
3031
#include "llvm/Support/raw_ostream.h"
3132
#include "llvm/Target/TargetMachine.h"
@@ -290,6 +291,13 @@ static mlir::rlc::Driver::Request getRequest()
290291
return Driver::Request::executable;
291292
}
292293

294+
static std::string toNative(llvm::StringRef path) {
295+
SmallVector<char> converted;
296+
llvm::sys::path::native(Twine(path), converted);
297+
std::string out(converted.begin(), converted.end());
298+
return out;
299+
}
300+
293301
static mlir::rlc::Driver configureDriver(
294302
char *argv[],
295303
llvm::SourceMgr &srcManager,
@@ -300,6 +308,7 @@ static mlir::rlc::Driver configureDriver(
300308
auto pathToRlc = llvm::sys::fs::getMainExecutable(argv[0], (void *) &main);
301309
auto rlcDirectory =
302310
llvm::sys::path::parent_path(pathToRlc).str() + "/../lib/rlc/stdlib";
311+
rlcDirectory = toNative(rlcDirectory);
303312
llvm::SmallVector<std::string, 4> includes(
304313
IncludeDirs.begin(), IncludeDirs.end());
305314
auto directory = llvm::sys::path::parent_path(InputFilePath);
@@ -312,6 +321,7 @@ static mlir::rlc::Driver configureDriver(
312321
? llvm::sys::path::parent_path(pathToRlc).str() +
313322
"/../lib/" + FUZZER_LIBRARY_FILENAME
314323
: customFuzzerLibPath.getValue();
324+
fuzzerLibPath = toNative(fuzzerLibPath);
315325

316326
ExtraObjectFiles.addValue(fuzzerLibPath);
317327
RPath.addValue(llvm::sys::path::parent_path(fuzzerLibPath).str());
@@ -324,8 +334,8 @@ static mlir::rlc::Driver configureDriver(
324334
if (envVal.has_value())
325335
runtimeLibPath = *envVal;
326336
else
327-
runtimeLibPath = llvm::sys::path::parent_path(pathToRlc).str() +
328-
"/../lib/" + RUNTIME_LIBRARY_FILENAME;
337+
runtimeLibPath = toNative(llvm::sys::path::parent_path(pathToRlc).str() +
338+
"/../lib/" + RUNTIME_LIBRARY_FILENAME);
329339
}
330340
ExtraObjectFiles.addValue(runtimeLibPath);
331341

0 commit comments

Comments
 (0)