Skip to content

Commit 86fdfd0

Browse files
committed
Remove coverage feature for edition 2018 compatibility
1 parent 9525fce commit 86fdfd0

File tree

12 files changed

+76
-45
lines changed

12 files changed

+76
-45
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ jobs:
6868
- run: cargo clippy --no-deps --all-features -p example-tests -- -D warnings
6969
- run: cargo clippy --no-deps --all-features -p wasm-bindgen-externref-xform -- -D warnings
7070
- run: cargo clippy --no-deps --all-features --target wasm32-unknown-unknown -p wasm-bindgen-futures -- -D warnings
71-
- run: cargo clippy --no-deps --features spans,strict-macro -p wasm-bindgen-macro -- -D warnings
72-
- run: cargo clippy --no-deps --features extra-traits,spans,strict-macro -p wasm-bindgen-macro-support -- -D warnings
71+
- run: cargo clippy --no-deps --all-features -p wasm-bindgen-macro -- -D warnings
72+
- run: cargo clippy --no-deps --all-features -p wasm-bindgen-macro-support -- -D warnings
7373
- run: cargo clippy --no-deps --all-features -p wasm-bindgen-multi-value-xform -- -D warnings
7474
- run: cargo clippy --no-deps --all-features -p wasm-bindgen-shared -- -D warnings
7575
- run: cargo clippy --no-deps --all-features --target wasm32-unknown-unknown -p wasm-bindgen-test -- -D warnings
76-
- run: cargo clippy --no-deps -p wasm-bindgen-test-macro -- -D warnings
76+
- run: cargo clippy --no-deps --all-features -p wasm-bindgen-test-macro -- -D warnings
7777
- run: cargo clippy --no-deps --all-features -p wasm-bindgen-threads-xform -- -D warnings
7878
- run: cargo clippy --no-deps --all-features --target wasm32-unknown-unknown -p typescript-tests -- -D warnings
7979
- run: cargo clippy --no-deps --all-features -p wasm-bindgen-wasm-conventions -- -D warnings

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
* Fixed `js-sys` and `wasm-bindgen-futures` relying on internal paths of `wasm-bindgen` that are not crate feature additive.
99
[#4305](https://github.com/rustwasm/wasm-bindgen/pull/4305)
1010

11+
* Fixed `wasm-bindgen` not being compatible with edition 2018.
12+
[#4306](https://github.com/rustwasm/wasm-bindgen/pull/4306)
13+
1114
--------------------------------------------------------------------------------
1215

1316
## [0.2.96](https://github.com/rustwasm/wasm-bindgen/compare/0.2.95...0.2.96)

Cargo.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@ wasm-bindgen-macro = { path = "crates/macro", version = "=0.2.96", default-featu
5252
"atomics",
5353
] }
5454

55-
[target.'cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none"), wasm_bindgen_unstable_test_coverage))'.dependencies]
56-
wasm-bindgen-macro = { path = "crates/macro", version = "=0.2.96", default-features = false, features = [
57-
"coverage",
58-
] }
59-
6055
[dev-dependencies]
6156
wasm-bindgen-test = { path = 'crates/test' }
6257

crates/backend/Cargo.toml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ version = "0.2.96"
1515

1616
[features]
1717
atomics = []
18-
coverage = []
1918
default = ["std"]
2019
extra-traits = ["syn/extra-traits"]
2120
spans = []
@@ -30,5 +29,12 @@ quote = '1.0'
3029
syn = { version = '2.0', features = ['full'] }
3130
wasm-bindgen-shared = { path = "../shared", version = "=0.2.96" }
3231

33-
[lints]
34-
workspace = true
32+
[lints.rust]
33+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(wasm_bindgen_unstable_test_coverage)'] }
34+
35+
[lints.clippy]
36+
large_enum_variant = "allow"
37+
new_without_default = "allow"
38+
overly_complex_bool_expr = "allow"
39+
too_many_arguments = "allow"
40+
type_complexity = "allow"

crates/backend/src/codegen.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,8 +1966,8 @@ fn respan(input: TokenStream, span: &dyn ToTokens) -> TokenStream {
19661966
}
19671967

19681968
fn coverage() -> Option<TokenStream> {
1969-
#[cfg(feature = "coverage")]
1969+
#[cfg(wasm_bindgen_unstable_test_coverage)]
19701970
return Some(quote! { #[coverage(off)] });
1971-
#[cfg(not(feature = "coverage"))]
1971+
#[cfg(not(wasm_bindgen_unstable_test_coverage))]
19721972
None
19731973
}

crates/macro-support/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ version = "0.2.96"
1515

1616
[features]
1717
atomics = ["wasm-bindgen-backend/atomics"]
18-
coverage = ["wasm-bindgen-backend/coverage"]
1918
default = ["std"]
2019
extra-traits = ["syn/extra-traits"]
2120
spans = ["wasm-bindgen-backend/spans"]

crates/macro/Cargo.toml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ proc-macro = true
1818

1919
[features]
2020
atomics = ["wasm-bindgen-macro-support/atomics"]
21-
coverage = ["wasm-bindgen-macro-support/coverage"]
2221
default = ["std"]
2322
spans = ["wasm-bindgen-macro-support/spans"]
2423
std = ["wasm-bindgen-macro-support/std"]
@@ -36,5 +35,12 @@ wasm-bindgen = { path = "../.." }
3635
wasm-bindgen-futures = { path = "../futures" }
3736
web-sys = { path = "../web-sys", features = ["Worker"] }
3837

39-
[lints]
40-
workspace = true
38+
[lints.rust]
39+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(wasm_bindgen_unstable_test_coverage)'] }
40+
41+
[lints.clippy]
42+
large_enum_variant = "allow"
43+
new_without_default = "allow"
44+
overly_complex_bool_expr = "allow"
45+
too_many_arguments = "allow"
46+
type_complexity = "allow"

crates/macro/src/lib.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#![doc(html_root_url = "https://docs.rs/wasm-bindgen-macro/0.2")]
22
#![cfg_attr(
3-
any(feature = "coverage", all(not(feature = "std"), feature = "atomics")),
3+
any(
4+
wasm_bindgen_unstable_test_coverage,
5+
all(not(feature = "std"), feature = "atomics")
6+
),
47
feature(allow_internal_unstable),
58
allow(internal_features)
69
)]
@@ -11,7 +14,10 @@ use proc_macro::TokenStream;
1114
use quote::quote;
1215

1316
#[proc_macro_attribute]
14-
#[cfg_attr(feature = "coverage", allow_internal_unstable(coverage_attribute))]
17+
#[cfg_attr(
18+
wasm_bindgen_unstable_test_coverage,
19+
allow_internal_unstable(coverage_attribute)
20+
)]
1521
#[cfg_attr(
1622
all(not(feature = "std"), feature = "atomics"),
1723
allow_internal_unstable(thread_local)
@@ -42,7 +48,10 @@ pub fn wasm_bindgen(attr: TokenStream, input: TokenStream) -> TokenStream {
4248
/// let worker = Worker::new(&wasm_bindgen::link_to!(module = "/src/worker.js"));
4349
/// ```
4450
#[proc_macro]
45-
#[cfg_attr(feature = "coverage", allow_internal_unstable(coverage_attribute))]
51+
#[cfg_attr(
52+
wasm_bindgen_unstable_test_coverage,
53+
allow_internal_unstable(coverage_attribute)
54+
)]
4655
pub fn link_to(input: TokenStream) -> TokenStream {
4756
match wasm_bindgen_macro_support::expand_link_to(input.into()) {
4857
Ok(tokens) => {
@@ -59,7 +68,10 @@ pub fn link_to(input: TokenStream) -> TokenStream {
5968
}
6069

6170
#[proc_macro_attribute]
62-
#[cfg_attr(feature = "coverage", allow_internal_unstable(coverage_attribute))]
71+
#[cfg_attr(
72+
wasm_bindgen_unstable_test_coverage,
73+
allow_internal_unstable(coverage_attribute)
74+
)]
6375
pub fn __wasm_bindgen_class_marker(attr: TokenStream, input: TokenStream) -> TokenStream {
6476
match wasm_bindgen_macro_support::expand_class_marker(attr.into(), input.into()) {
6577
Ok(tokens) => {

crates/test-macro/Cargo.toml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ version = "0.3.46"
1212
[lib]
1313
proc-macro = true
1414

15-
[features]
16-
coverage = []
17-
1815
[dependencies]
1916
proc-macro2 = "1.0"
2017
quote = "1.0"
@@ -30,5 +27,12 @@ tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
3027
trybuild = "1.0"
3128
wasm-bindgen-test = { path = "../test" }
3229

33-
[lints]
34-
workspace = true
30+
[lints.rust]
31+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(wasm_bindgen_unstable_test_coverage)'] }
32+
33+
[lints.clippy]
34+
large_enum_variant = "allow"
35+
new_without_default = "allow"
36+
overly_complex_bool_expr = "allow"
37+
too_many_arguments = "allow"
38+
type_complexity = "allow"

crates/test-macro/src/lib.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! going on here.
33
44
#![cfg_attr(
5-
feature = "coverage",
5+
wasm_bindgen_unstable_test_coverage,
66
feature(allow_internal_unstable),
77
allow(internal_features)
88
)]
@@ -18,7 +18,10 @@ use std::sync::atomic::*;
1818
static CNT: AtomicUsize = AtomicUsize::new(0);
1919

2020
#[proc_macro_attribute]
21-
#[cfg_attr(feature = "coverage", allow_internal_unstable(coverage_attribute))]
21+
#[cfg_attr(
22+
wasm_bindgen_unstable_test_coverage,
23+
allow_internal_unstable(coverage_attribute)
24+
)]
2225
pub fn wasm_bindgen_test(
2326
attr: proc_macro::TokenStream,
2427
body: proc_macro::TokenStream,
@@ -106,17 +109,12 @@ pub fn wasm_bindgen_test(
106109
// main test harness. This is the entry point for all tests.
107110
let name = format_ident!("__wbgt_{}_{}", ident, CNT.fetch_add(1, Ordering::SeqCst));
108111
let wasm_bindgen_path = attributes.wasm_bindgen_path;
109-
let coverage = if cfg!(feature = "coverage") {
110-
Some(quote! { #[coverage(off)] })
111-
} else {
112-
None
113-
};
114112
tokens.extend(
115113
quote! {
116114
const _: () = {
117115
#[no_mangle]
118116
#[cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))]
119-
#coverage
117+
#[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))]
120118
pub extern "C" fn #name(cx: &#wasm_bindgen_path::__rt::Context) {
121119
let test_name = ::core::concat!(::core::module_path!(), "::", ::core::stringify!(#ident));
122120
#test_body

crates/test/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ wasm-bindgen-test-macro = { path = '../test-macro', version = '=0.3.46' }
2424

2525
[target.'cfg(all(target_arch = "wasm32", wasm_bindgen_unstable_test_coverage))'.dependencies]
2626
minicov = "0.3"
27-
wasm-bindgen-test-macro = { path = '../test-macro', version = '=0.3.46', features = ["coverage"] }
2827

2928
[lints.rust]
3029
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(wasm_bindgen_unstable_test_coverage)'] }

guide/src/wasm-bindgen-test/coverage.md

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ You can ask the runner to generate coverage data from functions marked as `#[was
99

1010
## Enabling the feature
1111

12-
To enable this feature, you need to enable `cfg(wasm_bindgen_unstable_test_coverage)`.
12+
To enable this feature, you need to set `cfg(wasm_bindgen_unstable_test_coverage)` for `wasm-bindgen-test` and its dependencies.
13+
14+
Currently it is particularly difficult to [deliver compile-line arguments to proc-macros when cross-compiling with Cargo][1]. To circumvent this [host-config] can be used.
15+
16+
[1]: https://github.com/rust-lang/cargo/issues/4423
17+
[host-config]: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#host-config
1318

1419
## Generating the data
1520

@@ -21,18 +26,18 @@ Due to the current limitation of `llvm-cov`, we can't collect profiling symbols
2126

2227
### Arguments to the test runner
2328

24-
The following environment variables can be used to control the coverage output when [executing the test runner][1]:
29+
The following environment variables can be used to control the coverage output when [executing the test runner][2]:
2530

2631
- `WASM_BINDGEN_UNSTABLE_TEST_PROFRAW_OUT` to control the file name of the profraw or the directory in which it is placed. It might be necessary to provide the full path if e.g. running tests in a workspace.
2732
- `WASM_BINDGEN_UNSTABLE_TEST_PROFRAW_PREFIX` to add a custom prefix to the profraw files. This can be useful if you're running the tests automatically in succession.
2833

29-
[1]: usage.html#appendix-using-wasm-bindgen-test-without-wasm-pack
34+
[2]: usage.html#appendix-using-wasm-bindgen-test-without-wasm-pack
3035

3136
### Target features
3237

33-
This feature relies on the [minicov] crate, which provides a profiling runtime for WebAssembly. It in turn uses [cc] to compile the runtime to Wasm, which [currently doesn't support accounting for target feature][2]. Use e.g. `CFLAGS_wasm32_unknown_unknown="-matomics -mbulk-memory"` to account for that.
38+
This feature relies on the [minicov] crate, which provides a profiling runtime for WebAssembly. It in turn uses [cc] to compile the runtime to Wasm, which [currently doesn't support accounting for target feature][3]. Use e.g. `CFLAGS_wasm32_unknown_unknown="-matomics -mbulk-memory"` to account for that.
3439

35-
[2]: https://github.com/rust-lang/cc-rs/issues/268
40+
[3]: https://github.com/rust-lang/cc-rs/issues/268
3641
[cc]: https://crates.io/crates/cc
3742
[minicov]: https://crates.io/crates/minicov
3843

@@ -42,10 +47,13 @@ This adapts code taken from the [Rustc book], see that for more examples and gen
4247

4348
```sh
4449
# Run the tests:
45-
# `--tests` to not run documentation tests, which is currently not supported.
50+
# - `CARGO_HOST_RUSTFLAGS` to pass the configuration to `wasm-bindgen-macro`.
51+
# - `-Ztarget-applies-to-host -Zhost-config` to enable `CARGO_HOST_RUSTFLAGS`.
52+
# - `--tests` to not run documentation tests, which is currently not supported.
53+
CARGO_HOST_RUSTFLAGS=--cfg=wasm_bindgen_unstable_test_coverage \
4654
RUSTFLAGS="-Cinstrument-coverage -Zno-profiler-runtime --emit=llvm-ir --cfg=wasm_bindgen_unstable_test_coverage" \
4755
CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER=wasm-bindgen-test-runner \
48-
cargo +nightly test --tests
56+
cargo +nightly test -Ztarget-applies-to-host -Zhost-config --tests
4957
# Compile to object files:
5058
# - Extract a list of compiled artifacts from Cargo and filter them with `jq`.
5159
# - Figure out the path to the LLVM IR file corresponding to an artifact.
@@ -54,8 +62,9 @@ crate_name=name_of_the_tested_crate_in_snake_case
5462
objects=()
5563
IFS=$'\n'
5664
for file in $(
65+
CARGO_HOST_RUSTFLAGS=--cfg=wasm_bindgen_unstable_test_coverage \
5766
RUSTFLAGS="-Cinstrument-coverage -Zno-profiler-runtime --emit=llvm-ir --cfg=wasm_bindgen_unstable_test_coverage" \
58-
cargo +nightly test --tests --no-run --message-format=json | \
67+
cargo +nightly test -Ztarget-applies-to-host -Zhost-config --tests --no-run --message-format=json | \
5968
jq -r "select(.reason == \"compiler-artifact\") | (select(.target.kind == [\"test\"]) // select(.target.name == \"$crate_name\")) | .filenames[0]"
6069
)
6170
do
@@ -80,7 +89,7 @@ llvm-cov-19 show -show-instantiations=false -Xdemangler=rustfilt -output-dir cov
8089

8190
## Attribution
8291

83-
These methods have originally been pioneered by [Hacken OÜ], see [their guide][3] as well.
92+
These methods have originally been pioneered by [Hacken OÜ], see [their guide][4] as well.
8493

85-
[3]: https://hknio.github.io/wasmcov
94+
[4]: https://hknio.github.io/wasmcov
8695
[Hacken OÜ]: https://hacken.io

0 commit comments

Comments
 (0)