Skip to content

Commit 9f09f8a

Browse files
committed
Make CppInterOp llvm 21 compatible
1 parent f65f80a commit 9f09f8a

File tree

7 files changed

+159
-10
lines changed

7 files changed

+159
-10
lines changed

.github/workflows/emscripten.yml

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,34 @@ jobs:
7777
llvm_enable_projects: "clang;lld"
7878
llvm_targets_to_build: "WebAssembly"
7979
emsdk_ver: "3.1.73"
80+
- name: ubu24-arm-clang-repl-21-emscripten
81+
os: ubuntu-24.04-arm
82+
clang-runtime: '21'
83+
cling: Off
84+
llvm_enable_projects: "clang;lld"
85+
llvm_targets_to_build: "WebAssembly"
86+
emsdk_ver: "3.1.73"
87+
- name: osx15-arm-clang-repl-21-emscripten
88+
os: macos-15
89+
clang-runtime: '21'
90+
cling: Off
91+
llvm_enable_projects: "clang;lld"
92+
llvm_targets_to_build: "WebAssembly"
93+
emsdk_ver: "3.1.73"
94+
- name: ubu24-x86-clang-repl-21-emscripten
95+
os: ubuntu-24.04
96+
clang-runtime: '21'
97+
cling: Off
98+
llvm_enable_projects: "clang;lld"
99+
llvm_targets_to_build: "WebAssembly"
100+
emsdk_ver: "3.1.73"
101+
- name: win2025-x86-clang-repl-21-emscripten
102+
os: windows-2025
103+
clang-runtime: '21'
104+
cling: Off
105+
llvm_enable_projects: "clang;lld"
106+
llvm_targets_to_build: "WebAssembly"
107+
emsdk_ver: "3.1.73"
80108

