@@ -163,7 +163,7 @@ impl TryToTokens for ast::Program {
163
163
let prefix_json_bytes = syn:: LitByteStr :: new ( & prefix_json_bytes, Span :: call_site ( ) ) ;
164
164
165
165
( quote ! {
166
- #[ cfg( all( target_arch = "wasm32" , target_os = "unknown" ) ) ]
166
+ #[ cfg( all( target_arch = "wasm32" , any ( target_os = "unknown" , target_os = "none" ) ) ) ]
167
167
#[ automatically_derived]
168
168
const _: ( ) = {
169
169
use #wasm_bindgen:: __rt:: { flat_len, flat_byte_slices} ;
@@ -201,7 +201,7 @@ impl TryToTokens for ast::LinkToModule {
201
201
#program
202
202
#extern_fn
203
203
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 {
205
205
<#wasm_bindgen:: __rt:: alloc:: string:: String as #wasm_bindgen:: convert:: FromWasmAbi >:: from_abi( #name( ) . join( ) )
206
206
} ) ;
207
207
@@ -275,12 +275,12 @@ impl ToTokens for ast::Struct {
275
275
let ptr = #wasm_bindgen:: convert:: IntoWasmAbi :: into_abi( value) ;
276
276
277
277
#[ 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" ) ) ) ]
279
279
extern "C" {
280
280
fn #new_fn( ptr: u32 ) -> u32 ;
281
281
}
282
282
283
- #[ cfg( not( all( target_arch = "wasm32" , target_os = "unknown" ) ) ) ]
283
+ #[ cfg( not( all( target_arch = "wasm32" , any ( target_os = "unknown" , target_os = "none" ) ) ) ) ]
284
284
unsafe fn #new_fn( _: u32 ) -> u32 {
285
285
panic!( "cannot convert to JsValue outside of the Wasm target" )
286
286
}
@@ -292,7 +292,7 @@ impl ToTokens for ast::Struct {
292
292
}
293
293
}
294
294
295
- #[ cfg( all( target_arch = "wasm32" , target_os = "unknown" ) ) ]
295
+ #[ cfg( all( target_arch = "wasm32" , any ( target_os = "unknown" , target_os = "none" ) ) ) ]
296
296
#[ automatically_derived]
297
297
const _: ( ) = {
298
298
#[ no_mangle]
@@ -381,12 +381,12 @@ impl ToTokens for ast::Struct {
381
381
let idx = #wasm_bindgen:: convert:: IntoWasmAbi :: into_abi( & value) ;
382
382
383
383
#[ 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" ) ) ) ]
385
385
extern "C" {
386
386
fn #unwrap_fn( ptr: u32 ) -> u32 ;
387
387
}
388
388
389
- #[ cfg( not( all( target_arch = "wasm32" , target_os = "unknown" ) ) ) ]
389
+ #[ cfg( not( all( target_arch = "wasm32" , any ( target_os = "unknown" , target_os = "none" ) ) ) ) ]
390
390
unsafe fn #unwrap_fn( _: u32 ) -> u32 {
391
391
panic!( "cannot convert from JsValue outside of the Wasm target" )
392
392
}
@@ -493,7 +493,7 @@ impl ToTokens for ast::StructField {
493
493
( quote ! {
494
494
#[ automatically_derived]
495
495
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) ]
497
497
#[ doc( hidden) ]
498
498
#[ cfg_attr( wasm_bindgen_unstable_test_coverage, coverage( off) ) ]
499
499
pub unsafe extern "C" fn #getter( js: u32 )
@@ -532,7 +532,7 @@ impl ToTokens for ast::StructField {
532
532
let ( args, names) = splat ( wasm_bindgen, & Ident :: new ( "val" , rust_name. span ( ) ) , & abi) ;
533
533
534
534
( quote ! {
535
- #[ cfg( all( target_arch = "wasm32" , target_os = "unknown" ) ) ]
535
+ #[ cfg( all( target_arch = "wasm32" , any ( target_os = "unknown" , target_os = "none" ) ) ) ]
536
536
#[ automatically_derived]
537
537
const _: ( ) = {
538
538
#[ no_mangle]
@@ -791,7 +791,7 @@ impl TryToTokens for ast::Export {
791
791
const _: ( ) = {
792
792
#( #attrs) *
793
793
#[ cfg_attr(
794
- all( target_arch = "wasm32" , target_os = "unknown" ) ,
794
+ all( target_arch = "wasm32" , any ( target_os = "unknown" , target_os = "none" ) ) ,
795
795
export_name = #export_name,
796
796
) ]
797
797
#[ cfg_attr( wasm_bindgen_unstable_test_coverage, coverage( off) ) ]
@@ -1066,11 +1066,11 @@ impl ToTokens for ast::ImportType {
1066
1066
impl JsCast for #rust_name {
1067
1067
fn instanceof( val: & JsValue ) -> bool {
1068
1068
#[ 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" ) ) ) ]
1070
1070
extern "C" {
1071
1071
fn #instanceof_shim( val: u32 ) -> u32 ;
1072
1072
}
1073
- #[ cfg( not( all( target_arch = "wasm32" , target_os = "unknown" ) ) ) ]
1073
+ #[ cfg( not( all( target_arch = "wasm32" , any ( target_os = "unknown" , target_os = "none" ) ) ) ) ]
1074
1074
unsafe fn #instanceof_shim( _: u32 ) -> u32 {
1075
1075
panic!( "cannot check instanceof on non-wasm targets" ) ;
1076
1076
}
@@ -1675,14 +1675,15 @@ impl ToTokens for ast::ImportStatic {
1675
1675
fn to_tokens ( & self , into : & mut TokenStream ) {
1676
1676
let ty = & self . ty ;
1677
1677
1678
- if self . thread_local {
1678
+ if let Some ( thread_local ) = self . thread_local {
1679
1679
thread_local_import (
1680
1680
& self . vis ,
1681
1681
& self . rust_name ,
1682
1682
& self . wasm_bindgen ,
1683
1683
ty,
1684
1684
ty,
1685
1685
& self . shim ,
1686
+ thread_local,
1686
1687
)
1687
1688
. to_tokens ( into)
1688
1689
} else {
@@ -1695,7 +1696,7 @@ impl ToTokens for ast::ImportStatic {
1695
1696
1696
1697
into. extend ( quote ! {
1697
1698
#[ automatically_derived]
1698
- #[ deprecated = "use with `#[wasm_bindgen(thread_local )]` instead" ]
1699
+ #[ deprecated = "use with `#[wasm_bindgen(thread_local_v2 )]` instead" ]
1699
1700
} ) ;
1700
1701
into. extend (
1701
1702
quote_spanned ! { name. span( ) => #vis static #name: #wasm_bindgen:: JsStatic <#ty> = {
@@ -1735,6 +1736,7 @@ impl ToTokens for ast::ImportString {
1735
1736
& actual_ty,
1736
1737
& self . ty ,
1737
1738
& self . shim ,
1739
+ self . thread_local ,
1738
1740
)
1739
1741
. to_tokens ( into) ;
1740
1742
}
@@ -1747,15 +1749,52 @@ fn thread_local_import(
1747
1749
actual_ty : & syn:: Type ,
1748
1750
ty : & syn:: Type ,
1749
1751
shim_name : & Ident ,
1752
+ thread_local : ast:: ThreadLocal ,
1750
1753
) -> TokenStream {
1751
1754
let init = static_init ( wasm_bindgen, ty, shim_name) ;
1752
1755
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
+ }
1758
1780
} ;
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
+ }
1759
1798
}
1760
1799
}
1761
1800
}
@@ -1766,12 +1805,12 @@ fn static_init(wasm_bindgen: &syn::Path, ty: &syn::Type, shim_name: &Ident) -> T
1766
1805
} ;
1767
1806
quote ! {
1768
1807
#[ 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" ) ) ) ]
1770
1809
extern "C" {
1771
1810
fn #shim_name( ) -> #abi_ret;
1772
1811
}
1773
1812
1774
- #[ cfg( not( all( target_arch = "wasm32" , target_os = "unknown" ) ) ) ]
1813
+ #[ cfg( not( all( target_arch = "wasm32" , any ( target_os = "unknown" , target_os = "none" ) ) ) ) ]
1775
1814
unsafe fn #shim_name( ) -> #abi_ret {
1776
1815
panic!( "cannot access imported statics on non-wasm targets" )
1777
1816
}
@@ -1818,7 +1857,7 @@ impl<'a, T: ToTokens> ToTokens for Descriptor<'a, T> {
1818
1857
let attrs = & self . attrs ;
1819
1858
let wasm_bindgen = & self . wasm_bindgen ;
1820
1859
( quote ! {
1821
- #[ cfg( all( target_arch = "wasm32" , target_os = "unknown" ) ) ]
1860
+ #[ cfg( all( target_arch = "wasm32" , any ( target_os = "unknown" , target_os = "none" ) ) ) ]
1822
1861
#[ automatically_derived]
1823
1862
const _: ( ) = {
1824
1863
#( #attrs) *
@@ -1845,14 +1884,14 @@ fn extern_fn(
1845
1884
abi_ret : TokenStream ,
1846
1885
) -> TokenStream {
1847
1886
quote ! {
1848
- #[ cfg( all( target_arch = "wasm32" , target_os = "unknown" ) ) ]
1887
+ #[ cfg( all( target_arch = "wasm32" , any ( target_os = "unknown" , target_os = "none" ) ) ) ]
1849
1888
#( #attrs) *
1850
1889
#[ link( wasm_import_module = "__wbindgen_placeholder__" ) ]
1851
1890
extern "C" {
1852
1891
fn #import_name( #( #abi_arguments) , * ) -> #abi_ret;
1853
1892
}
1854
1893
1855
- #[ cfg( not( all( target_arch = "wasm32" , target_os = "unknown" ) ) ) ]
1894
+ #[ cfg( not( all( target_arch = "wasm32" , any ( target_os = "unknown" , target_os = "none" ) ) ) ) ]
1856
1895
unsafe fn #import_name( #( #abi_arguments) , * ) -> #abi_ret {
1857
1896
#(
1858
1897
drop( #abi_argument_names) ;
0 commit comments