From d53eb0d770333e43f0098bb3f6797d5c2f85a1ce 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 --- .github/workflows/release_nightly.yml | 1 + .github/workflows/test_extension_dockerfile.yml | 1 + .github/workflows/test_web.yml | 2 ++ web/README.md | 2 ++ web/docker/Dockerfile | 2 +- web/packages/core/tools/build_wasm.ts | 11 +++++++++++ 6 files changed, 18 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release_nightly.yml b/.github/workflows/release_nightly.yml index df3fbba9ef9c..07547e351fdc 100644 --- a/.github/workflows/release_nightly.yml +++ b/.github/workflows/release_nightly.yml @@ -336,6 +336,7 @@ jobs: with: toolchain: 1.81.0 targets: wasm32-unknown-unknown + components: rust-src - name: Setup Node.js uses: actions/setup-node@v4 diff --git a/.github/workflows/test_extension_dockerfile.yml b/.github/workflows/test_extension_dockerfile.yml index 27acaa7c89e7..f15d5ee104f7 100644 --- a/.github/workflows/test_extension_dockerfile.yml +++ b/.github/workflows/test_extension_dockerfile.yml @@ -21,6 +21,7 @@ jobs: with: toolchain: stable targets: wasm32-unknown-unknown + components: rust-src - name: Setup Node.js uses: actions/setup-node@v4 diff --git a/.github/workflows/test_web.yml b/.github/workflows/test_web.yml index 83c51c795424..29ce7cc0e152 100644 --- a/.github/workflows/test_web.yml +++ b/.github/workflows/test_web.yml @@ -52,6 +52,7 @@ jobs: uses: dtolnay/rust-toolchain@stable with: targets: wasm32-unknown-unknown + components: rust-src - name: Cache Cargo output uses: Swatinem/rust-cache@v2 @@ -117,6 +118,7 @@ jobs: uses: dtolnay/rust-toolchain@stable with: targets: wasm32-unknown-unknown + components: rust-src - name: Cache Cargo output uses: Swatinem/rust-cache@v2 diff --git a/web/README.md b/web/README.md index fef30a31af9f..8b6c848d551c 100644 --- a/web/README.md +++ b/web/README.md @@ -45,6 +45,7 @@ to update to the latest stable version of rust. You may run `rustup update` to d rust using the above instructions). For the compiler to be able to output WebAssembly, an additional target has to be added to it: `rustup target add wasm32-unknown-unknown` +Because we use `RUSTC_BOOTSTRAP` in order to use certain Nightly flags with stable Rust you will also need to run `rustup component add rust-src`. #### Java @@ -106,6 +107,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. + - You will also need to run `rustup component add rust-src` with either of the previous two commands since we rebuild std for the vanilla WASM module. 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/docker/Dockerfile b/web/docker/Dockerfile index 1f2797972708..eafcaa30b193 100644 --- a/web/docker/Dockerfile +++ b/web/docker/Dockerfile @@ -11,7 +11,7 @@ RUN wget --progress=:giga https://github.com/WebAssembly/binaryen/releases/downl mv wasm-opt /usr/local/bin # Installing Rust using rustup: -RUN wget 'https://sh.rustup.rs' --quiet -O- | sh -s -- -y --profile minimal --target wasm32-unknown-unknown +RUN wget 'https://sh.rustup.rs' --quiet -O- | sh -s -- -y --profile minimal --target wasm32-unknown-unknown --component rust-src ENV PATH="/root/.cargo/bin:$PATH" # wasm-bindgen-cli version must match wasm-bindgen crate version. # Be sure to update in test_web.yml, release_nightly.yml, Cargo.toml, and web/README.md as well. diff --git a/web/packages/core/tools/build_wasm.ts b/web/packages/core/tools/build_wasm.ts index 61c93ea52c3a..34a8842abc2a 100644 --- a/web/packages/core/tools/build_wasm.ts +++ b/web/packages/core/tools/build_wasm.ts @@ -42,12 +42,19 @@ function cargoBuild({ profile, features, rustFlags, + extensions, }: { profile?: string; features?: string[]; rustFlags?: string[]; + extensions?: boolean; }) { let args = ["build", "--locked", "--target", "wasm32-unknown-unknown"]; + if (!extensions) { + args.push("-Z"); + args.push("build-std=std,panic_abort"); + } + if (profile) { args.push("--profile", profile); } @@ -73,6 +80,7 @@ function cargoBuild({ execFileSync("cargo", args, { env: Object.assign(Object.assign({}, process.env), { RUSTFLAGS: totalRustFlags, + RUSTC_BOOTSTRAP: extensions ? "0" : "1", }), stdio: "inherit", }); @@ -95,6 +103,8 @@ function buildWasm( ); wasmBindgenFlags.push("--reference-types"); wasmOptFlags.push("--enable-reference-types"); + } else { + rustFlags.push("-C", "target-cpu=mvp"); } let originalWasmPath; if (wasmSource === "cargo" || wasmSource === "cargo_and_store") { @@ -102,6 +112,7 @@ function buildWasm( cargoBuild({ profile, rustFlags, + extensions, }); originalWasmPath = `../../../target/wasm32-unknown-unknown/${profile}/ruffle_web.wasm`; if (wasmSource === "cargo_and_store") { From 399264c66d34c65cb08e8b61c3ecccfe23fa589f Mon Sep 17 00:00:00 2001 From: Daniel Jacobs Date: Thu, 9 Jan 2025 14:38:29 -0500 Subject: [PATCH 2/2] web: Make the default WASM module for `npm run build` be with extensions --- .github/workflows/test_web.yml | 2 -- web/README.md | 5 ++--- web/package.json | 4 ++-- web/packages/core/tools/build_wasm.ts | 22 +++++++++++----------- 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/.github/workflows/test_web.yml b/.github/workflows/test_web.yml index 29ce7cc0e152..83c51c795424 100644 --- a/.github/workflows/test_web.yml +++ b/.github/workflows/test_web.yml @@ -52,7 +52,6 @@ jobs: uses: dtolnay/rust-toolchain@stable with: targets: wasm32-unknown-unknown - components: rust-src - name: Cache Cargo output uses: Swatinem/rust-cache@v2 @@ -118,7 +117,6 @@ jobs: uses: dtolnay/rust-toolchain@stable with: targets: wasm32-unknown-unknown - components: rust-src - name: Cache Cargo output uses: Swatinem/rust-cache@v2 diff --git a/web/README.md b/web/README.md index 8b6c848d551c..9b54f123641c 100644 --- a/web/README.md +++ b/web/README.md @@ -45,7 +45,6 @@ to update to the latest stable version of rust. You may run `rustup update` to d rust using the above instructions). For the compiler to be able to output WebAssembly, an additional target has to be added to it: `rustup target add wasm32-unknown-unknown` -Because we use `RUSTC_BOOTSTRAP` in order to use certain Nightly flags with stable Rust you will also need to run `rustup component add rust-src`. #### Java @@ -104,8 +103,8 @@ In this project, you may run the following commands to build all packages: - This will build the wasm binary and every node package (notably selfhosted and extension). - Output will be available in the `dist/` folder of each package (for example, `./packages/selfhosted/dist`). - You may also use `npm run build:debug` to disable Webpack optimizations and activate the (extremely verbose) ActionScript debugging output. - - 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. + - There is `npm run build:dual-wasm` as well, to build a second WebAssembly module that disables all supported WebAssembly extensions, + potentially resulting in support for more browsers, 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. - You will also need to run `rustup component add rust-src` with either of the previous two commands since we rebuild std for the vanilla WASM module. diff --git a/web/package.json b/web/package.json index 8f85844447d4..989c0a35c3c5 100644 --- a/web/package.json +++ b/web/package.json @@ -45,8 +45,8 @@ "scripts": { "build": "npm run build --workspace=ruffle-core && npm run build --workspace=ruffle-demo --workspace=ruffle-extension --workspace=ruffle-selfhosted", "build:debug": "cross-env NODE_ENV=development CARGO_FEATURES=avm_debug npm run build", - "build:dual-wasm": "cross-env ENABLE_WASM_EXTENSIONS=true npm run build", - "build:repro": "cross-env ENABLE_WASM_EXTENSIONS=true ENABLE_VERSION_SEAL=true npm run build", + "build:dual-wasm": "cross-env BUILD_WASM_MVP=true npm run build", + "build:repro": "cross-env BUILD_WASM_MVP=true ENABLE_VERSION_SEAL=true npm run build", "demo": "npm run preview --workspace ruffle-demo", "test": "npm test --workspaces --if-present", "wdio": "npm run wdio --workspaces --if-present --", diff --git a/web/packages/core/tools/build_wasm.ts b/web/packages/core/tools/build_wasm.ts index 34a8842abc2a..bab1d3a41b28 100644 --- a/web/packages/core/tools/build_wasm.ts +++ b/web/packages/core/tools/build_wasm.ts @@ -155,7 +155,7 @@ function detectWasmOpt() { return false; } } -const buildExtensions = !!process.env["ENABLE_WASM_EXTENSIONS"]; +const buildWasmMvp = !!process.env["BUILD_WASM_MVP"]; const wasmSource = process.env["WASM_SOURCE"] || "cargo"; const hasWasmOpt = detectWasmOpt(); if (!hasWasmOpt) { @@ -167,15 +167,15 @@ if (wasmSource === "cargo_and_store") { rmSync("../../dist", { recursive: true, force: true }); mkdirSync("../../dist"); } -buildWasm("web-vanilla-wasm", "ruffle_web", hasWasmOpt, false, wasmSource); -if (buildExtensions) { - buildWasm( - "web-wasm-extensions", - "ruffle_web-wasm_extensions", - hasWasmOpt, - true, - wasmSource, - ); +buildWasm( + "web-wasm-extensions", + "ruffle_web-wasm_extensions", + hasWasmOpt, + true, + wasmSource, +); +if (buildWasmMvp) { + buildWasm("web-vanilla-wasm", "ruffle_web", hasWasmOpt, false, wasmSource); } else { - copyStandIn("ruffle_web", "ruffle_web-wasm_extensions"); + copyStandIn("ruffle_web-wasm_extensions", "ruffle_web"); }