81109
steps:
82110
- uses: actions/checkout@v4
@@ -199,7 +227,7 @@ jobs:
199227
else
200228
# Apply patches
201229
llvm_vers=$(echo "${{ matrix.clang-runtime }}" | tr '[:lower:]' '[:upper:]')
202-
if [[ "${llvm_vers}" == "19" || "${llvm_vers}" == "20" ]]; then
230+
if [[ "${llvm_vers}" == "19" || "${llvm_vers}" == "20" || "${llvm_vers}" == "21" ]]; then
203231
git apply -v ../patches/llvm/emscripten-clang${{ matrix.clang-runtime }}-*.patch
204232
echo "Apply emscripten-clang${{ matrix.clang-runtime }}-*.patch patches:"
205233
fi
@@ -314,6 +342,11 @@ jobs:
314342
git apply -v Windows-emscripten-clang20-1-CrossCompile.patch
315343
git apply -v emscripten-clang20-2-shift-temporary-files-to-tmp-dir.patch
316344
}
345+
elseif ( "${{ matrix.clang-runtime }}" -imatch "21" )
346+
{
347+
git apply -v Windows-emscripten-clang21-1-CrossCompile.patch
348+
git apply -v emscripten-clang21-2-shift-temporary-files-to-tmp-dir.patch
349+
}
317350
cd build
318351
echo "Apply clang${{ matrix.clang-runtime }}-*.patch patches:"
319352
emcmake cmake -DCMAKE_BUILD_TYPE=Release `
@@ -423,6 +456,30 @@ jobs:
423456
cling: Off
424457
micromamba_shell_init: powershell
425458
emsdk_ver: "3.1.73"
459+
- name: ubu24-x86-clang-repl-21-emscripten_wasm
460+
os: ubuntu-24.04
461+
clang-runtime: '21'
462+
cling: Off
463+
micromamba_shell_init: bash
464+
emsdk_ver: "3.1.73"
465+
- name: osx15-arm-clang-repl-21-emscripten_wasm
466+
os: macos-15
467+
clang-runtime: '21'
468+
cling: Off
469+
micromamba_shell_init: bash
470+
emsdk_ver: "3.1.73"
471+
- name: ubu24-arm-clang-repl-21-emscripten_wasm
472+
os: ubuntu-24.04-arm
473+
clang-runtime: '21'
474+
cling: Off
475+
micromamba_shell_init: bash
476+
emsdk_ver: "3.1.73"
477+
- name: win2025-x86-clang-repl-21-emscripten
478+
os: windows-2025
479+
clang-runtime: '21'
480+
cling: Off
481+
micromamba_shell_init: powershell
482+
emsdk_ver: "3.1.73"
426483

427484
steps:
428485
- uses: actions/checkout@v4

.github/workflows/main.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ jobs:
2323
matrix:
2424
include:
2525
# Ubuntu Arm Jobs
26+
- name: ubu24-arm-gcc12-clang-repl-21
27+
os: ubuntu-24.04-arm
28+
compiler: gcc-12
29+
clang-runtime: '21'
30+
cling: Off
31+
cppyy: Off
32+
llvm_enable_projects: "clang"
33+
llvm_targets_to_build: "host;NVPTX"
2634
- name: ubu22-arm-gcc12-clang-repl-20-coverage
2735
os: ubuntu-22.04-arm
2836
compiler: gcc-12
@@ -66,6 +74,14 @@ jobs:
6674
llvm_enable_projects: "clang"
6775
llvm_targets_to_build: "host;NVPTX"
6876
# Ubuntu X86 Jobs
77+
- name: ubu24-x86-gcc12-clang-repl-21
78+
os: ubuntu-24.04
79+
compiler: gcc-12
80+
clang-runtime: '21'
81+
cling: Off
82+
cppyy: Off
83+
llvm_enable_projects: "clang"
84+
llvm_targets_to_build: "host;NVPTX"
6985
- name: ubu24-x86-gcc12-clang-repl-20
7086
os: ubuntu-24.04
7187
compiler: gcc-12
@@ -100,6 +116,14 @@ jobs:
100116
llvm_enable_projects: "clang"
101117
llvm_targets_to_build: "host;NVPTX"
102118
# MacOS Arm Jobs
119+
- name: osx15-arm-clang-clang-repl-21
120+
os: macos-15
121+
compiler: clang
122+
clang-runtime: '21'
123+
cling: Off
124+
cppyy: Off
125+
llvm_enable_projects: "clang"
126+
llvm_targets_to_build: "host"
103127
- name: osx15-arm-clang-clang-repl-20
104128
os: macos-15
105129
compiler: clang
@@ -134,6 +158,14 @@ jobs:
134158
llvm_enable_projects: "clang"
135159
llvm_targets_to_build: "host;NVPTX"
136160
# MacOS X86 Jobs
161+
- name: osx13-x86-clang-clang-repl-21
162+
os: macos-13
163+
compiler: clang
164+
clang-runtime: '21'
165+
cling: Off
166+
cppyy: Off
167+
llvm_enable_projects: "clang"
168+
llvm_targets_to_build: "host"
137169
- name: osx13-x86-clang-clang-repl-20
138170
os: macos-13
139171
compiler: clang
@@ -168,6 +200,13 @@ jobs:
168200
llvm_enable_projects: "clang"
169201
llvm_targets_to_build: "host;NVPTX"
170202
# Windows Arm Jobs
203+
- name: win11-msvc-clang-repl-21
204+
os: windows-11-arm
205+
compiler: msvc
206+
clang-runtime: '21'
207+
cling: Off
208+
llvm_enable_projects: "clang"
209+
llvm_targets_to_build: "host;NVPTX"
171210
- name: win11-msvc-clang-repl-20
172211
os: windows-11-arm
173212
compiler: msvc
@@ -184,6 +223,13 @@ jobs:
184223
llvm_enable_projects: "clang"
185224
llvm_targets_to_build: "host;NVPTX"
186225
# Windows X86 Jobs
226+
- name: win2025-msvc-clang-repl-21
227+
os: windows-2025
228+
compiler: msvc
229+
clang-runtime: '21'
230+
cling: Off
231+
llvm_enable_projects: "clang"
232+
llvm_targets_to_build: "host;NVPTX"
187233
- name: win2025-msvc-clang-repl-20
188234
os: windows-2025
189235
compiler: msvc

CMakeLists.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ include(GNUInstallDirs)
6868
## Define supported version of clang and llvm
6969

7070
set(CLANG_MIN_SUPPORTED 18.0)
71-
set(CLANG_MAX_SUPPORTED "20.1.x")
72-
set(CLANG_VERSION_UPPER_BOUND 21.0.0)
71+
set(CLANG_MAX_SUPPORTED "21.1.x")
72+
set(CLANG_VERSION_UPPER_BOUND 22.0.0)
7373
set(LLD_MIN_SUPPORTED 18.0)
74-
set(LLD_MAX_SUPPORTED "20.1.x")
75-
set(LLD_VERSION_UPPER_BOUND 21.0.0)
74+
set(LLD_MAX_SUPPORTED "21.1.x")
75+
set(LLD_VERSION_UPPER_BOUND 22.0.0)
7676
set(LLVM_MIN_SUPPORTED 18.0)
77-
set(LLVM_MAX_SUPPORTED "20.1.x")
78-
set(LLVM_VERSION_UPPER_BOUND 21.0.0)
77+
set(LLVM_MAX_SUPPORTED "21.1.x")
78+
set(LLVM_VERSION_UPPER_BOUND 22.0.0)
7979

8080
## Set Cmake packages search order
8181

lib/CppInterOp/Compatibility.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ static inline char* GetEnv(const char* Var_Name) {
2727
#endif
2828
}
2929

30+
#if CLANG_VERSION_MAJOR < 21
31+
#define clang_LookupResult_Found clang::LookupResult::Found
32+
#define clang_LookupResult_Not_Found clang::LookupResult::NotFound
33+
#define clang_LookupResult_Found_Overloaded clang::LookupResult::FoundOverloaded
34+
#else
35+
#define clang_LookupResult_Found clang::LookupResultKind::Found
36+
#define clang_LookupResult_Not_Found clang::LookupResultKind::NotFound
37+
#define clang_LookupResult_Found_Overloaded \
38+
clang::LookupResultKind::FoundOverloaded
39+
#endif
40+
3041
#if CLANG_VERSION_MAJOR < 19
3142
#define Template_Deduction_Result Sema::TemplateDeductionResult
3243
#define Template_Deduction_Result_Success \

lib/CppInterOp/CppInterOp.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,16 +1107,16 @@ bool GetClassTemplatedMethods(const std::string& name, TCppScope_t parent,
11071107
auto* DC = clang::Decl::castToDeclContext(D);
11081108
Cpp_utils::Lookup::Named(&S, R, DC);
11091109

1110-
if (R.getResultKind() == clang::LookupResult::NotFound && funcs.empty())
1110+
if (R.getResultKind() == clang_LookupResult_Not_Found && funcs.empty())
11111111
return false;
11121112

11131113
// Distinct match, single Decl
1114-
else if (R.getResultKind() == clang::LookupResult::Found) {
1114+
else if (R.getResultKind() == clang_LookupResult_Found) {
11151115
if (IsTemplatedFunction(R.getFoundDecl()))
11161116
funcs.push_back(R.getFoundDecl());
11171117
}
11181118
// Loop over overload set
1119-
else if (R.getResultKind() == clang::LookupResult::FoundOverloaded) {
1119+
else if (R.getResultKind() == clang_LookupResult_Found_Overloaded) {
11201120
for (auto* Found : R)
11211121
if (IsTemplatedFunction(Found))
11221122
funcs.push_back(Found);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
diff --git a/llvm/cmake/modules/CrossCompile.cmake b/llvm/cmake/modules/CrossCompile.cmake
2+
index 39b4abaa0..474ceddbb 100644
3+
--- a/llvm/cmake/modules/CrossCompile.cmake
4+
+++ b/llvm/cmake/modules/CrossCompile.cmake
5+
@@ -74,10 +74,12 @@ function(llvm_create_cross_target project_name target_name toolchain buildtype)
6+
endif()
7+
8+
add_custom_command(OUTPUT ${${project_name}_${target_name}_BUILD}/CMakeCache.txt
9+
- COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}"
10+
+ COMMAND ${CMAKE_COMMAND} -G Ninja
11+
-DCMAKE_MAKE_PROGRAM="${CMAKE_MAKE_PROGRAM}"
12+
- -DCMAKE_C_COMPILER_LAUNCHER="${CMAKE_C_COMPILER_LAUNCHER}"
13+
- -DCMAKE_CXX_COMPILER_LAUNCHER="${CMAKE_CXX_COMPILER_LAUNCHER}"
14+
+ -DCMAKE_C_COMPILER="clang-cl"
15+
+ -DCMAKE_CXX_COMPILER="clang-cl"
16+
+ -DCMAKE_ASM_MASM_COMPILER=llvm-ml
17+
+ -DCMAKE_ASM_MASM_FLAGS="-m64"
18+
${CROSS_TOOLCHAIN_FLAGS_${target_name}} ${CMAKE_CURRENT_SOURCE_DIR}
19+
${CROSS_TOOLCHAIN_FLAGS_${project_name}_${target_name}}
20+
-DLLVM_TARGET_IS_CROSSCOMPILE_HOST=TRUE
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
diff --git a/clang/lib/Interpreter/Wasm.cpp b/clang/lib/Interpreter/Wasm.cpp
2+
index aa10b160ccf8..184867e2b55f 100644
3+
--- a/clang/lib/Interpreter/Wasm.cpp
4+
+++ b/clang/lib/Interpreter/Wasm.cpp
5+
@@ -76,8 +76,8 @@ llvm::Error WasmIncrementalExecutor::addModule(PartialTranslationUnit &PTU) {
6+
llvm::TargetMachine *TargetMachine = Target->createTargetMachine(
7+
PTU.TheModule->getTargetTriple(), "", "", TO, llvm::Reloc::Model::PIC_);
8+
PTU.TheModule->setDataLayout(TargetMachine->createDataLayout());
9+
- std::string ObjectFileName = PTU.TheModule->getName().str() + ".o";
10+
- std::string BinaryFileName = PTU.TheModule->getName().str() + ".wasm";
11+
+ std::string ObjectFileName = "/tmp/" + PTU.TheModule->getName().str() + ".o";
12+
+ std::string BinaryFileName = "/tmp/" + PTU.TheModule->getName().str() + ".wasm";
13+
14+
std::error_code Error;
15+
llvm::raw_fd_ostream ObjectFileOutput(llvm::StringRef(ObjectFileName), Error);

0 commit comments

Comments
 (0)