Skip to content

Commit be44844

Browse files
committed
upgrade to llvm 22
1 parent f4ad53f commit be44844

4 files changed

Lines changed: 34 additions & 15 deletions

File tree

‎.github/workflows/pages.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- uses: pnpm/action-setup@v2
1818
- uses: actions/setup-node@v3
1919
with:
20-
node-version: "20"
20+
node-version: "22"
2121
cache: "pnpm"
2222
- run: pnpm install --frozen-lockfile
2323
- name: cache built clangd

‎build.sh‎

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,27 @@
66
# 0. Configs
77

88
# sudo apt install vim git build-essential cmake ninja-build python3
9+
set -e
910

1011
## Note: Better to make sure WASI SDK version matches the LLVM version
11-
EMSDK_VER=3.1.52
12-
WASI_SDK_VER=22.0
13-
WASI_SDK_VER_MAJOR=22
14-
LLVM_VER=18.1.2
15-
LLVM_VER_MAJOR=18
12+
EMSDK_VER=4.0.22
13+
WASI_SDK_VER=29.0
14+
WASI_SDK_VER_MAJOR=29
15+
LLVM_VER=21.1.0
16+
LLVM_VER_MAJOR=21
1617

1718
WORKSPACE_DIR=$PWD
18-
ROOT_DIR=$(mktemp -d)
19+
ROOT_DIR=${ROOT_DIR:-$(mktemp -d)}
1920
cd $ROOT_DIR
21+
echo "Working directory: $ROOT_DIR"
2022

2123
# 1. Get Emscripten
2224

23-
git clone --branch $EMSDK_VER --depth 1 https://github.com/emscripten-core/emsdk
25+
if [[ -d emsdk ]]; then
26+
echo "Emscripten SDK already exists, skipping clone."
27+
else
28+
git clone --branch $EMSDK_VER --depth 1 https://github.com/emscripten-core/emsdk
29+
fi
2430
pushd emsdk
2531
./emsdk install $EMSDK_VER
2632
./emsdk activate $EMSDK_VER
@@ -29,11 +35,20 @@ popd
2935

3036
# 2. Prepare WASI sysroot
3137

32-
wget -O- https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-$WASI_SDK_VER_MAJOR/wasi-sysroot-$WASI_SDK_VER.tar.gz | tar -xz
38+
if [[ -d wasi-sysroot-$WASI_SDK_VER ]]; then
39+
echo "WASI sysroot already exists, skipping download."
40+
else
41+
wget -O- https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-$WASI_SDK_VER_MAJOR/wasi-sysroot-$WASI_SDK_VER.tar.gz | tar -xz
42+
fi
3343

3444
# 3. Build LLVM
3545

36-
git clone --branch llvmorg-$LLVM_VER --depth 1 https://github.com/llvm/llvm-project
46+
if [[ -d llvm-project ]]; then
47+
echo "LLVM project already exists, skipping clone."
48+
else
49+
git clone --branch llvmorg-$LLVM_VER --depth 1 https://github.com/llvm/llvm-project
50+
fi
51+
3752
cd llvm-project
3853

3954
## Build native tools first
@@ -43,7 +58,11 @@ cmake -G Ninja -S llvm -B build-native \
4358
cmake --build build-native --target llvm-tblgen clang-tblgen
4459

4560
## Apply a patch for blocking stdin read
46-
git apply $WORKSPACE_DIR/wait_stdin.patch
61+
if [[ -f $ROOT_DIR/llvm-project/.patched-wait-stdin ]]; then
62+
echo "Patch for wait_stdin already applied, skipping."
63+
else
64+
git apply $WORKSPACE_DIR/wait_stdin.patch && touch $ROOT_DIR/llvm-project/.patched-wait-stdin
65+
fi
4766

4867
## Build clangd (1st time, just for compiler headers)
4968
emcmake cmake -G Ninja -S llvm -B build \
@@ -70,12 +89,12 @@ emcmake cmake -G Ninja -S llvm -B build \
7089
cmake --build build --target clangd
7190

7291
## Copy installed headers to WASI sysroot
73-
cp -r build/lib/clang/$LLVM_VER_MAJOR/include/* $ROOT_DIR/wasi-sysroot/include/
92+
cp -r build/lib/clang/$LLVM_VER_MAJOR/include/* $ROOT_DIR/wasi-sysroot-$WASI_SDK_VER/include/
7493

7594
## Build clangd (2nd time, for the real thing)
7695
emcmake cmake -G Ninja -S llvm -B build \
7796
-DCMAKE_CXX_FLAGS="-pthread -Dwait4=__syscall_wait4" \
78-
-DCMAKE_EXE_LINKER_FLAGS="-pthread -s ENVIRONMENT=worker -s NO_INVOKE_RUN -s EXIT_RUNTIME -s INITIAL_MEMORY=2GB -s ALLOW_MEMORY_GROWTH -s MAXIMUM_MEMORY=4GB -s STACK_SIZE=256kB -s EXPORTED_RUNTIME_METHODS=FS,callMain -s MODULARIZE -s EXPORT_ES6 -s WASM_BIGINT -s ASSERTIONS -s ASYNCIFY -s PTHREAD_POOL_SIZE='Math.max(navigator.hardwareConcurrency, 8)' --embed-file=$ROOT_DIR/wasi-sysroot/include@/usr/include" \
97+
-DCMAKE_EXE_LINKER_FLAGS="-pthread -s ENVIRONMENT=worker -s NO_INVOKE_RUN -s EXIT_RUNTIME -s INITIAL_MEMORY=2GB -s ALLOW_MEMORY_GROWTH -s MAXIMUM_MEMORY=4GB -s STACK_SIZE=256kB -s EXPORTED_RUNTIME_METHODS=FS,callMain -s MODULARIZE -s EXPORT_ES6 -s WASM_BIGINT -s ASSERTIONS -s ASYNCIFY -s PTHREAD_POOL_SIZE='Math.max(navigator.hardwareConcurrency, 8)' --embed-file=$ROOT_DIR/wasi-sysroot-$WASI_SDK_VER/include@/usr/include" \
7998
-DCMAKE_BUILD_TYPE=MinSizeRel \
8099
-DLLVM_TARGET_ARCH=wasm32-emscripten \
81100
-DLLVM_DEFAULT_TARGET_TRIPLE=wasm32-wasi \

‎src/config.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const FILE_PATH = "/home/web_user/main.cpp";
44

55
export const COMPILE_ARGS = [
66
"-xc++",
7-
"-std=c++2b",
7+
"-std=c++2c",
88
"-pedantic-errors",
99
"-Wall",
1010
];

‎src/runner.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { COMPILE_ARGS } from "./config";
22
import { AnsiUp } from "ansi_up";
33

44
const COMPILER_EXPLORER_API_BASE = "https://godbolt.org/api";
5-
const COMPILER_ID = "g141";
5+
const COMPILER_ID = "clang2110";
66

77
export interface ExecuteOptions {
88
args: string[];

0 commit comments

Comments
 (0)