@@ -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,9 +201,10 @@ 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 {
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+ } ) ;
207208
208209 #wasm_bindgen:: __rt:: alloc:: string:: String :: clone( & __VAL)
209210 }
@@ -275,12 +276,12 @@ impl ToTokens for ast::Struct {
275276 let ptr = #wasm_bindgen:: convert:: IntoWasmAbi :: into_abi( value) ;
276277
277278 #[ 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" ) ) ) ]
279280 extern "C" {
280281 fn #new_fn( ptr: u32 ) -> u32 ;
281282 }
282283
283- #[ cfg( not( all( target_arch = "wasm32" , target_os = "unknown" ) ) ) ]
284+ #[ cfg( not( all( target_arch = "wasm32" , any ( target_os = "unknown" , target_os = "none" ) ) ) ) ]
284285 unsafe fn #new_fn( _: u32 ) -> u32 {
285286 panic!( "cannot convert to JsValue outside of the Wasm target" )
286287 }
@@ -292,7 +293,7 @@ impl ToTokens for ast::Struct {
292293 }
293294 }
294295
295- #[ cfg( all( target_arch = "wasm32" , target_os = "unknown" ) ) ]
296+ #[ cfg( all( target_arch = "wasm32" , any ( target_os = "unknown" , target_os = "none" ) ) ) ]
296297 #[ automatically_derived]
297298 const _: ( ) = {
298299 #[ no_mangle]
@@ -381,12 +382,12 @@ impl ToTokens for ast::Struct {
381382 let idx = #wasm_bindgen:: convert:: IntoWasmAbi :: into_abi( & value) ;
382383
383384 #[ 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" ) ) ) ]
385386 extern "C" {
386387 fn #unwrap_fn( ptr: u32 ) -> u32 ;
387388 }
388389
389- #[ cfg( not( all( target_arch = "wasm32" , target_os = "unknown" ) ) ) ]
390+ #[ cfg( not( all( target_arch = "wasm32" , any ( target_os = "unknown" , target_os = "none" ) ) ) ) ]
390391 unsafe fn #unwrap_fn( _: u32 ) -> u32 {
391392 panic!( "cannot convert from JsValue outside of the Wasm target" )
392393 }
@@ -493,7 +494,7 @@ impl ToTokens for ast::StructField {
493494 ( quote ! {
494495 #[ automatically_derived]
495496 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) ]
497498 #[ doc( hidden) ]
498499 #[ cfg_attr( wasm_bindgen_unstable_test_coverage, coverage( off) ) ]
499500 pub unsafe extern "C" fn #getter( js: u32 )
@@ -532,7 +533,7 @@ impl ToTokens for ast::StructField {
532533 let ( args, names) = splat ( wasm_bindgen, & Ident :: new ( "val" , rust_name. span ( ) ) , & abi) ;
533534
534535 ( quote ! {
535- #[ cfg( all( target_arch = "wasm32" , target_os = "unknown" ) ) ]
536+ #[ cfg( all( target_arch = "wasm32" , any ( target_os = "unknown" , target_os = "none" ) ) ) ]
536537 #[ automatically_derived]
537538 const _: ( ) = {
538539 #[ no_mangle]
@@ -791,7 +792,7 @@ impl TryToTokens for ast::Export {
791792 const _: ( ) = {
792793 #( #attrs) *
793794 #[ cfg_attr(
794- all( target_arch = "wasm32" , target_os = "unknown" ) ,
795+ all( target_arch = "wasm32" , any ( target_os = "unknown" , target_os = "none" ) ) ,
795796 export_name = #export_name,
796797 ) ]
797798 #[ cfg_attr( wasm_bindgen_unstable_test_coverage, coverage( off) ) ]
@@ -1066,11 +1067,11 @@ impl ToTokens for ast::ImportType {
10661067 impl JsCast for #rust_name {
10671068 fn instanceof( val: & JsValue ) -> bool {
10681069 #[ 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" ) ) ) ]
10701071 extern "C" {
10711072 fn #instanceof_shim( val: u32 ) -> u32 ;
10721073 }
1073- #[ cfg( not( all( target_arch = "wasm32" , target_os = "unknown" ) ) ) ]
1074+ #[ cfg( not( all( target_arch = "wasm32" , any ( target_os = "unknown" , target_os = "none" ) ) ) ) ]
10741075 unsafe fn #instanceof_shim( _: u32 ) -> u32 {
10751076 panic!( "cannot check instanceof on non-wasm targets" ) ;
10761077 }
@@ -1675,14 +1676,15 @@ impl ToTokens for ast::ImportStatic {
16751676 fn to_tokens ( & self , into : & mut TokenStream ) {
16761677 let ty = & self . ty ;
16771678
1678- if self . thread_local {
1679+ if let Some ( thread_local ) = self . thread_local {
16791680 thread_local_import (
16801681 & self . vis ,
16811682 & self . rust_name ,
16821683 & self . wasm_bindgen ,
16831684 ty,
16841685 ty,
16851686 & self . shim ,
1687+ thread_local,
16861688 )
16871689 . to_tokens ( into)
16881690 } else {
@@ -1695,7 +1697,7 @@ impl ToTokens for ast::ImportStatic {
16951697
16961698 into. extend ( quote ! {
16971699 #[ automatically_derived]
1698- #[ deprecated = "use with `#[wasm_bindgen(thread_local )]` instead" ]
1700+ #[ deprecated = "use with `#[wasm_bindgen(thread_local_v2 )]` instead" ]
16991701 } ) ;
17001702 into. extend (
17011703 quote_spanned ! { name. span( ) => #vis static #name: #wasm_bindgen:: JsStatic <#ty> = {
@@ -1735,6 +1737,7 @@ impl ToTokens for ast::ImportString {
17351737 & actual_ty,
17361738 & self . ty ,
17371739 & self . shim ,
1740+ self . thread_local ,
17381741 )
17391742 . to_tokens ( into) ;
17401743 }
@@ -1747,15 +1750,52 @@ fn thread_local_import(
17471750 actual_ty : & syn:: Type ,
17481751 ty : & syn:: Type ,
17491752 shim_name : & Ident ,
1753+ thread_local : ast:: ThreadLocal ,
17501754) -> TokenStream {
17511755 let init = static_init ( wasm_bindgen, ty, shim_name) ;
17521756
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+ }
17581789 } ;
1790+
1791+ quote ! {
1792+ #vis static #name: #wasm_bindgen:: JsThreadLocal <#actual_ty> = {
1793+ fn init( ) -> #actual_ty {
1794+ #init
1795+ }
1796+ #inner
1797+ } ;
1798+ }
17591799 }
17601800 }
17611801}
@@ -1766,12 +1806,12 @@ fn static_init(wasm_bindgen: &syn::Path, ty: &syn::Type, shim_name: &Ident) -> T
17661806 } ;
17671807 quote ! {
17681808 #[ 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" ) ) ) ]
17701810 extern "C" {
17711811 fn #shim_name( ) -> #abi_ret;
17721812 }
17731813
1774- #[ cfg( not( all( target_arch = "wasm32" , target_os = "unknown" ) ) ) ]
1814+ #[ cfg( not( all( target_arch = "wasm32" , any ( target_os = "unknown" , target_os = "none" ) ) ) ) ]
17751815 unsafe fn #shim_name( ) -> #abi_ret {
17761816 panic!( "cannot access imported statics on non-wasm targets" )
17771817 }
@@ -1818,7 +1858,7 @@ impl<'a, T: ToTokens> ToTokens for Descriptor<'a, T> {
18181858 let attrs = & self . attrs ;
18191859 let wasm_bindgen = & self . wasm_bindgen ;
18201860 ( quote ! {
1821- #[ cfg( all( target_arch = "wasm32" , target_os = "unknown" ) ) ]
1861+ #[ cfg( all( target_arch = "wasm32" , any ( target_os = "unknown" , target_os = "none" ) ) ) ]
18221862 #[ automatically_derived]
18231863 const _: ( ) = {
18241864 #( #attrs) *
@@ -1845,14 +1885,14 @@ fn extern_fn(
18451885 abi_ret : TokenStream ,
18461886) -> TokenStream {
18471887 quote ! {
1848- #[ cfg( all( target_arch = "wasm32" , target_os = "unknown" ) ) ]
1888+ #[ cfg( all( target_arch = "wasm32" , any ( target_os = "unknown" , target_os = "none" ) ) ) ]
18491889 #( #attrs) *
18501890 #[ link( wasm_import_module = "__wbindgen_placeholder__" ) ]
18511891 extern "C" {
18521892 fn #import_name( #( #abi_arguments) , * ) -> #abi_ret;
18531893 }
18541894
1855- #[ cfg( not( all( target_arch = "wasm32" , target_os = "unknown" ) ) ) ]
1895+ #[ cfg( not( all( target_arch = "wasm32" , any ( target_os = "unknown" , target_os = "none" ) ) ) ) ]
18561896 unsafe fn #import_name( #( #abi_arguments) , * ) -> #abi_ret {
18571897 #(
18581898 drop( #abi_argument_names) ;
0 commit comments