Skip to content

Commit e7a056f

Browse files
committed
Share wasm-bindgen compat abi selection code
1 parent 4d2766e commit e7a056f

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

compiler/rustc_middle/src/ty/layout.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2752,7 +2752,7 @@ where
27522752
attrs
27532753
});
27542754

2755-
if target.arch == "wasm32" && target.os == "unknown" {
2755+
if call::use_wasm_bindgen_compat_abi(target) {
27562756
// wasm-bindgen depends on ABI details and is incompatible with the
27572757
// correct C ABI, so this is being kept around until wasm-bindgen
27582758
// can be fixed to work with the correct ABI. See #63649 for further

compiler/rustc_target/src/abi/call/mod.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::abi::{self, Abi, Align, FieldsShape, Size};
22
use crate::abi::{HasDataLayout, LayoutOf, TyAndLayout, TyAndLayoutMethods};
3-
use crate::spec::{self, HasTargetSpec};
3+
use crate::spec::{self, HasTargetSpec, Target};
44

55
mod aarch64;
66
mod amdgpu;
@@ -631,9 +631,10 @@ impl<'a, Ty> FnAbi<'a, Ty> {
631631
"nvptx64" => nvptx64::compute_abi_info(self),
632632
"hexagon" => hexagon::compute_abi_info(self),
633633
"riscv32" | "riscv64" => riscv::compute_abi_info(cx, self),
634-
"wasm32" => match cx.target_spec().os.as_str() {
635-
"emscripten" | "wasi" => wasm32::compute_abi_info(cx, self),
636-
_ => wasm32_bindgen_compat::compute_abi_info(self),
634+
"wasm32" => if use_wasm_bindgen_compat_abi(cx.target_spec()) {
635+
wasm32_bindgen_compat::compute_abi_info(self)
636+
} else {
637+
wasm32::compute_abi_info(cx, self)
637638
},
638639
"asmjs" => wasm32::compute_abi_info(cx, self),
639640
a => return Err(format!("unrecognized arch \"{}\" in target specification", a)),
@@ -642,3 +643,14 @@ impl<'a, Ty> FnAbi<'a, Ty> {
642643
Ok(())
643644
}
644645
}
646+
647+
pub fn use_wasm_bindgen_compat_abi(target_spec: &Target) -> bool {
648+
if target_spec.arch.as_str() == "wasm32" {
649+
match target_spec.os.as_str() {
650+
"emscripten" | "wasi" => false,
651+
_ => true,
652+
}
653+
} else {
654+
false
655+
}
656+
}

0 commit comments

Comments
 (0)