Closed greyltc closed 6 months ago
Thanks for the report! Can you detail how you got a wasm32-wasip2 compiler? I was poking at that locally and had a surprisingly difficult time getting this to work, but for other reasons unrelated to the one that you encountered. This may indicate a configuration issue or an issue with the wasip2 toolchain to smooth over.
Can you detail how you got a wasm32-wasip2 compiler?
@alexcrichton sure, I built the 1.78.0 rustc release package for Arch Linux like this: https://gitlab.archlinux.org/greyltc/rust/-/blob/add-wasm32-wasip2/PKGBUILD?ref_type=heads#L73-230
but basically, that just amounted to adding
[target.wasm32-wasip2]
sanitizers = false
profiler = false
wasi-root = "/usr/share/wasi-sysroot"
to config.toml and "wasm32-wasip2"
to the [build]
target array. Which is a small departure from how the official Arch rust package is made: https://gitlab.archlinux.org/greyltc/rust/-/compare/main...add-wasm32-wasip2?from_project_id=38540
Did I leave anything out there?
Seems I also had to use your special linker, wasm-component-ld, which I built/packaged like this: https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=wasm-component-ld
Ah ok makes sense! The wit-bindgen crate currently assumes that https://github.com/rust-lang/rust/pull/122411 is part of Rust, which didn't make the 1.78 release. The 1.79 release of Rust will be the first to include that PR which should resolve most of this error.
Otherwise though one important thing to note is that wasi-libc objects are built differently for wasm32-wasip1 and wasm32-wasip2, so you'll eventually want a distinct wasi-root
for each target.
https://github.com/rust-lang/rust/pull/122411 seems to have sorted it, thanks! I built the rust package with that PR patched in like this: https://gitlab.archlinux.org/greyltc/rust/-/compare/main...add-wasm32-wasip2?from_project_id=38540
I also made a wasip2-libc package which gives me a wasi-root that has a wasm32-wasip2
target in it: https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=wasip2-libc
and the missing cabi_realloc
compile problem is gone:
$ CARGO_HOME=cargocache cargo build --release --example http-proxy --target wasm32-wasip2
Updating crates.io index
Downloaded wit-bindgen-rt v0.23.0
Downloaded bitflags v2.5.0
Downloaded 2 crates (47.0 KB) in 2.37s
Compiling wit-bindgen-rt v0.23.0
Compiling bitflags v2.5.0
Compiling wasi v0.13.0+wasi-0.2.0 (/tmp/t4/wasi)
Finished `release` profile [optimized] target(s) in 4.44s
Though I can't seem to run it successfully like I did with the cli_command example:
$ wasmtime target/wasm32-wasip2/release/examples/http_proxy.wasm
Error: failed to run main module `target/wasm32-wasip2/release/examples/http_proxy.wasm`
Caused by:
0: component imports instance `wasi:http/types@0.2.0`, but a matching implementation was not found in the linker
1: instance export `fields` has the wrong type
2: resource implementation is missing
To fix that error, the cli invocation to run an wasi-http proxy world is wasmtime serve
.
Thanks for your help, I very much appreciate it.
$ wasmtime serve target/wasm32-wasip2/release/examples/http_proxy.wasm
Error: component imports instance `wasi:cli/environment@0.2.0`, but a matching implementation was not found in the linker
Caused by:
0: instance export `get-environment` has the wrong type
1: function implementation is missing
wasmtime serve
shows another error.
Ah for that you'll want to pass -Scli
to the wasmtime serve
command.
$ wasmtime serve -Scli target/wasm32-wasip2/release/examples/http_proxy.wasm
Serving HTTP on http://0.0.0.0:8080/
Works! :champagne: Thanks again.
Hi, I'm trying to build the examples here for the
wasm32-wasip2
target. The cli-command example works fine, but the http-proxy example fails while linking withmodule does not export a function named 'cabi_realloc'
, see below.Should I expect
cargo build --release --example http-proxy --target wasm32-wasip2
to work?