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/web/README.md b/web/README.md index fef30a31af9f..9b54f123641c 100644 --- a/web/README.md +++ b/web/README.md @@ -103,9 +103,10 @@ 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. 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/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 61c93ea52c3a..bab1d3a41b28 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") { @@ -144,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) { @@ -156,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"); }