Skip to content

Commit c4a864e

Browse files
committed
Added support for the wasm32v1-none target
1 parent fe5d89f commit c4a864e

File tree

575 files changed

+2249
-1560
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

575 files changed

+2249
-1560
lines changed

.cargo/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[target.wasm32-unknown-unknown]
1+
[target.'cfg(target_arch = "wasm32")']
22
runner = 'cargo run -p wasm-bindgen-cli --bin wasm-bindgen-test-runner --'
33

44
[target.'cfg(all())']

.github/workflows/main.yml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,37 @@ jobs:
9292
- run: cargo clippy --no-deps --all-features --target wasm32-unknown-unknown -p js-sys -- -D warnings
9393
- run: cargo clippy --no-deps --all-features --target wasm32-unknown-unknown -p web-sys -- -D warnings
9494

95+
# Run `cargo clippy` over crates that support `no_std`
96+
clippy_no_std:
97+
name: Clippy `no_std`
98+
runs-on: ubuntu-latest
99+
steps:
100+
- uses: actions/checkout@v4
101+
- run: rustup update --no-self-update stable && rustup default stable
102+
- run: rustup target add wasm32-unknown-unknown
103+
- run: cargo clippy --no-deps --no-default-features --target wasm32-unknown-unknown -p wasm-bindgen -- -D warnings
104+
- run: cargo clippy --no-deps --no-default-features --target wasm32-unknown-unknown -p js-sys -- -D warnings
105+
- run: cargo clippy --no-deps --no-default-features --target wasm32-unknown-unknown -p web-sys -- -D warnings
106+
- run: cargo clippy --no-deps --no-default-features --target wasm32-unknown-unknown -p wasm-bindgen-futures -- -D warnings
107+
- run: cargo clippy --no-deps --no-default-features --target wasm32-unknown-unknown -p wasm-bindgen-test -- -D warnings
108+
109+
# Run `cargo clippy` over crates that support `no_std` with `target_feature = "atomics"` support.
110+
clippy_no_std_atomics:
111+
name: Clippy `no_std` with `atomics`
112+
runs-on: ubuntu-latest
113+
env:
114+
CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUSTFLAGS: -Ctarget-feature=+atomics,+bulk-memory
115+
steps:
116+
- uses: actions/checkout@v4
117+
- run: rustup default nightly-2024-07-06
118+
- run: rustup target add wasm32-unknown-unknown
119+
- run: rustup component add clippy rust-src
120+
- run: cargo clippy --no-deps --no-default-features --target wasm32-unknown-unknown -p wasm-bindgen -Zbuild-std=panic_abort,core,alloc -- -D warnings
121+
- run: cargo clippy --no-deps --no-default-features --target wasm32-unknown-unknown -p js-sys -Zbuild-std=panic_abort,core,alloc -- -D warnings
122+
- run: cargo clippy --no-deps --no-default-features --target wasm32-unknown-unknown -p web-sys -Zbuild-std=panic_abort,core,alloc -- -D warnings
123+
- run: cargo clippy --no-deps --no-default-features --target wasm32-unknown-unknown -p wasm-bindgen-futures -Zbuild-std=panic_abort,core,alloc -- -D warnings
124+
- run: cargo clippy --no-deps --no-default-features --target wasm32-unknown-unknown -p wasm-bindgen-test -Zbuild-std=panic_abort,core,alloc -- -D warnings
125+
95126
# Run `cargo clippy` over the project
96127
clippy_project:
97128
name: Clippy (project)
@@ -100,7 +131,6 @@ jobs:
100131
- uses: actions/checkout@v4
101132
- run: rustup update --no-self-update stable && rustup default stable
102133
- run: rustup target add wasm32-unknown-unknown
103-
- run: cargo clippy --no-deps --no-default-features --target wasm32-unknown-unknown -- -D warnings
104134
- run: cargo clippy --no-deps --all-features --target wasm32-unknown-unknown -- -D warnings
105135
- run: cargo clippy --no-deps --all-features --target wasm32-unknown-unknown --tests -- -D warnings
106136
- run: for i in examples/*/; do cd "$i"; cargo +stable clippy --no-deps --all-features --target wasm32-unknown-unknown -- -D warnings || exit 1; cd ../..; done

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@
2323
* Added WASM ABI support for `u128` and `i128`
2424
[#4222](https://github.com/rustwasm/wasm-bindgen/pull/4222)
2525

26+
* Added support for the `wasm32v1-none` target.
27+
[#4277](https://github.com/rustwasm/wasm-bindgen/pull/4277)
28+
29+
* Added support for `no_std` to `js-sys`, `web-sys`, `wasm-bindgen-futures` and `wasm-bindgen-test`.
30+
[#4277](https://github.com/rustwasm/wasm-bindgen/pull/4277)
31+
32+
* Added support for `no_std` to `link_to!`, `static_string` (via `thread_local_v2`) and `throw`.
33+
[#4277](https://github.com/rustwasm/wasm-bindgen/pull/4277)
34+
2635
### Changed
2736

2837
* String enums now generate private TypeScript types but only if used.
@@ -46,6 +55,9 @@
4655
* `wasm-bindgen-test-runner` now tries to restart the WebDriver on failure, instead of spending its timeout period trying to connect to a non-existing WebDriver.
4756
[#4267](https://github.com/rustwasm/wasm-bindgen/pull/4267)
4857

58+
* Deprecated `#[wasm_bindgen(thread_local)]` in favor of `#[wasm_bindgen(thread_local_v2)]`, which creates a `wasm_bindgen::JsThreadLocal`. It is similar to `std::thread::LocalKey` but supports `no_std`.
59+
[#4277](https://github.com/rustwasm/wasm-bindgen/pull/4277)
60+
4961
### Fixed
5062

5163
* Fixed methods with `self: &Self` consuming the object.

Cargo.toml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ default = ["spans", "std"]
2626
enable-interning = ["std"]
2727
serde-serialize = ["serde", "serde_json", "std"]
2828
spans = ["wasm-bindgen-macro/spans"]
29-
std = []
29+
std = ["wasm-bindgen-macro/std", "once_cell/std"]
3030

3131
# Whether or not the `#[wasm_bindgen]` macro is strict and generates an error on
3232
# all unused attributes
@@ -42,10 +42,16 @@ xxx_debug_only_print_generated_code = ["wasm-bindgen-macro/xxx_debug_only_print_
4242

4343
[dependencies]
4444
cfg-if = "1.0.0"
45-
once_cell = "1.12"
45+
once_cell = { version = "1.12", default-features = false }
4646
serde = { version = "1.0", optional = true }
4747
serde_json = { version = "1.0", optional = true }
48-
wasm-bindgen-macro = { path = "crates/macro", version = "=0.2.95" }
48+
wasm-bindgen-macro = { path = "crates/macro", version = "=0.2.95", default-features = false }
49+
50+
[target.'cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none"), target_feature = "atomics"))'.dependencies]
51+
once_cell = { version = "1.12", default-features = false, features = ["critical-section"] }
52+
wasm-bindgen-macro = { path = "crates/macro", version = "=0.2.95", default-features = false, features = [
53+
"atomics",
54+
] }
4955

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

crates/backend/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ rust-version = "1.57"
1414
version = "0.2.95"
1515

1616
[features]
17+
atomics = []
18+
default = ["std"]
1719
extra-traits = ["syn/extra-traits"]
1820
spans = []
21+
std = []
1922

2023
[dependencies]
2124
bumpalo = "3.0.0"

crates/backend/src/ast.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,17 @@ pub struct ImportStatic {
275275
pub js_name: String,
276276
/// Path to wasm_bindgen
277277
pub wasm_bindgen: Path,
278-
/// [`true`] if using the new `thread_local` representation.
279-
pub thread_local: bool,
278+
/// Version of `thread_local`, if any.
279+
pub thread_local: Option<ThreadLocal>,
280+
}
281+
282+
/// Which version of the `thread_local` attribute is enabled.
283+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
284+
pub enum ThreadLocal {
285+
/// V1.
286+
V1,
287+
/// V2.
288+
V2,
280289
}
281290

282291
/// The type of a static string being imported
@@ -297,6 +306,8 @@ pub struct ImportString {
297306
pub js_sys: Path,
298307
/// The string to export.
299308
pub string: String,
309+
/// Version of `thread_local`.
310+
pub thread_local: ThreadLocal,
300311
}
301312

302313
/// The metadata for a type being imported

crates/backend/src/codegen.rs

Lines changed: 63 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ impl TryToTokens for ast::Program {
163163
let prefix_json_bytes = syn::LitByteStr::new(&prefix_json_bytes, Span::call_site());
164164

165165
(quote! {
166-
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
166+
#[cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))]
167167
#[automatically_derived]
168168
const _: () = {
169169
use #wasm_bindgen::__rt::{flat_len, flat_byte_slices};
@@ -201,7 +201,7 @@ impl TryToTokens for ast::LinkToModule {
201201
#program
202202
#extern_fn
203203

204-
static __VAL: #wasm_bindgen::__rt::Lazy<String> = #wasm_bindgen::__rt::Lazy::new(|| unsafe {
204+
static __VAL: #wasm_bindgen::__rt::LazyLock<#wasm_bindgen::__rt::alloc::string::String> = #wasm_bindgen::__rt::LazyLock::new(|| unsafe {
205205
<#wasm_bindgen::__rt::alloc::string::String as #wasm_bindgen::convert::FromWasmAbi>::from_abi(#name().join())
206206
});
207207

@@ -275,12 +275,12 @@ impl ToTokens for ast::Struct {
275275
let ptr = #wasm_bindgen::convert::IntoWasmAbi::into_abi(value);
276276

277277
#[link(wasm_import_module = "__wbindgen_placeholder__")]
278-
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
278+
#[cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))]
279279
extern "C" {
280280
fn #new_fn(ptr: u32) -> u32;
281281
}
282282

283-
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
283+
#[cfg(not(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none"))))]
284284
unsafe fn #new_fn(_: u32) -> u32 {
285285
panic!("cannot convert to JsValue outside of the Wasm target")
286286
}
@@ -292,7 +292,7 @@ impl ToTokens for ast::Struct {
292292
}
293293
}
294294

295-
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
295+
#[cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))]
296296
#[automatically_derived]
297297
const _: () = {
298298
#[no_mangle]
@@ -381,12 +381,12 @@ impl ToTokens for ast::Struct {
381381
let idx = #wasm_bindgen::convert::IntoWasmAbi::into_abi(&value);
382382

383383
#[link(wasm_import_module = "__wbindgen_placeholder__")]
384-
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
384+
#[cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))]
385385
extern "C" {
386386
fn #unwrap_fn(ptr: u32) -> u32;
387387
}
388388

389-
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
389+
#[cfg(not(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none"))))]
390390
unsafe fn #unwrap_fn(_: u32) -> u32 {
391391
panic!("cannot convert from JsValue outside of the Wasm target")
392392
}
@@ -493,7 +493,7 @@ impl ToTokens for ast::StructField {
493493
(quote! {
494494
#[automatically_derived]
495495
const _: () = {
496-
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), no_mangle)]
496+
#[cfg_attr(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")), no_mangle)]
497497
#[doc(hidden)]
498498
#[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))]
499499
pub unsafe extern "C" fn #getter(js: u32)
@@ -532,7 +532,7 @@ impl ToTokens for ast::StructField {
532532
let (args, names) = splat(wasm_bindgen, &Ident::new("val", rust_name.span()), &abi);
533533

534534
(quote! {
535-
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
535+
#[cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))]
536536
#[automatically_derived]
537537
const _: () = {
538538
#[no_mangle]
@@ -791,7 +791,7 @@ impl TryToTokens for ast::Export {
791791
const _: () = {
792792
#(#attrs)*
793793
#[cfg_attr(
794-
all(target_arch = "wasm32", target_os = "unknown"),
794+
all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")),
795795
export_name = #export_name,
796796
)]
797797
#[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))]
@@ -1066,11 +1066,11 @@ impl ToTokens for ast::ImportType {
10661066
impl JsCast for #rust_name {
10671067
fn instanceof(val: &JsValue) -> bool {
10681068
#[link(wasm_import_module = "__wbindgen_placeholder__")]
1069-
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
1069+
#[cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))]
10701070
extern "C" {
10711071
fn #instanceof_shim(val: u32) -> u32;
10721072
}
1073-
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
1073+
#[cfg(not(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none"))))]
10741074
unsafe fn #instanceof_shim(_: u32) -> u32 {
10751075
panic!("cannot check instanceof on non-wasm targets");
10761076
}
@@ -1675,14 +1675,15 @@ impl ToTokens for ast::ImportStatic {
16751675
fn to_tokens(&self, into: &mut TokenStream) {
16761676
let ty = &self.ty;
16771677

1678-
if self.thread_local {
1678+
if let Some(thread_local) = self.thread_local {
16791679
thread_local_import(
16801680
&self.vis,
16811681
&self.rust_name,
16821682
&self.wasm_bindgen,
16831683
ty,
16841684
ty,
16851685
&self.shim,
1686+
thread_local,
16861687
)
16871688
.to_tokens(into)
16881689
} else {
@@ -1695,7 +1696,7 @@ impl ToTokens for ast::ImportStatic {
16951696

16961697
into.extend(quote! {
16971698
#[automatically_derived]
1698-
#[deprecated = "use with `#[wasm_bindgen(thread_local)]` instead"]
1699+
#[deprecated = "use with `#[wasm_bindgen(thread_local_v2)]` instead"]
16991700
});
17001701
into.extend(
17011702
quote_spanned! { name.span() => #vis static #name: #wasm_bindgen::JsStatic<#ty> = {
@@ -1735,6 +1736,7 @@ impl ToTokens for ast::ImportString {
17351736
&actual_ty,
17361737
&self.ty,
17371738
&self.shim,
1739+
self.thread_local,
17381740
)
17391741
.to_tokens(into);
17401742
}
@@ -1747,15 +1749,52 @@ fn thread_local_import(
17471749
actual_ty: &syn::Type,
17481750
ty: &syn::Type,
17491751
shim_name: &Ident,
1752+
thread_local: ast::ThreadLocal,
17501753
) -> TokenStream {
17511754
let init = static_init(wasm_bindgen, ty, shim_name);
17521755

1753-
quote! {
1754-
thread_local! {
1755-
#[automatically_derived]
1756-
#vis static #name: #actual_ty = {
1757-
#init
1756+
match thread_local {
1757+
ast::ThreadLocal::V1 => quote! {
1758+
thread_local! {
1759+
#[automatically_derived]
1760+
#[deprecated = "use with `#[wasm_bindgen(thread_local_v2)]` instead"]
1761+
#vis static #name: #actual_ty = {
1762+
#init
1763+
};
1764+
}
1765+
},
1766+
ast::ThreadLocal::V2 => {
1767+
#[cfg(feature = "std")]
1768+
let inner = quote! {
1769+
thread_local!(static _VAL: #actual_ty = init(););
1770+
#wasm_bindgen::JsThreadLocal {
1771+
__inner: &_VAL,
1772+
}
1773+
};
1774+
#[cfg(all(not(feature = "std"), not(feature = "atomics")))]
1775+
let inner = quote! {
1776+
static _VAL: #wasm_bindgen::__rt::LazyCell<#actual_ty> = #wasm_bindgen::__rt::LazyCell::new(init);
1777+
#wasm_bindgen::JsThreadLocal {
1778+
__inner: &_VAL,
1779+
}
17581780
};
1781+
#[cfg(all(not(feature = "std"), feature = "atomics"))]
1782+
let inner = quote! {
1783+
#[thread_local]
1784+
static _VAL: #wasm_bindgen::__rt::LazyCell<#actual_ty> = #wasm_bindgen::__rt::LazyCell::new(init);
1785+
#wasm_bindgen::JsThreadLocal {
1786+
__inner: || unsafe { #wasm_bindgen::__rt::LazyCell::force(&_VAL) as *const #actual_ty },
1787+
}
1788+
};
1789+
1790+
quote! {
1791+
#vis static #name: #wasm_bindgen::JsThreadLocal<#actual_ty> = {
1792+
fn init() -> #actual_ty {
1793+
#init
1794+
}
1795+
#inner
1796+
};
1797+
}
17591798
}
17601799
}
17611800
}
@@ -1766,12 +1805,12 @@ fn static_init(wasm_bindgen: &syn::Path, ty: &syn::Type, shim_name: &Ident) -> T
17661805
};
17671806
quote! {
17681807
#[link(wasm_import_module = "__wbindgen_placeholder__")]
1769-
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
1808+
#[cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))]
17701809
extern "C" {
17711810
fn #shim_name() -> #abi_ret;
17721811
}
17731812

1774-
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
1813+
#[cfg(not(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none"))))]
17751814
unsafe fn #shim_name() -> #abi_ret {
17761815
panic!("cannot access imported statics on non-wasm targets")
17771816
}
@@ -1818,7 +1857,7 @@ impl<'a, T: ToTokens> ToTokens for Descriptor<'a, T> {
18181857
let attrs = &self.attrs;
18191858
let wasm_bindgen = &self.wasm_bindgen;
18201859
(quote! {
1821-
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
1860+
#[cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))]
18221861
#[automatically_derived]
18231862
const _: () = {
18241863
#(#attrs)*
@@ -1845,14 +1884,14 @@ fn extern_fn(
18451884
abi_ret: TokenStream,
18461885
) -> TokenStream {
18471886
quote! {
1848-
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
1887+
#[cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))]
18491888
#(#attrs)*
18501889
#[link(wasm_import_module = "__wbindgen_placeholder__")]
18511890
extern "C" {
18521891
fn #import_name(#(#abi_arguments),*) -> #abi_ret;
18531892
}
18541893

1855-
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
1894+
#[cfg(not(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none"))))]
18561895
unsafe fn #import_name(#(#abi_arguments),*) -> #abi_ret {
18571896
#(
18581897
drop(#abi_argument_names);

crates/cli/tests/reference/anyref-import-catch.wat

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
(type (;2;) (func (result i32 i32)))
55
(type (;3;) (func (param i32)))
66
(import "./reference_test_bg.js" "__wbindgen_init_externref_table" (func (;0;) (type 0)))
7-
(func $__externref_table_dealloc (;1;) (type 3) (param i32))
8-
(func $__externref_table_alloc (;2;) (type 1) (result i32))
9-
(func $__wbindgen_exn_store (;3;) (type 3) (param i32))
7+
(func $__wbindgen_exn_store (;1;) (type 3) (param i32))
8+
(func $__externref_table_dealloc (;2;) (type 3) (param i32))
9+
(func $__externref_table_alloc (;3;) (type 1) (result i32))
1010
(func $"exported multivalue shim" (;4;) (type 2) (result i32 i32))
1111
(table (;0;) 128 externref)
1212
(memory (;0;) 17)

0 commit comments

Comments
 (0)