purpleprotocol / mimalloc_rust

A Rust wrapper over Microsoft's MiMalloc memory allocator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

libmimalloc-sys fails to build for wasm target on Windows

Boscop opened this issue · comments

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

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

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

@Boscop Sure, that makes sense