Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable support for wasm32-wasi #3233

Merged
merged 5 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 13 additions & 13 deletions crates/backend/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,12 @@ impl ToTokens for ast::Struct {
let ptr = wasm_bindgen::convert::IntoWasmAbi::into_abi(value);

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

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

#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
#[cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))]
#[automatically_derived]
const _: () = {
#[no_mangle]
Expand Down Expand Up @@ -295,7 +295,7 @@ impl ToTokens for ast::StructField {
(quote! {
#[automatically_derived]
const _: () = {
#[cfg_attr(all(target_arch = "wasm32", not(target_os = "emscripten")), no_mangle)]
#[cfg_attr(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))), no_mangle)]
#[doc(hidden)]
pub unsafe extern "C" fn #getter(js: u32)
-> <#ty as wasm_bindgen::convert::IntoWasmAbi>::Abi
Expand Down Expand Up @@ -329,7 +329,7 @@ impl ToTokens for ast::StructField {
}

(quote! {
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
#[cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))]
#[automatically_derived]
const _: () = {
#[no_mangle]
Expand Down Expand Up @@ -555,7 +555,7 @@ impl TryToTokens for ast::Export {
const _: () = {
#(#attrs)*
#[cfg_attr(
all(target_arch = "wasm32", not(target_os = "emscripten")),
all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))),
export_name = #export_name,
)]
pub unsafe extern "C" fn #generated_name(#(#args),*) -> #projection::Abi {
Expand Down Expand Up @@ -803,11 +803,11 @@ impl ToTokens for ast::ImportType {
impl JsCast for #rust_name {
fn instanceof(val: &JsValue) -> bool {
#[link(wasm_import_module = "__wbindgen_placeholder__")]
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
#[cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))]
extern "C" {
fn #instanceof_shim(val: u32) -> u32;
}
#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))]
#[cfg(not(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi")))))]
unsafe fn #instanceof_shim(_: u32) -> u32 {
panic!("cannot check instanceof on non-wasm targets");
}
Expand Down Expand Up @@ -1145,14 +1145,14 @@ impl TryToTokens for ast::ImportFunction {
// the best we can in the meantime.
let extern_fn = respan(
quote! {
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
#[cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))]
#(#attrs)*
#[link(wasm_import_module = "__wbindgen_placeholder__")]
extern "C" {
fn #import_name(#(#abi_arguments),*) -> #abi_ret;
}

#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))]
#[cfg(not(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi")))))]
unsafe fn #import_name(#(#abi_arguments),*) -> #abi_ret {
#(
drop(#abi_argument_names);
Expand Down Expand Up @@ -1315,11 +1315,11 @@ impl ToTokens for ast::ImportStatic {
#vis static #name: wasm_bindgen::JsStatic<#ty> = {
fn init() -> #ty {
#[link(wasm_import_module = "__wbindgen_placeholder__")]
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
#[cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))]
extern "C" {
fn #shim_name() -> <#ty as wasm_bindgen::convert::FromWasmAbi>::Abi;
}
#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))]
#[cfg(not(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi")))))]
unsafe fn #shim_name() -> <#ty as wasm_bindgen::convert::FromWasmAbi>::Abi {
panic!("cannot access imported statics on non-wasm targets")
}
Expand Down Expand Up @@ -1381,7 +1381,7 @@ impl<'a, T: ToTokens> ToTokens for Descriptor<'a, T> {
let inner = &self.inner;
let attrs = &self.attrs;
(quote! {
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
#[cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))]
#[automatically_derived]
const _: () = {
#(#attrs)*
Expand Down
14 changes: 10 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ macro_rules! if_std {

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

$(
#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))]
#[cfg(not(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi")))))]
#[allow(unused_variables)]
unsafe extern fn $name($($args)*) -> $ret {
panic!("function not implemented on non-wasm32 targets")
Expand Down Expand Up @@ -1318,7 +1318,10 @@ pub trait UnwrapThrowExt<T>: Sized {

impl<T> UnwrapThrowExt<T> for Option<T> {
fn expect_throw(self, message: &str) -> T {
if cfg!(all(target_arch = "wasm32", not(target_os = "emscripten"))) {
if cfg!(all(
target_arch = "wasm32",
not(any(target_os = "emscripten", target_os = "wasi"))
)) {
match self {
Some(val) => val,
None => throw_str(message),
Expand All @@ -1334,7 +1337,10 @@ where
E: core::fmt::Debug,
{
fn expect_throw(self, message: &str) -> T {
if cfg!(all(target_arch = "wasm32", not(target_os = "emscripten"))) {
if cfg!(all(
target_arch = "wasm32",
not(any(target_os = "emscripten", target_os = "wasi"))
)) {
match self {
Ok(val) => val,
Err(_) => throw_str(message),
Expand Down