purpleprotocol / mimalloc_rust

A Rust wrapper over Microsoft's MiMalloc memory allocator
MIT License
503 stars 41 forks source link

libmimalloc-sys fails to build for wasm target on Windows #11

Closed Boscop closed 4 years ago

Boscop commented 4 years ago

Not sure if this allocator is intended to also work for wasm, but in my frontend I need speed more than size (it's a UI for a desktop application), so I thought I'd try it.. But it fails to build for wasm:

error[E0432]: unresolved imports `libc::c_void`, `libc::size_t`
 --> C:\Users\me\.cargo\registry\src\github.com-1ecc6299db9ec823\libmimalloc-sys-0.1.9\src\lib.rs:3:12
  |
3 | use libc::{c_void, size_t};
  |            ^^^^^^  ^^^^^^ no `size_t` in the root
  |            |
  |            no `c_void` in the root

error: could not compile `libmimalloc-sys`.
octavonce commented 4 years ago

@Boscop While the original mimalloc library compiles on WASM, the wrapper uses rust's libc to do ffi calls. Unfortunately, there is no WASM target available for libc. Check this out.

Boscop commented 4 years ago

@octavonce Ah, right. It seems you're only using c_void and size_t from libc, right? Could you please use the types from std::os::raw instead? Specifically c_void. (And size_t is always defined as usize, so you can use that.) It's more idiomatic to not depend on libc unless it's really necessary, I also switched my ffi crates to use those types. It would be sad if these types would prevent this allocator from building for wasm..

octavonce commented 4 years ago

@Boscop Sure, that makes sense