Skip to content

Commit 0d1ae06

Browse files
authored
Add clear error message to communicate new feature resolver version requirements (#4312)
1 parent 7fa2afa commit 0d1ae06

File tree

15 files changed

+117
-9
lines changed

15 files changed

+117
-9
lines changed

.github/workflows/main.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,34 @@ jobs:
538538
name: doc_api
539539
path: docs.tar.gz
540540

541+
msrv-resolver:
542+
name: Check for feature resolver v1 error message
543+
runs-on: ubuntu-latest
544+
strategy:
545+
fail-fast: false
546+
matrix:
547+
rust:
548+
- 1.57
549+
- stable
550+
target:
551+
- x86_64-unknown-linux-gnu
552+
- wasm32-unknown-unknown
553+
features:
554+
- --no-default-features
555+
- ""
556+
defaults:
557+
run:
558+
working-directory: crates/msrv/resolver
559+
steps:
560+
- uses: actions/checkout@v4
561+
- run: rustup update --no-self-update ${{ matrix.rust }} && rustup default ${{ matrix.rust }} && rustup target add ${{ matrix.target }}
562+
- if: matrix.rust == '1.57'
563+
run: |
564+
cargo update -p bumpalo --precise 3.12.0
565+
cargo update -p log --precise 0.4.18
566+
cargo update -p scoped-tls --precise 1.0.0
567+
- run: diff <(cargo build --target ${{ matrix.target }} ${{ matrix.features }} --message-format json | jq -r "select(.reason == \"compiler-message\") | .message.message") error-${{ matrix.rust }}.txt
568+
541569
msrv-lib:
542570
name: Check MSRV for libraries
543571
runs-on: ubuntu-latest

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# `wasm-bindgen` Change Log
22
--------------------------------------------------------------------------------
33

4+
## Unreleased
5+
6+
### Changed
7+
8+
* Add clear error message to communicate new feature resolver version requirements.
9+
[#4312](https://github.com/rustwasm/wasm-bindgen/pull/4312)
10+
11+
--------------------------------------------------------------------------------
12+
413
## [0.2.97](https://github.com/rustwasm/wasm-bindgen/compare/0.2.96...0.2.97)
514

615
Released 2024-11-30

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ wasm-bindgen-macro = { path = "crates/macro", version = "=0.2.97", default-featu
5757
"coverage",
5858
] }
5959

60+
[target.'cfg(__wasm_bindgen_resolver_1)'.dependencies]
61+
wasm-bindgen-macro = { path = "crates/macro", version = "=0.2.97", default-features = false, features = [
62+
"xxx_resolver_1",
63+
] }
64+
6065
[dev-dependencies]
6166
wasm-bindgen-test = { path = 'crates/test' }
6267

crates/backend/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ default = ["std"]
2020
extra-traits = ["syn/extra-traits"]
2121
spans = []
2222
std = []
23+
xxx_resolver_1 = []
2324

2425
[dependencies]
2526
bumpalo = "3.0.0"

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(all(not(feature = "xxx_resolver_1"), feature = "coverage"))]
19701970
return Some(quote! { #[coverage(off)] });
1971-
#[cfg(not(feature = "coverage"))]
1971+
#[cfg(any(feature = "xxx_resolver_1", not(feature = "coverage")))]
19721972
None
19731973
}

crates/macro-support/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ extra-traits = ["syn/extra-traits"]
2121
spans = ["wasm-bindgen-backend/spans"]
2222
std = ["wasm-bindgen-backend/std"]
2323
strict-macro = []
24+
xxx_resolver_1 = ["wasm-bindgen-backend/xxx_resolver_1"]
2425

2526
[dependencies]
2627
proc-macro2 = "1.0"

crates/macro/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ spans = ["wasm-bindgen-macro-support/spans"]
2424
std = ["wasm-bindgen-macro-support/std"]
2525
strict-macro = ["wasm-bindgen-macro-support/strict-macro"]
2626
xxx_debug_only_print_generated_code = []
27+
xxx_resolver_1 = ["wasm-bindgen-macro-support/xxx_resolver_1"]
2728

2829
[dependencies]
2930
quote = "1.0"

crates/macro/src/lib.rs

Lines changed: 27 additions & 5 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+
all(
4+
not(feature = "xxx_resolver_1"),
5+
any(feature = "coverage", all(not(feature = "std"), feature = "atomics"))
6+
),
47
feature(allow_internal_unstable),
58
allow(internal_features)
69
)]
@@ -10,10 +13,23 @@ extern crate proc_macro;
1013
use proc_macro::TokenStream;
1114
use quote::quote;
1215

