Skip to content

Commit d53eb0d

Browse files
danielhjacobstorokati44
authored andcommitted
web: Allow building an MVP vanilla WASM module
1 parent 8d84d8b commit d53eb0d

File tree

6 files changed

+18
-1
lines changed

6 files changed

+18
-1
lines changed

.github/workflows/release_nightly.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ jobs:
336336
with:
337337
toolchain: 1.81.0
338338
targets: wasm32-unknown-unknown
339+
components: rust-src
339340

340341
- name: Setup Node.js
341342
uses: actions/setup-node@v4

.github/workflows/test_extension_dockerfile.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
with:
2222
toolchain: stable
2323
targets: wasm32-unknown-unknown
24+
components: rust-src
2425

2526
- name: Setup Node.js
2627
uses: actions/setup-node@v4

.github/workflows/test_web.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ jobs:
5252
uses: dtolnay/rust-toolchain@stable
5353
with:
5454
targets: wasm32-unknown-unknown
55+
components: rust-src
5556

5657
- name: Cache Cargo output
5758
uses: Swatinem/rust-cache@v2
@@ -117,6 +118,7 @@ jobs:
117118
uses: dtolnay/rust-toolchain@stable
118119
with:
119120
targets: wasm32-unknown-unknown
121+
components: rust-src
120122

121123
- name: Cache Cargo output
122124
uses: Swatinem/rust-cache@v2

web/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ to update to the latest stable version of rust. You may run `rustup update` to d
4545
rust using the above instructions).
4646

4747
For the compiler to be able to output WebAssembly, an additional target has to be added to it: `rustup target add wasm32-unknown-unknown`
48+
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`.
4849

4950
#### Java
5051

@@ -106,6 +107,7 @@ In this project, you may run the following commands to build all packages:
106107
- There is `npm run build:dual-wasm` as well, to build a second WebAssembly module that makes use of some WebAssembly extensions,
107108
potentially resulting in better performance in browsers that support them, at the expense of longer build time.
108109
- `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.
110+
- 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.
109111

110112
From here, you may follow the instructions to [use Ruffle on your website](packages/selfhosted/README.md),
111113
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).

web/docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ RUN wget --progress=:giga https://github.com/WebAssembly/binaryen/releases/downl
1111
mv wasm-opt /usr/local/bin
1212

1313
# Installing Rust using rustup:
14-
RUN wget 'https://sh.rustup.rs' --quiet -O- | sh -s -- -y --profile minimal --target wasm32-unknown-unknown
14+
RUN wget 'https://sh.rustup.rs' --quiet -O- | sh -s -- -y --profile minimal --target wasm32-unknown-unknown --component rust-src
1515
ENV PATH="/root/.cargo/bin:$PATH"
1616
# wasm-bindgen-cli version must match wasm-bindgen crate version.
1717
# Be sure to update in test_web.yml, release_nightly.yml, Cargo.toml, and web/README.md as well.

web/packages/core/tools/build_wasm.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,19 @@ function cargoBuild({
4242
profile,
4343
features,
4444
rustFlags,
45+
extensions,
4546
}: {
4647
profile?: string;
4748
features?: string[];
4849
rustFlags?: string[];
50+
extensions?: boolean;
4951
}) {
5052
let args = ["build", "--locked", "--target", "wasm32-unknown-unknown"];
53+
if (!extensions) {
54+
args.push("-Z");
55+
args.push("build-std=std,panic_abort");
56+
}
57+
5158
if (profile) {
5259
args.push("--profile", profile);
5360
}
@@ -73,6 +80,7 @@ function cargoBuild({
7380
execFileSync("cargo", args, {
7481
env: Object.assign(Object.assign({}, process.env), {
7582
RUSTFLAGS: totalRustFlags,
83+
RUSTC_BOOTSTRAP: extensions ? "0" : "1",
7684
}),
7785
stdio: "inherit",
7886
});
@@ -95,13 +103,16 @@ function buildWasm(
95103
);
96104
wasmBindgenFlags.push("--reference-types");
97105
wasmOptFlags.push("--enable-reference-types");
106+
} else {
107+
rustFlags.push("-C", "target-cpu=mvp");
98108
}
99109
let originalWasmPath;
100110
if (wasmSource === "cargo" || wasmSource === "cargo_and_store") {
101111
console.log(`Building ${flavor} with cargo...`);
102112
cargoBuild({
103113
profile,
104114
rustFlags,
115+
extensions,
105116
});
106117
originalWasmPath = `../../../target/wasm32-unknown-unknown/${profile}/ruffle_web.wasm`;
107118
if (wasmSource === "cargo_and_store") {

0 commit comments

Comments
 (0)