Closed AndreasHae closed 5 months ago
Thank you for the detailed report!
This issue arises from the absence of a usable libc when targeting wasm. You can circumvent this problem by instructing clang to use the libc provided by wasi-sdk.
You can obtain the wasi-libc from here or wasi-sdk release (wasi-sysroot).
Alternatively, creating a Rust build environment based on the docker image provided by wasi-sdk allows building wasm without the need for special options.
liblzma-rs GitHub Actions workflow adopts this approach.
If you opt for using docker, you may find this project helpful as a reference.
I just had to export these variables:
export CC_wasm32_wasi=/opt/wasi-sdk/bin/clang
export CARGO_TARGET_WASM32_WASI_LINKER=/opt/wasi-sdk/bin/clang
Hi! I'm having trouble trying to build this crate for wasm32-wasi, and I have the same error, though I have not been able to fix it due to my unfamiliarity with clang and RUSTFLAGS.
I have wasi-sdk installed to /opt/wasi-sdk, I am compiling for the wasm32-wasi target, and here is my .cargo/config.toml.
I would really rather not use docker due to the size of my drive.
[target.wasm32-wasi]
rustflags = [
"-C",
"llvm-args=--target=wasm32-wasi --sysroot=/opt/wasi-sdk/share/wasi-sysroot/",
]
linker = "/opt/wasi-sdk/bin/clang"
ar = "/opt/wasi-sdk/bin/llvm-ar"
Help would be much appreciated. Thanks! <3
In case anyone else sees this, I made a really horrendous build script in python that you can find here. I cannot speak for its quality, but it might help someone.
It builds all crates in the current directory.
Also, there's no need to fiddle with the .cargo/config.toml
. You just need to set the environment variables.
I'm trying to use this library in a WebAssembly project. When compiling for my native
x86_64-apple-darwin
target, all is good. However, when I try to run the build with thewasm32-unknown-unknown
target (exactly like in the Github Action), I get all kinds of errors aboutassert.h
missing.Edit: was able to reproduce the exact same issue on WSL
So I cloned the project and tried to compile it in the exact same way as in the Github Action.
I tried both the native Apple Clang distribution:
and the version from Homebrew llvm:
but to no avail.
I also tried to create
assert.h
myself. Then I got the same error forstring.h
instead. When I defined this as well, it complained aboutmemcpy
missing. It seems like something is missing on my machine that is present in the Github Action because there it seems to work, but I can't figure out what it is.Looking forward to any pointers what I'm doing wrong. Here's the complete log: