diff --git a/cli/package.json b/cli/package.json index 672db18e..4d20aa2c 100644 --- a/cli/package.json +++ b/cli/package.json @@ -69,7 +69,6 @@ "dependencies": { "@napi-rs/cross-toolchain": "^0.0.14", "@octokit/rest": "^20.0.2", - "@tybys/wasm-util": "0.8.1", "clipanion": "^3.2.1", "colorette": "^2.0.20", "debug": "^4.3.4", @@ -79,7 +78,8 @@ "lodash-es": "^4.17.21", "semver": "^7.5.4", "toml": "^3.0.0", - "typanion": "^3.14.0" + "typanion": "^3.14.0", + "wasm-sjlj": "^1.0.4" }, "devDependencies": { "@emnapi/core": "^1.0.0", diff --git a/cli/src/api/build.ts b/cli/src/api/build.ts index 53d7436e..35af94ff 100644 --- a/cli/src/api/build.ts +++ b/cli/src/api/build.ts @@ -6,6 +6,7 @@ import { tmpdir, homedir } from 'node:os' import { parse, join, resolve } from 'node:path' import * as colors from 'colorette' +import { include as setjmpInclude, lib as setjmpLib } from 'wasm-sjlj' import { BuildOptions as RawBuildOptions } from '../def/build.js' import { @@ -534,6 +535,7 @@ class Builder { 'wasm32-wasi-threads', ) this.envs.EMNAPI_LINK_DIR = emnapi + this.envs.SETJMP_LINK_DIR = setjmpLib const { WASI_SDK_PATH } = process.env if (WASI_SDK_PATH && existsSync(WASI_SDK_PATH)) { @@ -548,11 +550,11 @@ class Builder { this.setEnvIfNotExists('RANLIB', join(WASI_SDK_PATH, 'bin', 'ranlib')) this.setEnvIfNotExists( 'CFLAGS', - `--target=wasm32-wasi-threads --sysroot=${WASI_SDK_PATH}/share/wasi-sysroot -pthread`, + `--target=wasm32-wasi-threads --sysroot=${WASI_SDK_PATH}/share/wasi-sysroot -pthread -I${setjmpInclude}`, ) this.setEnvIfNotExists( 'CXXFLAGS', - `--target=wasm32-wasi-threads --sysroot=${WASI_SDK_PATH}/share/wasi-sysroot -pthread`, + `--target=wasm32-wasi-threads --sysroot=${WASI_SDK_PATH}/share/wasi-sysroot -pthread -I${setjmpInclude}`, ) this.setEnvIfNotExists( `LDFLAGS`, diff --git a/crates/build/src/wasi.rs b/crates/build/src/wasi.rs index 77b389d2..1e350178 100644 --- a/crates/build/src/wasi.rs +++ b/crates/build/src/wasi.rs @@ -4,8 +4,12 @@ pub fn setup() { let link_dir = env::var("EMNAPI_LINK_DIR").expect("EMNAPI_LINK_DIR must be set"); println!("cargo:rerun-if-env-changed=EMNAPI_LINK_DIR"); println!("cargo:rerun-if-env-changed=WASI_REGISTER_TMP_PATH"); - println!("cargo:rustc-link-search={}", link_dir); + if let Ok(setjmp_link_dir) = env::var("SETJMP_LINK_DIR") { + println!("cargo:rustc-link-search={link_dir}"); + println!("cargo:rustc-link-search={setjmp_link_dir}"); + } println!("cargo:rustc-link-lib=static=emnapi-basic-mt"); + println!("cargo:rustc-link-lib=static=setjmp-mt"); println!("cargo:rustc-link-arg=--export-dynamic"); println!("cargo:rustc-link-arg=--export=malloc"); println!("cargo:rustc-link-arg=--export=free"); diff --git a/yarn.lock b/yarn.lock index f6766e9f..7617244a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -744,7 +744,6 @@ __metadata: "@emnapi/runtime": "npm:^1.0.0" "@napi-rs/cross-toolchain": "npm:^0.0.14" "@octokit/rest": "npm:^20.0.2" - "@tybys/wasm-util": "npm:0.8.1" "@types/debug": "npm:^4.1.12" "@types/inquirer": "npm:^9.0.7" "@types/js-yaml": "npm:^4.0.9" @@ -767,6 +766,7 @@ __metadata: tslib: "npm:^2.6.2" typanion: "npm:^3.14.0" typescript: "npm:^5.3.3" + wasm-sjlj: "npm:^1.0.4" peerDependencies: "@emnapi/runtime": ^1.0.0 emnapi: ^1.0.0 @@ -2177,7 +2177,7 @@ __metadata: languageName: node linkType: hard -"@tybys/wasm-util@npm:0.8.1, @tybys/wasm-util@npm:^0.8.1": +"@tybys/wasm-util@npm:^0.8.1": version: 0.8.1 resolution: "@tybys/wasm-util@npm:0.8.1" dependencies: @@ -12709,6 +12709,15 @@ __metadata: languageName: node linkType: hard +"wasm-sjlj@npm:^1.0.4": + version: 1.0.4 + resolution: "wasm-sjlj@npm:1.0.4" + dependencies: + node-gyp: "npm:latest" + checksum: 10c0/79b0d48c23e55e98e8cac86610003714dc5b874c76bc88501eab70c4c96f4c6d49420e036825fc7c55f42317620433f25ff7fb0ea2dc9e6db505b79450653301 + languageName: node + linkType: hard + "wcwidth@npm:^1.0.0, wcwidth@npm:^1.0.1": version: 1.0.1 resolution: "wcwidth@npm:1.0.1"