Skip to content

Commit b5e411b

Browse files
committed
Update wasm-bindgen
1 parent 1d75ac4 commit b5e411b

9 files changed

Lines changed: 58 additions & 27 deletions

File tree

.github/workflows/build.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
description: with Atomics,
3737
atomics: true,
3838
component: --component rust-src,
39+
cflags: -matomics -mbulk-memory,
3940
flags: "-Ctarget-feature=+atomics,+bulk-memory",
4041
build-std: true,
4142
}
@@ -92,7 +93,8 @@ jobs:
9293
cargo update -p syn --precise 2.0.67
9394
- name: Build
9495
env:
95-
RUSTFLAGS: ${{ matrix.rust.flags }}
96+
CFLAGS_wasm32_unknown_unknown: ${{ matrix.rust.cflags }}
97+
CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUSTFLAGS: ${{ matrix.rust.flags }}
9698
run:
9799
cargo build ${{ matrix.features.features }} --target ${{ matrix.target.target }}
98100
$BUILD_STD_COMPONENTS

.github/workflows/coverage-documentation.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,19 @@ jobs:
3939

4040
env:
4141
CFLAGS_wasm32_unknown_unknown: ${{ matrix.mt.cflags }}
42-
RUSTFLAGS:
42+
CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUSTFLAGS:
4343
-Cinstrument-coverage -Zcoverage-options=condition -Zno-profiler-runtime --emit=llvm-ir
44-
--cfg=wasm_bindgen_unstable_test_coverage ${{ matrix.mt.flags }}
44+
--cfg=web_time_test_coverage ${{ matrix.mt.flags }}
4545

4646
steps:
4747
- name: Checkout
4848
uses: actions/checkout@v4
4949
- name: Install `wasm-bindgen-cli`
50-
uses: taiki-e/install-action@v2
50+
uses: taiki-e/cache-cargo-install-action@v2
5151
with:
5252
tool: wasm-bindgen-cli
53+
git: https://github.com/daxpedda/wasm-bindgen
54+
rev: d4cb4a5d94090c18b469796250744612fd347dbd
5355
- name: Install Clang v19
5456
run: |
5557
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
@@ -72,7 +74,7 @@ jobs:
7274
run: |
7375
chromedriver --port=9000 &
7476
mkdir coverage-output
75-
WASM_BINDGEN_UNSTABLE_TEST_PROFRAW_OUT=$(realpath coverage-output) cargo test --workspace --features serde --target wasm32-unknown-unknown $BUILD_STD_COMPONENTS ${{ matrix.features.features }} --tests
77+
LLVM_PROFILE_FILE=$(realpath coverage-output)/%m_%p.profraw cargo test --workspace --features serde --target wasm32-unknown-unknown $BUILD_STD_COMPONENTS ${{ matrix.features.features }} --tests
7678
- name: Prepare Object Files
7779
run: |
7880
mkdir coverage-input

