Stream: general

Topic: wit-bindgen rust host + guest: get-environment has the wrong


view this post on Zulip eirikb (Jul 18 2024 at 20:11):

Hi. I'm getting this error with trying to use wit-bindgen on both host and guest:

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

I've created a test setup that includes all the source and how to build/run:
https://github.com/eirikb/wit-test

Contribute to eirikb/wit-test development by creating an account on GitHub.

view this post on Zulip Alex Crichton (Jul 18 2024 at 20:13):

The *.wit file you're using isn't a perfect reflection of what the wasm binary is using, notably it omits all of WASI which the Rust standard library uses for its own implementation (e.g. getting env vars). This basically means that WASI is missing from your linker for which I'd recommend reading the wasmtime-wasi docs where you're likely interested in this function

view this post on Zulip eirikb (Jul 18 2024 at 20:15):

Just noticed I was pointed to that link in another thread. Didn't notice. Sorry about that. Will take a look now!

view this post on Zulip eirikb (Jul 18 2024 at 20:15):

I'm not sure if I need WASI. Perhaps I do in order for WIT to work? I don't plan on exposing anything from host to guest beside the methods I provide

view this post on Zulip Alex Crichton (Jul 18 2024 at 20:16):

For that you'd want to use wasm32-unknown-unknown as a compile target

view this post on Zulip Alex Crichton (Jul 18 2024 at 20:17):

to force the standard library to do nothing and have everything implemented as nops

view this post on Zulip eirikb (Jul 18 2024 at 20:23):

I tried doing cargo build --target wasm32-unknown-unknown on the module, then point to that wasm file.
But then I get:

attempted to parse a wasm module with a component parser

view this post on Zulip Alex Crichton (Jul 18 2024 at 20:26):

If you're using cargo component you can continue using cargo component build, and if you're using cargo build you'll have to follow that up with wasm-tools component new to create a component

view this post on Zulip eirikb (Jul 18 2024 at 20:27):

Ok tried cargo component build --target wasm32-unknown-unknown
And I think it ran. At least I didn't get any errors.
Since it doesn't do anything it is hard to tell. I will change the WIT to return a string

view this post on Zulip eirikb (Jul 18 2024 at 20:29):

Oh my I think it worked! Nice

view this post on Zulip eirikb (Jul 18 2024 at 20:34):

Thank you. I've updated the repo just in case someone stumbles over it


Last updated: Oct 23 2024 at 20:03 UTC