Skip to content

Commit af6b0fc

Browse files
committed
Make CppInterOp llvm 21 compatible
1 parent c849ba4 commit af6b0fc

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
@@ -321,6 +349,11 @@ jobs:
321349
git apply -v emscripten-clang20-2-shift-temporary-files-to-tmp-dir.patch
322350
git apply -v emscripten-clang20-3-enable_exception_handling.patch
323351
}
352+
elseif ( "${{ matrix.clang-runtime }}" -imatch "21" )
353+
{
354+
git apply -v Windows-emscripten-clang21-1-CrossCompile.patch
355+
git apply -v emscripten-clang21-2-shift-temporary-files-to-tmp-dir.patch
356+
}
324357
cd build
325358
echo "Apply clang${{ matrix.clang-runtime }}-*.patch patches:"
326359
emcmake cmake -DCMAKE_BUILD_TYPE=Release `
@@ -431,6 +464,30 @@ jobs:
431464
cling: Off
432465
micromamba_shell_init: powershell
433466
emsdk_ver: "3.1.73"
467+
- name: ubu24-x86-clang-repl-21-emscripten_wasm
468+
os: ubuntu-24.04
469+
clang-runtime: '21'
470+
cling: Off
471+
micromamba_shell_init: bash
472+
emsdk_ver: "3.1.73"
473+
- name: osx15-arm-clang-repl-21-emscripten_wasm
474+
os: macos-15
475+
clang-runtime: '21'
476+
cling: Off
477+
micromamba_shell_init: bash
478+
emsdk_ver: "3.1.73"
479+
- name: ubu24-arm-clang-repl-21-emscripten_wasm
480+
os: ubuntu-24.04-arm
481+
clang-runtime: '21'
482+
cling: Off
483+
micromamba_shell_init: bash
484+
emsdk_ver: "3.1.73"
485+
- name: win2025-x86-clang-repl-21-emscripten
486+
os: windows-2025
487+
clang-runtime: '21'
488+
cling: Off
489+
micromamba_shell_init: powershell
490+
emsdk_ver: "3.1.73"
434491

435492
steps:
436493
- 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
@@ -31,6 +31,17 @@ static inline char* GetEnv(const char* Var_Name) {
3131
#endif
3232
}
3333

34+
#if CLANG_VERSION_MAJOR < 21
35+
#define clang_LookupResult_Found clang::LookupResult::Found
36+
#define clang_LookupResult_Not_Found clang::LookupResult::NotFound
37+
#define clang_LookupResult_Found_Overloaded clang::LookupResult::FoundOverloaded
38+
#else
39+
#define clang_LookupResult_Found clang::LookupResultKind::Found
40+
#define clang_LookupResult_Not_Found clang::LookupResultKind::NotFound
41+
#define clang_LookupResult_Found_Overloaded \
42+
clang::LookupResultKind::FoundOverloaded
43+
#endif
44+
3445
#if CLANG_VERSION_MAJOR < 19
3546
#define Template_Deduction_Result Sema::TemplateDeductionResult
3647
#define Template_Deduction_Result_Success \

lib/CppInterOp/CppInterOp.cpp

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

1138-
if (R.getResultKind() == clang::LookupResult::NotFound && funcs.empty())
1138+
if (R.getResultKind() == clang_LookupResult_Not_Found && funcs.empty())
11391139
return false;
11401140

11411141
// Distinct match, single Decl
1142-
else if (R.getResultKind() == clang::LookupResult::Found) {
1142+
else if (R.getResultKind() == clang_LookupResult_Found) {
11431143
if (IsTemplatedFunction(R.getFoundDecl()))
11441144
funcs.push_back(R.getFoundDecl());
11451145
}
11461146
// Loop over overload set
1147-
else if (R.getResultKind() == clang::LookupResult::FoundOverloaded) {
1147+
else if (R.getResultKind() == clang_LookupResult_Found_Overloaded) {
11481148
for (auto* Found : R)
11491149
if (IsTemplatedFunction(Found))
11501150
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)