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: Allow building an MVP vanilla WASM module #18528

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 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
21 changes: 20 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,27 @@ 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"]
? [
process.env["NIGHTLY_VERSION"]
? `+nightly-${process.env["NIGHTLY_VERSION"]}`
: "+nightly",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is the following commands should work in CI:

rustup install nightly-2024-12-02
rustup target add wasm32-unknown-unknown --toolchain nightly-2024-12-02
BUILD_WASM_MVP=1 NIGHTLY_VERSION=2024-12-02 npm run build:repro

"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 +114,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