Skip to content

Commit 18c420e

Browse files
committed
Enable running ClangReplInterpreterTests in an Emscripten environment
1 parent 4b1d5b8 commit 18c420e

File tree

7 files changed

+68
-14
lines changed

7 files changed

+68
-14
lines changed

clang/unittests/Interpreter/CMakeLists.txt

Lines changed: 47 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,28 @@ 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+
target_link_options(ClangReplInterpreterTests
53+
PUBLIC "SHELL: -s MAIN_MODULE=1"
54+
PUBLIC "SHELL: -s ALLOW_MEMORY_GROWTH=1"
55+
PUBLIC "SHELL: -s STACK_SIZE=32mb"
56+
PUBLIC "SHELL: -s INITIAL_MEMORY=128mb"
57+
PUBLIC "SHELL: --emrun"
58+
)
59+
set_target_properties(ClangReplInterpreterTests PROPERTIES
60+
SUFFIX ".html"
61+
)
62+
endif()
63+
2964
# Exceptions on Windows are not yet supported.
3065
if(NOT WIN32)
3166
add_subdirectory(ExceptionTests)

clang/unittests/Interpreter/CodeCompletionTest.cpp

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

3131
void SetUp() override {
32+
#ifndef __EMSCRIPTEN__
3233
if (!HostSupportsJIT())
3334
GTEST_SKIP();
35+
#endif
3436
std::unique_ptr<CompilerInstance> CI = cantFail(CB.CreateCpp());
3537
this->Interp = cantFail(clang::Interpreter::create(std::move(CI)));
3638
}

clang/unittests/Interpreter/IncrementalCompilerBuilderTest.cpp

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

3939
TEST(IncrementalCompilerBuilder, SetTargetTriple) {
40+
#ifdef __EMSCRIPTEN__
41+
GTEST_SKIP() << "Test fails for Emscipten builds";
42+
#endif
4043
auto CB = clang::IncrementalCompilerBuilder();
4144
CB.SetTargetTriple("armv6-none-eabi");
4245
auto CI = cantFail(CB.CreateCpp());

clang/unittests/Interpreter/InterpreterExtensionsTest.cpp

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

7777
TEST_F(InterpreterExtensionsTest, FindRuntimeInterface) {
78+
#ifndef __EMSCRIPTEN__
7879
if (!HostSupportsJIT())
7980
GTEST_SKIP();
80-
81+
#endif
8182
clang::IncrementalCompilerBuilder CB;
8283
llvm::Error ErrOut = llvm::Error::success();
8384
auto CI = cantFail(CB.CreateCpp());

clang/unittests/Interpreter/InterpreterTest.cpp

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

149149
TEST_F(InterpreterTest, UndoCommand) {
150+
#ifdef __EMSCRIPTEN__
151+
GTEST_SKIP() << "Test fails for Emscipten builds";
152+
#endif
150153
Args ExtraArgs = {"-Xclang", "-diagnostic-log-file", "-Xclang", "-"};
151154

152155
// Create the diagnostic engine with unowned consumer.
@@ -256,6 +259,9 @@ static NamedDecl *LookupSingleName(Interpreter &Interp, const char *Name) {
256259
}
257260

258261
TEST_F(InterpreterTest, InstantiateTemplate) {
262+
#ifdef __EMSCRIPTEN__
263+
GTEST_SKIP() << "Test fails for Emscipten builds";
264+
#endif
259265
// FIXME: We cannot yet handle delayed template parsing. If we run with
260266
// -fdelayed-template-parsing we try adding the newly created decl to the
261267
// active PTU which causes an assert.
@@ -295,6 +301,9 @@ TEST_F(InterpreterTest, InstantiateTemplate) {
295301
}
296302

297303
TEST_F(InterpreterTest, Value) {
304+
#ifdef __EMSCRIPTEN__
305+
GTEST_SKIP() << "Test fails for Emscipten builds";
306+
#endif
298307
std::vector<const char *> Args = {"-fno-sized-deallocation"};
299308
std::unique_ptr<Interpreter> Interp = createInterpreter(Args);
300309

clang/unittests/Interpreter/InterpreterTestFixture.h

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

4040
void SetUp() override {
41+
#ifndef __EMSCRIPTEN__
4142
if (!HostSupportsJIT())
4243
GTEST_SKIP();
44+
#endif
4345
}
4446

4547
void TearDown() override {}

llvm/cmake/modules/AddLLVM.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1764,7 +1764,9 @@ function(add_unittest test_suite test_name)
17641764
set(LLVM_REQUIRES_RTTI OFF)
17651765
endif()
17661766
1767-
list(APPEND LLVM_LINK_COMPONENTS Support) # gtest needs it for raw_ostream
1767+
if(NOT EMSCRIPTEN)
1768+
list(APPEND LLVM_LINK_COMPONENTS Support) # gtest needs it for raw_ostream
1769+
endif()
17681770
add_llvm_executable(${test_name} IGNORE_EXTERNALIZE_DEBUGINFO NO_INSTALL_RPATH ${ARGN})
17691771
get_subproject_title(subproject_title)
17701772
set_target_properties(${test_name} PROPERTIES FOLDER "${subproject_title}/Tests/Unit")

0 commit comments

Comments
 (0)