Skip to content

Commit

Permalink
Enable some Wasm features during the build (#356)
Browse files Browse the repository at this point in the history
* Enable some Wasm features during the build

* More comments

* CHANGELOG
  • Loading branch information
tomaka authored Mar 28, 2023
1 parent 15afeca commit d8287a4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions wasm-node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Add an arbitrary limit to the size of unprocessed networking packets, in order to avoid DoS attacks. This limit is necessary in order to bypass limitations in the networking APIs exposed by browsers. ([#312](https://github.com/smol-dot/smoldot/pull/312))
- Rename `/webrtc` to `/webrtc-direct` in multiaddresses, in accordance with the rest of the libp2p ecosystem. ([#326](https://github.com/smol-dot/smoldot/pull/326))
- Improved the ganularity of the tasks that handle JSON-RPC requests and libp2p connections. Smoldot now yields more often to the browser, reducing the chances and the severity of freezes during the rendering of the web page. ([#349](https://github.com/smol-dot/smoldot/pull/349))
- Smoldot is now compiled with the `bulk-memory-operations` and `sign-extensions-ops` WebAssembly features enabled. This is expected to considerably speed up its execution. The minimum version required to run smoldot is now Chrome 75, Firefox 79, NodeJS v12.5, and Deno v0.4. ([#356](https://github.com/smol-dot/smoldot/pull/356))

### Fixed

Expand Down
12 changes: 11 additions & 1 deletion wasm-node/javascript/prepare.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,20 @@ child_process.execSync(

// The important step in this script is running `cargo build --target wasm32-wasi` on the Rust
// code. This generates a `wasm` file in `target/wasm32-wasi`.
// Some optional Wasm features are enabled during the compilation in order to speed up the
// execution of smoldot.
// Note that this doesn't enable these features in the Rust standard library (which comes
// precompiled), but the missing optimizations shouldn't be too much of a problem. The Rust
// standard library could be compiled with these features using the `-Z build-std` flag, but at
// the time of the writing of this comment this would require an unstable version of Rust.
// Use `rustc --print target-features --target wasm32-wasi` to see the list of target features.
// See <https://webassembly.org/roadmap/> to know which version of which engine supports which
// feature.
// See also the issue: <https://github.com/smol-dot/smoldot/issues/350>
child_process.execSync(
"cargo +" + rustVersion + " build --package smoldot-light-wasm --target wasm32-wasi --no-default-features " +
(buildProfile == 'debug' ? '' : ("--profile " + buildProfile)),
{ 'stdio': 'inherit' }
{ 'stdio': 'inherit', 'env': { 'RUSTFLAGS': '-C target-feature=+bulk-memory,+sign-ext', ...process.env } }
);

// The code below will write a variable number of files to the `src/instance/autogen` directory.
Expand Down

0 comments on commit d8287a4

Please sign in to comment.