From 44e59a00128f6b11ef60cc4cc2a8190c4e78474f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=96R=C3=96K=20Attila?= Date: Sat, 8 Jan 2022 04:45:18 +0100 Subject: [PATCH] web,ci: Only build the vanilla module by default, use it as stand-in for the other And enable the module that really uses WebAssembly extensions for the releases by running the new "npm run build:dual-wasm" command, which sets the ENABLE_WASM_EXTENSIONS=true environment variable. --- .github/workflows/release_nightly.yml | 2 +- web/README.md | 2 ++ web/package.json | 1 + web/packages/core/package.json | 18 ++++++++++++------ 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release_nightly.yml b/.github/workflows/release_nightly.yml index 51e013b20..d06227d7d 100644 --- a/.github/workflows/release_nightly.yml +++ b/.github/workflows/release_nightly.yml @@ -268,7 +268,7 @@ jobs: shell: bash -l {0} run: | npm ci - npm run build + npm run build:dual-wasm npm run docs - name: Sign Firefox extension diff --git a/web/README.md b/web/README.md index 30969e3ec..a16464098 100644 --- a/web/README.md +++ b/web/README.md @@ -85,6 +85,8 @@ In this project, you may run the following commands to build all packages: - Output will be available in the `dist/` of each package (for example, `./packages/selfhosted/dist`), save for the extension which is directory `build/`. - 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. From here, you may follow the instructions to [use Ruffle on your website](packages/selfhosted/README.md), or run a demo locally with `npm run demo`. diff --git a/web/package.json b/web/package.json index a78da9b68..992508bc5 100644 --- a/web/package.json +++ b/web/package.json @@ -39,6 +39,7 @@ "scripts": { "build": "npm run build --workspaces", "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", "demo": "npm run serve --workspace ruffle-demo", "test": "npm run test --workspaces --if-present", "docs": "npm run docs --workspaces --if-present", diff --git a/web/packages/core/package.json b/web/packages/core/package.json index e759687c2..a906bb8a9 100644 --- a/web/packages/core/package.json +++ b/web/packages/core/package.json @@ -11,18 +11,23 @@ "scripts": { "build": "npm run build:ruffle_web && npm run build:ruffle_web-wasm_extensions && npm run build:ts", - "//1": "# Unfortunately, we have to set $RUSTFLAGS here, instead of in .cargo/config.toml (for example), because it's not possible to specify them per-profile; see cargo issue #7878.", - "//2": "# Enabling 'build-std' would also be great, but it's not stable yet.", + "//1": "# Setting ENABLE_WASM_EXTENSIONS=true causes a second module to be built as well, that utilizes WebAssembly extensions, instead of it just being a 'fake' - a copy of the 'vanilla' one.", + "//2": "# Unfortunately, we have to set $RUSTFLAGS here, instead of in .cargo/config.toml (for example), because it's not possible to specify them per-profile; see cargo issue #7878.", + "//3": "# Enabling 'build-std' would also be great, but it's not stable yet.", "build:ruffle_web": "cross-env OUT_NAME=ruffle_web RUSTFLAGS=\"--cfg=web_sys_unstable_apis\" npm run build:cargo_bindgen_opt", - "build:ruffle_web-wasm_extensions": "echo \"Building module with WebAssembly extensions\" && cross-env OUT_NAME=ruffle_web-wasm_extensions RUSTFLAGS=\"--cfg=web_sys_unstable_apis -C target-feature=+bulk-memory,+simd128,+nontrapping-fptoint,+sign-ext\" npm run build:cargo_bindgen_opt", - "//3": "# This just chains together the three commands after it.", + "//4": "# Dispatches to either building the real, or copying the fake (stand-in), 'with-extensions' module.", + "build:ruffle_web-wasm_extensions": "node -e \"process.exit(process.env.ENABLE_WASM_EXTENSIONS == 'true' ? 0 : 1)\" && npm run build:ruffle_web-wasm_extensions-real || npm run build:ruffle_web-wasm_extensions-fake", + "build:ruffle_web-wasm_extensions-real": "echo \"Building module with WebAssembly extensions\" && cross-env OUT_NAME=ruffle_web-wasm_extensions RUSTFLAGS=\"--cfg=web_sys_unstable_apis -C target-feature=+bulk-memory,+simd128,+nontrapping-fptoint,+sign-ext\" npm run build:cargo_bindgen_opt", + "build:ruffle_web-wasm_extensions-fake": "echo \"Copying the vanilla module as stand-in\" && shx cp ./pkg/ruffle_web_bg.wasm ./pkg/ruffle_web-wasm_extensions_bg.wasm && shx cp ./pkg/ruffle_web_bg.wasm.d.ts ./pkg/ruffle_web-wasm_extensions_bg.wasm.d.ts && shx cp ./pkg/ruffle_web.js ./pkg/ruffle_web-wasm_extensions.js && shx cp ./pkg/ruffle_web.d.ts ./pkg/ruffle_web-wasm_extensions.d.ts", + + "//5": "# This just chains together the three commands after it.", "build:cargo_bindgen_opt": "npm run build:cargo && npm run build:wasm-bindgen && npm run build:wasm-opt", "build:cargo": "cross-env-shell \"cargo build --release --target wasm32-unknown-unknown --features \\\"$CARGO_FEATURES\\\"\"", - "build:wasm-bindgen": "cross-env-shell \"wasm-bindgen ../../../target/wasm32-unknown-unknown/release/ruffle_web.wasm --target web --out-dir ./pkg --out-name $OUT_NAME\"", - "build:wasm-opt": "cross-env-shell \"wasm-opt -o ./pkg/${OUT_NAME}_bg.wasm -O -g ./pkg/${OUT_NAME}_bg.wasm || npm run build:wasm-opt-failed\"", + "build:wasm-bindgen": "cross-env-shell wasm-bindgen \"../../../target/wasm32-unknown-unknown/release/ruffle_web.wasm\" --target web --out-dir ./pkg --out-name \"$OUT_NAME\"", + "build:wasm-opt": "cross-env-shell wasm-opt -o \"./pkg/${OUT_NAME}_bg.wasm\" -O -g \"./pkg/${OUT_NAME}_bg.wasm\" || npm run build:wasm-opt-failed", "build:wasm-opt-failed": "echo 'NOTE: Since wasm-opt could not be found (or it failed), the resulting module might not perform that well, but it should still work.' && echo ; [ \"$CI\" != true ] # > nul", @@ -41,6 +46,7 @@ "eslint-plugin-jsdoc": "^37.1.0", "mocha": "^9.1.3", "replace-in-file": "^6.3.2", + "shx": "^0.3.3", "ts-node": "^10.4.0", "typedoc": "^0.22.10", "typescript": "^4.5.2"