Skip to content

Commit bf50db6

Browse files
authored
fix: lock js-component-bindgen version (#358)
* fix: lock js-component-bindgen version Pin bindgen to v2.11.0 and require --locked in CI * fix: explicitly configure splicer filesystem access Newer preview2-shim releases no longer expose the host filesystem by default, preventing the splicer from reading wit paths.
1 parent 4d812f5 commit bf50db6

14 files changed

Lines changed: 354 additions & 27 deletions

File tree

‎.github/workflows/main.yml‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
run: cargo fmt -- --check
3535

3636
- name: Run clippy
37-
run: cargo clippy --workspace --all-targets --all-features
37+
run: cargo clippy --locked --workspace --all-targets --all-features
3838

3939
#########
4040
# Build #
@@ -59,7 +59,7 @@ jobs:
5959
uses: actions/cache@v4
6060
id: splicer-build
6161
with:
62-
key: splicer-${{ matrix.os }}-${{ hashFiles('Cargo.lock', 'crates/spidermonkey-embedding-splicer/src/**/*.rs') }}
62+
key: splicer-${{ matrix.os }}-${{ hashFiles('Makefile', 'Cargo.lock', 'crates/spidermonkey-embedding-splicer/src/**/*.rs') }}
6363
path: |
6464
lib
6565
target
@@ -134,7 +134,7 @@ jobs:
134134
uses: actions/cache/restore@v4
135135
id: splicer-build
136136
with:
137-
key: splicer-${{ matrix.os }}-${{ hashFiles('Cargo.lock', 'crates/spidermonkey-embedding-splicer/src/**/*.rs') }}
137+
key: splicer-${{ matrix.os }}-${{ hashFiles('Makefile', 'Cargo.lock', 'crates/spidermonkey-embedding-splicer/src/**/*.rs') }}
138138
path: |
139139
lib
140140
target
@@ -195,7 +195,7 @@ jobs:
195195
uses: actions/cache/restore@v4
196196
id: splicer-build
197197
with:
198-
key: splicer-${{ matrix.os }}-${{ hashFiles('Cargo.lock', 'crates/spidermonkey-embedding-splicer/src/**/*.rs') }}
198+
key: splicer-${{ matrix.os }}-${{ hashFiles('Makefile', 'Cargo.lock', 'crates/spidermonkey-embedding-splicer/src/**/*.rs') }}
199199
path: |
200200
lib
201201
target
@@ -239,7 +239,7 @@ jobs:
239239
uses: actions/cache/restore@v4
240240
id: splicer-build
241241
with:
242-
key: splicer-${{ matrix.os }}-${{ hashFiles('Cargo.lock', 'crates/spidermonkey-embedding-splicer/src/**/*.rs') }}
242+
key: splicer-${{ matrix.os }}-${{ hashFiles('Makefile', 'Cargo.lock', 'crates/spidermonkey-embedding-splicer/src/**/*.rs') }}
243243
path: |
244244
lib
245245
target

‎Cargo.lock‎

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ wit-parser = { version = "0.258.0", features = ["decoding", "serde"] }
3333
wit-bindgen = { version = "0.54.0", features = ["macros", "async", "realloc"] }
3434
wit-bindgen-core = { version = "0.61.1", default-features = false }
3535

36-
js-component-bindgen = { version = "2.11.0" }
36+
js-component-bindgen = { version = "=2.11.0" }

‎Makefile‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ debug: lib/starlingmonkey_embedding.debug.wasm lib/spidermonkey-embedding-splice
1717
release: lib/starlingmonkey_embedding.wasm lib/spidermonkey-embedding-splicer.js
1818
release-weval: lib/starlingmonkey_ics.wevalcache lib/spidermonkey-embedding-splicer.js
1919

20-
lib/spidermonkey-embedding-splicer.js: target/wasm32-wasip1/release/splicer_component.wasm crates/spidermonkey-embedding-splicer/wit/spidermonkey-embedding-splicer.wit | obj lib
20+
lib/spidermonkey-embedding-splicer.js: Makefile target/wasm32-wasip1/release/splicer_component.wasm crates/spidermonkey-embedding-splicer/wit/spidermonkey-embedding-splicer.wit | obj lib
2121
@$(JCO) new target/wasm32-wasip1/release/splicer_component.wasm -o obj/spidermonkey-embedding-splicer.wasm --wasi-reactor
22-
@$(JCO) transpile -q --name spidermonkey-embedding-splicer obj/spidermonkey-embedding-splicer.wasm -o lib -- -O1
22+
@$(JCO) transpile -q --instantiation async --no-wasi-shim --name spidermonkey-embedding-splicer obj/spidermonkey-embedding-splicer.wasm -o lib -- -O1
2323

24-
target/wasm32-wasip1/release/splicer_component.wasm: Cargo.toml crates/spidermonkey-embedding-splicer/Cargo.toml crates/spidermonkey-embedding-splicer/src/*.rs crates/splicer-component/src/*.rs
25-
cargo build --lib --release --target wasm32-wasip1
24+
target/wasm32-wasip1/release/splicer_component.wasm: Cargo.toml Cargo.lock crates/spidermonkey-embedding-splicer/Cargo.toml crates/spidermonkey-embedding-splicer/src/*.rs crates/splicer-component/src/*.rs
25+
cargo build --locked --lib --release --target wasm32-wasip1
2626

2727
lib/starlingmonkey_embedding.wasm: $(STARLINGMONKEY_DEPS) | lib
2828
cmake -B build-release -DCMAKE_BUILD_TYPE=Release

‎README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ export function componentize(opts: {
218218
*/
219219
sourcePath: string;
220220
/**
221-
* Path to WIT file or folder
221+
* Path to a WIT file or folder. Dependencies must be inside the given folder
222+
* or, for a file, its parent folder. Subfolders are included.
222223
*/
223224
witPath?: string;
224225
/**

‎examples/hello-world/test.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export TEST_BINARY_PATH=$(realpath host)/target/release/wasmtime-test
77
# Build the JS component if not present
88
echo -e "[info] expecting component WASM at [$COMPONENT_WASM_PATH]...";
99
if [ ! -f "$COMPONENT_WASM_PATH" ]; then
10-
cd guest && npm install && npm run build && cd ..
10+
cd guest && npm install --no-save ../../.. && npm run build && cd ..
1111
fi
1212

1313
# Build the Rust embedding test binary if not present

‎package-lock.json‎

Lines changed: 163 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
"import": "./src/componentize.js"
1616
},
1717
"devDependencies": {
18-
"@bytecodealliance/preview2-shim": "^0.17.4",
1918
"cross-env": "^7.0.3",
2019
"semver": "^7.7.2",
2120
"vitest": "^3.2.4"
2221
},
2322
"dependencies": {
2423
"@bytecodealliance/jco": "^1.15.1",
24+
"@bytecodealliance/preview2-shim": "^0.29.0",
2525
"@bytecodealliance/weval": "^0.5.0",
2626
"@bytecodealliance/wizer": "^10.0.0",
2727
"es-module-lexer": "^1.6.0",

‎src/componentize.js‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
preview1AdapterReactorPath,
2020
} from '@bytecodealliance/jco';
2121

22-
import { splicer } from '../lib/spidermonkey-embedding-splicer.js';
22+
import { createSplicer } from './splicer.js';
2323

2424
import { maybeWindowsPath } from './platform.js';
2525

@@ -148,12 +148,16 @@ export async function componentize(
148148
features.delete('fetch-event');
149149
}
150150

151-
// Splice the bindigns for the given WIT world into the engine WASM
151+
const { splicer, witPath: splicerWitPath } = await createSplicer(
152+
witWorld == null ? witPath : undefined,
153+
);
154+
155+
// Splice the bindings for the given WIT world into the engine WASM
152156
let { wasm, jsBindings, exports, imports } = splicer.spliceBindings(
153157
await readFile(engine),
154158
[...features],
155159
witWorld,
156-
maybeWindowsPath(witPath),
160+
splicerWitPath,
157161
worldName,
158162
false,
159163
);
@@ -393,7 +397,7 @@ export async function componentize(
393397
bin,
394398
[...features],
395399
witWorld,
396-
maybeWindowsPath(witPath),
400+
splicerWitPath,
397401
worldName,
398402
);
399403

‎src/splicer.js‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { readFile, realpath, stat } from 'node:fs/promises';
2+
import { basename, dirname } from 'node:path';
3+
import { WASIShim } from '@bytecodealliance/preview2-shim/instantiation';
4+
5+
import { instantiate } from '../lib/spidermonkey-embedding-splicer.js';
6+
7+
// Compiled modules can be shared, but instances must retain isolated preopens.
8+
const coreModules = new Map();
9+
10+
function getCoreModule(name) {
11+
if (!coreModules.has(name)) {
12+
coreModules.set(
13+
name,
14+
readFile(new URL(`../lib/${name}`, import.meta.url)).then(WebAssembly.compile),
15+
);
16+
}
17+
return coreModules.get(name);
18+
}
19+
20+
export async function createSplicer(witPath) {
21+
const preopens = {};
22+
let guestWitPath;
23+
24+
if (witPath != null) {
25+
const hostPath = await realpath(witPath);
26+
const isDirectory = (await stat(hostPath)).isDirectory();
27+
preopens['/wit'] = isDirectory ? hostPath : dirname(hostPath);
28+
guestWitPath = isDirectory ? '/wit' : `/wit/${basename(hostPath)}`;
29+
}
30+
31+
const wasi = new WASIShim({ sandbox: { preopens } });
32+
const { splicer } = await instantiate(getCoreModule, wasi.getImportObject());
33+
return { splicer, witPath: guestWitPath };
34+
}

0 commit comments

Comments
 (0)