Skip to content

Commit 43c4b81

Browse files
committed
Add C ABI for wasm-bindgen compat
1 parent 63955bb commit 43c4b81

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/librustc_target/abi/call/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ mod x86;
2121
mod x86_64;
2222
mod x86_win64;
2323
mod wasm32;
24+
mod wasm32_bindgen_compat;
2425

2526
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
2627
pub enum PassMode {
@@ -564,6 +565,8 @@ impl<'a, Ty> FnType<'a, Ty> {
564565
"hexagon" => hexagon::compute_abi_info(self),
565566
"riscv32" => riscv::compute_abi_info(self, 32),
566567
"riscv64" => riscv::compute_abi_info(self, 64),
568+
"wasm32" if cx.target_spec().target_os != "emscripten"
569+
=> wasm32_bindgen_compat::compute_abi_info(self),
567570
"wasm32" | "asmjs" => wasm32::compute_abi_info(cx, self),
568571
a => return Err(format!("unrecognized arch \"{}\" in target specification", a))
569572
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// This is not and has never been a correct C ABI for WebAssembly, but
2+
// for a long time this was the C ABI that Rust used. wasm-bindgen
3+
// depends on ABI details for this ABI and is incompatible with the
4+
// correct C ABI, so this ABI is being kept around until wasm-bindgen
5+
// can be fixed to work with the correct ABI. See #63649 for further
6+
// discussion.
7+
8+
use crate::abi::call::{FnType, ArgType};
9+
10+
fn classify_ret_ty<Ty>(ret: &mut ArgType<'_, Ty>) {
11+
ret.extend_integer_width_to(32);
12+
}
13+
14+
fn classify_arg_ty<Ty>(arg: &mut ArgType<'_, Ty>) {
15+
arg.extend_integer_width_to(32);
16+
}
17+
18+
pub fn compute_abi_info<Ty>(fty: &mut FnType<'_, Ty>) {
19+
if !fty.ret.is_ignore() {
20+
classify_ret_ty(&mut fty.ret);
21+
}
22+
23+
for arg in &mut fty.args {
24+
if arg.is_ignore() { continue; }
25+
classify_arg_ty(arg);
26+
}
27+
}

0 commit comments

Comments
 (0)