cargo-wasi icon indicating copy to clipboard operation
cargo-wasi copied to clipboard

Lack of support for C dependencies (wasi-sdk?)

Open kornelski opened this issue 3 years ago • 4 comments

cargo add zstd-sys # or any other C-dependent crate
cargo wasi build

Results in:

warning: zstd/lib/common/zstd_deps.h:29:10: fatal error: 'string.h' file not found
warning: #include <string.h>
…
error occurred: Command "clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=wasm32-wasi" "-I" "zstd/lib/" "-I" "zstd/lib/common" "-I" "zstd/lib/legacy" "-fvisibility=hidden" "-DZSTD_LIB_DEPRECATED=0" "-DXXH_PRIVATE_API=" "-DZSTDLIB_VISIBILITY=" "-DZDICTLIB_VISIBILITY=" "-DZSTDERRORLIB_VISIBILITY=" "-DZSTD_LEGACY_SUPPORT=1" "-o" "/private/tmp/testing/target/wasm32-wasi/debug/build/zstd-sys-1e822e2310f0cb71/out/zstd/lib/common/entropy_common.o" "-c" "zstd/lib/common/entropy_common.c" with args "clang" did not execute successfully (status code exit status: 1).

(cargo-wasi v0.1.23, Rust 1.55, macOS 15b/x86-64)

From what I could gather, compiling C deps with headers requires wasi-sdk and adding a flag to clang: --sysroot=${WASI_SDK_PATH}/share/wasi-sysroot".

Could cargo wasi support installing and configuring the SDK? Without it it's hard to build any non-trivial Rust project (about 23% of Rust crates depend on C code).

kornelski avatar Sep 10 '21 18:09 kornelski

I agree this would be great to support! I don't know the best way to finagle it but having something like a separate command which installs the sdk is probably the best starting point, and this could probably manage the install via the pre-compiled binaries on wasi-sdk's CI.

alexcrichton avatar Sep 13 '21 14:09 alexcrichton