Skip to content

Commit c38f6ea

Browse files
committed
Update and improve documentation
1 parent 3fed409 commit c38f6ea

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

examples/wasm_threads/README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,22 @@
22

33
This is a port of [wasm_threads `simple.rs` example](https://github.com/chemicstry/wasm_thread/tree/main?tab=readme-ov-file#simple).
44

5-
It should also work similarly with `wasm-bindgen-rayon` and `wasm-mt`.
5+
It should also work similarly with `wasm-bindgen-rayon` and other packages that use SharedArrayBuffer.
6+
7+
An explanation of that approach is described [here](https://rustwasm.github.io/wasm-bindgen/examples/raytrace.html)
68

79
## Limitations
810

911
It has a few considerable advantages over the `webworker*` examples, but also considerable disadvantages.
1012

11-
For starters, `trunk serve` won't work currently, as it doesn't do Cross Site Isolation (setting 2 headers), which is [required for this approach to workers](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer#security_requirements).
12-
`sfz` works, with `cargo install sfz` and run `sfz dist --coi` in the root directory of this example, then click on index.html in the website directory.
13+
For starters, this needs Cross Site Isolation (setting 2 headers), which is [required for this approach to workers](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer#security_requirements).
14+
We've added them in the trunk config.
1315

1416
These same headers are also required during deployment. Github pages does not allow setting headers, and alternatives such as using `<meta>` did not work in my testing, so these sites can't be deployed like that. Cloudflare Pages is a free alternative that allows setting headers that worked for me.
1517

1618
Then it also requires nightly Rust, because [the standard library needs to be rebuild](https://github.com/RReverser/wasm-bindgen-rayon?tab=readme-ov-file#building-rust-code).
1719

18-
Additional limitations are listed [here](https://github.com/chemicstry/wasm_thread/tree/7bc7dccebf2d96775b60bf0fda6b4173aa993aff?tab=readme-ov-file#notes-on-wasm-limitations).
20+
Additional limitations are listed [here](https://rustwasm.github.io/wasm-bindgen/examples/raytrace.html#caveats) (some of them might be solved or worked around in libraries). Specifically for `wasm_thread` limitations are explained in the comments in the source code.
1921

2022
## Advantages
2123

@@ -30,3 +32,10 @@ Additional limitations are listed [here](https://github.com/chemicstry/wasm_thre
3032
Note that this requires the [toolchain file](./rust-toolchain.toml) and the [cargo config](.cargo/config.toml).
3133

3234
The `_headers` file and its copy in `index.html` is simply an example of how to set the headers using Cloudflare Pages.
35+
36+
If you get errors such as
37+
38+
> [Firefox] The WebAssembly.Memory object cannot be serialized. The Cross-Origin-Opener-Policy and Cross-Origin-Embedder-Policy HTTP headers can be used to enable this.
39+
> [Chrome] SharedArrayBuffer transfer requires self.crossOriginIsolated.
40+
41+
Then the headers did not set correctly. You can check the response headers on the `/` file in the network tab of the browser developer tools.

examples/wasm_threads/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@
1717
data-bindgen-target="web"
1818
/>
1919
<link data-trunk rel="copy-file" href="assets/_headers" />
20+
<p>See the console for the thread output</p>
2021
</body>
2122
</html>

0 commit comments

Comments
 (0)