Skip to content

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 48 additions & 12 deletions clang/unittests/Interpreter/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
if(EMSCRIPTEN)
set(LLVM_COMPONENTS_TO_LINK
""
)
set(LLVM_LIBS_TO_LINK
""
)
set(CLANG_LIBS_TO_LINK
clangInterpreter
)
else()
set(LLVM_COMPONENTS_TO_LINK
${LLVM_TARGETS_TO_BUILD}
Core
MC
OrcJIT
Support
TargetParser
)
set(LLVM_LIBS_TO_LINK
LLVMTestingSupport
)
set(CLANG_LIBS_TO_LINK
clangAST
clangBasic
clangInterpreter
clangFrontend
clangSema
)
endif()

set(CLANG_REPL_TEST_SOURCES
IncrementalCompilerBuilderTest.cpp
IncrementalProcessingTest.cpp
Expand All @@ -20,30 +51,35 @@ add_distinct_clang_unittest(ClangReplInterpreterTests
EXPORT_SYMBOLS

CLANG_LIBS
clangAST
clangBasic
clangInterpreter
clangFrontend
clangSema
${CLANG_LIBS_TO_LINK}

LINK_LIBS
LLVMTestingSupport
${LLVM_LIBS_TO_LINK}

LLVM_COMPONENTS
${LLVM_TARGETS_TO_BUILD}
Core
MC
OrcJIT
Support
TargetParser
${LLVM_COMPONENTS_TO_LINK}
)

if(EMSCRIPTEN)
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"
)
endif()

if(TARGET compiler-rt)
add_dependencies(ClangReplInterpreterTests
llvm-jitlink-executor
compiler-rt
)
message(STATUS "Adding dependency on compiler-rt for out of process JIT tests")

endif()

# Exceptions on Windows are not yet supported.
Expand Down
2 changes: 2 additions & 0 deletions clang/unittests/Interpreter/CodeCompletionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ class CodeCompletionTest : public InterpreterTestBase {
std::unique_ptr<clang::Interpreter> Interp;

void SetUp() override {
#ifndef __EMSCRIPTEN__
if (!HostSupportsJIT())
GTEST_SKIP();
#endif
std::unique_ptr<CompilerInstance> CI = cantFail(CB.CreateCpp());
this->Interp = cantFail(clang::Interpreter::create(std::move(CI)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ TEST(IncrementalCompilerBuilder, SetCompilerArgs) {
}

TEST(IncrementalCompilerBuilder, SetTargetTriple) {
#ifdef __EMSCRIPTEN__
GTEST_SKIP() << "Test fails for Emscipten builds";
#endif
Copy link
Member

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 ?

auto CB = clang::IncrementalCompilerBuilder();
CB.SetTargetTriple("armv6-none-eabi");
auto CI = cantFail(CB.CreateCpp());
Expand Down
3 changes: 2 additions & 1 deletion clang/unittests/Interpreter/InterpreterExtensionsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ struct OutOfProcInterpreter : public Interpreter {
};

TEST_F(InterpreterExtensionsTest, FindRuntimeInterface) {
#ifndef __EMSCRIPTEN__
if (!HostSupportsJIT())
GTEST_SKIP();

#endif
clang::IncrementalCompilerBuilder CB;
llvm::Error ErrOut = llvm::Error::success();
auto CI = cantFail(CB.CreateCpp());
Expand Down
9 changes: 9 additions & 0 deletions clang/unittests/Interpreter/InterpreterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,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.
Expand Down Expand Up @@ -267,6 +270,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.
Expand Down Expand Up @@ -306,6 +312,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);

Expand Down
2 changes: 2 additions & 0 deletions clang/unittests/Interpreter/InterpreterTestFixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ class InterpreterTestBase : public ::testing::Test {
}

void SetUp() override {
#ifndef __EMSCRIPTEN__
if (!HostSupportsJIT())
GTEST_SKIP();
#endif
}

void TearDown() override {}
Expand Down
4 changes: 3 additions & 1 deletion llvm/cmake/modules/AddLLVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down