https://github.com/anutosh491 updated https://github.com/llvm/llvm-project/pull/175910
>From d534859cf3e4c79fc51c6c40de07a9ad7a7c23eb Mon Sep 17 00:00:00 2001 From: anutosh491 <[email protected]> Date: Thu, 8 Oct 2026 10:19:39 +0530 Subject: [PATCH] [clang-repl] Drop ORC link dependencies from Emscripten builds --- .../clang/Interpreter/IncrementalExecutor.h | 2 ++ clang/lib/Interpreter/CMakeLists.txt | 29 ++++++++++-------- clang/lib/Interpreter/IncrementalExecutor.cpp | 11 ++----- clang/lib/Interpreter/Wasm.cpp | 30 +++++++++++++++++++ clang/unittests/Interpreter/CMakeLists.txt | 9 ++++-- .../Interpreter/InterpreterExtensionsTest.cpp | 3 ++ 6 files changed, 59 insertions(+), 25 deletions(-) diff --git a/clang/include/clang/Interpreter/IncrementalExecutor.h b/clang/include/clang/Interpreter/IncrementalExecutor.h index f1a68c0288d00..2e037d1f090e5 100644 --- a/clang/include/clang/Interpreter/IncrementalExecutor.h +++ b/clang/include/clang/Interpreter/IncrementalExecutor.h @@ -56,8 +56,10 @@ class IncrementalExecutorBuilder { /// lldMain call because lld resets all cl options for test-isolation /// purposes. std::vector<std::string> LLVMArgs; +#ifndef __EMSCRIPTEN__ /// An optional external orc jit builder std::unique_ptr<llvm::orc::LLJITBuilder> JITBuilder; +#endif /// A default callback that can be used in the IncrementalCompilerBuilder to /// retrieve the path to the orc runtime. std::function<llvm::Error(const driver::Compilation &)> diff --git a/clang/lib/Interpreter/CMakeLists.txt b/clang/lib/Interpreter/CMakeLists.txt index 01d3295d1ac30..95bac67e1b9db 100644 --- a/clang/lib/Interpreter/CMakeLists.txt +++ b/clang/lib/Interpreter/CMakeLists.txt @@ -3,35 +3,39 @@ set(LLVM_LINK_COMPONENTS native MC Option - OrcJit - OrcDebugging - OrcShared - OrcTargetProcess Support Target TargetParser TransformUtils ) -if (EMSCRIPTEN AND "lld" IN_LIST LLVM_ENABLE_PROJECTS) - set(WASM_SRC Wasm.cpp) - set(WASM_LINK lldWasm) - set(COMMON_LINK lldCommon) +if (EMSCRIPTEN) + if (NOT "lld" IN_LIST LLVM_ENABLE_PROJECTS) + message(FATAL_ERROR "Building clangInterpreter for Emscripten requires lld") + endif() + set(EXECUTOR_SOURCES Wasm.cpp) + set(EXECUTOR_LIBS lldWasm lldCommon) +else() + list(APPEND LLVM_LINK_COMPONENTS + OrcJit + OrcDebugging + OrcShared + OrcTargetProcess + ) + set(EXECUTOR_SOURCES IncrementalExecutor.cpp OrcIncrementalExecutor.cpp) endif() add_clang_library(clangInterpreter DeviceOffload.cpp CodeCompletion.cpp IncrementalAction.cpp - IncrementalExecutor.cpp - OrcIncrementalExecutor.cpp IncrementalParser.cpp Interpreter.cpp InterpreterValuePrinter.cpp InterpreterUtils.cpp Value.cpp InterpreterValuePrinter.cpp - ${WASM_SRC} + ${EXECUTOR_SOURCES} PARTIAL_SOURCES_INTENDED DEPENDS @@ -51,8 +55,7 @@ add_clang_library(clangInterpreter clangParse clangSema clangSerialization - ${WASM_LINK} - ${COMMON_LINK} + ${EXECUTOR_LIBS} ) if ((MINGW OR CYGWIN) AND BUILD_SHARED_LIBS) diff --git a/clang/lib/Interpreter/IncrementalExecutor.cpp b/clang/lib/Interpreter/IncrementalExecutor.cpp index 101120626f766..db805bb4219a4 100644 --- a/clang/lib/Interpreter/IncrementalExecutor.cpp +++ b/clang/lib/Interpreter/IncrementalExecutor.cpp @@ -12,9 +12,6 @@ #include "clang/Interpreter/IncrementalExecutor.h" #include "OrcIncrementalExecutor.h" -#ifdef __EMSCRIPTEN__ -#include "Wasm.h" -#endif // __EMSCRIPTEN__ #include "clang/Basic/TargetInfo.h" #include "clang/Config/config.h" @@ -427,12 +424,8 @@ IncrementalExecutorBuilder::create(llvm::orc::ThreadSafeContext &TSC, } llvm::Error Err = llvm::Error::success(); - std::unique_ptr<IncrementalExecutor> Executor; -#ifdef __EMSCRIPTEN__ - Executor = std::make_unique<WasmIncrementalExecutor>(Err, LLVMArgs); -#else - Executor = std::make_unique<OrcIncrementalExecutor>(TSC, *JITBuilder, Err); -#endif + std::unique_ptr<IncrementalExecutor> Executor = + std::make_unique<OrcIncrementalExecutor>(TSC, *JITBuilder, Err); if (Err) return std::move(Err); diff --git a/clang/lib/Interpreter/Wasm.cpp b/clang/lib/Interpreter/Wasm.cpp index 017b049fb470c..dbafaae85b556 100644 --- a/clang/lib/Interpreter/Wasm.cpp +++ b/clang/lib/Interpreter/Wasm.cpp @@ -62,6 +62,36 @@ bool link(llvm::ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS, namespace clang { +IncrementalExecutorBuilder::~IncrementalExecutorBuilder() = default; + +llvm::Expected<std::unique_ptr<IncrementalExecutor>> +IncrementalExecutorBuilder::create(llvm::orc::ThreadSafeContext &TSC, + const clang::TargetInfo &TI) { + if (IE) + return std::move(IE); + + if (IsOutOfProcess) + return llvm::createStringError(llvm::inconvertibleErrorCode(), + "Out-of-process execution is not supported " + "by the WebAssembly executor"); + + llvm::Error Err = llvm::Error::success(); + std::unique_ptr<IncrementalExecutor> Executor = + std::make_unique<WasmIncrementalExecutor>(Err, LLVMArgs); + if (Err) + return std::move(Err); + return std::move(Executor); +} + +llvm::Error IncrementalExecutorBuilder::UpdateOrcRuntimePath( + const clang::driver::Compilation &C) { + if (IsOutOfProcess) + return llvm::createStringError(llvm::inconvertibleErrorCode(), + "Out-of-process execution is not supported " + "by the WebAssembly executor"); + return llvm::Error::success(); +} + WasmIncrementalExecutor::WasmIncrementalExecutor( llvm::Error &Err, std::vector<std::string> LLVMArgs) : StoredLLVMArgs(std::move(LLVMArgs)) { diff --git a/clang/unittests/Interpreter/CMakeLists.txt b/clang/unittests/Interpreter/CMakeLists.txt index d18d7819001b1..4ddc9b0528503 100644 --- a/clang/unittests/Interpreter/CMakeLists.txt +++ b/clang/unittests/Interpreter/CMakeLists.txt @@ -35,9 +35,12 @@ set(CLANG_REPL_TEST_SOURCES InterpreterTest.cpp InterpreterExtensionsTest.cpp CodeCompletionTest.cpp - DeviceOffloadTest.cpp ) +if(NOT EMSCRIPTEN) + list(APPEND CLANG_REPL_TEST_SOURCES DeviceOffloadTest.cpp) +endif() + if(TARGET compiler-rt AND LLVM_ON_UNIX) list(APPEND CLANG_REPL_TEST_SOURCES OutOfProcessInterpreterTests.cpp @@ -94,8 +97,8 @@ set_target_properties(ClangReplInterpreterTests PROPERTIES ) endif() -# Exceptions on Windows are not yet supported. -if(NOT WIN32) +# Interpreter exception tests are not supported on Windows or Emscripten. +if(NOT WIN32 AND NOT EMSCRIPTEN) add_subdirectory(ExceptionTests) endif() diff --git a/clang/unittests/Interpreter/InterpreterExtensionsTest.cpp b/clang/unittests/Interpreter/InterpreterExtensionsTest.cpp index 13825f2cbdddf..642869e124b8b 100644 --- a/clang/unittests/Interpreter/InterpreterExtensionsTest.cpp +++ b/clang/unittests/Interpreter/InterpreterExtensionsTest.cpp @@ -65,6 +65,7 @@ class InterpreterExtensionsTest : public InterpreterTestBase { } }; +#ifndef __EMSCRIPTEN__ class CustomJBInterpreter : public Interpreter { using CustomJITBuilderCreatorFunction = std::function<llvm::Expected<std::unique_ptr<llvm::orc::LLJITBuilder>>()>; @@ -138,6 +139,8 @@ TEST_F(InterpreterExtensionsTest, CustomCrossJIT) { EXPECT_EQ(1U, Objs.size()); } +#endif // __EMSCRIPTEN__ + TEST_F(InterpreterExtensionsTest, CustomIncrementalExecutor) { struct RecordingIncrementalExecutor : public clang::IncrementalExecutor { mutable unsigned RanCtors = false; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