16+
#[cfg(feature = "xxx_resolver_1")]
17+
compile_error!("Feature resolver version 2 or up is required.\n\
18+
Please add `resolver = \"2\"` to your `Cargo.toml`.\n\
19+
\n\
20+
See <https://doc.rust-lang.org/1.83.0/cargo/reference/resolver.html#feature-resolver-version-2>.");
21+
1322
#[proc_macro_attribute]
14-
#[cfg_attr(feature = "coverage", allow_internal_unstable(coverage_attribute))]
1523
#[cfg_attr(
16-
all(not(feature = "std"), feature = "atomics"),
24+
all(not(feature = "xxx_resolver_1"), feature = "coverage"),
25+
allow_internal_unstable(coverage_attribute)
26+
)]
27+
#[cfg_attr(
28+
all(
29+
not(feature = "xxx_resolver_1"),
30+
not(feature = "std"),
31+
feature = "atomics"
32+
),
1733
allow_internal_unstable(thread_local)
1834
)]
1935
pub fn wasm_bindgen(attr: TokenStream, input: TokenStream) -> TokenStream {
@@ -42,7 +58,10 @@ pub fn wasm_bindgen(attr: TokenStream, input: TokenStream) -> TokenStream {
4258
/// let worker = Worker::new(&wasm_bindgen::link_to!(module = "/src/worker.js"));
4359
/// ```
4460
#[proc_macro]
45-
#[cfg_attr(feature = "coverage", allow_internal_unstable(coverage_attribute))]
61+
#[cfg_attr(
62+
all(not(feature = "xxx_resolver_1"), feature = "coverage"),
63+
allow_internal_unstable(coverage_attribute)
64+
)]
4665
pub fn link_to(input: TokenStream) -> TokenStream {
4766
match wasm_bindgen_macro_support::expand_link_to(input.into()) {
4867
Ok(tokens) => {
@@ -59,7 +78,10 @@ pub fn link_to(input: TokenStream) -> TokenStream {
5978
}
6079

6180
#[proc_macro_attribute]
62-
#[cfg_attr(feature = "coverage", allow_internal_unstable(coverage_attribute))]
81+
#[cfg_attr(
82+
all(not(feature = "xxx_resolver_1"), feature = "coverage"),
83+
allow_internal_unstable(coverage_attribute)
84+
)]
6385
pub fn __wasm_bindgen_class_marker(attr: TokenStream, input: TokenStream) -> TokenStream {
6486
match wasm_bindgen_macro_support::expand_class_marker(attr.into(), input.into()) {
6587
Ok(tokens) => {

crates/msrv/resolver/Cargo.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[package]
2+
edition = "2021"
3+
name = "msrv-library-test"
4+
publish = false
5+
resolver = "1"
6+
version = "0.0.0"
7+
8+
[features]
9+
default = ["std"]
10+
std = [
11+
"wasm-bindgen/std",
12+
"js-sys/std",
13+
"wasm-bindgen-futures/std",
14+
"web-sys/std",
15+
"wasm-bindgen-test/std",
16+
]
17+
18+
[dependencies]
19+
js-sys = { path = "../../js-sys", default-features = false }
20+
wasm-bindgen = { path = "../../../", default-features = false }
21+
wasm-bindgen-futures = { path = "../../futures", default-features = false }
22+
wasm-bindgen-test = { path = "../../test", default-features = false }
23+
web-sys = { path = "../../web-sys", default-features = false }

crates/msrv/resolver/error-1.57.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Feature resolver version 2 or up is required.
2+
Please add `resolver = "2"` to your `Cargo.toml`.
3+
4+
See <https://doc.rust-lang.org/1.83.0/cargo/reference/resolver.html#feature-resolver-version-2>.
5+
aborting due to previous error

crates/msrv/resolver/error-stable.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Feature resolver version 2 or up is required.
2+
Please add `resolver = "2"` to your `Cargo.toml`.
3+
4+
See <https://doc.rust-lang.org/1.83.0/cargo/reference/resolver.html#feature-resolver-version-2>.

crates/msrv/resolver/src/lib.rs

Whitespace-only changes.

crates/test-macro/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ proc-macro = true
1414

1515
[features]
1616
coverage = []
17+
xxx_resolver_1 = []
1718

1819
[dependencies]
1920
proc-macro2 = "1.0"

crates/test-macro/src/lib.rs

Lines changed: 5 additions & 2 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+
all(not(feature = "xxx_resolver_1"), feature = "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+
all(not(feature = "xxx_resolver_1"), feature = "coverage"),
23+
allow_internal_unstable(coverage_attribute)
24+
)]
2225
pub fn wasm_bindgen_test(
2326
attr: proc_macro::TokenStream,
2427
body: proc_macro::TokenStream,

crates/test/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ wasm-bindgen-test-macro = { path = '../test-macro', version = '=0.3.47' }
2626
minicov = "0.3"
2727
wasm-bindgen-test-macro = { path = '../test-macro', version = '=0.3.47', features = ["coverage"] }
2828

29+
[target.'cfg(__wasm_bindgen_resolver_1)'.dependencies]
30+
wasm-bindgen-test-macro = { path = "../test-macro", version = "=0.3.47", features = [
31+
"xxx_resolver_1",
32+
] }
33+
2934
[lints.rust]
3035
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(wasm_bindgen_unstable_test_coverage)'] }
3136

0 commit comments

Comments
 (0)