.github/workflows/lint.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ jobs:
3434
description: with Atomics,
3535
atomics: true,
3636
component: ",rust-src",
37+
cflags: -matomics -mbulk-memory,
3738
flags: "-Ctarget-feature=+atomics,+bulk-memory",
3839
build-std: true,
3940
}
@@ -80,7 +81,8 @@ jobs:
8081
run: echo "BUILD_STD_COMPONENTS=-Zbuild-std=core,alloc" >> $GITHUB_ENV
8182
- name: Run Clippy
8283
env:
83-
RUSTFLAGS: ${{ matrix.rust.flags }}
84+
CFLAGS_wasm32_unknown_unknown: ${{ matrix.rust.cflags }}
85+
CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUSTFLAGS: ${{ matrix.rust.flags }}
8486
run:
8587
cargo clippy --workspace --all-targets ${{ matrix.features.features }} --target ${{
8688
matrix.target.target }} $BUILD_STD_COMPONENTS -- -D warnings
@@ -106,6 +108,7 @@ jobs:
106108
description: with Atomics,
107109
atomics: true,
108110
component: --component rust-src,
111+
cflags: -matomics -mbulk-memory,
109112
flags: "-Ctarget-feature=+atomics,+bulk-memory",
110113
build-std: true,
111114
}
@@ -158,7 +161,8 @@ jobs:
158161
run: echo "BUILD_STD_COMPONENTS=-Zbuild-std=core,alloc" >> $GITHUB_ENV
159162
- name: Run Rustdoc
160163
env:
161-
RUSTFLAGS: ${{ matrix.rust.flags }}
164+
CFLAGS_wasm32_unknown_unknown: ${{ matrix.rust.cflags }}
165+
CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUSTFLAGS: ${{ matrix.rust.flags }}
162166
RUSTDOCFLAGS: -D warnings ${{ matrix.rust.flags }} ${{ matrix.docsrs.flags }}
163167
run:
164168
cargo doc --workspace --no-deps --document-private-items --lib --examples ${{

.github/workflows/test.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ jobs:
3333
version: nightly,
3434
description: with Atomics,
3535
component: --component rust-src,
36+
cflags: -matomics -mbulk-memory,
3637
flags: "-Ctarget-feature=+atomics,+bulk-memory",
3738
build-std: true,
3839
atomics: true,
@@ -67,6 +68,7 @@ jobs:
6768
env: SAFARIDRIVER,
6869
binary: safaridriver,
6970
browser: true,
71+
macos: true,
7072
}
7173
- { os: ubuntu-24.04, description: Node.js, nodejs: true }
7274
environment:
@@ -119,11 +121,16 @@ jobs:
119121
with:
120122
tool: wasm-bindgen-cli
121123
git: https://github.com/daxpedda/wasm-bindgen
122-
rev: 9dc93d8c096cdb50c2c2d8a181f337ddfa927517
124+
rev: d4cb4a5d94090c18b469796250744612fd347dbd
123125
- name: Install Rust
124126
run: |
125127
rustup toolchain install ${{ matrix.rust.version }} --profile minimal ${{ matrix.rust.component }} --target ${{ matrix.target.target }}
126128
rustup default ${{ matrix.rust.version }}
129+
- name: Install Clang with `wasm32-unknown-unknown` support on MacOS
130+
if: matrix.driver.macos == true
131+
run: |
132+
brew install llvm
133+
echo "$(brew --prefix llvm)/bin" >> $GITHUB_PATH
127134
- name: Set `build-std` components
128135
if: matrix.rust.build-std == true && matrix.features.no_std == false
129136
run: echo "BUILD_STD_COMPONENTS=-Zbuild-std=panic_abort,std" >> $GITHUB_ENV
@@ -168,7 +175,8 @@ jobs:
168175
run: echo "${{ matrix.environment.name }}=1" >> $GITHUB_ENV
169176
- name: Test
170177
env:
171-
RUSTFLAGS: ${{ matrix.rust.flags }}
178+
CFLAGS_wasm32_unknown_unknown: ${{ matrix.rust.cflags }}
179+
CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUSTFLAGS: ${{ matrix.rust.flags }}
172180
RUSTDOCFLAGS: ${{ matrix.rust.flags }}
173181
run:
174182
cargo test --features serde ${{ matrix.features.features }} --target ${{

CONTRIBUTING.md

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ Example usage:
4444
# Installing Rust nightly and necessary components:
4545
rustup toolchain install nightly --target wasm32-unknown-unknown --component rust-src
4646
# Example `cargo build` usage:
47-
RUSTFLAGS=-Ctarget-feature=+atomics,+bulk-memory cargo +nightly build --target wasm32-unknown-unknown -Zbuild-std=panic_abort,std
47+
CFLAGS_wasm32_unknown_unknown="-matomics -mbulk-memory" RUSTFLAGS=-Ctarget-feature=+atomics,+bulk-memory cargo +nightly build --target wasm32-unknown-unknown -Zbuild-std=panic_abort,std
4848
# Example `no_std` `cargo build` usage:
49-
RUSTFLAGS=-Ctarget-feature=+atomics,+bulk-memory cargo +nightly build --target wasm32v1-none -Zbuild-std=core,alloc --no-default-features
49+
CFLAGS_wasm32_unknown_unknown="-matomics -mbulk-memory" RUSTFLAGS=-Ctarget-feature=+atomics,+bulk-memory cargo +nightly build --target wasm32v1-none -Zbuild-std=core,alloc --no-default-features
5050
```
5151

5252
[`build-std`]: https://doc.rust-lang.org/1.73.0/cargo/reference/unstable.html#build-std
@@ -61,11 +61,12 @@ Here is an example configuration for Visual Studio Code:
6161
```json
6262
"rust-analyzer.cargo.target": "wasm32-unknown-unknown",
6363
"rust-analyzer.cargo.extraArgs": [
64-
"-Zbuild-std=panic_abort,std"
64+
"-Zbuild-std=panic_abort,std",
6565
],
6666
"rust-analyzer.cargo.extraEnv": {
6767
"RUSTUP_TOOLCHAIN": "nightly",
68-
"RUSTFLAGS": "-Ctarget-feature=+atomics,+bulk-memory"
68+
"RUSTFLAGS": "-Ctarget-feature=+atomics,+bulk-memory",
69+
"CFLAGS_wasm32_unknown_unknown": "-matomics -mbulk-memory",
6970
},
7071
```
7172

@@ -99,7 +100,7 @@ cargo test --workspace --target wasm32-unknown-unknown
99100
# Run tests for `no_std`.
100101
cargo +nightly test --workspace --target wasm32v1-none --no-default-features
101102
# Run tests for Wasm atomics.
102-
RUSTFLAGS=-Ctarget-feature=+atomics,+bulk-memory cargo +nightly test --workspace --target wasm32-unknown-unknown -Zbuild-std=panic_abort,std
103+
CFLAGS_wasm32_unknown_unknown="-matomics -mbulk-memory" RUSTFLAGS=-Ctarget-feature=+atomics,+bulk-memory cargo +nightly test --workspace --target wasm32-unknown-unknown -Zbuild-std=panic_abort,std
103104
```
104105

105106
Make sure not to use `--all-features`.
@@ -175,33 +176,40 @@ full test coverage data via an artifact called `test-coverage`.
175176
If you want to generate test coverage locally, here is an example shell script that you can use:
176177

177178
```sh
179+
rm -rf coverage-input
180+
rm -rf coverage-output
181+
178182
# Single-threaded test run.
179183
st () {
180-
RUSTFLAGS="-Cinstrument-coverage -Zcoverage-options=condition -Zno-profiler-runtime --emit=llvm-ir --cfg=wasm_bindgen_unstable_test_coverage" cargo +nightly test --workspace --features serde --target wasm32-unknown-unknown --tests $@
184+
CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUSTFLAGS="-Cinstrument-coverage -Zcoverage-options=condition -Zno-profiler-runtime --emit=llvm-ir --cfg web_time_test_coverage" cargo +nightly $1 --workspace --features serde --target wasm32-unknown-unknown --tests ${@:2}
181185
}
182186

183187
# Multi-threaded test run.
184188
mt () {
185-
CFLAGS_wasm32_unknown_unknown="-matomics -mbulk-memory" RUSTFLAGS="-Cinstrument-coverage -Zcoverage-options=condition -Zno-profiler-runtime --emit=llvm-ir --cfg=wasm_bindgen_unstable_test_coverage -Ctarget-feature=+atomics,+bulk-memory" cargo +nightly test --workspace --features serde --target wasm32-unknown-unknown --tests $@
189+
CFLAGS_wasm32_unknown_unknown="-matomics -mbulk-memory" CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUSTFLAGS="-Cinstrument-coverage -Zcoverage-options=condition -Zno-profiler-runtime --emit=llvm-ir -Ctarget-feature=+atomics,+bulk-memory --cfg web_time_test_coverage" cargo +nightly $1 --workspace --features serde --target wasm32-unknown-unknown --tests ${@:2}
186190
}
187191

188192
# To collect object files.
189193
objects=()
190194

195+
# Start Chromedriver in the background
196+
chromedriver --port=9000 &
197+
pid=$!
198+
191199
# Run tests and adjust LLVM IR.
192200
test () {
193201
local command=$1
194202
local path=$2
195203

196204
# Run tests.
197205
mkdir -p coverage-input/$path
198-
WASM_BINDGEN_USE_BROWSER=1 CHROMEDRIVER=chromedriver WASM_BINDGEN_UNSTABLE_TEST_PROFRAW_OUT=$(realpath coverage-input/$path) $command ${@:3}
206+
WASM_BINDGEN_USE_BROWSER=1 CHROMEDRIVER_REMOTE=http://127.0.0.1:9000 LLVM_PROFILE_FILE=$(realpath coverage-input/$path/%m_%p.profraw) $command 'nextest run' ${@:3}
199207

200208
local crate_name=web_time
201209
local IFS=$'\n'
202210
for file in $(
203211
# Extract path to artifacts.
204-
$command ${@:3} --no-run --message-format=json | \
212+
$command 'test' ${@:3} --no-run --message-format=json | \
205213
jq -r "select(.reason == \"compiler-artifact\") | (select(.target.kind == [\"test\"]) // select(.target.name == \"$crate_name\")) | .filenames[0]"
206214
)
207215
do
@@ -227,6 +235,9 @@ test st 'st-no_std' --no-default-features
227235
test mt 'mt' -Zbuild-std=panic_abort,std
228236
test mt 'mt-no_std' -Zbuild-std=core,alloc --no-default-features
229237

238+
# Shutdown Chromedriver
239+
kill $pid
240+
230241
# Merge all generated `*.profraw` files.
231242
rust-profdata merge -sparse coverage-input/*/*.profraw -o coverage-input/coverage.profdata
232243
# Finally generate coverage information.

Cargo.toml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,22 @@ wasm-bindgen = { version = "0.2.98", default-features = false }
2929
[build-dependencies]
3030
rustversion = { version = "1.0.0", optional = true }
3131

32-
[dev-dependencies]
33-
wasm-bindgen-test = { version = "0.3", default-features = false }
34-
3532
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
3633
tests-native = { path = "tests-native", default-features = false, features = ["run"] }
3734

3835
[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
3936
getrandom = { version = "0.2", features = ["js"] }
4037
rand = { version = "0.8", default-features = false, features = ["getrandom", "std_rng"] }
4138
tests-web = { path = "tests-web", default-features = false, features = ["run"] }
39+
wasm-bindgen-test = { version = "0.3", default-features = false, features = [
40+
"msrv",
41+
"unstable-test-coverage",
42+
] }
4243

4344
[patch.crates-io]
4445
getrandom = { git = "https://github.com/daxpedda/getrandom", branch = "web-time" }
4546
js-sys = { git = "https://github.com/daxpedda/wasm-bindgen", branch = "web-time" }
47+
minicov = { git = "https://github.com/daxpedda/minicov", branch = "web-time" }
4648
serde_test = { git = "https://github.com/daxpedda/test", branch = "no_std" }
4749
wasm-bindgen = { git = "https://github.com/daxpedda/wasm-bindgen", branch = "web-time" }
4850
wasm-bindgen-futures = { git = "https://github.com/daxpedda/wasm-bindgen", branch = "web-time" }
@@ -90,9 +92,9 @@ single_use_lifetimes = "warn"
9092
trivial_casts = "warn"
9193
trivial_numeric_casts = "warn"
9294
unexpected_cfgs = { level = "warn", check-cfg = [
93-
'cfg(wasm_bindgen_unstable_test_coverage)',
9495
'cfg(v1_77)',
9596
'cfg(nightly)',
97+
'cfg(web_time_test_coverage)',
9698
] }
9799
unnameable_types = "warn"
98100
unreachable_pub = "warn"

src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
//! # #[cfg(target_arch = "wasm32")]
5555
//! # use tests_web as _;
5656
//! #
57-
//! # #[wasm_bindgen_test::wasm_bindgen_test]
57+
//! # #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
5858
//! # fn main() {
5959
//! let now = Instant::now();
6060
//! let time = SystemTime::now();
@@ -167,7 +167,6 @@
167167
#![cfg_attr(all(target_arch = "wasm32", not(feature = "std")), no_std)]
168168
#![cfg_attr(all(test, target_arch = "wasm32"), no_main)]
169169
#![cfg_attr(all(doc, docsrs), feature(doc_cfg))]
170-
#![cfg_attr(wasm_bindgen_unstable_test_coverage, feature(coverage_attribute))]
171170
#![cfg_attr(all(not(feature = "std"), nightly), feature(asm_experimental_arch))]
172171

173172
#[cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))]

src/time/instant.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ impl F64 {
300300
/// Put `debug_assert!` in a function to clap `coverage(off)` on it.
301301
///
302302
/// See <https://github.com/rust-lang/rust/issues/80549>.
303-
#[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))]
303+
#[cfg_attr(web_time_test_coverage, coverage(off))]
304304
fn check(this: f64) {
305305
debug_assert!(this.is_sign_positive(), "found negative input");
306306
debug_assert!(
@@ -327,7 +327,7 @@ impl F64 {
327327
}
328328

329329
#[cfg(test)]
330-
#[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))]
330+
#[cfg_attr(web_time_test_coverage, coverage(off))]
331331
mod test {
332332
//! Testing internal code.
333333

tests-web/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ serde_test = { version = "1", optional = true, default-features = false }
3737
static_assertions = "1"
3838
wasm-bindgen = { version = "0.2", default-features = false }
3939
wasm-bindgen-futures = { version = "0.4", default-features = false }
40-
wasm-bindgen-test = { version = "0.3", default-features = false }
40+
wasm-bindgen-test = { version = "0.3", default-features = false, features = [
41+
"msrv",
42+
"unstable-test-coverage",
43+
] }
4144
web-sys = { version = "0.3", default-features = false, features = [
4245
"CssStyleDeclaration",
4346
"Document",

0 commit comments

Comments
 (0)