@@ -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,9 +201,10 @@ 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 {
205
- <#wasm_bindgen:: __rt:: alloc:: string:: String as #wasm_bindgen:: convert:: FromWasmAbi >:: from_abi( #name( ) . join( ) )
206
- } ) ;
204
+ static __VAL: #wasm_bindgen:: __rt:: once_cell:: sync:: Lazy <#wasm_bindgen:: __rt:: alloc:: string:: String > =
205
+ #wasm_bindgen:: __rt:: once_cell:: sync:: Lazy :: new( || unsafe {
206
+ <#wasm_bindgen:: __rt:: alloc:: string:: String as #wasm_bindgen:: convert:: FromWasmAbi >:: from_abi( #name( ) . join( ) )
207
+ } ) ;
207
208
208
209
#wasm_bindgen:: __rt:: alloc:: string:: String :: clone( & __VAL)
209
210
}
@@ -275,12 +276,12 @@ impl ToTokens for ast::Struct {
275
276
let ptr = #wasm_bindgen:: convert:: IntoWasmAbi :: into_abi( value) ;
276
277
277
278
#[ link( wasm_import_module = "__wbindgen_placeholder__" ) ]
278
- #[ cfg( all( target_arch = "wasm32" , target_os = "unknown" ) ) ]
279
+ #[ cfg( all( target_arch = "wasm32" , any ( target_os = "unknown" , target_os = "none" ) ) ) ]
279
280
extern "C" {
280
281
fn #new_fn( ptr: u32 ) -> u32 ;
281
282
}
282
283
283
- #[ cfg( not( all( target_arch = "wasm32" , target_os = "unknown" ) ) ) ]
284
+ #[ cfg( not( all( target_arch = "wasm32" , any ( target_os = "unknown" , target_os = "none" ) ) ) ) ]
284
285
unsafe fn #new_fn( _: u32 ) -> u32 {
285
286
panic!( "cannot convert to JsValue outside of the Wasm target" )
286
287
}
@@ -292,7 +293,7 @@ impl ToTokens for ast::Struct {
292
293
}
293
294
}
294
295
295
- #[ cfg( all( target_arch = "wasm32" , target_os = "unknown" ) ) ]
296
+ #[ cfg( all( target_arch = "wasm32" , any ( target_os = "unknown" , target_os = "none" ) ) ) ]
296
297
#[ automatically_derived]
297
298
const _: ( ) = {
298
299
#[ no_mangle]
@@ -381,12 +382,12 @@ impl ToTokens for ast::Struct {
381
382
let idx = #wasm_bindgen:: convert:: IntoWasmAbi :: into_abi( & value) ;
382
383
383
384
#[ link( wasm_import_module = "__wbindgen_placeholder__" ) ]
384
- #[ cfg( all( target_arch = "wasm32" , target_os = "unknown" ) ) ]
385
+ #[ cfg( all( target_arch = "wasm32" , any ( target_os = "unknown" , target_os = "none" ) ) ) ]
385
386
extern "C" {
386
387
fn #unwrap_fn( ptr: u32 ) -> u32 ;
387
388
}
388
389
389
- #[ cfg( not( all( target_arch = "wasm32" , target_os = "unknown" ) ) ) ]
390
+ #[ cfg( not( all( target_arch = "wasm32" , any ( target_os = "unknown" , target_os = "none" ) ) ) ) ]
390
391
unsafe fn #unwrap_fn( _: u32 ) -> u32 {
391
392
panic!( "cannot convert from JsValue outside of the Wasm target" )
392
393
}
@@ -493,7 +494,7 @@ impl ToTokens for ast::StructField {
493
494
( quote ! {
494
495
#[ automatically_derived]
495
496
const _: ( ) = {
496
- #[ cfg_attr( all( target_arch = "wasm32" , target_os = "unknown" ) , no_mangle) ]
497
+ #[ cfg_attr( all( target_arch = "wasm32" , any ( target_os = "unknown" , target_os = "none" ) ) , no_mangle) ]
497
498
#[ doc( hidden) ]
498
499
#[ cfg_attr( wasm_bindgen_unstable_test_coverage, coverage( off) ) ]
499
500
pub unsafe extern "C" fn #getter( js: u32 )
@@ -532,7 +533,7 @@ impl ToTokens for ast::StructField {
532
533
let ( args, names) = splat ( wasm_bindgen, & Ident :: new ( "val" , rust_name. span ( ) ) , & abi) ;
533
534
534
535
( quote ! {
535
- #[ cfg( all( target_arch = "wasm32" , target_os = "unknown" ) ) ]
536
+ #[ cfg( all( target_arch = "wasm32" , any ( target_os = "unknown" , target_os = "none" ) ) ) ]
536
537
#[ automatically_derived]
537
538
const _: ( ) = {
538
539
#[ no_mangle]
@@ -791,7 +792,7 @@ impl TryToTokens for ast::Export {
791
792
const _: ( ) = {
792
793
#( #attrs) *
793
794
#[ cfg_attr(
794
- all( target_arch = "wasm32" , target_os = "unknown" ) ,
795
+ all( target_arch = "wasm32" , any ( target_os = "unknown" , target_os = "none" ) ) ,
795
796
export_name = #export_name,
796
797
) ]
797
798
#[ cfg_attr( wasm_bindgen_unstable_test_coverage, coverage( off) ) ]
@@ -1066,11 +1067,11 @@ impl ToTokens for ast::ImportType {
1066
1067
impl JsCast for #rust_name {
1067
1068
fn instanceof( val: & JsValue ) -> bool {
1068
1069
#[ link( wasm_import_module = "__wbindgen_placeholder__" ) ]
1069
- #[ cfg( all( target_arch = "wasm32" , target_os = "unknown" ) ) ]
1070
+ #[ cfg( all( target_arch = "wasm32" , any ( target_os = "unknown" , target_os = "none" ) ) ) ]
1070
1071
extern "C" {
1071
1072
fn #instanceof_shim( val: u32 ) -> u32 ;
1072
1073
}
1073
- #[ cfg( not( all( target_arch = "wasm32" , target_os = "unknown" ) ) ) ]
1074
+ #[ cfg( not( all( target_arch = "wasm32" , any ( target_os = "unknown" , target_os = "none" ) ) ) ) ]
1074
1075
unsafe fn #instanceof_shim( _: u32 ) -> u32 {
1075
1076
panic!( "cannot check instanceof on non-wasm targets" ) ;
1076
1077
}
@@ -1675,14 +1676,15 @@ impl ToTokens for ast::ImportStatic {
1675
1676
fn to_tokens ( & self , into : & mut TokenStream ) {
1676
1677
let ty = & self . ty ;
1677
1678
1678
- if self . thread_local {
1679
+ if let Some ( thread_local ) = self . thread_local {
1679
1680
thread_local_import (
1680
1681
& self . vis ,
1681
1682
& self . rust_name ,
1682
1683
& self . wasm_bindgen ,
1683
1684
ty,
1684
1685
ty,
1685
1686
& self . shim ,
1687
+ thread_local,
1686
1688
)
1687
1689
. to_tokens ( into)
1688
1690
} else {
@@ -1695,7 +1697,7 @@ impl ToTokens for ast::ImportStatic {
1695
1697
1696
1698
into. extend ( quote ! {
1697
1699
#[ automatically_derived]
1698
- #[ deprecated = "use with `#[wasm_bindgen(thread_local )]` instead" ]
1700
+ #[ deprecated = "use with `#[wasm_bindgen(thread_local_v2 )]` instead" ]
1699
1701
} ) ;
1700
1702
into. extend (
1701
1703
quote_spanned ! { name. span( ) => #vis static #name: #wasm_bindgen:: JsStatic <#ty> = {
@@ -1735,6 +1737,7 @@ impl ToTokens for ast::ImportString {
1735
1737
& actual_ty,
1736
1738
& self . ty ,
1737
1739
& self . shim ,
1740
+ self . thread_local ,
1738
1741
)
1739
1742
. to_tokens ( into) ;
1740
1743
}
@@ -1747,15 +1750,52 @@ fn thread_local_import(
1747
1750
actual_ty : & syn:: Type ,
1748
1751
ty : & syn:: Type ,
1749
1752
shim_name : & Ident ,
1753
+ thread_local : ast:: ThreadLocal ,
1750
1754
) -> TokenStream {
1751
1755
let init = static_init ( wasm_bindgen, ty, shim_name) ;
1752
1756
1753
- quote ! {
1754
- thread_local! {
1755
- #[ automatically_derived]
1756
- #vis static #name: #actual_ty = {
1757
- #init
1757
+ match thread_local {
1758
+ ast:: ThreadLocal :: V1 => quote ! {
1759
+ thread_local! {
1760
+ #[ automatically_derived]
1761
+ #[ deprecated = "use with `#[wasm_bindgen(thread_local_v2)]` instead" ]
1762
+ #vis static #name: #actual_ty = {
1763
+ #init
1764
+ } ;
1765
+ }
1766
+ } ,
1767
+ ast:: ThreadLocal :: V2 => {
1768
+ #[ cfg( feature = "std" ) ]
1769
+ let inner = quote ! {
1770
+ thread_local!( static _VAL: #actual_ty = init( ) ; ) ;
1771
+ #wasm_bindgen:: JsThreadLocal {
1772
+ __inner: & _VAL,
1773
+ }
1774
+ } ;
1775
+ #[ cfg( all( not( feature = "std" ) , not( feature = "atomics" ) ) ) ]
1776
+ let inner = quote ! {
1777
+ static _VAL: #wasm_bindgen:: __rt:: LazyCell <#actual_ty> = #wasm_bindgen:: __rt:: LazyCell :: new( init) ;
1778
+ #wasm_bindgen:: JsThreadLocal {
1779
+ __inner: & _VAL,
1780
+ }
1781
+ } ;
1782
+ #[ cfg( all( not( feature = "std" ) , feature = "atomics" ) ) ]
1783
+ let inner = quote ! {
1784
+ #[ thread_local]
1785
+ static _VAL: #wasm_bindgen:: __rt:: LazyCell <#actual_ty> = #wasm_bindgen:: __rt:: LazyCell :: new( init) ;
1786
+ #wasm_bindgen:: JsThreadLocal {
1787
+ __inner: || unsafe { #wasm_bindgen:: __rt:: LazyCell :: force( & _VAL) as * const #actual_ty } ,
1788
+ }
1758
1789
} ;
1790
+
1791
+ quote ! {
1792
+ #vis static #name: #wasm_bindgen:: JsThreadLocal <#actual_ty> = {
1793
+ fn init( ) -> #actual_ty {
1794
+ #init
1795
+ }
1796
+ #inner
1797
+ } ;
1798
+ }
1759
1799
}
1760
1800
}
1761
1801
}
@@ -1766,12 +1806,12 @@ fn static_init(wasm_bindgen: &syn::Path, ty: &syn::Type, shim_name: &Ident) -> T
1766
1806
} ;
1767
1807
quote ! {
1768
1808
#[ link( wasm_import_module = "__wbindgen_placeholder__" ) ]
1769
- #[ cfg( all( target_arch = "wasm32" , target_os = "unknown" ) ) ]
1809
+ #[ cfg( all( target_arch = "wasm32" , any ( target_os = "unknown" , target_os = "none" ) ) ) ]
1770
1810
extern "C" {
1771
1811
fn #shim_name( ) -> #abi_ret;
1772
1812
}
1773
1813
1774
- #[ cfg( not( all( target_arch = "wasm32" , target_os = "unknown" ) ) ) ]
1814
+ #[ cfg( not( all( target_arch = "wasm32" , any ( target_os = "unknown" , target_os = "none" ) ) ) ) ]
1775
1815
unsafe fn #shim_name( ) -> #abi_ret {
1776
1816
panic!( "cannot access imported statics on non-wasm targets" )
1777
1817
}
@@ -1818,7 +1858,7 @@ impl<'a, T: ToTokens> ToTokens for Descriptor<'a, T> {
1818
1858
let attrs = & self . attrs ;
1819
1859
let wasm_bindgen = & self . wasm_bindgen ;
1820
1860
( quote ! {
1821
- #[ cfg( all( target_arch = "wasm32" , target_os = "unknown" ) ) ]
1861
+ #[ cfg( all( target_arch = "wasm32" , any ( target_os = "unknown" , target_os = "none" ) ) ) ]
1822
1862
#[ automatically_derived]
1823
1863
const _: ( ) = {
1824
1864
#( #attrs) *
@@ -1845,14 +1885,14 @@ fn extern_fn(
1845
1885
abi_ret : TokenStream ,
1846
1886
) -> TokenStream {
1847
1887
quote ! {
1848
- #[ cfg( all( target_arch = "wasm32" , target_os = "unknown" ) ) ]
1888
+ #[ cfg( all( target_arch = "wasm32" , any ( target_os = "unknown" , target_os = "none" ) ) ) ]
1849
1889
#( #attrs) *
1850
1890
#[ link( wasm_import_module = "__wbindgen_placeholder__" ) ]
1851
1891
extern "C" {
1852
1892
fn #import_name( #( #abi_arguments) , * ) -> #abi_ret;
1853
1893
}
1854
1894
1855
- #[ cfg( not( all( target_arch = "wasm32" , target_os = "unknown" ) ) ) ]
1895
+ #[ cfg( not( all( target_arch = "wasm32" , any ( target_os = "unknown" , target_os = "none" ) ) ) ) ]
1856
1896
unsafe fn #import_name( #( #abi_arguments) , * ) -> #abi_ret {
1857
1897
#(
1858
1898
drop( #abi_argument_names) ;
0 commit comments