Skip to content

Commit 08b1f68

Browse files
authored
feat(cli,build): support setjmp.h (#1958)
1 parent 1951b60 commit 08b1f68

4 files changed

Lines changed: 22 additions & 7 deletions

File tree

cli/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
"dependencies": {
7070
"@napi-rs/cross-toolchain": "^0.0.14",
7171
"@octokit/rest": "^20.0.2",
72-
"@tybys/wasm-util": "0.8.1",
7372
"clipanion": "^3.2.1",
7473
"colorette": "^2.0.20",
7574
"debug": "^4.3.4",
@@ -79,7 +78,8 @@
7978
"lodash-es": "^4.17.21",
8079
"semver": "^7.5.4",
8180
"toml": "^3.0.0",
82-
"typanion": "^3.14.0"
81+
"typanion": "^3.14.0",
82+
"wasm-sjlj": "^1.0.4"
8383
},
8484
"devDependencies": {
8585
"@emnapi/core": "^1.0.0",

cli/src/api/build.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { tmpdir, homedir } from 'node:os'
66
import { parse, join, resolve } from 'node:path'
77

88
import * as colors from 'colorette'
9+
import { include as setjmpInclude, lib as setjmpLib } from 'wasm-sjlj'
910

1011
import { BuildOptions as RawBuildOptions } from '../def/build.js'
1112
import {
@@ -534,6 +535,7 @@ class Builder {
534535
'wasm32-wasi-threads',
535536
)
536537
this.envs.EMNAPI_LINK_DIR = emnapi
538+
this.envs.SETJMP_LINK_DIR = setjmpLib
537539
const { WASI_SDK_PATH } = process.env
538540

539541
if (WASI_SDK_PATH && existsSync(WASI_SDK_PATH)) {
@@ -548,11 +550,11 @@ class Builder {
548550
this.setEnvIfNotExists('RANLIB', join(WASI_SDK_PATH, 'bin', 'ranlib'))
549551
this.setEnvIfNotExists(
550552
'CFLAGS',
551-
`--target=wasm32-wasi-threads --sysroot=${WASI_SDK_PATH}/share/wasi-sysroot -pthread`,
553+
`--target=wasm32-wasi-threads --sysroot=${WASI_SDK_PATH}/share/wasi-sysroot -pthread -I${setjmpInclude}`,
552554
)
553555
this.setEnvIfNotExists(
554556
'CXXFLAGS',
555-
`--target=wasm32-wasi-threads --sysroot=${WASI_SDK_PATH}/share/wasi-sysroot -pthread`,
557+
`--target=wasm32-wasi-threads --sysroot=${WASI_SDK_PATH}/share/wasi-sysroot -pthread -I${setjmpInclude}`,
556558
)
557559
this.setEnvIfNotExists(
558560
`LDFLAGS`,

crates/build/src/wasi.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ pub fn setup() {
44
let link_dir = env::var("EMNAPI_LINK_DIR").expect("EMNAPI_LINK_DIR must be set");
55
println!("cargo:rerun-if-env-changed=EMNAPI_LINK_DIR");
66
println!("cargo:rerun-if-env-changed=WASI_REGISTER_TMP_PATH");
7-
println!("cargo:rustc-link-search={}", link_dir);
7+
if let Ok(setjmp_link_dir) = env::var("SETJMP_LINK_DIR") {
8+
println!("cargo:rustc-link-search={link_dir}");
9+
println!("cargo:rustc-link-search={setjmp_link_dir}");
10+
}
811
println!("cargo:rustc-link-lib=static=emnapi-basic-mt");
12+
println!("cargo:rustc-link-lib=static=setjmp-mt");
913
println!("cargo:rustc-link-arg=--export-dynamic");
1014
println!("cargo:rustc-link-arg=--export=malloc");
1115
println!("cargo:rustc-link-arg=--export=free");

yarn.lock

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,6 @@ __metadata:
744744
"@emnapi/runtime": "npm:^1.0.0"
745745
"@napi-rs/cross-toolchain": "npm:^0.0.14"
746746
"@octokit/rest": "npm:^20.0.2"
747-
"@tybys/wasm-util": "npm:0.8.1"
748747
"@types/debug": "npm:^4.1.12"
749748
"@types/inquirer": "npm:^9.0.7"
750749
"@types/js-yaml": "npm:^4.0.9"
@@ -767,6 +766,7 @@ __metadata:
767766
tslib: "npm:^2.6.2"
768767
typanion: "npm:^3.14.0"
769768
typescript: "npm:^5.3.3"
769+
wasm-sjlj: "npm:^1.0.4"
770770
peerDependencies:
771771
"@emnapi/runtime": ^1.0.0
772772
emnapi: ^1.0.0
@@ -2177,7 +2177,7 @@ __metadata:
21772177
languageName: node
21782178
linkType: hard
21792179

2180-
"@tybys/wasm-util@npm:0.8.1, @tybys/wasm-util@npm:^0.8.1":
2180+
"@tybys/wasm-util@npm:^0.8.1":
21812181
version: 0.8.1
21822182
resolution: "@tybys/wasm-util@npm:0.8.1"
21832183
dependencies:
@@ -12709,6 +12709,15 @@ __metadata:
1270912709
languageName: node
1271012710
linkType: hard
1271112711

12712+
"wasm-sjlj@npm:^1.0.4":
12713+
version: 1.0.4
12714+
resolution: "wasm-sjlj@npm:1.0.4"
12715+
dependencies:
12716+
node-gyp: "npm:latest"
12717+
checksum: 10c0/79b0d48c23e55e98e8cac86610003714dc5b874c76bc88501eab70c4c96f4c6d49420e036825fc7c55f42317620433f25ff7fb0ea2dc9e6db505b79450653301
12718+
languageName: node
12719+
linkType: hard
12720+
1271212721
"wcwidth@npm:^1.0.0, wcwidth@npm:^1.0.1":
1271312722
version: 1.0.1
1271412723
resolution: "wcwidth@npm:1.0.1"

0 commit comments

Comments
 (0)