Skip to content

Commit cd04b27

Browse files
authored
Disable support for wasm32-wasi (#3233)
1 parent a210654 commit cd04b27

File tree

3 files changed

+30
-18
lines changed

3 files changed

+30
-18
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
It was also automatically changed for `IdbFileHandle`, which is deprecated.
4141
[#3537](https://github.com/rustwasm/wasm-bindgen/pull/3537)
4242

43+
* Changed behavior when compiling to `wasm32-wasi` to match `wasm32-emscripten` and
44+
non-WASM targets, generating a stub that panics when called rather than a wasm-
45+
bindgen placeholder.
46+
[#3233](https://github.com/rustwasm/wasm-bindgen/pull/3233)
47+
4348
### Fixed
4449

4550
* Fixed bindings and comments for `Atomics.wait`.

crates/backend/src/codegen.rs

+15-14
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,12 @@ impl ToTokens for ast::Struct {
221221
let ptr = #wasm_bindgen::convert::IntoWasmAbi::into_abi(value);
222222

223223
#[link(wasm_import_module = "__wbindgen_placeholder__")]
224-
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
224+
#[cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))]
225225
extern "C" {
226226
fn #new_fn(ptr: u32) -> u32;
227227
}
228228

229-
#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))]
229+
#[cfg(not(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi")))))]
230230
unsafe fn #new_fn(_: u32) -> u32 {
231231
panic!("cannot convert to JsValue outside of the wasm target")
232232
}
@@ -238,7 +238,7 @@ impl ToTokens for ast::Struct {
238238
}
239239
}
240240

241-
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
241+
#[cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))]
242242
#[automatically_derived]
243243
const _: () = {
244244
#[no_mangle]
@@ -327,7 +327,7 @@ impl ToTokens for ast::StructField {
327327
(quote! {
328328
#[automatically_derived]
329329
const _: () = {
330-
#[cfg_attr(all(target_arch = "wasm32", not(target_os = "emscripten")), no_mangle)]
330+
#[cfg_attr(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))), no_mangle)]
331331
#[doc(hidden)]
332332
pub unsafe extern "C" fn #getter(js: u32)
333333
-> <#ty as #wasm_bindgen::convert::IntoWasmAbi>::Abi
@@ -362,7 +362,7 @@ impl ToTokens for ast::StructField {
362362
}
363363

364364
(quote! {
365-
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
365+
#[cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))]
366366
#[automatically_derived]
367367
const _: () = {
368368
#[no_mangle]
@@ -590,7 +590,7 @@ impl TryToTokens for ast::Export {
590590
const _: () = {
591591
#(#attrs)*
592592
#[cfg_attr(
593-
all(target_arch = "wasm32", not(target_os = "emscripten")),
593+
all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))),
594594
export_name = #export_name,
595595
)]
596596
pub unsafe extern "C" fn #generated_name(#(#args),*) -> #projection::Abi {
@@ -840,11 +840,11 @@ impl ToTokens for ast::ImportType {
840840
impl JsCast for #rust_name {
841841
fn instanceof(val: &JsValue) -> bool {
842842
#[link(wasm_import_module = "__wbindgen_placeholder__")]
843-
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
843+
#[cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))]
844844
extern "C" {
845845
fn #instanceof_shim(val: u32) -> u32;
846846
}
847-
#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))]
847+
#[cfg(not(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi")))))]
848848
unsafe fn #instanceof_shim(_: u32) -> u32 {
849849
panic!("cannot check instanceof on non-wasm targets");
850850
}
@@ -1355,12 +1355,13 @@ impl ToTokens for ast::ImportStatic {
13551355
#vis static #name: #wasm_bindgen::JsStatic<#ty> = {
13561356
fn init() -> #ty {
13571357
#[link(wasm_import_module = "__wbindgen_placeholder__")]
1358-
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
1358+
#[cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))]
13591359
extern "C" {
13601360
fn #shim_name() -> <#ty as #wasm_bindgen::convert::FromWasmAbi>::Abi;
13611361
}
1362-
#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))]
1363-
unsafe fn #shim_name() -> <#ty as #wasm_bindgen::convert::FromWasmAbi>::Abi {
1362+
1363+
#[cfg(not(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi")))))]
1364+
unsafe fn #shim_name() -> <#ty as wasm_bindgen::convert::FromWasmAbi>::Abi {
13641365
panic!("cannot access imported statics on non-wasm targets")
13651366
}
13661367

@@ -1424,7 +1425,7 @@ impl<'a, T: ToTokens> ToTokens for Descriptor<'a, T> {
14241425
let attrs = &self.attrs;
14251426
let wasm_bindgen = &self.wasm_bindgen;
14261427
(quote! {
1427-
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
1428+
#[cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))]
14281429
#[automatically_derived]
14291430
const _: () = {
14301431
#(#attrs)*
@@ -1450,14 +1451,14 @@ fn extern_fn(
14501451
abi_ret: TokenStream,
14511452
) -> TokenStream {
14521453
quote! {
1453-
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
1454+
#[cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))]
14541455
#(#attrs)*
14551456
#[link(wasm_import_module = "__wbindgen_placeholder__")]
14561457
extern "C" {
14571458
fn #import_name(#(#abi_arguments),*) -> #abi_ret;
14581459
}
14591460

1460-
#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))]
1461+
#[cfg(not(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi")))))]
14611462
unsafe fn #import_name(#(#abi_arguments),*) -> #abi_ret {
14621463
#(
14631464
drop(#abi_argument_names);

src/lib.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ macro_rules! if_std {
2828

2929
macro_rules! externs {
3030
($(#[$attr:meta])* extern "C" { $(fn $name:ident($($args:tt)*) -> $ret:ty;)* }) => (
31-
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
31+
#[cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))]
3232
$(#[$attr])*
3333
extern "C" {
3434
$(fn $name($($args)*) -> $ret;)*
3535
}
3636

3737
$(
38-
#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))]
38+
#[cfg(not(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi")))))]
3939
#[allow(unused_variables)]
4040
unsafe extern fn $name($($args)*) -> $ret {
4141
panic!("function not implemented on non-wasm32 targets")
@@ -1324,7 +1324,10 @@ pub trait UnwrapThrowExt<T>: Sized {
13241324
impl<T> UnwrapThrowExt<T> for Option<T> {
13251325
#[cfg_attr(debug_assertions, track_caller)]
13261326
fn expect_throw(self, message: &str) -> T {
1327-
if cfg!(all(target_arch = "wasm32", not(target_os = "emscripten"))) {
1327+
if cfg!(all(
1328+
target_arch = "wasm32",
1329+
not(any(target_os = "emscripten", target_os = "wasi"))
1330+
)) {
13281331
match self {
13291332
Some(val) => val,
13301333
None => throw_str(message),
@@ -1341,7 +1344,10 @@ where
13411344
{
13421345
#[cfg_attr(debug_assertions, track_caller)]
13431346
fn expect_throw(self, message: &str) -> T {
1344-
if cfg!(all(target_arch = "wasm32", not(target_os = "emscripten"))) {
1347+
if cfg!(all(
1348+
target_arch = "wasm32",
1349+
not(any(target_os = "emscripten", target_os = "wasi"))
1350+
)) {
13451351
match self {
13461352
Ok(val) => val,
13471353
Err(_) => throw_str(message),

0 commit comments

Comments
 (0)