Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

web: Make npm run build:dual-wasm create an MVP vanilla WASM module and make the default WASM module be with extensions #18528

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/release_nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test_extension_dockerfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
with:
toolchain: stable
targets: wasm32-unknown-unknown
components: rust-src

- name: Setup Node.js
uses: actions/setup-node@v4
Expand Down
5 changes: 3 additions & 2 deletions web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
2 changes: 1 addition & 1 deletion web/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 --",
Expand Down
33 changes: 22 additions & 11 deletions web/packages/core/tools/build_wasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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",
});
Expand All @@ -95,13 +103,16 @@ 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") {
console.log(`Building ${flavor} with cargo...`);
cargoBuild({
profile,
rustFlags,
extensions,
});
originalWasmPath = `../../../target/wasm32-unknown-unknown/${profile}/ruffle_web.wasm`;
if (wasmSource === "cargo_and_store") {
Expand Down Expand Up @@ -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) {
Expand All @@ -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");
}
Loading