Skip to content

Commit ae4a0b4

Browse files
authored
wasm bindgen submodule support (#802)
1 parent 6250133 commit ae4a0b4

File tree

7 files changed

+55
-34
lines changed

7 files changed

+55
-34
lines changed

.github/workflows/pullrequest.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v4
13+
with:
14+
submodules: true
1315

1416
- name: Install stable toolchain
1517
uses: dtolnay/rust-toolchain@stable
@@ -42,6 +44,8 @@ jobs:
4244

4345
steps:
4446
- uses: actions/checkout@v4
47+
with:
48+
submodules: true
4549

4650
- name: Install stable toolchain
4751
uses: dtolnay/rust-toolchain@stable
@@ -79,14 +83,17 @@ jobs:
7983
- name: Install wasmpack
8084
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
8185

86+
- name: Build wasm-bindgen
87+
run: cd wasm-bindgen && cargo build --release --package wasm-bindgen-cli --bin wasm-bindgen
88+
8289
- name: Build local worker-build
8390
run: cargo install --path ./worker-build --force --debug
8491

8592
- name: Install npm dependencies
8693
run: npm ci
8794

8895
- name: Run tests
89-
run: npm run test
96+
run: WASM_BINDGEN_PATH=./wasm-bindgen/target/release/wasm-bindgen npm run test
9097

9198
- name: Run tests (http)
92-
run: npm run test-http
99+
run: WASM_BINDGEN_PATH=./wasm-bindgen/target/release/wasm-bindgen npm run test-http

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "wasm-bindgen"]
2+
path = wasm-bindgen
3+
url = [email protected]:wasm-bindgen/wasm-bindgen

Cargo.lock

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

Cargo.toml

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ members = [
88
"worker-kv",
99
"examples/*",
1010
]
11-
exclude = ["examples/coredump", "examples/axum", "templates/*"]
11+
exclude = ["examples/coredump", "examples/axum", "templates/*", "wasm-bindgen"]
1212
resolver = "2"
1313

1414
[workspace.dependencies]
@@ -19,15 +19,17 @@ chrono = { version = "0.4.41", default-features = false, features = [
1919
futures-channel = "0.3.31"
2020
futures-util = { version = "0.3.31", default-features = false }
2121
http = "1.3"
22-
js-sys = "0.3.77"
22+
js-sys = { version = "0.3.78", path = "./wasm-bindgen/crates/js-sys" }
2323
serde = { version = "1.0.164", features = ["derive"] }
2424
serde_json = "1.0.140"
2525
serde-wasm-bindgen = "0.6.5"
26-
wasm-bindgen = "0.2.101"
27-
wasm-bindgen-cli-support = "0.2.101"
28-
wasm-bindgen-futures = "0.4.51"
29-
wasm-bindgen-macro-support = "0.2.101"
30-
wasm-bindgen-test = "0.3.51"
26+
wasm-bindgen = { version = "0.2.101", path = "./wasm-bindgen" }
27+
wasm-bindgen-cli-support = { version = "0.2.101", path = "./wasm-bindgen/crates/cli-support" }
28+
wasm-bindgen-futures = { version = "0.4.51", path = "./wasm-bindgen/crates/futures" }
29+
wasm-bindgen-macro-support = { version = "0.2.101", path = "./wasm-bindgen/crates/macro-support" }
30+
wasm-bindgen-shared = { version = "0.2.101", path = "./wasm-bindgen/crates/shared" }
31+
wasm-bindgen-test = { version = "0.3.51", path = "./wasm-bindgen/crates/test" }
32+
web-sys = { version = "0.3.78", path = "./wasm-bindgen/crates/web-sys" }
3133
worker = { path = "worker", version = "0.6.1", features = ["queue", "d1", "axum", "timezone"] }
3234
worker-build = { path = "worker-build", version = "0.1.4" }
3335
worker-codegen = { path = "worker-codegen", version = "0.2.0" }
@@ -57,3 +59,13 @@ lto = true
5759
[profile.release.package."*"]
5860
codegen-units = 1
5961
opt-level = "z"
62+
63+
[patch.crates-io]
64+
js-sys = { version = "0.3.78", path = './wasm-bindgen/crates/js-sys' }
65+
wasm-bindgen = { version = "0.2.101", path = './wasm-bindgen' }
66+
wasm-bindgen-cli-support = { version = "0.2.101", path = "./wasm-bindgen/crates/cli-support" }
67+
wasm-bindgen-futures = { version = "0.4.51", path = './wasm-bindgen/crates/futures' }
68+
wasm-bindgen-macro-support = { version = "0.2.101", path = "./wasm-bindgen/crates/macro-support" }
69+
wasm-bindgen-shared = { version = "0.2.101", path = "./wasm-bindgen/crates/shared" }
70+
wasm-bindgen-test = { version = "0.3.51", path = "./wasm-bindgen/crates/test" }
71+
web-sys = { version = "0.3.78", path = './wasm-bindgen/crates/web-sys' }

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
"vitest": "^3.2.4"
2323
},
2424
"scripts": {
25-
"install": "cargo install --path ./worker-build --force --debug",
26-
"test": "cd worker-sandbox && NO_MINIFY=1 worker-build --dev && NODE_OPTIONS=--experimental-vm-modules npx vitest run",
27-
"test-http": "cd worker-sandbox && NO_MINIFY=1 worker-build --dev --features http && NODE_OPTIONS=--experimental-vm-modules npx vitest run",
25+
"install": "cd wasm-bindgen && cargo build --release --package wasm-bindgen-cli --bin wasm-bindgen && cd .. && cargo install --path ./worker-build --force --debug",
26+
"test": "cd worker-sandbox && NO_MINIFY=1 WASM_BINDGEN_PATH=../wasm-bindgen/target/release/wasm-bindgen worker-build --dev && NODE_OPTIONS=--experimental-vm-modules npx vitest run",
27+
"test-http": "cd worker-sandbox && NO_MINIFY=1 WASM_BINDGEN_PATH=../wasm-bindgen/target/release/wasm-bindgen worker-build --dev --features http && NODE_OPTIONS=--experimental-vm-modules npx vitest run",
2828
"lint": "cargo clippy --features d1,queue --all-targets --workspace -- -D warnings",
2929
"lint:fix": "cargo fmt && cargo clippy --features d1,queue --all-targets --workspace --fix -- -D warnings"
3030
}

wasm-bindgen

Submodule wasm-bindgen added at 488a9cd

worker-build/src/wasm_pack/install/mod.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,26 @@ pub fn download_prebuilt_or_cargo_install(
5252
version: &str,
5353
install_permitted: bool,
5454
) -> Result<Status> {
55+
// Check for custom wasm-bindgen path via environment variable
56+
if matches!(tool, Tool::WasmBindgen) {
57+
if let Ok(custom_path) = env::var("WASM_BINDGEN_PATH") {
58+
let path = Path::new(&custom_path);
59+
if path.exists() {
60+
info!(
61+
"Using custom wasm-bindgen from WASM_BINDGEN_PATH: {}",
62+
custom_path
63+
);
64+
let download = Download::at(path.parent().unwrap_or(path));
65+
return Ok(Status::Found(download));
66+
} else {
67+
warn!(
68+
"WASM_BINDGEN_PATH set but path doesn't exist: {}",
69+
custom_path
70+
);
71+
}
72+
}
73+
}
74+
5575
// If the tool is installed globally and it has the right version, use
5676
// that. Assume that other tools are installed next to it.
5777
//

0 commit comments

Comments
 (0)