Skip to content

Commit

Permalink
Re-establish feature resolver version 1 compatibility (#4327)
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda authored Dec 6, 2024
1 parent e021ba4 commit f90ebda
Show file tree
Hide file tree
Showing 18 changed files with 87 additions and 160 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ jobs:
- 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 --features spans,strict-macro -p wasm-bindgen-macro -- -D warnings
- run: cargo clippy --no-deps --features extra-traits,spans,strict-macro -p wasm-bindgen-macro-support -- -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 -p wasm-bindgen-test-macro -- -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
Expand Down Expand Up @@ -540,7 +540,7 @@ jobs:
path: docs.tar.gz

msrv-resolver:
name: Check for feature resolver v1 error message
name: Check feature resolver version 1 compatibility
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand All @@ -565,7 +565,7 @@ jobs:
cargo update -p bumpalo --precise 3.12.0
cargo update -p log --precise 0.4.18
cargo update -p scoped-tls --precise 1.0.0
- run: diff <(cargo build --target ${{ matrix.target }} ${{ matrix.features }} --message-format json | jq -r "select(.reason == \"compiler-message\") | .message.message") error-${{ matrix.rust }}.txt
- run: cargo build --target ${{ matrix.target }} ${{ matrix.features }}

msrv-lib:
name: Check MSRV for libraries
Expand Down
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@

### Added

* Add clear error message to communicate new feature resolver version requirements.
[#4312](https://github.com/rustwasm/wasm-bindgen/pull/4312)

* Add support for multi-threading in Node.js.
[#4318](https://github.com/rustwasm/wasm-bindgen/pull/4318)

Expand All @@ -27,6 +24,9 @@
* Fix macro-hygiene for calls to `std::thread_local!`.
[#4315](https://github.com/rustwasm/wasm-bindgen/pull/4315)

* Fix feature resolver version 1 compatibility.
[#4327](https://github.com/rustwasm/wasm-bindgen/pull/4327)

--------------------------------------------------------------------------------

## [0.2.97](https://github.com/rustwasm/wasm-bindgen/compare/0.2.96...0.2.97)
Expand Down
17 changes: 1 addition & 16 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,6 @@ serde = { version = "1.0", optional = true }
serde_json = { version = "1.0", optional = true }
wasm-bindgen-macro = { path = "crates/macro", version = "=0.2.97", default-features = false }

[target.'cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none"), target_feature = "atomics"))'.dependencies]
wasm-bindgen-macro = { path = "crates/macro", version = "=0.2.97", default-features = false, features = [
"atomics",
] }

[target.'cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none"), wasm_bindgen_unstable_test_coverage))'.dependencies]
wasm-bindgen-macro = { path = "crates/macro", version = "=0.2.97", default-features = false, features = [
"coverage",
] }

[target.'cfg(__wasm_bindgen_resolver_1)'.dependencies]
wasm-bindgen-macro = { path = "crates/macro", version = "=0.2.97", default-features = false, features = [
"xxx_resolver_1",
] }

[dev-dependencies]
wasm-bindgen-test = { path = 'crates/test' }

Expand Down Expand Up @@ -90,7 +75,7 @@ too_many_arguments = "allow"
type_complexity = "allow"

[workspace]
exclude = ["crates/msrv"]
exclude = ["crates/msrv/resolver", "crates/msrv/lib", "crates/msrv/cli"]
members = [
"benchmarks",
"crates/cli",
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ Libraries that are released on [crates.io](https://crates.io) have a MSRV of v1.

CLI tools and their corresponding support libraries have a MSRV of v1.76. Changes to the MSRV will be accompanied by a patch version bump.

[Feature resolver version 2](https://doc.rust-lang.org/1.83.0/cargo/reference/resolver.html#feature-resolver-version-2) is required.

## License

This project is licensed under either of
Expand Down
4 changes: 0 additions & 4 deletions crates/backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,14 @@ rust-version = "1.57"
version = "0.2.97"

[features]
atomics = []
coverage = []
default = ["std"]
extra-traits = ["syn/extra-traits"]
spans = []
std = []
xxx_resolver_1 = []

[dependencies]
bumpalo = "3.0.0"
log = "0.4"
once_cell = "1.12"
proc-macro2 = "1.0"
quote = '1.0'
syn = { version = '2.0', features = ['full'] }
Expand Down
61 changes: 17 additions & 44 deletions crates/backend/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ use crate::ast;
use crate::encode;
use crate::encode::EncodeChunk;
use crate::Diagnostic;
use once_cell::sync::Lazy;
use proc_macro2::{Ident, Span, TokenStream};
use quote::format_ident;
use quote::quote_spanned;
use quote::{quote, ToTokens};
use std::cell::RefCell;
use std::collections::{HashMap, HashSet};
use std::sync::Mutex;
use syn::parse_quote;
use syn::spanned::Spanned;
use wasm_bindgen_shared as shared;
Expand Down Expand Up @@ -224,7 +223,6 @@ impl ToTokens for ast::Struct {
let free_fn = Ident::new(&shared::free_function(&name_str), Span::call_site());
let unwrap_fn = Ident::new(&shared::unwrap_function(&name_str), Span::call_site());
let wasm_bindgen = &self.wasm_bindgen;
let maybe_no_coverage = coverage();
(quote! {
#[automatically_derived]
impl #wasm_bindgen::describe::WasmDescribe for #name {
Expand Down Expand Up @@ -296,11 +294,11 @@ impl ToTokens for ast::Struct {
#[cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))]
#[automatically_derived]
const _: () = {
#wasm_bindgen::__wbindgen_coverage! {
#[no_mangle]
#[doc(hidden)]
// `allow_delayed` is whether it's ok to not actually free the `ptr` immediately
// if it's still borrowed.
#maybe_no_coverage
pub unsafe extern "C" fn #free_fn(ptr: u32, allow_delayed: u32) {
use #wasm_bindgen::__rt::alloc::rc::Rc;

Expand All @@ -315,6 +313,7 @@ impl ToTokens for ast::Struct {
let _ = <#name as #wasm_bindgen::convert::FromWasmAbi>::from_abi(ptr);
}
}
}
};

#[automatically_derived]
Expand Down Expand Up @@ -476,7 +475,6 @@ impl ToTokens for ast::StructField {
quote! { assert_copy::<#ty>() }
};
let maybe_assert_copy = respan(maybe_assert_copy, ty);
let maybe_no_coverage = coverage();

// Split this out so that it isn't affected by `quote_spanned!`.
//
Expand All @@ -495,9 +493,9 @@ impl ToTokens for ast::StructField {
(quote! {
#[automatically_derived]
const _: () = {
#wasm_bindgen::__wbindgen_coverage! {
#[cfg_attr(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")), no_mangle)]
#[doc(hidden)]
#maybe_no_coverage
pub unsafe extern "C" fn #getter(js: u32)
-> #wasm_bindgen::convert::WasmRet<<#ty as #wasm_bindgen::convert::IntoWasmAbi>::Abi>
{
Expand All @@ -512,6 +510,7 @@ impl ToTokens for ast::StructField {
let val = #val;
<#ty as IntoWasmAbi>::into_abi(val).into()
}
}
};
})
.to_tokens(tokens);
Expand All @@ -537,9 +536,9 @@ impl ToTokens for ast::StructField {
#[cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))]
#[automatically_derived]
const _: () = {
#wasm_bindgen::__wbindgen_coverage! {
#[no_mangle]
#[doc(hidden)]
#maybe_no_coverage
pub unsafe extern "C" fn #setter(
js: u32,
#(#args,)*
Expand All @@ -553,6 +552,7 @@ impl ToTokens for ast::StructField {
let val = <#ty as FromWasmAbi>::from_abi(val);
(*js).borrow_mut().#rust_name = val;
}
}
};
})
.to_tokens(tokens);
Expand Down Expand Up @@ -788,23 +788,22 @@ impl TryToTokens for ast::Export {
quote! {}
};

let maybe_no_coverage = coverage();

(quote! {
#[automatically_derived]
const _: () = {
#wasm_bindgen::__wbindgen_coverage! {
#(#attrs)*
#[cfg_attr(
all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")),
export_name = #export_name,
)]
#maybe_no_coverage
pub unsafe extern "C" fn #generated_name(#(#args),*) -> #wasm_bindgen::convert::WasmRet<#projection::Abi> {
#start_check

let #ret = #call;
#convert_ret
}
}
};
})
.to_tokens(into);
Expand Down Expand Up @@ -1159,8 +1158,6 @@ impl ToTokens for ast::StringEnum {
let hole = variant_count + 1;
let attrs = &self.rust_attrs;

let maybe_no_coverage = coverage();

let invalid_to_str_msg = format!(
"Converting an invalid string enum ({}) back to a string is currently not supported",
enum_name
Expand Down Expand Up @@ -1247,7 +1244,6 @@ impl ToTokens for ast::StringEnum {

#[automatically_derived]
impl #wasm_bindgen::describe::WasmDescribe for #enum_name {
#maybe_no_coverage
fn describe() {
use #wasm_bindgen::describe::*;
inform(STRING_ENUM);
Expand Down Expand Up @@ -1546,7 +1542,6 @@ impl ToTokens for ast::Enum {
} else {
quote! { u32 }
};
let maybe_no_coverage = coverage();
let cast_clauses = self.variants.iter().map(|variant| {
let variant_name = &variant.name;
quote! {
Expand Down Expand Up @@ -1594,7 +1589,6 @@ impl ToTokens for ast::Enum {

#[automatically_derived]
impl #wasm_bindgen::describe::WasmDescribe for #enum_name {
#maybe_no_coverage
fn describe() {
use #wasm_bindgen::describe::*;
inform(ENUM);
Expand Down Expand Up @@ -1778,20 +1772,9 @@ fn thread_local_import(
__inner: &_VAL,
}
};
#[cfg(all(not(feature = "std"), not(feature = "atomics")))]
let inner = quote! {
static _VAL: #wasm_bindgen::__rt::LazyCell<#actual_ty> = #wasm_bindgen::__rt::LazyCell::new(init);
#wasm_bindgen::JsThreadLocal {
__inner: &_VAL,
}
};
#[cfg(all(not(feature = "std"), feature = "atomics"))]
#[cfg(not(feature = "std"))]
let inner = quote! {
#[thread_local]
static _VAL: #wasm_bindgen::__rt::LazyCell<#actual_ty> = #wasm_bindgen::__rt::LazyCell::new(init);
#wasm_bindgen::JsThreadLocal {
__inner: || unsafe { #wasm_bindgen::__rt::LazyCell::force(&_VAL) as *const #actual_ty },
}
#wasm_bindgen::__wbindgen_thread_local!(#wasm_bindgen, #actual_ty)
};

quote! {
Expand Down Expand Up @@ -1847,20 +1830,16 @@ impl<T: ToTokens> ToTokens for Descriptor<'_, T> {
// It's up to the descriptors themselves to ensure they have unique
// names for unique items imported, currently done via `ShortHash` and
// hashing appropriate data into the symbol name.
static DESCRIPTORS_EMITTED: Lazy<Mutex<HashSet<String>>> = Lazy::new(Default::default);
thread_local! {
static DESCRIPTORS_EMITTED: RefCell<HashSet<String>> = RefCell::default();
}

let ident = self.ident;

if !DESCRIPTORS_EMITTED
.lock()
.unwrap()
.insert(ident.to_string())
{
if !DESCRIPTORS_EMITTED.with(|list| list.borrow_mut().insert(ident.to_string())) {
return;
}

let maybe_no_coverage = coverage();

let name = Ident::new(&format!("__wbindgen_describe_{}", ident), ident.span());
let inner = &self.inner;
let attrs = &self.attrs;
Expand All @@ -1869,16 +1848,17 @@ impl<T: ToTokens> ToTokens for Descriptor<'_, T> {
#[cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))]
#[automatically_derived]
const _: () = {
#wasm_bindgen::__wbindgen_coverage! {
#(#attrs)*
#[no_mangle]
#[doc(hidden)]
#maybe_no_coverage
pub extern "C" fn #name() {
use #wasm_bindgen::describe::*;
// See definition of `link_mem_intrinsics` for what this is doing
#wasm_bindgen::__rt::link_mem_intrinsics();
#inner
}
}
};
})
.to_tokens(tokens);
Expand Down Expand Up @@ -1963,10 +1943,3 @@ fn respan(input: TokenStream, span: &dyn ToTokens) -> TokenStream {
}
new_tokens.into_iter().collect()
}

fn coverage() -> Option<TokenStream> {
#[cfg(all(not(feature = "xxx_resolver_1"), feature = "coverage"))]
return Some(quote! { #[coverage(off)] });
#[cfg(any(feature = "xxx_resolver_1", not(feature = "coverage")))]
None
}
3 changes: 0 additions & 3 deletions crates/macro-support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@ rust-version = "1.57"
version = "0.2.97"

[features]
atomics = ["wasm-bindgen-backend/atomics"]
coverage = ["wasm-bindgen-backend/coverage"]
default = ["std"]
extra-traits = ["syn/extra-traits"]
spans = ["wasm-bindgen-backend/spans"]
std = ["wasm-bindgen-backend/std"]
strict-macro = []
xxx_resolver_1 = ["wasm-bindgen-backend/xxx_resolver_1"]

[dependencies]
proc-macro2 = "1.0"
Expand Down
3 changes: 0 additions & 3 deletions crates/macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@ version = "0.2.97"
proc-macro = true

[features]
atomics = ["wasm-bindgen-macro-support/atomics"]
coverage = ["wasm-bindgen-macro-support/coverage"]
default = ["std"]
spans = ["wasm-bindgen-macro-support/spans"]
std = ["wasm-bindgen-macro-support/std"]
strict-macro = ["wasm-bindgen-macro-support/strict-macro"]
xxx_debug_only_print_generated_code = []
xxx_resolver_1 = ["wasm-bindgen-macro-support/xxx_resolver_1"]

[dependencies]
quote = "1.0"
Expand Down
Loading

0 comments on commit f90ebda

Please sign in to comment.