Skip to content

Commit 542b1db

Browse files
authored
Use cfg(target_os = "unknown") (#4043)
1 parent 2308e61 commit 542b1db

File tree

3 files changed

+26
-41
lines changed

3 files changed

+26
-41
lines changed

crates/backend/src/codegen.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ impl TryToTokens for ast::Program {
159159
let prefix_json_bytes = syn::LitByteStr::new(&prefix_json_bytes, Span::call_site());
160160

161161
(quote! {
162-
#[cfg(target_arch = "wasm32")]
162+
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
163163
#[automatically_derived]
164164
const _: () = {
165165
use #wasm_bindgen::__rt::{flat_len, flat_byte_slices};
@@ -268,12 +268,12 @@ impl ToTokens for ast::Struct {
268268
let ptr = #wasm_bindgen::convert::IntoWasmAbi::into_abi(value);
269269

270270
#[link(wasm_import_module = "__wbindgen_placeholder__")]
271-
#[cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))]
271+
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
272272
extern "C" {
273273
fn #new_fn(ptr: u32) -> u32;
274274
}
275275

276-
#[cfg(not(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi")))))]
276+
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
277277
unsafe fn #new_fn(_: u32) -> u32 {
278278
panic!("cannot convert to JsValue outside of the wasm target")
279279
}
@@ -285,7 +285,7 @@ impl ToTokens for ast::Struct {
285285
}
286286
}
287287

288-
#[cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))]
288+
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
289289
#[automatically_derived]
290290
const _: () = {
291291
#[no_mangle]
@@ -373,12 +373,12 @@ impl ToTokens for ast::Struct {
373373
let idx = #wasm_bindgen::convert::IntoWasmAbi::into_abi(&value);
374374

375375
#[link(wasm_import_module = "__wbindgen_placeholder__")]
376-
#[cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))]
376+
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
377377
extern "C" {
378378
fn #unwrap_fn(ptr: u32) -> u32;
379379
}
380380

381-
#[cfg(not(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi")))))]
381+
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
382382
unsafe fn #unwrap_fn(_: u32) -> u32 {
383383
panic!("cannot convert from JsValue outside of the wasm target")
384384
}
@@ -481,7 +481,7 @@ impl ToTokens for ast::StructField {
481481
(quote! {
482482
#[automatically_derived]
483483
const _: () = {
484-
#[cfg_attr(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))), no_mangle)]
484+
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), no_mangle)]
485485
#[doc(hidden)]
486486
pub unsafe extern "C" fn #getter(js: u32)
487487
-> #wasm_bindgen::convert::WasmRet<<#ty as #wasm_bindgen::convert::IntoWasmAbi>::Abi>
@@ -519,7 +519,7 @@ impl ToTokens for ast::StructField {
519519
let (args, names) = splat(wasm_bindgen, &Ident::new("val", rust_name.span()), &abi);
520520

521521
(quote! {
522-
#[cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))]
522+
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
523523
#[automatically_derived]
524524
const _: () = {
525525
#[no_mangle]
@@ -777,7 +777,7 @@ impl TryToTokens for ast::Export {
777777
const _: () = {
778778
#(#attrs)*
779779
#[cfg_attr(
780-
all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))),
780+
all(target_arch = "wasm32", target_os = "unknown"),
781781
export_name = #export_name,
782782
)]
783783
pub unsafe extern "C" fn #generated_name(#(#args),*) -> #wasm_bindgen::convert::WasmRet<#projection::Abi> {
@@ -1036,11 +1036,11 @@ impl ToTokens for ast::ImportType {
10361036
impl JsCast for #rust_name {
10371037
fn instanceof(val: &JsValue) -> bool {
10381038
#[link(wasm_import_module = "__wbindgen_placeholder__")]
1039-
#[cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))]
1039+
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
10401040
extern "C" {
10411041
fn #instanceof_shim(val: u32) -> u32;
10421042
}
1043-
#[cfg(not(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi")))))]
1043+
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
10441044
unsafe fn #instanceof_shim(_: u32) -> u32 {
10451045
panic!("cannot check instanceof on non-wasm targets");
10461046
}
@@ -1655,12 +1655,12 @@ impl ToTokens for ast::ImportStatic {
16551655
#vis static #name: #wasm_bindgen::JsStatic<#ty> = {
16561656
fn init() -> #ty {
16571657
#[link(wasm_import_module = "__wbindgen_placeholder__")]
1658-
#[cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))]
1658+
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
16591659
extern "C" {
16601660
fn #shim_name() -> #abi_ret;
16611661
}
16621662

1663-
#[cfg(not(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi")))))]
1663+
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
16641664
unsafe fn #shim_name() -> #abi_ret {
16651665
panic!("cannot access imported statics on non-wasm targets")
16661666
}
@@ -1725,7 +1725,7 @@ impl<'a, T: ToTokens> ToTokens for Descriptor<'a, T> {
17251725
let attrs = &self.attrs;
17261726
let wasm_bindgen = &self.wasm_bindgen;
17271727
(quote! {
1728-
#[cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))]
1728+
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
17291729
#[automatically_derived]
17301730
const _: () = {
17311731
#(#attrs)*
@@ -1751,14 +1751,14 @@ fn extern_fn(
17511751
abi_ret: TokenStream,
17521752
) -> TokenStream {
17531753
quote! {
1754-
#[cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))]
1754+
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
17551755
#(#attrs)*
17561756
#[link(wasm_import_module = "__wbindgen_placeholder__")]
17571757
extern "C" {
17581758
fn #import_name(#(#abi_arguments),*) -> #abi_ret;
17591759
}
17601760

1761-
#[cfg(not(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi")))))]
1761+
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
17621762
unsafe fn #import_name(#(#abi_arguments),*) -> #abi_ret {
17631763
#(
17641764
drop(#abi_argument_names);

src/externref.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ fn internal_error(msg: &str) -> ! {
106106
std::process::abort();
107107
} else if #[cfg(all(
108108
target_arch = "wasm32",
109-
not(any(target_os = "emscripten", target_os = "wasi"))
109+
target_os = "unknown"
110110
))] {
111111
core::arch::wasm32::unreachable();
112112
} else {

src/lib.rs

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ macro_rules! if_std {
3232

3333
macro_rules! externs {
3434
($(#[$attr:meta])* extern "C" { $(fn $name:ident($($args:tt)*) -> $ret:ty;)* }) => (
35-
#[cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))]
35+
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
3636
$(#[$attr])*
3737
extern "C" {
3838
$(fn $name($($args)*) -> $ret;)*
3939
}
4040

4141
$(
42-
#[cfg(not(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi")))))]
42+
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
4343
#[allow(unused_variables)]
4444
unsafe extern fn $name($($args)*) -> $ret {
4545
panic!("function not implemented on non-wasm32 targets")
@@ -1340,20 +1340,14 @@ pub trait UnwrapThrowExt<T>: Sized {
13401340
#[cfg_attr(
13411341
any(
13421342
debug_assertions,
1343-
not(all(
1344-
target_arch = "wasm32",
1345-
not(any(target_os = "emscripten", target_os = "wasi"))
1346-
))
1343+
not(all(target_arch = "wasm32", target_os = "unknown"))
13471344
),
13481345
track_caller
13491346
)]
13501347
fn unwrap_throw(self) -> T {
13511348
if cfg!(all(
13521349
debug_assertions,
1353-
all(
1354-
target_arch = "wasm32",
1355-
not(any(target_os = "emscripten", target_os = "wasi"))
1356-
)
1350+
all(target_arch = "wasm32", target_os = "unknown")
13571351
)) {
13581352
let loc = core::panic::Location::caller();
13591353
let msg = alloc::format!(
@@ -1374,10 +1368,7 @@ pub trait UnwrapThrowExt<T>: Sized {
13741368
#[cfg_attr(
13751369
any(
13761370
debug_assertions,
1377-
not(all(
1378-
target_arch = "wasm32",
1379-
not(any(target_os = "emscripten", target_os = "wasi"))
1380-
))
1371+
not(all(target_arch = "wasm32", target_os = "unknown"))
13811372
),
13821373
track_caller
13831374
)]
@@ -1386,10 +1377,7 @@ pub trait UnwrapThrowExt<T>: Sized {
13861377

13871378
impl<T> UnwrapThrowExt<T> for Option<T> {
13881379
fn expect_throw(self, message: &str) -> T {
1389-
if cfg!(all(
1390-
target_arch = "wasm32",
1391-
not(any(target_os = "emscripten", target_os = "wasi"))
1392-
)) {
1380+
if cfg!(all(target_arch = "wasm32", target_os = "unknown")) {
13931381
match self {
13941382
Some(val) => val,
13951383
None => throw_str(message),
@@ -1408,7 +1396,7 @@ where
14081396
if cfg!(all(
14091397
debug_assertions,
14101398
target_arch = "wasm32",
1411-
not(any(target_os = "emscripten", target_os = "wasi"))
1399+
target_os = "unknown"
14121400
)) {
14131401
match self {
14141402
Ok(val) => val,
@@ -1431,10 +1419,7 @@ where
14311419
}
14321420

14331421
fn expect_throw(self, message: &str) -> T {
1434-
if cfg!(all(
1435-
target_arch = "wasm32",
1436-
not(any(target_os = "emscripten", target_os = "wasi"))
1437-
)) {
1422+
if cfg!(all(target_arch = "wasm32", target_os = "unknown")) {
14381423
match self {
14391424
Ok(val) => val,
14401425
Err(_) => throw_str(message),
@@ -1792,7 +1777,7 @@ pub mod __rt {
17921777
std::process::abort();
17931778
} else if #[cfg(all(
17941779
target_arch = "wasm32",
1795-
not(any(target_os = "emscripten", target_os = "wasi"))
1780+
target_os = "unknown"
17961781
))] {
17971782
core::arch::wasm32::unreachable();
17981783
} else {

0 commit comments

Comments
 (0)