Skip to content
This repository was archived by the owner on Apr 29, 2026. It is now read-only.

Commit 2d2675b

Browse files
use docker to build wasm32-emscripten
1 parent cdff6c1 commit 2d2675b

4 files changed

Lines changed: 80 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,13 @@ jobs:
2929
- name: Test
3030
run: ctest --test-dir build_test_ci --output-on-failure --build-config Debug
3131

32+
wasm32-emscripten:
33+
name: wasm32-emscripten
34+
runs-on: ubuntu-latest
35+
36+
steps:
37+
- uses: actions/checkout@v4
38+
39+
- name: build
40+
run: docker build -f src/targets/wasm32-emscripten/Dockerfile -t wasm32-emscripten-pe .
41+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM emscripten/emsdk:4.0.22
2+
3+
WORKDIR /app
4+
5+
COPY ../../../ .
6+
7+
WORKDIR /app/src/targets/wasm32-emscripten
8+
# TODO: fix permissions
9+
RUN chmod +x build.sh && ./build.sh
10+
11+
WORKDIR /
12+
RUN tar cJf wasm32-emscripten-pe-release.tar.xz /wasm32-emscripten-pe-release
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
```sh
2+
docker build -f src/targets/wasm32-emscripten/Dockerfile -t wasm32-emscripten-pe .
3+
docker run --rm wasm32-emscripten-pe cat /wasm32-emscripten-pe-release.tar.xz > wasm32-emscripten-pe-release.tar.xz
4+
```
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env bash
2+
# Only for Dockerfile
3+
set -euo pipefail
4+
5+
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)"
6+
ENGINE_DIR="$ROOT_DIR"
7+
OUT_DIR="/wasm32-emscripten-pe-release"
8+
9+
mkdir -p "$OUT_DIR"
10+
export EM_CACHE="${EM_CACHE:-$ROOT_DIR/.cache/emscripten}"
11+
mkdir -p "$EM_CACHE"
12+
13+
em++ \
14+
-std=c++23 \
15+
-O3 \
16+
-I"$ENGINE_DIR/include" \
17+
"$ENGINE_DIR/src/dll_main.cpp" \
18+
-fno-rtti \
19+
-fno-exceptions \
20+
-fno-cxx-exceptions \
21+
-fno-unwind-tables \
22+
-s MODULARIZE=1 \
23+
-s EXPORT_ES6=1 \
24+
-s ENVIRONMENT=web \
25+
-s ALLOW_MEMORY_GROWTH=1 \
26+
-s FILESYSTEM=0 \
27+
-s EXPORTED_RUNTIME_METHODS='["cwrap"]' \
28+
-s EXPORTED_FUNCTIONS='["_malloc","_free","_create_circuit","_create_circuit_ex","_destroy_circuit","_circuit_set_analyze_type","_circuit_set_tr","_circuit_set_ac_omega","_circuit_analyze","_circuit_digital_clk","_circuit_sample_u8","_circuit_set_model_digital"]' \
29+
-o "$OUT_DIR/phy_engine.js"
30+
31+
# The generated ESModule does not expose HEAP views on the returned Module by default.
32+
# Patch `updateMemoryViews()` so callers can access `Module.HEAPU8/HEAPU32/HEAPF64` and `Module.wasmMemory`.
33+
node - <<'NODE'
34+
import { readFileSync, writeFileSync } from "node:fs";
35+
import path from "node:path";
36+
37+
const file = "/wasm32-emscripten-pe-release/phy_engine.js";
38+
let s = readFileSync(file, "utf8");
39+
40+
const needle = "HEAPU64=new BigUint64Array(b)}";
41+
if (!s.includes(needle)) {
42+
console.error("patch failed: updateMemoryViews() signature not found");
43+
process.exit(1);
44+
}
45+
46+
const inject =
47+
"HEAPU64=new BigUint64Array(b);Module.HEAP8=HEAP8;Module.HEAPU8=HEAPU8;Module.HEAP32=HEAP32;Module.HEAPU32=HEAPU32;Module.HEAPF64=HEAPF64;Module.wasmMemory=wasmMemory}";
48+
49+
s = s.replace(needle, inject);
50+
writeFileSync(file, s);
51+
NODE
52+
53+
echo "Built:"
54+
ls -la "$OUT_DIR/phy_engine.js" "$OUT_DIR/phy_engine.wasm"

0 commit comments

Comments
 (0)