Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ categories = ["wasm", "web-programming"]
# - when changing internals of `rt`, release a new minor version of the macro and bump the
# version requirement here.
# - when adjusting the macro without touching `rt`, release a new patch version of the macro.
wasm_split_macros = { version = ">= 0.2.1, < 0.3", path = "crates/wasm_split_macros" }
wasm_split_macros = { version = ">= 0.2.2, < 0.3", path = "crates/wasm_split_macros" }
2 changes: 1 addition & 1 deletion crates/wasm_split/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wasm_split_helpers"
version = "0.2.1"
version = "0.2.2"
authors.workspace = true
categories.workspace = true
edition.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/wasm_split_cli/src/reloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ fn get_indirect_functions(
}

let mut referenced_indirects = visible_functions.clone();
for relocation in this.relocs.iter().flat_map(|(_, relocs)| relocs.iter()) {
for relocation in this.relocs.values().flat_map(|relocs| relocs.iter()) {
use RelocationType::*;
if !matches!(
relocation.ty,
Expand Down
2 changes: 1 addition & 1 deletion crates/wasm_split_macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wasm_split_macros"
version = "0.2.1"
version = "0.2.2"
authors.workspace = true
categories.workspace = true
edition.workspace = true
Expand Down
29 changes: 27 additions & 2 deletions crates/wasm_split_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,18 @@ pub fn wasm_split(args: TokenStream, input: TokenStream) -> TokenStream {
..item_fn.sig.clone()
};

// On WASM targets, we must use extern "C" for the import/export pair.
// #[link(wasm_import_module)] only creates proper WASM imports for
// non-Rust ABIs. Previously this worked because rustc passed
// --allow-undefined to wasm-ld by default, but rust-lang/rust#149868
// removed that. Using extern "C" ensures the import is a real WASM
// import and the export has a matching ABI for wasm-split to link.
let wasm_export_sig = Signature {
abi: parse_quote!(extern "C"),
ident: impl_export_ident.clone(),
..item_fn.sig.clone()
};

let mut args = Vec::new();
for (i, param) in wrapper_sig.inputs.iter_mut().enumerate() {
match param {
Expand Down Expand Up @@ -287,16 +299,29 @@ pub fn wasm_split(args: TokenStream, input: TokenStream) -> TokenStream {
}
#(#attrs)*
#vis #wrapper_sig {
// On WASM, use extern "C" so #[link(wasm_import_module)] creates
// a real WASM import (it is ignored on extern "Rust" blocks).
#[cfg(target_family = "wasm")]
#[link(wasm_import_module = #link_name)]
unsafe #declared_abi {
#[allow(improper_ctypes)]
unsafe extern "C" {
// We rewrite calls to this function instead of actually calling it. We just need to link to it. The name is unique by hashing.
#[unsafe(no_mangle)]
safe #import_sig;
}

// On WASM, the export must use extern "C" to match the import ABI.
#[cfg(target_family = "wasm")]
#(#attrs)*
#[allow(improper_ctypes_definitions)]
#[unsafe(no_mangle)]
#wasm_export_sig {
#(#stmts)*
}

// On non-WASM targets, use the declared ABI (no import needed).
#[cfg(not(target_family = "wasm"))]
#(#attrs)*
#[cfg_attr(target_family = "wasm", unsafe(no_mangle))]
#export_sig {
#(#stmts)*
}
Expand Down