From f008fb265429a7e3fb65ed04bc310ac0f464bee2 Mon Sep 17 00:00:00 2001 From: Daniel Jacobs Date: Fri, 8 Nov 2024 15:33:00 -0500 Subject: [PATCH 1/2] web: Allow building an MVP vanilla WASM module --- web/README.md | 1 + web/packages/core/tools/build_wasm.ts | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/web/README.md b/web/README.md index 9393fce7fc9a..51be380d425b 100644 --- a/web/README.md +++ b/web/README.md @@ -106,6 +106,7 @@ In this project, you may run the following commands to build all packages: - There is `npm run build:dual-wasm` as well, to build a second WebAssembly module that makes use of some WebAssembly extensions, potentially resulting in better performance in browsers that support them, at the expense of longer build time. - `npm run build:repro` enables reproducible builds. Note that this also requires a `version_seal.json`, which is not provided in the normal Git repository - only specially-marked reproducible source archives. Running this without a version seal will generate one based on the current state of your environment. + - With either of the prior two commands, you can set the environment variable `BUILD_WASM_MVP=1`. This will build the vanilla WASM module using nightly Rust and disable all WebAssembly features that Rust enables by default. You will first need to run the command `rustup target add wasm32-unknown-unknown --toolchain nightly` so nightly Rust can also output WebAssembly. From here, you may follow the instructions to [use Ruffle on your website](packages/selfhosted/README.md), run a demo locally with `npm run demo`, or [install the extension in your browser](https://github.com/ruffle-rs/ruffle/wiki/Using-Ruffle#browser-extension). diff --git a/web/packages/core/tools/build_wasm.ts b/web/packages/core/tools/build_wasm.ts index 61c93ea52c3a..bb70c03d0e9b 100644 --- a/web/packages/core/tools/build_wasm.ts +++ b/web/packages/core/tools/build_wasm.ts @@ -42,12 +42,25 @@ function cargoBuild({ profile, features, rustFlags, + extensions, }: { profile?: string; features?: string[]; rustFlags?: string[]; + extensions?: boolean; }) { - let args = ["build", "--locked", "--target", "wasm32-unknown-unknown"]; + let args = + !extensions && process.env["BUILD_WASM_MVP"] + ? [ + "+nightly", + "build", + "--locked", + "-Z", + "build-std=std,panic_abort", + "--target", + "wasm32-unknown-unknown", + ] + : ["build", "--locked", "--target", "wasm32-unknown-unknown"]; if (profile) { args.push("--profile", profile); } @@ -99,9 +112,13 @@ function buildWasm( let originalWasmPath; if (wasmSource === "cargo" || wasmSource === "cargo_and_store") { console.log(`Building ${flavor} with cargo...`); + if (process.env["BUILD_WASM_MVP"]) { + rustFlags.push("-C", "target-cpu=mvp"); + } cargoBuild({ profile, rustFlags, + extensions, }); originalWasmPath = `../../../target/wasm32-unknown-unknown/${profile}/ruffle_web.wasm`; if (wasmSource === "cargo_and_store") { From 694c3b13d84c639c300518b20557dce88ac037b0 Mon Sep 17 00:00:00 2001 From: Daniel Jacobs Date: Mon, 2 Dec 2024 12:07:50 -0500 Subject: [PATCH 2/2] web: Add envvar to pin the nightly Rust version when building dual-wasm --- web/packages/core/tools/build_wasm.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/web/packages/core/tools/build_wasm.ts b/web/packages/core/tools/build_wasm.ts index bb70c03d0e9b..4ffcef2e7199 100644 --- a/web/packages/core/tools/build_wasm.ts +++ b/web/packages/core/tools/build_wasm.ts @@ -52,7 +52,9 @@ function cargoBuild({ let args = !extensions && process.env["BUILD_WASM_MVP"] ? [ - "+nightly", + process.env["NIGHTLY_VERSION"] + ? `+nightly-${process.env["NIGHTLY_VERSION"]}` + : "+nightly", "build", "--locked", "-Z",