From 50b53e0f8c7ff08fa31eff385376bd724a246f7e Mon Sep 17 00:00:00 2001 From: mcbarton Date: Tue, 15 Jul 2025 17:05:24 +0100 Subject: [PATCH 1/4] Make CppInterOp llvm 21 compatible --- .github/workflows/emscripten.yml | 59 ++++++++++++++++++- .github/workflows/main.yml | 46 +++++++++++++++ CMakeLists.txt | 12 ++-- lib/CppInterOp/Compatibility.h | 11 ++++ lib/CppInterOp/CppInterOp.cpp | 6 +- ...ws-emscripten-clang21-1-CrossCompile.patch | 20 +++++++ ...1-2-shift-temporary-files-to-tmp-dir.patch | 15 +++++ 7 files changed, 159 insertions(+), 10 deletions(-) create mode 100644 patches/llvm/Windows-emscripten-clang21-1-CrossCompile.patch create mode 100644 patches/llvm/emscripten-clang21-2-shift-temporary-files-to-tmp-dir.patch diff --git a/.github/workflows/emscripten.yml b/.github/workflows/emscripten.yml index 75fb1f310..74b57b952 100644 --- a/.github/workflows/emscripten.yml +++ b/.github/workflows/emscripten.yml @@ -77,6 +77,34 @@ jobs: llvm_enable_projects: "clang;lld" llvm_targets_to_build: "WebAssembly" emsdk_ver: "3.1.73" + - name: ubu24-arm-clang-repl-21-emscripten + os: ubuntu-24.04-arm + clang-runtime: '21' + cling: Off + llvm_enable_projects: "clang;lld" + llvm_targets_to_build: "WebAssembly" + emsdk_ver: "3.1.73" + - name: osx15-arm-clang-repl-21-emscripten + os: macos-15 + clang-runtime: '21' + cling: Off + llvm_enable_projects: "clang;lld" + llvm_targets_to_build: "WebAssembly" + emsdk_ver: "3.1.73" + - name: ubu24-x86-clang-repl-21-emscripten + os: ubuntu-24.04 + clang-runtime: '21' + cling: Off + llvm_enable_projects: "clang;lld" + llvm_targets_to_build: "WebAssembly" + emsdk_ver: "3.1.73" + - name: win2025-x86-clang-repl-21-emscripten + os: windows-2025 + clang-runtime: '21' + cling: Off + llvm_enable_projects: "clang;lld" + llvm_targets_to_build: "WebAssembly" + emsdk_ver: "3.1.73" steps: - uses: actions/checkout@v4 @@ -199,7 +227,7 @@ jobs: else # Apply patches llvm_vers=$(echo "${{ matrix.clang-runtime }}" | tr '[:lower:]' '[:upper:]') - if [[ "${llvm_vers}" == "19" || "${llvm_vers}" == "20" ]]; then + if [[ "${llvm_vers}" == "19" || "${llvm_vers}" == "20" || "${llvm_vers}" == "21" ]]; then git apply -v ../patches/llvm/emscripten-clang${{ matrix.clang-runtime }}-*.patch echo "Apply emscripten-clang${{ matrix.clang-runtime }}-*.patch patches:" fi @@ -314,6 +342,11 @@ jobs: git apply -v Windows-emscripten-clang20-1-CrossCompile.patch git apply -v emscripten-clang20-2-shift-temporary-files-to-tmp-dir.patch } + elseif ( "${{ matrix.clang-runtime }}" -imatch "21" ) + { + git apply -v Windows-emscripten-clang21-1-CrossCompile.patch + git apply -v emscripten-clang21-2-shift-temporary-files-to-tmp-dir.patch + } cd build echo "Apply clang${{ matrix.clang-runtime }}-*.patch patches:" emcmake cmake -DCMAKE_BUILD_TYPE=Release ` @@ -423,6 +456,30 @@ jobs: cling: Off micromamba_shell_init: powershell emsdk_ver: "3.1.73" + - name: ubu24-x86-clang-repl-21-emscripten_wasm + os: ubuntu-24.04 + clang-runtime: '21' + cling: Off + micromamba_shell_init: bash + emsdk_ver: "3.1.73" + - name: osx15-arm-clang-repl-21-emscripten_wasm + os: macos-15 + clang-runtime: '21' + cling: Off + micromamba_shell_init: bash + emsdk_ver: "3.1.73" + - name: ubu24-arm-clang-repl-21-emscripten_wasm + os: ubuntu-24.04-arm + clang-runtime: '21' + cling: Off + micromamba_shell_init: bash + emsdk_ver: "3.1.73" + - name: win2025-x86-clang-repl-21-emscripten + os: windows-2025 + clang-runtime: '21' + cling: Off + micromamba_shell_init: powershell + emsdk_ver: "3.1.73" steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bc40f0bea..605780436 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -23,6 +23,14 @@ jobs: matrix: include: # Ubuntu Arm Jobs + - name: ubu24-arm-gcc12-clang-repl-21 + os: ubuntu-24.04-arm + compiler: gcc-12 + clang-runtime: '21' + cling: Off + cppyy: Off + llvm_enable_projects: "clang" + llvm_targets_to_build: "host;NVPTX" - name: ubu22-arm-gcc12-clang-repl-20-coverage os: ubuntu-22.04-arm compiler: gcc-12 @@ -66,6 +74,14 @@ jobs: llvm_enable_projects: "clang" llvm_targets_to_build: "host;NVPTX" # Ubuntu X86 Jobs + - name: ubu24-x86-gcc12-clang-repl-21 + os: ubuntu-24.04 + compiler: gcc-12 + clang-runtime: '21' + cling: Off + cppyy: Off + llvm_enable_projects: "clang" + llvm_targets_to_build: "host;NVPTX" - name: ubu24-x86-gcc12-clang-repl-20 os: ubuntu-24.04 compiler: gcc-12 @@ -100,6 +116,14 @@ jobs: llvm_enable_projects: "clang" llvm_targets_to_build: "host;NVPTX" # MacOS Arm Jobs + - name: osx15-arm-clang-clang-repl-21 + os: macos-15 + compiler: clang + clang-runtime: '21' + cling: Off + cppyy: Off + llvm_enable_projects: "clang" + llvm_targets_to_build: "host" - name: osx15-arm-clang-clang-repl-20 os: macos-15 compiler: clang @@ -134,6 +158,14 @@ jobs: llvm_enable_projects: "clang" llvm_targets_to_build: "host;NVPTX" # MacOS X86 Jobs + - name: osx13-x86-clang-clang-repl-21 + os: macos-13 + compiler: clang + clang-runtime: '21' + cling: Off + cppyy: Off + llvm_enable_projects: "clang" + llvm_targets_to_build: "host" - name: osx13-x86-clang-clang-repl-20 os: macos-13 compiler: clang @@ -168,6 +200,13 @@ jobs: llvm_enable_projects: "clang" llvm_targets_to_build: "host;NVPTX" # Windows Arm Jobs + - name: win11-msvc-clang-repl-21 + os: windows-11-arm + compiler: msvc + clang-runtime: '21' + cling: Off + llvm_enable_projects: "clang" + llvm_targets_to_build: "host;NVPTX" - name: win11-msvc-clang-repl-20 os: windows-11-arm compiler: msvc @@ -184,6 +223,13 @@ jobs: llvm_enable_projects: "clang" llvm_targets_to_build: "host;NVPTX" # Windows X86 Jobs + - name: win2025-msvc-clang-repl-21 + os: windows-2025 + compiler: msvc + clang-runtime: '21' + cling: Off + llvm_enable_projects: "clang" + llvm_targets_to_build: "host;NVPTX" - name: win2025-msvc-clang-repl-20 os: windows-2025 compiler: msvc diff --git a/CMakeLists.txt b/CMakeLists.txt index 981c57ced..cc8d38617 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,14 +68,14 @@ include(GNUInstallDirs) ## Define supported version of clang and llvm set(CLANG_MIN_SUPPORTED 18.0) - set(CLANG_MAX_SUPPORTED "20.1.x") - set(CLANG_VERSION_UPPER_BOUND 21.0.0) + set(CLANG_MAX_SUPPORTED "21.1.x") + set(CLANG_VERSION_UPPER_BOUND 22.0.0) set(LLD_MIN_SUPPORTED 18.0) - set(LLD_MAX_SUPPORTED "20.1.x") - set(LLD_VERSION_UPPER_BOUND 21.0.0) + set(LLD_MAX_SUPPORTED "21.1.x") + set(LLD_VERSION_UPPER_BOUND 22.0.0) set(LLVM_MIN_SUPPORTED 18.0) - set(LLVM_MAX_SUPPORTED "20.1.x") - set(LLVM_VERSION_UPPER_BOUND 21.0.0) + set(LLVM_MAX_SUPPORTED "21.1.x") + set(LLVM_VERSION_UPPER_BOUND 22.0.0) ## Set Cmake packages search order diff --git a/lib/CppInterOp/Compatibility.h b/lib/CppInterOp/Compatibility.h index 562b42b38..f91bca070 100644 --- a/lib/CppInterOp/Compatibility.h +++ b/lib/CppInterOp/Compatibility.h @@ -27,6 +27,17 @@ static inline char* GetEnv(const char* Var_Name) { #endif } +#if CLANG_VERSION_MAJOR < 21 +#define clang_LookupResult_Found clang::LookupResult::Found +#define clang_LookupResult_Not_Found clang::LookupResult::NotFound +#define clang_LookupResult_Found_Overloaded clang::LookupResult::FoundOverloaded +#else +#define clang_LookupResult_Found clang::LookupResultKind::Found +#define clang_LookupResult_Not_Found clang::LookupResultKind::NotFound +#define clang_LookupResult_Found_Overloaded \ + clang::LookupResultKind::FoundOverloaded +#endif + #if CLANG_VERSION_MAJOR < 19 #define Template_Deduction_Result Sema::TemplateDeductionResult #define Template_Deduction_Result_Success \ diff --git a/lib/CppInterOp/CppInterOp.cpp b/lib/CppInterOp/CppInterOp.cpp index 56add4d8d..d289a46cf 100755 --- a/lib/CppInterOp/CppInterOp.cpp +++ b/lib/CppInterOp/CppInterOp.cpp @@ -1107,16 +1107,16 @@ bool GetClassTemplatedMethods(const std::string& name, TCppScope_t parent, auto* DC = clang::Decl::castToDeclContext(D); Cpp_utils::Lookup::Named(&S, R, DC); - if (R.getResultKind() == clang::LookupResult::NotFound && funcs.empty()) + if (R.getResultKind() == clang_LookupResult_Not_Found && funcs.empty()) return false; // Distinct match, single Decl - else if (R.getResultKind() == clang::LookupResult::Found) { + else if (R.getResultKind() == clang_LookupResult_Found) { if (IsTemplatedFunction(R.getFoundDecl())) funcs.push_back(R.getFoundDecl()); } // Loop over overload set - else if (R.getResultKind() == clang::LookupResult::FoundOverloaded) { + else if (R.getResultKind() == clang_LookupResult_Found_Overloaded) { for (auto* Found : R) if (IsTemplatedFunction(Found)) funcs.push_back(Found); diff --git a/patches/llvm/Windows-emscripten-clang21-1-CrossCompile.patch b/patches/llvm/Windows-emscripten-clang21-1-CrossCompile.patch new file mode 100644 index 000000000..a1ffeccc8 --- /dev/null +++ b/patches/llvm/Windows-emscripten-clang21-1-CrossCompile.patch @@ -0,0 +1,20 @@ +diff --git a/llvm/cmake/modules/CrossCompile.cmake b/llvm/cmake/modules/CrossCompile.cmake +index 39b4abaa0..474ceddbb 100644 +--- a/llvm/cmake/modules/CrossCompile.cmake ++++ b/llvm/cmake/modules/CrossCompile.cmake +@@ -74,10 +74,12 @@ function(llvm_create_cross_target project_name target_name toolchain buildtype) + endif() + + add_custom_command(OUTPUT ${${project_name}_${target_name}_BUILD}/CMakeCache.txt +- COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" ++ COMMAND ${CMAKE_COMMAND} -G Ninja + -DCMAKE_MAKE_PROGRAM="${CMAKE_MAKE_PROGRAM}" +- -DCMAKE_C_COMPILER_LAUNCHER="${CMAKE_C_COMPILER_LAUNCHER}" +- -DCMAKE_CXX_COMPILER_LAUNCHER="${CMAKE_CXX_COMPILER_LAUNCHER}" ++ -DCMAKE_C_COMPILER="clang-cl" ++ -DCMAKE_CXX_COMPILER="clang-cl" ++ -DCMAKE_ASM_MASM_COMPILER=llvm-ml ++ -DCMAKE_ASM_MASM_FLAGS="-m64" + ${CROSS_TOOLCHAIN_FLAGS_${target_name}} ${CMAKE_CURRENT_SOURCE_DIR} + ${CROSS_TOOLCHAIN_FLAGS_${project_name}_${target_name}} + -DLLVM_TARGET_IS_CROSSCOMPILE_HOST=TRUE diff --git a/patches/llvm/emscripten-clang21-2-shift-temporary-files-to-tmp-dir.patch b/patches/llvm/emscripten-clang21-2-shift-temporary-files-to-tmp-dir.patch new file mode 100644 index 000000000..32ac45c13 --- /dev/null +++ b/patches/llvm/emscripten-clang21-2-shift-temporary-files-to-tmp-dir.patch @@ -0,0 +1,15 @@ +diff --git a/clang/lib/Interpreter/Wasm.cpp b/clang/lib/Interpreter/Wasm.cpp +index aa10b160ccf8..184867e2b55f 100644 +--- a/clang/lib/Interpreter/Wasm.cpp ++++ b/clang/lib/Interpreter/Wasm.cpp +@@ -76,8 +76,8 @@ llvm::Error WasmIncrementalExecutor::addModule(PartialTranslationUnit &PTU) { + llvm::TargetMachine *TargetMachine = Target->createTargetMachine( + PTU.TheModule->getTargetTriple(), "", "", TO, llvm::Reloc::Model::PIC_); + PTU.TheModule->setDataLayout(TargetMachine->createDataLayout()); +- std::string ObjectFileName = PTU.TheModule->getName().str() + ".o"; +- std::string BinaryFileName = PTU.TheModule->getName().str() + ".wasm"; ++ std::string ObjectFileName = "/tmp/" + PTU.TheModule->getName().str() + ".o"; ++ std::string BinaryFileName = "/tmp/" + PTU.TheModule->getName().str() + ".wasm"; + + std::error_code Error; + llvm::raw_fd_ostream ObjectFileOutput(llvm::StringRef(ObjectFileName), Error); From dc0d32521b53ac356325f65e1982ceceeca9f16d Mon Sep 17 00:00:00 2001 From: mcbarton Date: Tue, 15 Jul 2025 21:03:13 +0100 Subject: [PATCH 2/4] Update Windows-emscripten-clang21-1-CrossCompile.patch --- .../llvm/Windows-emscripten-clang21-1-CrossCompile.patch | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/patches/llvm/Windows-emscripten-clang21-1-CrossCompile.patch b/patches/llvm/Windows-emscripten-clang21-1-CrossCompile.patch index a1ffeccc8..00e0aef6f 100644 --- a/patches/llvm/Windows-emscripten-clang21-1-CrossCompile.patch +++ b/patches/llvm/Windows-emscripten-clang21-1-CrossCompile.patch @@ -8,9 +8,9 @@ index 39b4abaa0..474ceddbb 100644 add_custom_command(OUTPUT ${${project_name}_${target_name}_BUILD}/CMakeCache.txt - COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" + COMMAND ${CMAKE_COMMAND} -G Ninja - -DCMAKE_MAKE_PROGRAM="${CMAKE_MAKE_PROGRAM}" -- -DCMAKE_C_COMPILER_LAUNCHER="${CMAKE_C_COMPILER_LAUNCHER}" -- -DCMAKE_CXX_COMPILER_LAUNCHER="${CMAKE_CXX_COMPILER_LAUNCHER}" + "-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}" +- "-DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER}" +- "-DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER}" + -DCMAKE_C_COMPILER="clang-cl" + -DCMAKE_CXX_COMPILER="clang-cl" + -DCMAKE_ASM_MASM_COMPILER=llvm-ml From bcd32c81b72b4e5a267688c3f6f3d0dffe2ef764 Mon Sep 17 00:00:00 2001 From: mcbarton Date: Wed, 16 Jul 2025 09:20:19 +0100 Subject: [PATCH 3/4] Update exports.ld --- lib/CppInterOp/exports.ld | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/CppInterOp/exports.ld b/lib/CppInterOp/exports.ld index 49b7b0d83..c1c4e59e8 100644 --- a/lib/CppInterOp/exports.ld +++ b/lib/CppInterOp/exports.ld @@ -50,4 +50,5 @@ -Wl,--export=_ZNK5clang4Type14isFloatingTypeEv -Wl,--export=_ZNK5clang12FunctionDecl12getNumParamsEv -Wl,--export=__clang_Interpreter_SetValueNoAlloc --Wl,--export=__clang_Interpreter_SetValueWithAlloc \ No newline at end of file +-Wl,--export=__clang_Interpreter_SetValueWithAlloc +-Wl,--export=_ZN5clang11Interpreter6createENSt3__210unique_ptrINS_16CompilerInstanceENS1_14default_deleteIS3_EEEENS2_IN4llvm3orc12LLJITBuilderENS4_IS9_EEEE From 60df3d7d64c92aedcf8439f45fe32b65b949f4c1 Mon Sep 17 00:00:00 2001 From: mcbarton Date: Wed, 16 Jul 2025 10:59:46 +0100 Subject: [PATCH 4/4] Update exports.ld --- lib/CppInterOp/exports.ld | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/CppInterOp/exports.ld b/lib/CppInterOp/exports.ld index c1c4e59e8..65c3b439b 100644 --- a/lib/CppInterOp/exports.ld +++ b/lib/CppInterOp/exports.ld @@ -51,4 +51,5 @@ -Wl,--export=_ZNK5clang12FunctionDecl12getNumParamsEv -Wl,--export=__clang_Interpreter_SetValueNoAlloc -Wl,--export=__clang_Interpreter_SetValueWithAlloc --Wl,--export=_ZN5clang11Interpreter6createENSt3__210unique_ptrINS_16CompilerInstanceENS1_14default_deleteIS3_EEEENS2_IN4llvm3orc12LLJITBuilderENS4_IS9_EEEE +-Wl,--export=_ZN5clang11Interpreter6createENSt3__210unique_ptrINS_16CompilerInstanceENS1_14default_deleteIS3_EEEENS2_IN4llvm3orc12LLJITBuilderENS4_IS9_EEEE +-Wl,--export=_ZNK5clang13CXXRecordDecl19isInjectedClassNameEv