Skip to content

Commit

Permalink
Update wasm-bindgen
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda committed Dec 19, 2024
1 parent 1d75ac4 commit 7b64ab3
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 27 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
description: with Atomics,
atomics: true,
component: --component rust-src,
cflags: -matomics -mbulk-memory,
flags: "-Ctarget-feature=+atomics,+bulk-memory",
build-std: true,
}
Expand Down Expand Up @@ -92,7 +93,8 @@ jobs:
cargo update -p syn --precise 2.0.67
- name: Build
env:
RUSTFLAGS: ${{ matrix.rust.flags }}
CFLAGS_wasm32_unknown_unknown: ${{ matrix.rust.cflags }}
CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUSTFLAGS: ${{ matrix.rust.flags }}
run:
cargo build ${{ matrix.features.features }} --target ${{ matrix.target.target }}
$BUILD_STD_COMPONENTS
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/coverage-documentation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,19 @@ jobs:

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

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install `wasm-bindgen-cli`
uses: taiki-e/install-action@v2
uses: taiki-e/cache-cargo-install-action@v2
with:
tool: wasm-bindgen-cli
git: https://github.com/daxpedda/wasm-bindgen
rev: d4cb4a5d94090c18b469796250744612fd347dbd
- name: Install Clang v19
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
Expand All @@ -72,7 +74,7 @@ jobs:
run: |
chromedriver --port=9000 &
mkdir coverage-output
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
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
- name: Prepare Object Files
run: |
mkdir coverage-input
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
description: with Atomics,
atomics: true,
component: ",rust-src",
cflags: -matomics -mbulk-memory,
flags: "-Ctarget-feature=+atomics,+bulk-memory",
build-std: true,
}
Expand Down Expand Up @@ -80,7 +81,8 @@ jobs:
run: echo "BUILD_STD_COMPONENTS=-Zbuild-std=core,alloc" >> $GITHUB_ENV
- name: Run Clippy
env:
RUSTFLAGS: ${{ matrix.rust.flags }}
CFLAGS_wasm32_unknown_unknown: ${{ matrix.rust.cflags }}
CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUSTFLAGS: ${{ matrix.rust.flags }}
run:
cargo clippy --workspace --all-targets ${{ matrix.features.features }} --target ${{
matrix.target.target }} $BUILD_STD_COMPONENTS -- -D warnings
Expand All @@ -106,6 +108,7 @@ jobs:
description: with Atomics,
atomics: true,
component: --component rust-src,
cflags: -matomics -mbulk-memory,
flags: "-Ctarget-feature=+atomics,+bulk-memory",
build-std: true,
}
Expand Down Expand Up @@ -158,7 +161,8 @@ jobs:
run: echo "BUILD_STD_COMPONENTS=-Zbuild-std=core,alloc" >> $GITHUB_ENV
- name: Run Rustdoc
env:
RUSTFLAGS: ${{ matrix.rust.flags }}
CFLAGS_wasm32_unknown_unknown: ${{ matrix.rust.cflags }}
CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUSTFLAGS: ${{ matrix.rust.flags }}
RUSTDOCFLAGS: -D warnings ${{ matrix.rust.flags }} ${{ matrix.docsrs.flags }}
run:
cargo doc --workspace --no-deps --document-private-items --lib --examples ${{
Expand Down
12 changes: 10 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
version: nightly,
description: with Atomics,
component: --component rust-src,
cflags: -matomics -mbulk-memory,
flags: "-Ctarget-feature=+atomics,+bulk-memory",
build-std: true,
atomics: true,
Expand Down Expand Up @@ -67,6 +68,7 @@ jobs:
env: SAFARIDRIVER,
binary: safaridriver,
browser: true,
macos: true,
}
- { os: ubuntu-24.04, description: Node.js, nodejs: true }
environment:
Expand Down Expand Up @@ -119,11 +121,16 @@ jobs:
with:
tool: wasm-bindgen-cli
git: https://github.com/daxpedda/wasm-bindgen
rev: 9dc93d8c096cdb50c2c2d8a181f337ddfa927517
rev: d4cb4a5d94090c18b469796250744612fd347dbd
- name: Install Rust
run: |
rustup toolchain install ${{ matrix.rust.version }} --profile minimal ${{ matrix.rust.component }} --target ${{ matrix.target.target }}
rustup default ${{ matrix.rust.version }}
- name: Install Clang version with `wasm32-unknown-unknown` support on MacOS
if: matrix.driver.macos == true
run: |
brew install llvm
which clang
- name: Set `build-std` components
if: matrix.rust.build-std == true && matrix.features.no_std == false
run: echo "BUILD_STD_COMPONENTS=-Zbuild-std=panic_abort,std" >> $GITHUB_ENV
Expand Down Expand Up @@ -168,7 +175,8 @@ jobs:
run: echo "${{ matrix.environment.name }}=1" >> $GITHUB_ENV
- name: Test
env:
RUSTFLAGS: ${{ matrix.rust.flags }}
CFLAGS_wasm32_unknown_unknown: ${{ matrix.rust.cflags }}
CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUSTFLAGS: ${{ matrix.rust.flags }}
RUSTDOCFLAGS: ${{ matrix.rust.flags }}
run:
cargo test --features serde ${{ matrix.features.features }} --target ${{
Expand Down
29 changes: 20 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ Example usage:
# Installing Rust nightly and necessary components:
rustup toolchain install nightly --target wasm32-unknown-unknown --component rust-src
# Example `cargo build` usage:
RUSTFLAGS=-Ctarget-feature=+atomics,+bulk-memory cargo +nightly build --target wasm32-unknown-unknown -Zbuild-std=panic_abort,std
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
# Example `no_std` `cargo build` usage:
RUSTFLAGS=-Ctarget-feature=+atomics,+bulk-memory cargo +nightly build --target wasm32v1-none -Zbuild-std=core,alloc --no-default-features
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
```

[`build-std`]: https://doc.rust-lang.org/1.73.0/cargo/reference/unstable.html#build-std
Expand All @@ -61,11 +61,12 @@ Here is an example configuration for Visual Studio Code:
```json
"rust-analyzer.cargo.target": "wasm32-unknown-unknown",
"rust-analyzer.cargo.extraArgs": [
"-Zbuild-std=panic_abort,std"
"-Zbuild-std=panic_abort,std",
],
"rust-analyzer.cargo.extraEnv": {
"RUSTUP_TOOLCHAIN": "nightly",
"RUSTFLAGS": "-Ctarget-feature=+atomics,+bulk-memory"
"RUSTFLAGS": "-Ctarget-feature=+atomics,+bulk-memory",
"CFLAGS_wasm32_unknown_unknown": "-matomics -mbulk-memory",
},
```

Expand Down Expand Up @@ -99,7 +100,7 @@ cargo test --workspace --target wasm32-unknown-unknown
# Run tests for `no_std`.
cargo +nightly test --workspace --target wasm32v1-none --no-default-features
# Run tests for Wasm atomics.
RUSTFLAGS=-Ctarget-feature=+atomics,+bulk-memory cargo +nightly test --workspace --target wasm32-unknown-unknown -Zbuild-std=panic_abort,std
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
```

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

```sh
rm -rf coverage-input
rm -rf coverage-output

# Single-threaded test run.
st () {
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 $@
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}
}

# Multi-threaded test run.
mt () {
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 $@
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}
}

# To collect object files.
objects=()

# Start Chromedriver in the background
chromedriver --port=9000 &
pid=$!

# Run tests and adjust LLVM IR.
test () {
local command=$1
local path=$2

# Run tests.
mkdir -p coverage-input/$path
WASM_BINDGEN_USE_BROWSER=1 CHROMEDRIVER=chromedriver WASM_BINDGEN_UNSTABLE_TEST_PROFRAW_OUT=$(realpath coverage-input/$path) $command ${@:3}
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}

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

# Shutdown Chromedriver
kill $pid

# Merge all generated `*.profraw` files.
rust-profdata merge -sparse coverage-input/*/*.profraw -o coverage-input/coverage.profdata
# Finally generate coverage information.
Expand Down
10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,22 @@ wasm-bindgen = { version = "0.2.98", default-features = false }
[build-dependencies]
rustversion = { version = "1.0.0", optional = true }

[dev-dependencies]
wasm-bindgen-test = { version = "0.3", default-features = false }

[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
tests-native = { path = "tests-native", default-features = false, features = ["run"] }

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
getrandom = { version = "0.2", features = ["js"] }
rand = { version = "0.8", default-features = false, features = ["getrandom", "std_rng"] }
tests-web = { path = "tests-web", default-features = false, features = ["run"] }
wasm-bindgen-test = { version = "0.3", default-features = false, features = [
"msrv",
"unstable-test-coverage",
] }

[patch.crates-io]
getrandom = { git = "https://github.com/daxpedda/getrandom", branch = "web-time" }
js-sys = { git = "https://github.com/daxpedda/wasm-bindgen", branch = "web-time" }
minicov = { git = "https://github.com/daxpedda/minicov", branch = "web-time" }
serde_test = { git = "https://github.com/daxpedda/test", branch = "no_std" }
wasm-bindgen = { git = "https://github.com/daxpedda/wasm-bindgen", branch = "web-time" }
wasm-bindgen-futures = { git = "https://github.com/daxpedda/wasm-bindgen", branch = "web-time" }
Expand Down Expand Up @@ -90,9 +92,9 @@ single_use_lifetimes = "warn"
trivial_casts = "warn"
trivial_numeric_casts = "warn"
unexpected_cfgs = { level = "warn", check-cfg = [
'cfg(wasm_bindgen_unstable_test_coverage)',
'cfg(v1_77)',
'cfg(nightly)',
'cfg(web_time_test_coverage)',
] }
unnameable_types = "warn"
unreachable_pub = "warn"
Expand Down
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
//! # #[cfg(target_arch = "wasm32")]
//! # use tests_web as _;
//! #
//! # #[wasm_bindgen_test::wasm_bindgen_test]
//! # #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
//! # fn main() {
//! let now = Instant::now();
//! let time = SystemTime::now();
Expand Down Expand Up @@ -167,7 +167,6 @@
#![cfg_attr(all(target_arch = "wasm32", not(feature = "std")), no_std)]
#![cfg_attr(all(test, target_arch = "wasm32"), no_main)]
#![cfg_attr(all(doc, docsrs), feature(doc_cfg))]
#![cfg_attr(wasm_bindgen_unstable_test_coverage, feature(coverage_attribute))]
#![cfg_attr(all(not(feature = "std"), nightly), feature(asm_experimental_arch))]

#[cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))]
Expand Down
4 changes: 2 additions & 2 deletions src/time/instant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ impl F64 {
/// Put `debug_assert!` in a function to clap `coverage(off)` on it.
///
/// See <https://github.com/rust-lang/rust/issues/80549>.
#[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))]
#[cfg_attr(web_time_test_coverage, coverage(off))]
fn check(this: f64) {
debug_assert!(this.is_sign_positive(), "found negative input");
debug_assert!(
Expand All @@ -327,7 +327,7 @@ impl F64 {
}

#[cfg(test)]
#[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))]
#[cfg_attr(web_time_test_coverage, coverage(off))]
mod test {
//! Testing internal code.
Expand Down
5 changes: 4 additions & 1 deletion tests-web/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ serde_test = { version = "1", optional = true, default-features = false }
static_assertions = "1"
wasm-bindgen = { version = "0.2", default-features = false }
wasm-bindgen-futures = { version = "0.4", default-features = false }
wasm-bindgen-test = { version = "0.3", default-features = false }
wasm-bindgen-test = { version = "0.3", default-features = false, features = [
"msrv",
"unstable-test-coverage",
] }
web-sys = { version = "0.3", default-features = false, features = [
"CssStyleDeclaration",
"Document",
Expand Down

0 comments on commit 7b64ab3

Please sign in to comment.