-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Enable running ClangReplInterpreterTests in an Emscripten environment #150977
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Enable running ClangReplInterpreterTests in an Emscripten environment #150977
Conversation
@llvm/pr-subscribers-clang @llvm/pr-subscribers-backend-webassembly Author: None (mcbarton) Changes@vgvassilev @anutosh491 This is what it took for me to enable running ClangReplInterpreterTests in an Emscripten environment. When I ran this patch for llvm 20 we could run InterpreterTest.InstantiateTemplate , but now it crashes gtest when running in node. Let me know what you think. Full diff: https://github.com/llvm/llvm-project/pull/150977.diff 5 Files Affected:
diff --git a/clang/unittests/Interpreter/CMakeLists.txt b/clang/unittests/Interpreter/CMakeLists.txt
index 1dda9024075a1..a84ab045d4333 100644
--- a/clang/unittests/Interpreter/CMakeLists.txt
+++ b/clang/unittests/Interpreter/CMakeLists.txt
@@ -1,31 +1,60 @@
-add_distinct_clang_unittest(ClangReplInterpreterTests
- IncrementalCompilerBuilderTest.cpp
- IncrementalProcessingTest.cpp
- InterpreterTest.cpp
- InterpreterExtensionsTest.cpp
- CodeCompletionTest.cpp
-
- EXPORT_SYMBOLS
-
- CLANG_LIBS
- clangAST
- clangBasic
- clangInterpreter
- clangFrontend
- clangSema
-
- LINK_LIBS
- LLVMTestingSupport
-
- LLVM_COMPONENTS
- ${LLVM_TARGETS_TO_BUILD}
- Core
- MC
- OrcJIT
- Support
- TargetParser
+if(EMSCRIPTEN)
+
+ add_distinct_clang_unittest(ClangReplInterpreterTests
+ IncrementalCompilerBuilderTest.cpp
+ IncrementalProcessingTest.cpp
+ InterpreterTest.cpp
+ InterpreterExtensionsTest.cpp
+ CodeCompletionTest.cpp
+
+ CLANG_LIBS
+ clangInterpreter
+ )
+
+ target_link_options(ClangReplInterpreterTests
+ PUBLIC "SHELL: -s MAIN_MODULE=1"
+ PUBLIC "SHELL: -s ALLOW_MEMORY_GROWTH=1"
+ PUBLIC "SHELL: -s STACK_SIZE=32mb"
+ PUBLIC "SHELL: -s INITIAL_MEMORY=128mb"
+ PUBLIC "SHELL: --emrun"
)
+ set_target_properties(ClangReplInterpreterTests PROPERTIES
+ SUFFIX ".html"
+ )
+
+else()
+
+ add_distinct_clang_unittest(ClangReplInterpreterTests
+ IncrementalCompilerBuilderTest.cpp
+ IncrementalProcessingTest.cpp
+ InterpreterTest.cpp
+ InterpreterExtensionsTest.cpp
+ CodeCompletionTest.cpp
+
+ EXPORT_SYMBOLS
+
+ CLANG_LIBS
+ clangAST
+ clangBasic
+ clangInterpreter
+ clangFrontend
+ clangSema
+
+ LINK_LIBS
+ LLVMTestingSupport
+
+ LLVM_COMPONENTS
+ ${LLVM_TARGETS_TO_BUILD}
+ Core
+ MC
+ OrcJIT
+ Support
+ TargetParser
+ )
+
+endif()
+
# Exceptions on Windows are not yet supported.
if(NOT WIN32)
add_subdirectory(ExceptionTests)
diff --git a/clang/unittests/Interpreter/IncrementalCompilerBuilderTest.cpp b/clang/unittests/Interpreter/IncrementalCompilerBuilderTest.cpp
index c4a40071f55cf..7c17e28bf1a68 100644
--- a/clang/unittests/Interpreter/IncrementalCompilerBuilderTest.cpp
+++ b/clang/unittests/Interpreter/IncrementalCompilerBuilderTest.cpp
@@ -37,6 +37,9 @@ TEST(IncrementalCompilerBuilder, SetCompilerArgs) {
}
TEST(IncrementalCompilerBuilder, SetTargetTriple) {
+#ifdef EMSCRIPTEN
+ GTEST_SKIP() << "Test fails for Emscipten builds";
+#endif
auto CB = clang::IncrementalCompilerBuilder();
CB.SetTargetTriple("armv6-none-eabi");
auto CI = cantFail(CB.CreateCpp());
diff --git a/clang/unittests/Interpreter/InterpreterTest.cpp b/clang/unittests/Interpreter/InterpreterTest.cpp
index 768058b954d49..ad345d2f9e1b6 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -147,6 +147,9 @@ TEST_F(InterpreterTest, DeclsAndStatements) {
}
TEST_F(InterpreterTest, UndoCommand) {
+#ifdef EMSCRIPTEN
+ GTEST_SKIP() << "Test fails for Emscipten builds";
+#endif
Args ExtraArgs = {"-Xclang", "-diagnostic-log-file", "-Xclang", "-"};
// Create the diagnostic engine with unowned consumer.
@@ -256,6 +259,9 @@ static NamedDecl *LookupSingleName(Interpreter &Interp, const char *Name) {
}
TEST_F(InterpreterTest, InstantiateTemplate) {
+#ifdef EMSCRIPTEN
+ GTEST_SKIP() << "Test fails for Emscipten builds";
+#endif
// FIXME: We cannot yet handle delayed template parsing. If we run with
// -fdelayed-template-parsing we try adding the newly created decl to the
// active PTU which causes an assert.
@@ -295,6 +301,9 @@ TEST_F(InterpreterTest, InstantiateTemplate) {
}
TEST_F(InterpreterTest, Value) {
+#ifdef EMSCRIPTEN
+ GTEST_SKIP() << "Test fails for Emscipten builds";
+#endif
std::vector<const char *> Args = {"-fno-sized-deallocation"};
std::unique_ptr<Interpreter> Interp = createInterpreter(Args);
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 83772ed8d2b13..40614d2b47868 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -1764,7 +1764,9 @@ function(add_unittest test_suite test_name)
set(LLVM_REQUIRES_RTTI OFF)
endif()
- list(APPEND LLVM_LINK_COMPONENTS Support) # gtest needs it for raw_ostream
+ if(NOT EMSCRIPTEN)
+ list(APPEND LLVM_LINK_COMPONENTS Support) # gtest needs it for raw_ostream
+ endif()
add_llvm_executable(${test_name} IGNORE_EXTERNALIZE_DEBUGINFO NO_INSTALL_RPATH ${ARGN})
get_subproject_title(subproject_title)
set_target_properties(${test_name} PROPERTIES FOLDER "${subproject_title}/Tests/Unit")
diff --git a/llvm/lib/Target/WebAssembly/TargetInfo/WebAssemblyTargetInfo.cpp b/llvm/lib/Target/WebAssembly/TargetInfo/WebAssemblyTargetInfo.cpp
index e65fa8e60aeb1..d0371374daf2d 100644
--- a/llvm/lib/Target/WebAssembly/TargetInfo/WebAssemblyTargetInfo.cpp
+++ b/llvm/lib/Target/WebAssembly/TargetInfo/WebAssemblyTargetInfo.cpp
@@ -29,8 +29,9 @@ Target &llvm::getTheWebAssemblyTarget64() {
extern "C" LLVM_ABI LLVM_EXTERNAL_VISIBILITY void
LLVMInitializeWebAssemblyTargetInfo() {
- RegisterTarget<Triple::wasm32> X(getTheWebAssemblyTarget32(), "wasm32",
- "WebAssembly 32-bit", "WebAssembly");
+ RegisterTarget<Triple::wasm32, /*HasJIT=*/true> X(
+ getTheWebAssemblyTarget32(), "wasm32", "WebAssembly 32-bit",
+ "WebAssembly");
RegisterTarget<Triple::wasm64> Y(getTheWebAssemblyTarget64(), "wasm64",
"WebAssembly 64-bit", "WebAssembly");
}
|
|
a8d742a
to
de87852
Compare
@@ -29,8 +29,9 @@ Target &llvm::getTheWebAssemblyTarget64() { | |||
|
|||
extern "C" LLVM_ABI LLVM_EXTERNAL_VISIBILITY void | |||
LLVMInitializeWebAssemblyTargetInfo() { | |||
RegisterTarget<Triple::wasm32> X(getTheWebAssemblyTarget32(), "wasm32", | |||
"WebAssembly 32-bit", "WebAssembly"); | |||
RegisterTarget<Triple::wasm32, /*HasJIT=*/true> X( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what HasJIT
means exactly here, but wasm doesn't support JIT in the traditional sense.. at least you cannot write new instructions to memory at runtime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change was made along with the main_module flag (main_module flag helped me in other ways) so I could get past this check in the test set up https://github.com/mcbarton/llvm-project/blob/de878527f1671d6effa690a7e01d86cd41446fcc/clang/unittests/Interpreter/InterpreterTestFixture.h#L27 . Is it best to skip this check for Emscripten then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vgvassilev do you have any issues with me skipping the hostsupportsjit check for the tests when building with Emscripten (see https://github.com/mcbarton/llvm-project/blob/de878527f1671d6effa690a7e01d86cd41446fcc/clang/unittests/Interpreter/InterpreterTestFixture.h#L41 ), given @sbc comment that wasm doesn't support JIT in the traditional sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not have any issues there -- anything that makes the tests run on that platform would be a good first step.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you have any issues with me skipping the hostsupportsjit check for the tests
Yes we can start with that.
@@ -37,6 +37,9 @@ TEST(IncrementalCompilerBuilder, SetCompilerArgs) { | |||
} | |||
|
|||
TEST(IncrementalCompilerBuilder, SetTargetTriple) { | |||
#ifdef __EMSCRIPTEN__ | |||
GTEST_SKIP() << "Test fails for Emscipten builds"; | |||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, we should be able to fetch the target triple.
Can we try ?
#ifdef __EMSCRIPTEN__
const char* triple = "wasm32-unknown-emscripten";
const char* expected = "wasm32-unknown-emscripten";
#else
const char* triple = "armv6-none-eabi";
const char* expected = "armv6-unknown-none-eabi";
#endif
here and use triple
and expected
below ?
Hi, Could you paste the errors for Also just curious if the llvm/cmake/modules/AddLLVM.cmake changes are necessary (is Support being fetched for something where its not required) ? |
ded0a3b
to
18c420e
Compare
@anutosh491 @vgvassilev I have double checked locally that just skipping hostsupportsjit allows the tests to still pass, and have pushed the changes to this PR. I have not applied the suggestion here #150977 (comment), as I believe it to be flawed (e.g. Emscripten/WebAssembly can have the wasm64-unknown-emscripten target as well as the wasm32-unknown-emscripten target). With regards to the InstantiateTemplate Value test comment here #150977 (comment) the test crashes gtest, and I don't want this PR to become about fixing every test straight away. Finally with regards to the cmake change it is necessary. When you make the tests a main module, if there are any duplicate libraries being linked to then you get a duplicate symbol error when it tries to build the javascript. It still links to the llvmsupport library, but through clangInterpreter. I think this PR is ready to go in now as a first step in having Emscripten tests for llvm clang-repl interpreter. Subsequent PRs can deal with getting everything to pass. |
So we would be testing this through cppinterop's CI is it ?
Interested in seeing what the error message says. We can fix it later if its totally unseen before. Also regarding Addllvm.cmake, it is a very involved file in general. Would be good if we can skip any changes there. Let's see what others say. |
@anutosh491 Yes the plan is that for now CppInterOps ci will be made to run the tests for the llvm 21 branch, assuming it gets cherry picked for the release (I also have the patch for llvm 20 and will create one for llvm 19 so CppInterOp can run for these versions too). Hopefully showing it working will give greater chances that llvm gets a Emscripten ci workflow (would be quite easy to create given we have CppInterOps ci). If you want to run the tests locally to see the error, then remove -DLLVM_INCLUDE_TESTS=OFF from CppInterOps Emscripten instructions (you shouldn't apply any of the patches either), build the ClangReplInterpreterTests target, then go from the build folder to the test folder (e.g execute cd ./tools/clang/unittests/Interpreter) . Then you can execute the tests using |
@vgvassilev @anutosh491 This is what it took for me to enable running ClangReplInterpreterTests in an Emscripten environment. When I ran this patch for llvm 20 we could run InterpreterTest.InstantiateTemplate , but now it crashes gtest when running in node. Let me know what you think.