second-state/rustwasmc

c library ssvmup build can not find <stdlib.h>

Opened this issue · 3 comments

cs686 commented

I use libdeflate lib, but can not ssvmup build
image

hydai commented

Hi @cs686,

Thanks for your information.
ssvmup relies on wasm-bindgen and wasm32-wasi backend.

Unfortunately, the current version of wasm-bindgen/wasm32-wasi backend has some issues when linking rust application with C/C++ libraries. You can find more details in this issue( https://github.com/rustwasm/wasm-bindgen/pull/2209/files ).

Currently, we don't have an easy solution for it.

I've tried libdeflate-sys with standalone wasm32-wasi backend, and it also doesn't work. The error message is attached below:

$ cargo build --target wasm32-wasi

   Compiling libdeflate-sys v0.5.0
The following warnings were emitted during compilation:
warning: libdeflate/lib/aligned_malloc.c:36:10: fatal error: 'stdlib.h' file not found
warning: #include <stdlib.h>
warning:          ^~~~~~~~~~
warning: 1 error generated.

error: failed to run custom build command for `libdeflate-sys v0.5.0`

Caused by:
  process didn't exit successfully: `/home/hydai/workspace/wasm-learning/nodejs/libdeflater/target/release/build/libdeflate-sys-ec0c99f338ab6167/bui
ld-script-build` (exit code: 1)
--- stdout
TARGET = Some("wasm32-wasi")
OPT_LEVEL = Some("3")
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("false")
running: "clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-wasi" "-I" "libdeflate/" "-I" "libdeflate/lib/" "-I" "libdef
late/common/" "-o" "/home/hydai/workspace/wasm-learning/nodejs/libdeflater/target/wasm32-wasi/release/build/libdeflate-sys-ab91f28b9c57ff1b/out/lib/
libdeflate/lib/aligned_malloc.o" "-c" "libdeflate/lib/aligned_malloc.c"
cargo:warning=libdeflate/lib/aligned_malloc.c:36:10: fatal error: 'stdlib.h' file not found
cargo:warning=#include <stdlib.h>
cargo:warning=         ^~~~~~~~~~
cargo:warning=1 error generated.
exit code: 1

--- stderr


error occurred: Command "clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-wasi" "-I" "libdeflate/" "-I" "libdeflate/lib
/" "-I" "libdeflate/common/" "-o" "/home/hydai/workspace/wasm-learning/nodejs/libdeflater/target/wasm32-wasi/release/build/libdeflate-sys-ab91f28b9c
57ff1b/out/lib/libdeflate/lib/aligned_malloc.o" "-c" "libdeflate/lib/aligned_malloc.c" with args "clang" did not execute successfully (status code exit code: 1).

The sys C libraries often make operating system calls that are not permitted by the WebAssembly sandbox. WebAssembly only allows very limited number of system calls via the WASI interface.

In this particular case, I would recommend to use a pure Rust implementation of deflate.

https://docs.rs/deflate/0.8.6/deflate/

cs686 commented

@juntao thank,I will try