Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
[build]
target = "wasm32-unknown-unknown"

[target.wasm32-unknown-unknown]
rustflags = ["-C", "target-feature=+atomics"]
rustflags = [
"-C", "target-feature=+atomics",
"-Clink-args=--shared-memory",
"-Clink-args=--import-memory",
"-Clink-args=--max-memory=1073741824",
"-Clink-args=--export=__wasm_init_tls",
"-Clink-args=--export=__tls_size",
"-Clink-args=--export=__tls_align",
"-Clink-args=--export=__tls_base",
]
# Ciantic: Tested +simd128 22.7.2021, didn't work! Got some wasm-opt problems.
# 2024-10-01 - It now works, but threading works without it. So probably best to wait for it to stabilize.
# 2025-06-12 - mutable-globals is enabled by default, and bulk-memory is enabled by default on Rust 1.87+
# 2025-10-02 - rust now requires extra -Clink-args to enable shared-memory, see https://github.com/rust-lang/rust/pull/147225

[unstable]
build-std = ["panic_abort", "std"]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
rust: nightly
rust-wasm: true
rust-src: true
tool-cargo-binstall: txtpp
tool-cargo-install: txtpp
- run: task install-ci
working-directory: example
- run: task build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ jobs:
rust: nightly
rust-wasm: true
rust-src: true
tool-cargo-binstall: txtpp
tool-cargo-install: txtpp
- run: task check
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wasm-bindgen-spawn"
version = "0.0.2"
version = "0.0.3"
edition = "2024"
description = "Web Worker Multithreading library for wasm-bindgen the uses shared memory"
repository = "https://github.com/Pistonite/wasm-bindgen-spawn"
Expand All @@ -20,12 +20,12 @@ include = [
]

[dependencies]
js-sys = "0.3.77"
js-sys = "0.3.83"
oneshot = { version = "0.1.11", default-features = false, features = ["std"] }
static_assertions = "1.1.0"
thiserror = "2.0.12"
wasm-bindgen = "0.2.100"
wasm-bindgen-futures = { version = "0.4.50", optional = true }
thiserror = "2.0.17"
wasm-bindgen = "0.2.106"
wasm-bindgen-futures = { version = "0.4.56", optional = true }

