rust-lang / crates-build-env

Build environment for third-party Rust crates
MIT License
71 stars 93 forks source link

Missing WASI SDK support #136

Open jeffcharles opened 1 year ago

jeffcharles commented 1 year ago

Affected crates: quickjs-wasm-sys, quickjs-wasm-rs, javy, javy-apis

The four crates above need access to a WASI SDK to compile some vendored C source code to the wasm32-wasi target. Unfortunately I can't find an Ubuntu package for the WASI SDK. There is a wasi-libc package but that's not sufficient since Clang also requires an additional runtime archive file to be installed and that archive file is not part of an Ubuntu package.

From https://github.com/WebAssembly/wasi-sdk:

One could also use a standard Clang installation, build a sysroot from the sources mentioned above, and compile with --target=wasm32-wasi --sysroot=/path/to/sysroot. In this scenario, one would also need the libclang_rt.builtins-wasm32.a objects available separately in the release downloads which must be extracted into $CLANG_INSTALL_DIR/$CLANG_VERSION/lib/wasi/.

The compiled WASI SDK is also too large to vendor given cargo's size limits on crates.

I'm not sure how to proceed.

syphar commented 1 year ago

Hi @jeffcharles

from what I know, there are two typical solutions to this:

jeffcharles commented 1 year ago

I've opened https://github.com/rust-lang/crates-build-env/pull/137 to add a couple packages. I think with those two packages and vendoring the libclang_rt.builtins-wasm32.a archive in the crate, it should be possible to build the C code. It worked in an Ubuntu 22.02 Docker container. I did have to copy the system LLVM to the crate's OUT_DIR to install the vendored archive and use that copy of clang and llvm-ar to build the code but it worked.

syphar commented 1 year ago

Sorry for the delay in responding.

I merged the pr above, though I can only get to deploying the image to our build server next week.

Until then you could try the build using the crates-build-env docker image, when the build is finished.