wasm-bindgen 0.2.92

Easy support for interacting between JS and Rust.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
name: CI
on:
  push:
    branches: [main]
    tags-ignore: [dev]
  pull_request:
    branches: [main]
defaults:
  run:
    shell: bash

# Cancel any in-flight jobs for the same PR/branch so there's only one active
# at a time
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

permissions:
  contents: read #  to fetch code (actions/checkout)

jobs:
  # Check Code style quickly by running `rustfmt` over all code
  rustfmt:
    name: Rustfmt
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - run: rustup update --no-self-update stable && rustup default stable
    - run: rustup component add rustfmt
    - run: cargo fmt --all -- --check

  # Run `cargo check` over everything
  check:
    name: Check
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - run: rustup update --no-self-update stable && rustup default stable
    - run: cargo check --all

  # Run `cargo clippy` over everything
  clippy:
    name: Clippy
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - run: rustup update --no-self-update stable && rustup default stable
    - run: rustup target add wasm32-unknown-unknown
    - run: cargo clippy --no-deps --all-features -p wasm-bindgen-backend -- -D warnings
    - run: cargo clippy --no-deps --all-features -p wasm-bindgen-cli -- -D warnings
    - run: cargo clippy --no-deps --all-features -p wasm-bindgen-cli-support -- -D warnings
    - run: cargo clippy --no-deps --all-features -p example-tests -- -D warnings
    - run: cargo clippy --no-deps --all-features -p wasm-bindgen-externref-xform -- -D warnings
    - run: cargo clippy --no-deps --all-features --target wasm32-unknown-unknown -p wasm-bindgen-futures -- -D warnings
    - run: cargo clippy --no-deps --all-features --target wasm32-unknown-unknown -p js-sys -- -D warnings
    - run: cargo clippy --no-deps --all-features -p wasm-bindgen-macro -- -D warnings
    - run: cargo clippy --no-deps --all-features -p wasm-bindgen-macro-support -- -D warnings
    - run: cargo clippy --no-deps --all-features -p wasm-bindgen-multi-value-xform -- -D warnings
    - run: cargo clippy --no-deps --all-features -p wasm-bindgen-shared -- -D warnings
    - run: cargo clippy --no-deps --all-features --target wasm32-unknown-unknown -p wasm-bindgen-test -- -D warnings
    - run: cargo clippy --no-deps --all-features -p wasm-bindgen-test-macro -- -D warnings
    - run: cargo clippy --no-deps --all-features -p wasm-bindgen-threads-xform -- -D warnings
    - run: cargo clippy --no-deps --all-features --target wasm32-unknown-unknown -p typescript-tests -- -D warnings
    - run: cargo clippy --no-deps --all-features -p wasm-bindgen-wasm-conventions -- -D warnings
    - run: cargo clippy --no-deps --all-features -p wasm-bindgen-wasm-interpreter -- -D warnings
    - run: cargo clippy --no-deps --all-features -p wasm-bindgen-webidl -- -D warnings
    - run: cargo clippy --no-deps --all-features -p webidl-tests -- -D warnings
    - run: cargo clippy --no-deps --all-features --target wasm32-unknown-unknown -p web-sys -- -D warnings
    - run: cargo clippy --no-deps --all-features --target wasm32-unknown-unknown -- -D warnings
    - run: cargo clippy --no-deps --all-features --target wasm32-unknown-unknown --tests -- -D warnings
    - run: cargo clippy --no-deps --all-features --target wasm32-unknown-unknown -p wasm-bindgen-benchmark -- -D warnings
    - run: for i in examples/*/; do cd "$i"; cargo +stable clippy --no-deps --all-features --target wasm32-unknown-unknown -- -D warnings || exit 1; cd ../..; done

  test_wasm_bindgen:
    name: "Run wasm-bindgen crate tests (unix)"
    runs-on: ubuntu-latest
    env:
      WASM_BINDGEN_SPLIT_LINKED_MODULES: 1
    steps:
    - uses: actions/checkout@v4
    - run: rustup update --no-self-update stable && rustup default stable
    - run: rustup target add wasm32-unknown-unknown
    - uses: actions/setup-node@v4
      with:
        node-version: '20'
    - uses: ./.github/actions/setup-geckodriver
    - run: cargo test --target wasm32-unknown-unknown
    - run: cargo test --target wasm32-unknown-unknown --features serde-serialize
    - run: cargo test --target wasm32-unknown-unknown --features enable-interning
    - run: cargo test --target wasm32-unknown-unknown -p wasm-bindgen-futures
    - run: cargo test --target wasm32-unknown-unknown --test wasm
      env:
        WASM_BINDGEN_NO_DEBUG: 1
    - run: cargo test --target wasm32-unknown-unknown
      env:
        WASM_BINDGEN_EXTERNREF: 1
    - run: cargo test --target wasm32-unknown-unknown
      env:
        WASM_BINDGEN_MULTI_VALUE: 1

  test_threads:
    name: "Run wasm-bindgen crate tests with multithreading enabled"
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - run: rustup default nightly-2024-02-06
    - run: rustup target add wasm32-unknown-unknown
    - run: rustup component add rust-src
    # Note: we only run the browser tests here, because wasm-bindgen doesn't support threading in Node yet.
    - run: |
        RUSTFLAGS='-C target-feature=+atomics,+bulk-memory,+mutable-globals' \
          cargo test --target wasm32-unknown-unknown --test headless -Z build-std=std,panic_abort

  # I don't know why this is failing so comment this out for now, but ideally
  # this would be figured out at some point and solved.
  # test_wasm_bindgen_windows:
  #   name: "Run wasm-bindgen crate tests (Windows)"
  #   runs-on: windows-latest
  #   steps:
  #   - uses: actions/checkout@v4
  #   - run: rustup update --no-self-update stable && rustup default stable
  #   - run: rustup target add wasm32-unknown-unknown
  #   - uses: actions/setup-node@v4
  #     with:
  #       node-version: '20'
  #   - uses: ./.github/actions/setup-geckodriver
  #   - run: cargo test --target wasm32-unknown-unknown
  #     env:
  #       RUST_LOG: wasm_bindgen_test_runner
  #       GECKODRIVER_ARGS: --log trace
  #   - run: cargo test --target wasm32-unknown-unknown -p js-sys
  #   - run: cargo test --target wasm32-unknown-unknown -p webidl-tests
  #     env:
  #       WBINDGEN_I_PROMISE_JS_SYNTAX_WORKS_IN_NODE: 1
  #   - run: cargo build --manifest-path crates/web-sys/Cargo.toml --target wasm32-unknown-unknown --features "Node Window Document"

  test_native:
    name: Run native tests
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - run: rustup update --no-self-update stable && rustup default stable
    - run: rustup target add wasm32-unknown-unknown
    - uses: actions/setup-node@v4
      with:
        node-version: '20'
    - run: cargo test
    - run: cargo test -p wasm-bindgen-cli-support
    - run: cargo test -p wasm-bindgen-cli
    - run: cargo test -p wasm-bindgen-externref-xform
    - run: cargo test -p wasm-bindgen-macro-support
    - run: cargo test -p wasm-bindgen-multi-value-xform
    - run: cargo test -p wasm-bindgen-wasm-interpreter
    - run: cargo test -p wasm-bindgen-futures
    - run: cargo test -p wasm-bindgen-shared

  test_web_sys:
    name: "Run web-sys crate tests"
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - run: rustup update --no-self-update stable && rustup default stable
    - run: rustup target add wasm32-unknown-unknown
    - uses: actions/setup-node@v4
      with:
        node-version: '20'
    - uses: ./.github/actions/setup-geckodriver
    - run: cargo build --manifest-path crates/web-sys/Cargo.toml --target wasm32-unknown-unknown
    - run: cargo build --manifest-path crates/web-sys/Cargo.toml --target wasm32-unknown-unknown --features Node
    - run: cargo build --manifest-path crates/web-sys/Cargo.toml --target wasm32-unknown-unknown --features Element
    - run: cargo build --manifest-path crates/web-sys/Cargo.toml --target wasm32-unknown-unknown --features Window
    - run: cargo test --manifest-path crates/web-sys/Cargo.toml --target wasm32-unknown-unknown --all-features
    - run: cargo test --manifest-path crates/web-sys/Cargo.toml --target wasm32-unknown-unknown --all-features
      env:
        RUSTFLAGS: --cfg=web_sys_unstable_apis

  check_web_sys:
    name: "Verify that web-sys is compiled correctly"
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - run: rustup update --no-self-update stable && rustup default stable
    - run: cd crates/web-sys && cargo run --release --package wasm-bindgen-webidl -- webidls src/features ./Cargo.toml
    - run: git diff --exit-code

  test_js_sys:
    name: "Run js-sys crate tests"
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - run: rustup update --no-self-update stable && rustup default stable
    - run: rustup target add wasm32-unknown-unknown
    - uses: actions/setup-node@v4
      with:
        node-version: '20'
    - uses: ./.github/actions/setup-geckodriver
    - run: cargo test -p js-sys --target wasm32-unknown-unknown
    - run: cargo test -p js-sys --target wasm32-unknown-unknown
      env:
        RUSTFLAGS: --cfg=js_sys_unstable_apis

  test_webidl:
    name: "Run wasm-bindgen-webidl crate tests"
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - run: rustup update --no-self-update stable && rustup default stable
    - run: rustup target add wasm32-unknown-unknown
    - uses: actions/setup-node@v4
      with:
        node-version: '20'
    - run: cargo test -p wasm-bindgen-webidl
    - run: cargo test -p webidl-tests --target wasm32-unknown-unknown
      env:
        WBINDGEN_I_PROMISE_JS_SYNTAX_WORKS_IN_NODE: 1
    - run: cargo test -p webidl-tests --target wasm32-unknown-unknown
      env:
        RUSTFLAGS: --cfg=web_sys_unstable_apis

  test_typescript_output:
    name: "Test TypeScript output of wasm-bindgen"
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - run: rustup update --no-self-update stable && rustup default stable
    - run: rustup target add wasm32-unknown-unknown
    - uses: actions/setup-node@v4
      with:
        node-version: '20'
    - run: cd crates/typescript-tests && ./run.sh

  test_deno:
    name: "Build and test the deno example"
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - run: rustup update --no-self-update stable && rustup default stable
    - run: rustup target add wasm32-unknown-unknown
    - uses: denoland/setup-deno@v1
      with:
        deno-version: v1.x
    - run: cd examples/deno && ./build.sh && deno run --allow-read test.ts

  test_ui:
    name: Run UI compile-fail tests
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - run: rustup update --no-self-update 1.76.0 && rustup default 1.76.0
    - run: cargo test -p wasm-bindgen-macro
    - run: cargo test -p wasm-bindgen-test-macro

  build_examples:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - run: rustup update --no-self-update stable && rustup default stable
    - run: rustup target add wasm32-unknown-unknown
    - run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh -s -- -f
    - run: |
        curl -L https://github.com/WebAssembly/binaryen/releases/download/version_112/binaryen-version_112-x86_64-linux.tar.gz -sSf > binaryen-version_112-x86_64-linux.tar.gz
        tar -xz -f binaryen-version_112-x86_64-linux.tar.gz binaryen-version_112/bin/wasm2js
        echo "$PWD/binaryen-version_112/bin" >> $GITHUB_PATH
    - run: |
        cargo build -p wasm-bindgen-cli
        ln -snf `pwd`/target/debug/wasm-bindgen $(dirname `which cargo`)/wasm-bindgen
    - run: mv _package.json package.json && npm install && rm package.json
    - run: |
        for dir in `ls examples | grep -v README | grep -v raytrace | grep -v deno | grep -v wasm-audio-worklet`; do
          (cd examples/$dir &&
            (npm run build -- --output-path ../../exbuild/$dir ||
              (./build.sh && mkdir -p ../../exbuild/$dir && cp -r ./* ../../exbuild/$dir && rm ../../exbuild/$dir/**/.gitignore))
          ) || exit 1;
        done
      env:
        RUSTFLAGS: --cfg=web_sys_unstable_apis
    - uses: actions/upload-artifact@v4
      with:
        name: examples1
        path: exbuild

  build_nightly:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - run: rustup default nightly-2024-02-06
    - run: rustup target add wasm32-unknown-unknown
    - run: rustup component add rust-src
    - run: |
        for dir in raytrace-parallel wasm-audio-worklet; do
          (cd examples/$dir &&
            ./build.sh && mkdir -p ../../exbuild/$dir && cp -r ./* ../../exbuild/$dir
          ) || exit 1;
        done
    - uses: actions/upload-artifact@v4
      with:
        name: examples2
        path: exbuild

  test_examples:
    needs:
    - build_examples
    - build_nightly
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - uses: actions/download-artifact@v4
      with:
        name: examples1
        path: exbuild
    - uses: actions/download-artifact@v4
      with:
        name: examples2
        path: exbuild
    - run: rustup update --no-self-update stable && rustup default stable
    - run: cargo test -p example-tests
      env:
        EXBUILD: ${{ github.workspace }}/exbuild

  build_benchmarks:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - run: rustup update --no-self-update stable && rustup default stable
    - run: rustup target add wasm32-unknown-unknown
    - run: cargo build --manifest-path benchmarks/Cargo.toml --release --target wasm32-unknown-unknown
    - run: cargo run -p wasm-bindgen-cli -- target/wasm32-unknown-unknown/release/wasm_bindgen_benchmark.wasm --out-dir benchmarks/pkg --target web
    - uses: actions/upload-artifact@v4
      with:
        name: benchmarks
        path: benchmarks

  dist_linux_x86_64_musl:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - run: rustup update --no-self-update stable && rustup default stable
    - run: rustup target add x86_64-unknown-linux-musl
    - run: sudo apt update -y && sudo apt install musl-tools -y
    - run: |
        cargo build --manifest-path crates/cli/Cargo.toml --target x86_64-unknown-linux-musl --features vendored-openssl --release
        strip -g target/x86_64-unknown-linux-musl/release/wasm-bindgen
        strip -g target/x86_64-unknown-linux-musl/release/wasm-bindgen-test-runner
        strip -g target/x86_64-unknown-linux-musl/release/wasm2es6js
    - uses: actions/upload-artifact@v4
      with:
        name: dist_linux_x86_64_musl
        path: "target/x86_64-unknown-linux-musl/release/wasm*"

  dist_linux_aarch64_gnu:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - run: rustup update --no-self-update stable && rustup default stable
    - run: rustup target add aarch64-unknown-linux-gnu
    - run: sudo apt update -y && sudo apt install gcc-aarch64-linux-gnu -y
    - run: |
        cargo build --manifest-path crates/cli/Cargo.toml --target aarch64-unknown-linux-gnu --features vendored-openssl --release
      env:
        CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
    - uses: actions/upload-artifact@v4
      with:
        name: dist_linux_aarch64_gnu
        path: "target/aarch64-unknown-linux-gnu/release/wasm*"

  dist_macos_x86_64:
    runs-on: macos-latest
    steps:
    - uses: actions/checkout@v4
    - run: rustup update --no-self-update stable && rustup default stable
    - run: cargo build --manifest-path crates/cli/Cargo.toml --release
      env:
        MACOSX_DEPLOYMENT_TARGET: 10.7
    - uses: actions/upload-artifact@v4
      with:
        name: dist_macos_x86_64
        path: "target/release/wasm*"

  dist_macos_aarch64:
    runs-on: macos-latest
    steps:
    - uses: actions/checkout@v4
    - run: rustup update --no-self-update stable && rustup default stable
    - run: rustup target add aarch64-apple-darwin
    - run: |
        cargo build --manifest-path crates/cli/Cargo.toml --target aarch64-apple-darwin --release
      env:
        MACOSX_DEPLOYMENT_TARGET: 10.7
    - uses: actions/upload-artifact@v4
      with:
        name: dist_macos_aarch64
        path: "target/aarch64-apple-darwin/release/wasm*"

  dist_windows:
    runs-on: windows-latest
    steps:
    - uses: actions/checkout@v4
    - run: rustup update --no-self-update stable && rustup default stable
    - run: cargo build --manifest-path crates/cli/Cargo.toml --release
      env:
        RUSTFLAGS: -Ctarget-feature=+crt-static
    - uses: actions/upload-artifact@v4
      with:
        name: dist_windows
        path: "target/release/wasm*"

  doc_book:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - run: |
        curl -L https://github.com/rust-lang/mdBook/releases/download/v0.4.28/mdbook-v0.4.28-x86_64-unknown-linux-gnu.tar.gz | tar xzf -
        echo $PWD >> $GITHUB_PATH
    - run: (cd guide && mdbook build)
    - uses: actions/upload-artifact@v4
      with:
        name: doc_book
        path: guide/book/html

  doc_api:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - run: rustup update --no-self-update nightly && rustup default nightly
    - run: cargo doc --no-deps --features 'serde-serialize'
    - run: cargo doc --no-deps --manifest-path crates/js-sys/Cargo.toml
    - run: cargo doc --no-deps --manifest-path crates/web-sys/Cargo.toml --all-features
      env:
        RUSTDOCFLAGS: --cfg=web_sys_unstable_apis
    - run: cargo doc --no-deps --manifest-path crates/futures/Cargo.toml
    - run: tar czvf docs.tar.gz target/doc
    - uses: actions/upload-artifact@v4
      with:
        name: doc_api
        path: docs.tar.gz


  deploy:
    permissions:
      contents: write #  to push changes in repo (jamesives/github-pages-deploy-action)

    needs:
      - doc_api
      - doc_book
      - dist_linux_x86_64_musl
      - dist_linux_aarch64_gnu
      - dist_macos_x86_64
      - dist_macos_aarch64
      - dist_windows
      - build_examples
      - build_nightly
      - build_benchmarks
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
      with:
        fetch-depth: 0
    - uses: actions/download-artifact@v4
      with:
        path: artifacts
    - run: find artifacts
    - run: |
        set -ex
        mkdir -p gh-release
        tag=`git describe --tags`
        mk() {
          target=$1
          src=$2
          name=wasm-bindgen-$tag-$target
          mkdir -p tmp/$name
          rm -f artifacts/$src/*.d
          rm -f artifacts/$src/*.pdb
          cp README.md \
            LICENSE-MIT \
            LICENSE-APACHE \
            artifacts/$src/wasm* \
            tmp/$name/
          chmod +x tmp/$name/wasm*
          tar czvf gh-release/$name.tar.gz -C tmp $name
          sha256sum gh-release/$name.tar.gz > gh-release/$name.tar.gz.sha256sum
        }
        mk x86_64-unknown-linux-musl dist_linux_x86_64_musl
        mk aarch64-unknown-linux-gnu dist_linux_aarch64_gnu
        mk x86_64-apple-darwin dist_macos_x86_64
        mk aarch64-apple-darwin dist_macos_aarch64
        mk x86_64-pc-windows-msvc dist_windows
    - uses: actions/upload-artifact@v4
      with:
        name: gh-release
        path: gh-release
    - run: |
        mv artifacts/doc_book gh-pages
        tar xf artifacts/doc_api/docs.tar.gz
        mv target/doc gh-pages/api
        mv artifacts/examples1 gh-pages/exbuild
        mv artifacts/examples2/* gh-pages/exbuild
        mv artifacts/benchmarks gh-pages/benchmarks
        tar czf gh-pages.tar.gz gh-pages
    - uses: actions/upload-artifact@v4
      with:
        name: gh-pages
        path: gh-pages.tar.gz
    - uses: JamesIves/github-pages-deploy-action@v4
      with:
        branch: gh-pages
        folder: gh-pages
        single-commit: true
      if: github.event_name == 'push' && github.ref == 'refs/heads/main'
    - uses: softprops/action-gh-release@v1
      if: startsWith(github.ref, 'refs/tags/')
      with:
        files: "gh-release/*.tar.gz*"
    - uses: dtolnay/rust-toolchain@stable
      if: startsWith(github.ref, 'refs/tags/')
    - run: rustc publish.rs
      if: startsWith(github.ref, 'refs/tags/')
    - run: ./publish publish
      if: startsWith(github.ref, 'refs/tags/')
      env:
        CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_PUBLISH_TOKEN }}