Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kornelski opened this issue Sep 10, 2021 · 4 comments
Open

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

kornelski opened this issue Sep 10, 2021 · 4 comments

Comments

@kornelski
Copy link

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

@alexcrichton
Copy link
Member

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.

@inklesspen1rus
Copy link

inklesspen1rus commented Jun 2, 2024

Target wasm32-wasip1 successfully compiles with zstd-sys dependency via cargo build --target wasm32-wasip1.
Probably, we have just to wait.... a bit....

@jedisct1
Copy link

jedisct1 commented Jun 2, 2024

Easier to use cargo-zigbuild, so you can use the same command to cross-compile to any target, including wasi.

cargo-zigbuild --target=wasm32-wasi

@inklesspen1rus
Copy link

zigbuild doesn't build zstd-sys for me 😢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants