Skip to content

Commit

Permalink
web: Allow building an MVP vanilla WASM module
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhjacobs committed Dec 2, 2024
1 parent 6a8f77c commit f008fb2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
19 changes: 18 additions & 1 deletion web/packages/core/tools/build_wasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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") {
Expand Down

0 comments on commit f008fb2

Please sign in to comment.