Skip to content

Commit 2858faa

Browse files
authored
web: Drop wasm-pack, invoke wasm-bindgen and wasm-opt directly from npm (#2482)
1 parent 1bbe3c9 commit 2858faa

File tree

6 files changed

+49
-12
lines changed

6 files changed

+49
-12
lines changed

.github/workflows/release_nightlies.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,23 @@ jobs:
8282
with:
8383
profile: minimal
8484
toolchain: stable
85+
target: wasm32-unknown-unknown
8586

8687
- name: Install linux dependencies
8788
if: matrix.os == 'ubuntu-latest'
8889
run: sudo apt-get -y install libasound2-dev libxcb-shape0-dev libxcb-xfixes0-dev
8990

90-
- name: Install wasm-pack
91-
run: cargo install wasm-pack
91+
- name: Install wasm-bindgen
92+
run: cargo install wasm-bindgen-cli
93+
94+
- name: Setup conda
95+
uses: conda-incubator/setup-miniconda@v2
96+
with:
97+
activate-environment: binaryen
98+
99+
- name: Install binaryen
100+
shell: bash -l {0}
101+
run: conda install -c conda-forge binaryen
92102

93103
- name: Setup node
94104
if: matrix.os == 'ubuntu-latest'
@@ -99,6 +109,7 @@ jobs:
99109
- name: Build web
100110
if: matrix.os == 'ubuntu-latest'
101111
working-directory: web
112+
shell: bash -l {0}
102113
run: |
103114
npm run bootstrap
104115
npm run build

.github/workflows/test_web.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,27 @@ jobs:
3333
with:
3434
profile: minimal
3535
toolchain: ${{ matrix.rust_version }}
36+
target: wasm32-unknown-unknown
3637

3738
- name: Install linux dependencies
3839
if: matrix.os == 'ubuntu-latest'
3940
run: sudo apt-get -y install libasound2-dev libxcb-shape0-dev libxcb-xfixes0-dev
4041

41-
- name: Install wasm-pack
42-
run: cargo install wasm-pack
42+
- name: Install wasm-bindgen
43+
run: cargo install wasm-bindgen-cli
44+
45+
- name: Setup conda
46+
uses: conda-incubator/setup-miniconda@v2
47+
with:
48+
activate-environment: binaryen
49+
50+
- name: Install binaryen
51+
shell: bash -l {0}
52+
run: conda install -c conda-forge binaryen
4353

4454
- name: Build web
4555
working-directory: web
56+
shell: bash -l {0}
4657
run: |
4758
npm run bootstrap
4859
npm run format:check

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ dist/
55
pkg/
66
web/packages/core/docs
77
web/packages/core/tsd
8-
wasm-pack.log
98
*.swd
109

1110
# NPM

web/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,3 @@ features = [
5656
[dev-dependencies]
5757
wasm-bindgen-test = "0.3.19"
5858

59-
[package.metadata.wasm-pack.profile.release]
60-
wasm-opt = ['-O', '-g']

web/README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,29 @@ We do not have a Minimum Supported Rust Version policy. If it fails to build, it
4444
to update to the latest stable version of rust. You may run `rustup update` to do this (if you installed
4545
rust using the above instructions).
4646

47+
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+
4749
#### Node.js
4850

4951
Follow the instructions [to install node.js](https://nodejs.org/en/) on your machine.
5052

5153
We recommend using the currently active LTS 12, but we do also run tests with maintenance LTS 10.
5254

53-
#### wasm-pack
55+
#### wasm-bindgen
56+
57+
This can be installed with `cargo install wasm-bindgen-cli`.
58+
59+
#### Binaryen
60+
61+
This is optional, used to further optimize the built WebAssembly module.
62+
Some ways to install Binaryen:
63+
- download one of the [prebuilt releases](https://github.com/WebAssembly/binaryen/releases/)
64+
- using your Linux distribution's package manager (`sudo apt install binaryen`, `sudo dnf install binaryen`)
65+
- from [Homebrew](https://formulae.brew.sh/formula/binaryen)
66+
- from [Anaconda](https://anaconda.org/conda-forge/binaryen)
67+
- [compile it yourself](https://github.com/WebAssembly/binaryen#building)
5468

55-
Follow the instructions [to install wasm-pack](https://rustwasm.github.io/wasm-pack/installer/) on your machine.
69+
Just make sure the `wasm-opt` program is in `$PATH`, and that it works.
5670

5771
### Building
5872

web/packages/core/package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99
"pkg/"
1010
],
1111
"scripts": {
12-
"build": "npm run build:wasm && npm run build:ts",
12+
"build": "npm run build:cargo && npm run build:wasm-bindgen && npm run build:wasm-opt && npm run build:ts",
13+
"build:cargo": "cargo build --release --target wasm32-unknown-unknown",
14+
"build:wasm-bindgen": "wasm-bindgen ../../../target/wasm32-unknown-unknown/release/ruffle_web.wasm --out-dir ./pkg --out-name ruffle_web",
15+
"build:wasm-opt": "wasm-opt ./pkg/ruffle_web_bg.wasm -O -g --output ./pkg/ruffle_web_bg.opt.wasm && move-file ./pkg/ruffle_web_bg.opt.wasm ./pkg/ruffle_web_bg.wasm || npm run build:wasm-opt-note",
16+
"build:wasm-opt-note": "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.'",
1317
"build:ts": "tsc -d && node tools/set_version.js",
14-
"build:wasm": "wasm-pack build ../../ --out-dir packages/core/pkg",
1518
"docs": "typedoc",
1619
"test": "mocha -r esm -r ts-node/register test/**.ts"
1720
},
@@ -28,7 +31,8 @@
2831
"replace-in-file": "^6.1.0",
2932
"ts-node": "^9.0.0",
3033
"typedoc": "^0.20.0",
31-
"typescript": "^4.0.5"
34+
"typescript": "^4.0.5",
35+
"move-file-cli": "^2.0.0"
3236
},
3337
"dependencies": {
3438
"@types/source-map": "^0.5.2"

0 commit comments

Comments
 (0)