kornelski / lodepng-rust

All-in-one PNG image encoder/decoder in pure Rust
https://lib.rs/lodepng
zlib License
100 stars 23 forks source link

Unable to build on wasm32-unknown-unknown due to libc malloc #43

Closed carado closed 2 years ago

carado commented 4 years ago

Creating a project with lodepng as a dependency and building with --target wasm32-unknown-unknown yields the following errors:

   Compiling lodepng v2.5.0
error[E0425]: cannot find function `malloc` in crate `libc`
  --> /home/carado/.cargo/registry/src/github.com-1ecc6299db9ec823/lodepng-2.5.0/src/rustimpl.rs:53:15
   |
53 |         libc::malloc(size) as *mut _
   |               ^^^^^^ not found in `libc`

error[E0425]: cannot find function `realloc` in crate `libc`
  --> /home/carado/.cargo/registry/src/github.com-1ecc6299db9ec823/lodepng-2.5.0/src/rustimpl.rs:58:11
   |
58 |     libc::realloc(ptr as *mut _, size) as *mut _
   |           ^^^^^^^ not found in `libc`
   |
help: possible candidate is found in another module, you can import it into scope
   |
16 | use std::alloc::realloc;
   |

error[E0425]: cannot find function `free` in crate `libc`
  --> /home/carado/.cargo/registry/src/github.com-1ecc6299db9ec823/lodepng-2.5.0/src/rustimpl.rs:62:11
   |
62 |     libc::free(ptr as *mut _)
   |           ^^^^ not found in `libc`

error[E0425]: cannot find function `free` in crate `libc`
   --> /home/carado/.cargo/registry/src/github.com-1ecc6299db9ec823/lodepng-2.5.0/src/lib.rs:818:11
    |
818 |     libc::free(ptr as *mut _);
    |           ^^^^ not found in `libc`

error: aborting due to 4 previous errors

Is using the system's malloc and free really necessary ?

kornelski commented 4 years ago

WASM seems to have malloc: https://github.com/rust-lang/libc/pull/1092/files maybe you need rustup update/cargo update?

carado commented 4 years ago

I tried using the latest lodepng and latest nightly rustc.