Skip to content

Commit b24b8a5

Browse files
authored
Enable running ClangReplInterpreterTests in an Emscripten environment (#150977)
@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.
1 parent ddb2dc5 commit b24b8a5

File tree

6 files changed

+102
-13
lines changed

6 files changed

+102
-13
lines changed

clang/unittests/Interpreter/CMakeLists.txt

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,34 @@
1+
if(EMSCRIPTEN)
2+
set(LLVM_COMPONENTS_TO_LINK
3+
""
4+
)
5+
set(LLVM_LIBS_TO_LINK
6+
""
7+
)
8+
set(CLANG_LIBS_TO_LINK
9+
clangInterpreter
10+
)
11+
else()
12+
set(LLVM_COMPONENTS_TO_LINK
13+
${LLVM_TARGETS_TO_BUILD}
14+
Core
15+
MC
16+
OrcJIT
17+
Support
18+
TargetParser
19+
)
20+
set(LLVM_LIBS_TO_LINK
21+
LLVMTestingSupport
22+
)
23+
set(CLANG_LIBS_TO_LINK
24+
clangAST
25+
clangBasic
26+
clangInterpreter
27+
clangFrontend
28+
clangSema
29+
)
30+
endif()
31+
132
add_distinct_clang_unittest(ClangReplInterpreterTests
233
IncrementalCompilerBuilderTest.cpp
334
IncrementalProcessingTest.cpp
@@ -8,24 +39,33 @@ add_distinct_clang_unittest(ClangReplInterpreterTests
839
EXPORT_SYMBOLS
940

1041
CLANG_LIBS
11-
clangAST
12-
clangBasic
13-
clangInterpreter
14-
clangFrontend
15-
clangSema
42+
${CLANG_LIBS_TO_LINK}
1643

1744
LINK_LIBS
18-
LLVMTestingSupport
45+
${LLVM_LIBS_TO_LINK}
1946

2047
LLVM_COMPONENTS
21-
${LLVM_TARGETS_TO_BUILD}
22-
Core
23-
MC
24-
OrcJIT
25-
Support
26-
TargetParser
48+
${LLVM_COMPONENTS_TO_LINK}
2749
)
2850

51+
if(EMSCRIPTEN)
52+
# Without the above you try to link to LLVMSupport twice, and end
53+
# up with a duplicate symbol error when creating the main module
54+
get_target_property(LINKED_LIBS ClangReplInterpreterTests LINK_LIBRARIES)
55+
list(REMOVE_ITEM LINKED_LIBS LLVMSupport)
56+
set_target_properties(ClangReplInterpreterTests PROPERTIES LINK_LIBRARIES "${LINKED_LIBS}")
57+
target_link_options(ClangReplInterpreterTests
58+
PUBLIC "SHELL: -s MAIN_MODULE=1"
59+
PUBLIC "SHELL: -s ALLOW_MEMORY_GROWTH=1"
60+
PUBLIC "SHELL: -s STACK_SIZE=32mb"
61+
PUBLIC "SHELL: -s INITIAL_MEMORY=128mb"
62+
PUBLIC "SHELL: --emrun"
63+
)
64+
set_target_properties(ClangReplInterpreterTests PROPERTIES
65+
SUFFIX ".html"
66+
)
67+
endif()
68+
2969
# Exceptions on Windows are not yet supported.
3070
if(NOT WIN32)
3171
add_subdirectory(ExceptionTests)

clang/unittests/Interpreter/CodeCompletionTest.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,14 @@ class CodeCompletionTest : public InterpreterTestBase {
2929
std::unique_ptr<clang::Interpreter> Interp;
3030

3131
void SetUp() override {
32+
// FIXME : WebAssembly doesn't currently support Jit (see
33+
// https: // github.com/llvm/llvm-project/pull/150977#discussion_r2237521095).
34+
// so this check of HostSupportsJIT has been skipped
35+
// over until support is added, and HostSupportsJIT can return true.
36+
#ifndef __EMSCRIPTEN__
3237
if (!HostSupportsJIT())
3338
GTEST_SKIP();
39+
#endif
3440
std::unique_ptr<CompilerInstance> CI = cantFail(CB.CreateCpp());
3541
this->Interp = cantFail(clang::Interpreter::create(std::move(CI)));
3642
}

clang/unittests/Interpreter/IncrementalCompilerBuilderTest.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ TEST(IncrementalCompilerBuilder, SetCompilerArgs) {
3737
}
3838

3939
TEST(IncrementalCompilerBuilder, SetTargetTriple) {
40+
// FIXME : This test doesn't current work for Emscripten builds.
41+
// It should be possible to make it work.For details on how it fails and
42+
// the current progress to enable this test see
43+
// the following Github issue https: //
44+
// github.com/llvm/llvm-project/issues/153461
45+
#ifdef __EMSCRIPTEN__
46+
GTEST_SKIP() << "Test fails for Emscipten builds";
47+
#endif
4048
auto CB = clang::IncrementalCompilerBuilder();
4149
CB.SetTargetTriple("armv6-none-eabi");
4250
auto CI = cantFail(CB.CreateCpp());

clang/unittests/Interpreter/InterpreterExtensionsTest.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,14 @@ struct OutOfProcInterpreter : public Interpreter {
7575
};
7676

7777
TEST_F(InterpreterExtensionsTest, FindRuntimeInterface) {
78+
// FIXME : WebAssembly doesn't currently support Jit (see
79+
// https: // github.com/llvm/llvm-project/pull/150977#discussion_r2237521095).
80+
// so this check of HostSupportsJIT has been skipped
81+
// over until support is added, and HostSupportsJIT can return true.
82+
#ifndef __EMSCRIPTEN__
7883
if (!HostSupportsJIT())
7984
GTEST_SKIP();
80-
85+
#endif
8186
clang::IncrementalCompilerBuilder CB;
8287
llvm::Error ErrOut = llvm::Error::success();
8388
auto CI = cantFail(CB.CreateCpp());

clang/unittests/Interpreter/InterpreterTest.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,14 @@ TEST_F(InterpreterTest, DeclsAndStatements) {
147147
}
148148

149149
TEST_F(InterpreterTest, UndoCommand) {
150+
// FIXME : This test doesn't current work for Emscripten builds.
151+
// It should be possible to make it work.For details on how it fails and
152+
// the current progress to enable this test see
153+
// the following Github issue https: //
154+
// github.com/llvm/llvm-project/issues/153461
155+
#ifdef __EMSCRIPTEN__
156+
GTEST_SKIP() << "Test fails for Emscipten builds";
157+
#endif
150158
Args ExtraArgs = {"-Xclang", "-diagnostic-log-file", "-Xclang", "-"};
151159

152160
// Create the diagnostic engine with unowned consumer.
@@ -256,6 +264,14 @@ static NamedDecl *LookupSingleName(Interpreter &Interp, const char *Name) {
256264
}
257265

258266
TEST_F(InterpreterTest, InstantiateTemplate) {
267+
// FIXME : This test doesn't current work for Emscripten builds.
268+
// It should be possible to make it work.For details on how it fails and
269+
// the current progress to enable this test see
270+
// the following Github issue https: //
271+
// github.com/llvm/llvm-project/issues/153461
272+
#ifdef __EMSCRIPTEN__
273+
GTEST_SKIP() << "Test fails for Emscipten builds";
274+
#endif
259275
// FIXME: We cannot yet handle delayed template parsing. If we run with
260276
// -fdelayed-template-parsing we try adding the newly created decl to the
261277
// active PTU which causes an assert.
@@ -295,6 +311,14 @@ TEST_F(InterpreterTest, InstantiateTemplate) {
295311
}
296312

297313
TEST_F(InterpreterTest, Value) {
314+
// FIXME : This test doesn't current work for Emscripten builds.
315+
// It should be possible to make it work.For details on how it fails and
316+
// the current progress to enable this test see
317+
// the following Github issue https: //
318+
// github.com/llvm/llvm-project/issues/153461
319+
#ifdef __EMSCRIPTEN__
320+
GTEST_SKIP() << "Test fails for Emscipten builds";
321+
#endif
298322
std::vector<const char *> Args = {"-fno-sized-deallocation"};
299323
std::unique_ptr<Interpreter> Interp = createInterpreter(Args);
300324

clang/unittests/Interpreter/InterpreterTestFixture.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,14 @@ class InterpreterTestBase : public ::testing::Test {
3838
}
3939

4040
void SetUp() override {
41+
// FIXME : WebAssembly doesn't currently support Jit (see
42+
// https: // github.com/llvm/llvm-project/pull/150977#discussion_r2237521095).
43+
// so this check of HostSupportsJIT has been skipped
44+
// over until support is added, and HostSupportsJIT can return true.
45+
#ifndef __EMSCRIPTEN__
4146
if (!HostSupportsJIT())
4247
GTEST_SKIP();
48+
#endif
4349
}
4450

4551
void TearDown() override {}

0 commit comments

Comments
 (0)