[features]
default = ["async"]
Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,16 @@ Read the full article for more details on the implications of Cross-Origin Isola
2. Add the following to `.cargo/config.toml`
```toml
[target.wasm32-unknown-unknown]
rustflags = ["-C", "target-feature=+atomics"]
rustflags = [
"-C", "target-feature=+atomics",
"-Clink-args=--shared-memory",
"-Clink-args=--import-memory",
"-Clink-args=--max-memory=1073741824",
"-Clink-args=--export=__wasm_init_tls",
"-Clink-args=--export=__tls_size",
"-Clink-args=--export=__tls_align",
"-Clink-args=--export=__tls_base",
]
# You also need `bulk-memory` for Rust < 1.87. For 1.87+ it's enabled by default
# rustflags = ["-C", "target-feature=+atomics,+bulk-memory"]

Expand Down
1 change: 1 addition & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ includes:
cargo:
taskfile: ./mono-dev/task/cargo.yaml
internal: true
optional: true

tasks:
install-cargo-extra-tools:
Expand Down
15 changes: 13 additions & 2 deletions example/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
[target.wasm32-unknown-unknown]
rustflags = ["-C", "target-feature=+atomics,+bulk-memory,+mutable-globals"]
rustflags = [
"-C", "target-feature=+atomics",
"-Clink-args=--shared-memory",
"-Clink-args=--import-memory",
"-Clink-args=--max-memory=1073741824",
"-Clink-args=--export=__wasm_init_tls",
"-Clink-args=--export=__tls_size",
"-Clink-args=--export=__tls_align",
"-Clink-args=--export=__tls_base",
]
# Ciantic: Tested +simd128 22.7.2021, didn't work! Got some wasm-opt problems.
# 10.01.2024 - It now works, but threading works without it. So probably best to wait for it to stabilize.
# 2024-10-01 - It now works, but threading works without it. So probably best to wait for it to stabilize.
# 2025-06-12 - mutable-globals is enabled by default, and bulk-memory is enabled by default on Rust 1.87+
# 2025-10-02 - rust now requires extra -Clink-args to enable shared-memory, see https://github.com/rust-lang/rust/pull/147225

[unstable]
build-std = ["panic_abort", "std"]
Expand Down
87 changes: 34 additions & 53 deletions example/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ edition = "2024"

[dependencies]
console_error_panic_hook = "0.1.7"
js-sys = "0.3.77"
wasm-bindgen = "0.2.100"
wasm-bindgen-futures = "0.4.50"
js-sys = "0.3.83"
wasm-bindgen = "0.2.106"
wasm-bindgen-futures = "0.4.56"
wasm-bindgen-spawn = { path = ".." }

[lib]
Expand Down
2 changes: 1 addition & 1 deletion example/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{
cell::OnceCell,
sync::{atomic::AtomicUsize, Arc, Mutex},
sync::{Arc, Mutex, atomic::AtomicUsize},
};

use js_sys::Function;
Expand Down
4 changes: 2 additions & 2 deletions src/js/createDispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ return (async function () {
const DISPATCHER =
wbg +
`
self.onmessage=async(_)=>{let{recv:a,start_send:i,url:o,memory:t,wasm:n}=_.data;await wasm_bindgen({memory:t,module_or_path:n}),wasm_bindgen.__dispatch_start(i);while(!0){let r=wasm_bindgen.__dispatch_recv(a);if(!r)break;let[w,d,m,c,p]=r;await new Promise((e)=>{let s=new Worker(o);s.onmessage=({data:g})=>{if(g)return s.postMessage({id:w,f:d,send:m,start:c,memory:t,wasm:n}),e();s.terminate()}});while(!wasm_bindgen.__dispatch_poll_worker(p))await new Promise((e)=>setTimeout(e,0))}wasm_bindgen.__dispatch_drop(a),self.postMessage(0)};self.postMessage(1);
self.onmessage=async(o)=>{let{recv:a,start_send:w,url:d,memory:t,wasm:n}=o.data;await wasm_bindgen({memory:t,module_or_path:n}),wasm_bindgen.__dispatch_start(w);while(!0){let r=wasm_bindgen.__dispatch_recv(a);if(!r)break;let[_,m,i,c,g]=r;await new Promise((s)=>{let e=new Worker(d);e.onmessage=({data:p})=>{switch(p){case 0:e.terminate();return;case 1:return e.postMessage({id:_,f:m,send:i,start:c,memory:t,wasm:n}),s();case 2:wasm_bindgen.__worker_send(_,i),e.terminate();return}}});while(!wasm_bindgen.__dispatch_poll_worker(g))await new Promise((s)=>setTimeout(s,0))}wasm_bindgen.__dispatch_drop(a),self.postMessage(0)};self.postMessage(1);

`;
const dispatcherUrl = URL.createObjectURL(
Expand All @@ -12,7 +12,7 @@ self.onmessage=async(_)=>{let{recv:a,start_send:i,url:o,memory:t,wasm:n}=_.data;
const WORKER =
wbg +
`
self.onmessage=async(n)=>{let{id:s,f:_,send:a,start:o,memory:r,wasm:t}=n.data;await wasm_bindgen({memory:r,module_or_path:t});try{let e=wasm_bindgen.__worker_main(_,o);wasm_bindgen.__worker_send(s,a,e)}catch(e){self.console.error(e),wasm_bindgen.__worker_send(s,a)}self.postMessage(0)};self.postMessage(1);
self.onmessage=async(s)=>{let{id:a,f:n,send:o,start:r,memory:t,wasm:_}=s.data;await wasm_bindgen({memory:t,module_or_path:_});try{let e=wasm_bindgen.__worker_main(n,r);wasm_bindgen.__worker_send(a,o,e)}catch(e){self.console.error(e),self.postMessage(2);return}self.postMessage(0)};self.postMessage(1);

`;
const workerUrl = URL.createObjectURL(
Expand Down
6 changes: 3 additions & 3 deletions src/js/createDispatcher.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading