mimalloc_rust
mimalloc_rust copied to clipboard
Mimalloc fails to build with wasm32 as target
I'm trying to use mimalloc as allocator in a wasm project of mine; as far as I know mimalloc supports wasm as target, but it failes to build. I'm not sure what dependency or similar it requires to build successfully.
warning: In file included from c_src/mimalloc/src/static.c:17:
warning: In file included from c_src/mimalloc/include/mimalloc-internal.h:11:
warning: In file included from c_src/mimalloc/include/mimalloc-types.h:13:
warning: c_src/mimalloc/include/mimalloc-atomic.h:320:10: fatal error: 'sched.h' file not found
warning: #include <sched.h>
warning: ^~~~~~~~~
warning: 1 error generated.
error: failed to run custom build command for `libmimalloc-sys v0.1.24`
Caused by:
process didn't exit successfully: `/home/amnesia/source/rust/projects/wassup/target/debug/build/libmimalloc-sys-36ec66d83887a64d/build-script-build` (exit status: 1)
--- stdout
OPT_LEVEL = Some("0")
TARGET = Some("wasm32-wasi")
HOST = Some("x86_64-unknown-linux-gnu")
CC_wasm32-wasi = None
CC_wasm32_wasi = None
TARGET_CC = None
CC = None
CFLAGS_wasm32-wasi = None
CFLAGS_wasm32_wasi = None
TARGET_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("true")
running: "clang" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=wasm32-wasi" "-I" "c_src/mimalloc/include" "-I" "c_src/mimalloc/src" "-Wall" "-Wextra" "-DMI_DEBUG=0" "-o" "/home/amnesia/source/rust/projects/wassup/target/wasm32-wasi/debug/build/libmimalloc-sys-6e61d97d3b6b6e10/out/c_src/mimalloc/src/static.o" "-c" "c_src/mimalloc/src/static.c"
cargo:warning=In file included from c_src/mimalloc/src/static.c:17:
cargo:warning=In file included from c_src/mimalloc/include/mimalloc-internal.h:11:
cargo:warning=In file included from c_src/mimalloc/include/mimalloc-types.h:13:
cargo:warning=c_src/mimalloc/include/mimalloc-atomic.h:320:10: fatal error: 'sched.h' file not found
cargo:warning=#include <sched.h>
cargo:warning= ^~~~~~~~~
cargo:warning=1 error generated.
exit status: 1
--- stderr
error occurred: Command "clang" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=wasm32-wasi" "-I" "c_src/mimalloc/include" "-I" "c_src/mimalloc/src" "-Wall" "-Wextra" "-DMI_DEBUG=0" "-o" "/home/amnesia/source/rust/projects/wassup/target/wasm32-wasi/debug/build/libmimalloc-sys-6e61d97d3b6b6e10/out/c_src/mimalloc/src/static.o" "-c" "c_src/mimalloc/src/static.c" with args "clang" did not execute successfully (status code exit status: 1).
I get a similar error, but with unistd.h
instead. I believe this is due to this crate being bindings and not a native rust crate.
If anyone has figured this out, I would love to know what the workaround is. Seems like as mimalloc supports WASM already, this should be very feasible.
Seems this won't be happening any time soon for wasm32-unknown-unknown
😢 https://github.com/rustwasm/team/issues/291 but emscripten maybe will work? Mimalloc would have to be ported completely to rust for it to be able to compile on wasm32-unknown-unknown
https://github.com/rustwasm/team/issues/291#issuecomment-645482430:
The only way to mix Rust and C code when targeting WebAssembly is to use the wasm32-unknown-emscripten target. You cannot use wasm-bindgen when you do that because wasm-bindgen is fundamentally incompatible with C. Using WASI will not work. There is no workaround. There are long term plans to make wasm32-unknown-unknown and wasm32-wasi compatible with C, but there is no ETA for that.
Seems this won't be happening any time soon for
wasm32-unknown-unknown
cry rustwasm/team#291 but emscripten maybe will work? Mimalloc would have to be ported completely to rust for it to be able to compile onwasm32-unknown-unknown
The only way to mix Rust and C code when targeting WebAssembly is to use the wasm32-unknown-emscripten target. You cannot use wasm-bindgen when you do that because wasm-bindgen is fundamentally incompatible with C. Using WASI will not work. There is no workaround. There are long term plans to make wasm32-unknown-unknown and wasm32-wasi compatible with C, but there is no ETA for that.
That sucks :/ Thanks for looking into it
@post-rex yea, np.