Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mimalloc fails to build with wasm32 as target #76

Open
JavaDerg opened this issue Apr 5, 2022 · 5 comments
Open

Mimalloc fails to build with wasm32 as target #76

JavaDerg opened this issue Apr 5, 2022 · 5 comments

Comments

@JavaDerg
Copy link

JavaDerg commented Apr 5, 2022

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).

@Titaniumtown
Copy link

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.

@robert-chiniquy
Copy link

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.

@Titaniumtown
Copy link

Titaniumtown commented May 18, 2022

Seems this won't be happening any time soon for wasm32-unknown-unknown 😢 rustwasm/team#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

rustwasm/team#291 (comment):

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.

@JavaDerg
Copy link
Author

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 on wasm32-unknown-unknown

rustwasm/team#291 (comment):

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

@Titaniumtown
Copy link

@post-rex yea, np.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants