Skip to content

Commit 5e14c06

Browse files
committed
Update Emscripten llvm support to llvm 22
1 parent c156cb3 commit 5e14c06

6 files changed

Lines changed: 139 additions & 31 deletions

.github/workflows/deploy-pages.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ jobs:
2121
fail-fast: false
2222
matrix:
2323
include:
24-
- name: osx26-arm-clang-repl-21-emscripten
24+
- name: osx26-arm-clang-repl-22-emscripten
2525
os: macos-26
26-
clang-runtime: '21'
26+
clang-runtime: '22'
2727
micromamba_shell_init: bash
2828
emsdk_ver: "4.0.9"
2929
build_static_library: Off

.github/workflows/emscripten.yml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,34 @@ jobs:
2121
fail-fast: false
2222
matrix:
2323
include:
24-
- name: ubu24-arm-clang-repl-21-emscripten
24+
- name: ubu24-arm-clang-repl-22-emscripten
2525
os: ubuntu-24.04-arm
26-
clang-runtime: '21'
26+
clang-runtime: '22'
2727
llvm_enable_projects: "clang;lld"
2828
llvm_targets_to_build: "WebAssembly"
2929
emsdk_ver: "4.0.9"
3030
build_static_library: ${{ github.event_name == 'schedule' && 'On' || 'Off' }}
3131
micromamba_shell_init: bash
3232
run-in-prs: true
33-
- name: osx26-arm-clang-repl-21-emscripten
33+
- name: osx26-arm-clang-repl-22-emscripten
3434
os: macos-26
35-
clang-runtime: '21'
35+
clang-runtime: '22'
3636
llvm_enable_projects: "clang;lld"
3737
llvm_targets_to_build: "WebAssembly"
3838
emsdk_ver: "4.0.9"
3939
build_static_library: ${{ github.event_name == 'schedule' && 'On' || 'Off' }}
4040
micromamba_shell_init: bash
41-
- name: ubu24-x86-clang-repl-21-emscripten
41+
- name: ubu24-x86-clang-repl-22-emscripten
4242
os: ubuntu-24.04
43-
clang-runtime: '21'
43+
clang-runtime: '22'
4444
llvm_enable_projects: "clang;lld"
4545
llvm_targets_to_build: "WebAssembly"
4646
emsdk_ver: "4.0.9"
4747
build_static_library: ${{ github.event_name == 'schedule' && 'On' || 'Off' }}
4848
micromamba_shell_init: bash
49-
- name: win2025-x86-clang-repl-21-emscripten
49+
- name: win2025-x86-clang-repl-22-emscripten
5050
os: windows-2025
51-
clang-runtime: '21'
51+
clang-runtime: '22'
5252
llvm_enable_projects: "clang;lld"
5353
llvm_targets_to_build: "WebAssembly"
5454
emsdk_ver: "4.0.9"
@@ -178,7 +178,7 @@ jobs:
178178
else
179179
# Apply patches
180180
llvm_vers=$(echo "${{ matrix.clang-runtime }}" | tr '[:lower:]' '[:upper:]')
181-
if [[ "${llvm_vers}" == "19" || "${llvm_vers}" == "20" || "${llvm_vers}" == "21" ]]; then
181+
if [[ "${llvm_vers}" == "19" || "${llvm_vers}" == "20" || "${llvm_vers}" == "21" || "${llvm_vers}" == "22" ]]; then
182182
git apply -v ../patches/llvm/emscripten-clang${{ matrix.clang-runtime }}-*.patch
183183
echo "Apply emscripten-clang${{ matrix.clang-runtime }}-*.patch patches:"
184184
fi
@@ -312,6 +312,11 @@ jobs:
312312
git apply -v emscripten-clang21-2-enable_exception_handling.patch
313313
git apply -v emscripten-clang21-3-webassembly_target_machine_reordering.patch
314314
}
315+
elseif ( "${{ matrix.clang-runtime }}" -imatch "22" )
316+
{
317+
git apply -v emscripten-clang22-1-enable_exception_handling.patch
318+
git apply -v emscripten-clang22-2-webassembly_target_machine_reordering.patch
319+
}
315320
cd build
316321
echo "Apply clang${{ matrix.clang-runtime }}-*.patch patches:"
317322
emcmake cmake -DCMAKE_BUILD_TYPE=Release `

Emscripten-build-instructions.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ It should be noted that the wasm build of CppInterOp is still experimental and s
55
## CppInterOp Wasm Build Instructions
66

77
This document first starts with the instructions on how to build a wasm build of CppInterOp. Before we start it should be noted that
8-
unlike the non wasm version of CppInterOp we currently only support the Clang-REPL backend using llvm>19.
8+
unlike the non wasm version of CppInterOp we currently only support the Clang-REPL backend using llvm>20.
99
We will first make folder to build our wasm build of CppInterOp. This can be done by executing the following command
1010

1111
```bash
@@ -42,11 +42,11 @@ $env:PWD_DIR= $PWD.Path
4242
$env:SYSROOT_PATH="$env:EMSDK/upstream/emscripten/cache/sysroot"
4343
```
4444

45-
Now clone the 21.x release of the LLVM project repository and CppInterOp (the building of the emscripten version of llvm can be
45+
Now clone the 22.x release of the LLVM project repository and CppInterOp (the building of the emscripten version of llvm can be
4646
avoided by executing micromamba install llvm -c <https://repo.mamba.pm/emscripten-forge> and setting the LLVM_BUILD_DIR/$env:LLVM_BUILD_DIR appropriately)
4747

4848
```bash
49-
git clone --depth=1 --branch release/21.x https://github.com/llvm/llvm-project.git
49+
git clone --depth=1 --branch release/22.x https://github.com/llvm/llvm-project.git
5050
git clone --depth=1 https://github.com/compiler-research/CppInterOp.git
5151
```
5252

@@ -55,17 +55,16 @@ executing
5555

5656
```bash
5757
cd ./llvm-project/
58-
git apply -v ../CppInterOp/patches/llvm/emscripten-clang21-*.patch
58+
git apply -v ../CppInterOp/patches/llvm/emscripten-clang22-*.patch
5959
```
6060

6161
On Windows execute the following
6262

6363
```powershell
6464
cd .\llvm-project\
65-
cp -r ..\patches\llvm\emscripten-clang21*
66-
git apply -v emscripten-clang21-1-shift-temporary-files-to-tmp-dir.patch
67-
git apply -v emscripten-clang21-2-enable_exception_handling.patch
68-
git apply -v emscripten-clang21-3-webassembly_target_machine_reordering.patch
65+
cp -r ..\patches\llvm\emscripten-clang22*
66+
git apply -v emscripten-clang22-1-enable_exception_handling.patch
67+
git apply -v emscripten-clang22-2-webassembly_target_machine_reordering.patch
6968
```
7069

7170
We are now in a position to build an emscripten build of llvm by executing the following on Linux
@@ -342,7 +341,7 @@ of llvm you are building against)
342341
```bash
343342
cd ../..
344343
git clone --depth=1 https://github.com/compiler-research/xeus-cpp.git
345-
export LLVM_VERSION=21
344+
export LLVM_VERSION=22
346345
cd ./xeus-cpp
347346
mkdir build
348347
cd build
@@ -363,7 +362,7 @@ and on Windows by executing
363362
```powershell
364363
cd ..\..
365364
git clone --depth=1 https://github.com/compiler-research/xeus-cpp.git
366-
$env:LLVM_VERSION=21
365+
$env:LLVM_VERSION=22
367366
cd .\xeus-cpp
368367
mkdir build
369368
cd build

docs/Emscripten-build-instructions.rst

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ experimental and subject to change. Try a Jupyter Lite demo of xeus-cpp by click
1616
This document first starts with the instructions on how to build a wasm
1717
build of CppInterOp. Before we start it should be noted that unlike the
1818
non wasm version of CppInterOp we currently only support the Clang-REPL
19-
backend using llvm>19. We will first make folder to
19+
backend using llvm>20. We will first make folder to
2020
build our wasm build of CppInterOp. This can be done by executing the
2121
following command
2222

@@ -57,15 +57,15 @@ and on Windows execute in Powershell
5757
$env:PWD_DIR= $PWD.Path
5858
$env:SYSROOT_PATH="$env:EMSDK/upstream/emscripten/cache/sysroot"
5959
60-
Now clone the 21.x release of the LLVM project repository and CppInterOp
60+
Now clone the 22.x release of the LLVM project repository and CppInterOp
6161
(the building of the emscripten version of llvm can be avoided by
6262
executing micromamba install llvm -c
6363
<https://repo.mamba.pm/emscripten-forge> and setting the LLVM_BUILD_DIR/$env:LLVM_BUILD_DIR
6464
appropriately)
6565

6666
.. code:: bash
6767
68-
git clone --depth=1 --branch release/21.x https://github.com/llvm/llvm-project.git
68+
git clone --depth=1 --branch release/22.x https://github.com/llvm/llvm-project.git
6969
git clone --depth=1 https://github.com/compiler-research/CppInterOp.git
7070
7171
Now move into the cloned llvm-project folder and apply the required patches. On Linux and osx this
@@ -74,17 +74,16 @@ executing
7474
.. code:: bash
7575
7676
cd ./llvm-project/
77-
git apply -v ../CppInterOp/patches/llvm/emscripten-clang21-*.patch
77+
git apply -v ../CppInterOp/patches/llvm/emscripten-clang22-*.patch
7878
7979
On Windows execute the following
8080

8181
.. code:: powershell
8282
8383
cd .\llvm-project\
84-
cp -r ..\patches\llvm\emscripten-clang21*
85-
git apply -v emscripten-clang21-1-shift-temporary-files-to-tmp-dir.patch
86-
git apply -v emscripten-clang21-2-enable_exception_handling.patch
87-
git apply -v emscripten-clang21-3-webassembly_target_machine_reordering.patch
84+
cp -r ..\patches\llvm\emscripten-clang22*
85+
git apply -v emscripten-clang22-1-enable_exception_handling.patch
86+
git apply -v emscripten-clang22-2-webassembly_target_machine_reordering.patch
8887
8988
We are now in a position to build an emscripten build of llvm by executing the following on Linux
9089
and osx
@@ -366,7 +365,7 @@ by executing (replace LLVM_VERSION with the version of llvm you are building aga
366365
367366
cd ../..
368367
git clone --depth=1 https://github.com/compiler-research/xeus-cpp.git
369-
export LLVM_VERSION=21
368+
export LLVM_VERSION=22
370369
cd ./xeus-cpp
371370
mkdir build
372371
cd build
@@ -387,7 +386,7 @@ and on Windows by executing
387386
388387
cd ..\..
389388
git clone --depth=1 https://github.com/compiler-research/xeus-cpp.git
390-
$env:LLVM_VERSION=21
389+
$env:LLVM_VERSION=22
391390
cd .\xeus-cpp
392391
mkdir build
393392
cd build
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
diff --git a/clang/include/clang/Frontend/CompilerInstance.h b/clang/include/clang/Frontend/CompilerInstance.h
2+
index f56da69a05caf..f5dfc36953308 100644
3+
--- a/clang/include/clang/Frontend/CompilerInstance.h
4+
+++ b/clang/include/clang/Frontend/CompilerInstance.h
5+
@@ -246,6 +246,11 @@ class CompilerInstance : public ModuleLoader {
6+
/// Load the list of plugins requested in the \c FrontendOptions.
7+
void LoadRequestedPlugins();
8+
9+
+ /// Parse and apply LLVM command line arguments from FrontendOptions.
10+
+ /// This processes the LLVMArgs option that comes from -mllvm flags.
11+
+ /// This should be called after plugins are loaded and before ExecuteAction.
12+
+ void parseLLVMArgs();
13+
+
14+
/// @}
15+
/// @name Compiler Invocation and Options
16+
/// @{
17+
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
18+
index 2cd7888b0d192..a1ea9486ac406 100644
19+
--- a/clang/lib/Frontend/CompilerInstance.cpp
20+
+++ b/clang/lib/Frontend/CompilerInstance.cpp
21+
@@ -1102,6 +1102,20 @@ void CompilerInstance::LoadRequestedPlugins() {
22+
}
23+
}
24+
25+
+void CompilerInstance::parseLLVMArgs() {
26+
+ if (!getFrontendOpts().LLVMArgs.empty()) {
27+
+ unsigned NumArgs = getFrontendOpts().LLVMArgs.size();
28+
+ auto Args = std::make_unique<const char *[]>(NumArgs + 2);
29+
+ Args[0] = "clang (LLVM option parsing)";
30+
+ for (unsigned i = 0; i != NumArgs; ++i)
31+
+ Args[i + 1] = getFrontendOpts().LLVMArgs[i].c_str();
32+
+ Args[NumArgs + 1] = nullptr;
33+
+ llvm::cl::ParseCommandLineOptions(NumArgs + 1, Args.get(), /*Overview=*/"",
34+
+ /*Errs=*/nullptr,
35+
+ /*VFS=*/&getVirtualFileSystem());
36+
+ }
37+
+}
38+
+
39+
/// Determine the appropriate source input kind based on language
40+
/// options.
41+
static Language getLanguageFromOptions(const LangOptions &LangOpts) {
42+
diff --git a/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
43+
index 05f646b43e3c4..9fa6fbb0017e1 100644
44+
--- a/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
45+
+++ b/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
46+
@@ -237,17 +237,7 @@ bool ExecuteCompilerInvocation(CompilerInstance *Clang) {
47+
//
48+
// FIXME: Remove this, one day.
49+
// This should happen AFTER plugins have been loaded!
50+
- if (!Clang->getFrontendOpts().LLVMArgs.empty()) {
51+
- unsigned NumArgs = Clang->getFrontendOpts().LLVMArgs.size();
52+
- auto Args = std::make_unique<const char*[]>(NumArgs + 2);
53+
- Args[0] = "clang (LLVM option parsing)";
54+
- for (unsigned i = 0; i != NumArgs; ++i)
55+
- Args[i + 1] = Clang->getFrontendOpts().LLVMArgs[i].c_str();
56+
- Args[NumArgs + 1] = nullptr;
57+
- llvm::cl::ParseCommandLineOptions(NumArgs + 1, Args.get(), /*Overview=*/"",
58+
- /*Errs=*/nullptr,
59+
- /*VFS=*/&Clang->getVirtualFileSystem());
60+
- }
61+
+ Clang->parseLLVMArgs();
62+
63+
#if CLANG_ENABLE_STATIC_ANALYZER
64+
// These should happen AFTER plugins have been loaded!
65+
diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp
66+
index 9c94cfa5ee381..bfb6c2a0505d1 100644
67+
--- a/clang/lib/Interpreter/Interpreter.cpp
68+
+++ b/clang/lib/Interpreter/Interpreter.cpp
69+
@@ -257,6 +257,9 @@ Interpreter::Interpreter(std::unique_ptr<CompilerInstance> Instance,
70+
auto LLVMCtx = std::make_unique<llvm::LLVMContext>();
71+
TSCtx = std::make_unique<llvm::orc::ThreadSafeContext>(std::move(LLVMCtx));
72+
73+
+ // Honor -mllvm options
74+
+ CI->parseLLVMArgs();
75+
+
76+
Act = TSCtx->withContextDo([&](llvm::LLVMContext *Ctx) {
77+
return std::make_unique<IncrementalAction>(*CI, *Ctx, ErrOut, *this,
78+
std::move(Consumer));
79+
@@ -465,6 +468,12 @@ Interpreter::Parse(llvm::StringRef Code) {
80+
return std::move(Err);
81+
}
82+
83+
+ // Re-apply stored -mllvm options; wasm builds reset LLVM opts in wasm-ld.
84+
+ llvm::Triple Triple(getCompilerInstance()->getTargetOpts().Triple);
85+
+ if (Triple.isWasm()) {
86+
+ getCompilerInstance()->parseLLVMArgs();
87+
+ }
88+
+
89+
// Tell the interpreter sliently ignore unused expressions since value
90+
// printing could cause it.
91+
getCompilerInstance()->getDiagnostics().setSeverity(
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
2+
index 6827ee652794..3ad7ec5d32b6 100644
3+
--- a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
4+
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
5+
@@ -227,8 +227,8 @@ WebAssemblyTargetMachine::WebAssemblyTargetMachine(
6+
this->Options.DataSections = true;
7+
this->Options.UniqueSectionNames = true;
8+
9+
- initAsmInfo();
10+
basicCheckForEHAndSjLj(this);
11+
+ initAsmInfo();
12+
// Note that we don't use setRequiresStructuredCFG(true). It disables
13+
// optimizations than we're ok with, and want, such as critical edge
14+
// splitting and tail merging.

0 commit comments

Comments
 (0)