Skip to content

Commit cd87645

Browse files
authored
workaround: to avoid linking issues with targets wasm32-wasi and x86_64-unknown-linux-gnu, only export name malloc in the context of target wasm32-unknown-unknown (yskopets#4)
1 parent 902b6a4 commit cd87645

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/allocator.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,14 @@
1515
#[global_allocator]
1616
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
1717

18+
// Apparently, Rust toolchain doesn't handle well exported name `malloc`
19+
// when this package is compiled to targets other than `wasm32-unknown-unknown`.
20+
// Specifically, linking issues have been observed with targets `wasm32-wasi`
21+
// and `x86_64-unknown-linux-gnu`, which is a blocker for unit testing.
22+
// Therefore, export name `malloc` only in the context of target `wasm32-unknown-unknown`.
23+
#[cfg_attr(all(target_arch = "wasm32", target_vendor = "unknown", target_os = "unknown"), export_name = "malloc")]
1824
#[no_mangle]
19-
pub extern "C" fn malloc(size: usize) -> *mut u8 {
25+
pub extern "C" fn proxy_on_memory_allocate(size: usize) -> *mut u8 {
2026
let mut vec: Vec<u8> = Vec::with_capacity(size);
2127
unsafe {
2228
vec.set_len(size);

0 commit comments

Comments
 (0)