Stream: general

Topic: ✔ Guest missing imports


view this post on Zulip bachrc (Feb 21 2023 at 17:16):

Hi here, I just converted my wasm to a component, and I indeed see that in the wit that wasm-tools told be, it is now asking multiple imports. Like wasi-stderr, wasi-stdio...

And when trying to instantiate with wasmtime, well it panics because apparently, the WASM misses some imports.
https://github.com/bytecodealliance/wasmtime/issues/5830
This is a very similar problem to this issue, but I didn't understand the answer given by pchickey. How can I do the bindings? Thanks in advance

Hello I am currently experimenting with the component model and encounter the following problem. I know that the component model is not stable but maybe someone can help me. To reproduce the error ...

view this post on Zulip Pat Hickey (Feb 21 2023 at 17:17):

A host implementation of those imports is provided over in the preview2-prototyping repo under host/

view this post on Zulip Pat Hickey (Feb 21 2023 at 17:17):

it uses a fork of wasi-common, and its very incomplete and buggy

view this post on Zulip Pat Hickey (Feb 21 2023 at 17:17):

and its rapidly changing

view this post on Zulip bachrc (Feb 21 2023 at 17:19):

Oh I see, so I cannot make the bindings for now? Am I forced to use this?

view this post on Zulip Pat Hickey (Feb 21 2023 at 17:19):

so, you need to depend on that crate, and use its add_to_linker and WasiCommand export like here: https://github.com/bytecodealliance/preview2-prototyping/blob/main/host/src/main.rs

Polyfill adapter for preview1-using wasm modules to call preview2 functions. - preview2-prototyping/main.rs at main · bytecodealliance/preview2-prototyping

view this post on Zulip Pat Hickey (Feb 21 2023 at 17:20):

but note that you need to depend on the previee2-prototyping wasi-common, not the crates.io wasi-common, so please use a git dependency

view this post on Zulip Pat Hickey (Feb 21 2023 at 17:21):

you can either use the implementation in prototyping's host, or you can write your own using wasmtime's wit bindgen. i dont recommend writing your own because its quite hard

view this post on Zulip Pat Hickey (Feb 21 2023 at 17:21):

but if you need to, it is possible

view this post on Zulip Pat Hickey (Feb 21 2023 at 17:21):

you'll have to follow the general pattern we used in that repo of invoking wasmtime::component::bindgen!() to do so, and then impl all of the traits.

view this post on Zulip bachrc (Feb 21 2023 at 17:22):

Yup, I tried to pull your host project :

[dependencies]
.......
wasmtime = { version = "^6.0.0", features = ["component-model", "async"] }
host = { git = "https://github.com/bytecodealliance/preview2-prototyping" }

But when trying to build, I have a version conflict that I... don't understand o.o

wasmtime_host_test git:(main)  cargo check
    Updating crates.io index
    Updating git repository `https://github.com/bytecodealliance/preview2-prototyping`
    Updating git repository `https://github.com/bytecodealliance/wasmtime`
error: failed to select a version for `wasmtime-fiber`.
    ... required by package `wasmtime v6.0.0 (https://github.com/bytecodealliance/wasmtime?branch=release-6.0.0#c00d3f05)`
    ... which satisfies git dependency `wasmtime` of package `host v0.0.0 (https://github.com/bytecodealliance/preview2-prototyping#7736fd0c)`
    ... which satisfies git dependency `host` of package `wasmtime_host_test v0.1.0 (/home/yohann/devs/neo-michel/wasmtime_host_test)`
versions that meet the requirements `=6.0.0` are: 6.0.0

the package `wasmtime-fiber` links to the native library `wasmtime-fiber-shims`, but it conflicts with a previous package which links to `wasmtime-fiber-shims` as well:
package `wasmtime-fiber v6.0.0`
    ... which satisfies dependency `wasmtime-fiber = "=6.0.0"` of package `wasmtime v6.0.0`
    ... which satisfies dependency `wasmtime = "^6.0.0"` of package `wasmtime_host_test v0.1.0 (/home/yohann/devs/neo-michel/wasmtime_host_test)`
Only one package in the dependency graph may specify the same links value. This helps ensure that only one copy of a native library is linked in the final binary. Try to adjust your dependencies so that only one package uses the links ='wasmtime-fiber' value. For more information, see https://doc.rust-lang.org/cargo/reference/resolver.html#links.

failed to select a version for `wasmtime-fiber` which could resolve this conflict

view this post on Zulip Pat Hickey (Feb 21 2023 at 17:23):

thats crgo's way of showing you there are multiple versions of wasmtime pulled in

view this post on Zulip Pat Hickey (Feb 21 2023 at 17:23):

(not ideal)

view this post on Zulip bjorn3 (Feb 21 2023 at 17:23):

You need to use

wasmtime = { git = "https://github.com/bytecodealliance/wasmtime", features = ["component-model"], branch = 'release-6.0.0' }

as that is what preview2-prototyping used too.

view this post on Zulip bachrc (Feb 21 2023 at 17:24):

Yeah, but all I see are version 6.0.0, so there should be no problem haha

view this post on Zulip bachrc (Feb 21 2023 at 17:24):

Thank to both of you, I'm gonna try this :)

view this post on Zulip Pat Hickey (Feb 21 2023 at 17:24):

git versions and crates.io versions are not compatible, even if they say the same string

view this post on Zulip Pat Hickey (Feb 21 2023 at 17:24):

we can update preview2-prototyping to point at the crates.io release, it landed this morning, but all of the people who hack on that are in a meeting today so we havent gotten to it yet

view this post on Zulip bachrc (Feb 21 2023 at 17:27):

Okay, I understand better now :) And this is working like this! Thank you for your kind and quick answers and your hard work :)

view this post on Zulip Notification Bot (Feb 21 2023 at 17:27):

bachrc has marked this topic as resolved.

view this post on Zulip Notification Bot (Feb 21 2023 at 17:36):

bachrc has marked this topic as unresolved.

view this post on Zulip bachrc (Feb 21 2023 at 17:38):

Well, I guess using the add_to_linker is incompatible with the one given by my bindgen! macro? :(

view this post on Zulip bachrc (Feb 21 2023 at 17:38):

let mut linker = Linker::new(&engine);
host::add_to_linker(&mut linker, |x| x)?;
Michel::add_to_linker(&mut linker, |state: &mut MichelApiForPlugins| state)?;

view this post on Zulip Pat Hickey (Feb 21 2023 at 17:41):

can you share the error message?

view this post on Zulip bachrc (Feb 21 2023 at 17:41):

Here the compiler isn't happy because there is two types or states given to the linker : WasiCtx (by the host), and MichelApiForPlugins (which is my state)

view this post on Zulip bachrc (Feb 21 2023 at 17:42):

error[E0631]: type mismatch in closure arguments
  --> wasmtime_host_test/src/main.rs:34:5
   |
34 |     Michel::add_to_linker(&mut linker, |state: &mut MichelApiForPlugins| state)?;
   |     ^^^^^^^^^^^^^^^^^^^^^              --------------------------------- found signature defined here
   |     |
   |     expected due to this
   |
   = note: expected closure signature `for<'a> fn(&'a mut WasiCtx) -> _`
              found closure signature `for<'a> fn(&'a mut MichelApiForPlugins) -> _`

view this post on Zulip Pat Hickey (Feb 21 2023 at 17:42):

right, so you want to make some struct Ctx { wasi: WasiCtx, michel: MichaelApiForPlugins }, and in the linker you use |ctx| &mut ctx.wasi for wasi, |ctx| &mut ctx.michel for michel

view this post on Zulip Pat Hickey (Feb 21 2023 at 17:42):

thats how the linker is designed to deal with compositions of state

view this post on Zulip bachrc (Feb 21 2023 at 17:43):

Oh okay I see! I hope my struggles will help people searching here :) Thanks again for your answer!

view this post on Zulip bachrc (Feb 21 2023 at 18:00):

Yup, but making the Linker contain our new Ctx is incompatible with the instantiate_async generated by the bindgen!.

let (bindings,_) = Michel::instantiate_async(&mut store, &component, &linker).await?;

Here it waits for the same generic type for store and linker. Well I guess my Store should not be MichelPluginForApi anymore, but Ctx ? But for creating a Ctx object, I need to create a WasiCtx. You know how I could do this? :(

view this post on Zulip bachrc (Feb 21 2023 at 18:00):

Oh yes, the WasiCtxBuilder !

view this post on Zulip bachrc (Feb 21 2023 at 18:01):

I'm trying this now.

view this post on Zulip Pat Hickey (Feb 21 2023 at 18:01):

yes

view this post on Zulip Pat Hickey (Feb 21 2023 at 18:01):

and your store will need to be a Store<Ctx>

view this post on Zulip bachrc (Feb 21 2023 at 21:14):

Sorry to bother again, but trying to get the WasiCtsBuilder with the wasmtime-wasi dependency :

wasmtime-wasi = { git = "https://github.com/bytecodealliance/wasmtime", branch = 'release-6.0.0' }

But again, a version conflict. I don't see what's wrong here :(

stdout :     Updating crates.io index
    Updating git repository `https://github.com/bytecodealliance/wasmtime`
error: failed to select a version for `wasi-common`.
    ... required by package `wasmtime-wasi v6.0.0 (https://github.com/bytecodealliance/wasmtime?branch=release-6.0.0#c00d3f05)`
    ... which satisfies git dependency `wasmtime-wasi` of package `wasmtime_host_test v0.1.0 (/home/yohann/devs/neo-michel/wasmtime_host_test)`
versions that meet the requirements `=6.0.0` are: 6.0.0

the package `wasi-common` links to the native library `wasi-common-19`, but it conflicts with a previous package which links to `wasi-common-19` as well:
package `wasi-common v0.0.0 (https://github.com/bytecodealliance/preview2-prototyping#7736fd0c)`
    ... which satisfies git dependency `wasi-common` (locked to 0.0.0) of package `host v0.0.0 (https://github.com/bytecodealliance/preview2-prototyping#7736fd0c)`
    ... which satisfies git dependency `host` (locked to 0.0.0) of package `wasmtime_host_test v0.1.0 (/home/yohann/devs/neo-michel/wasmtime_host_test)`
Only one package in the dependency graph may specify the same links value. This helps ensure that only one copy of a native library is linked in the final binary. Try to adjust your dependencies so that only one package uses the links ='wasi-common' value. For more information, see https://doc.rust-lang.org/cargo/reference/resolver.html#links.

failed to select a version for `wasi-common` which could resolve this conflict

view this post on Zulip Pat Hickey (Feb 21 2023 at 21:52):

You can’t use wasi-common from the prototype repo and the one upstream in Wasmtime in the same project right now.

view this post on Zulip Pat Hickey (Feb 21 2023 at 21:53):

We will merge all that functionality back in upstream at some point, but right now they can’t coexist

view this post on Zulip Pat Hickey (Feb 21 2023 at 21:53):

If you delete the links section in the prototype cargo.toml it might work

view this post on Zulip bachrc (Feb 21 2023 at 22:08):

Ah. So I can't use WasiCtxBuilder, and so using wit-bindgen

view this post on Zulip bachrc (Feb 21 2023 at 22:09):

I can't modify the prototype Cargo.toml without doing a fork

view this post on Zulip bachrc (Feb 21 2023 at 22:14):

And i don't see any links section in https://github.com/bytecodealliance/preview2-prototyping/blob/main/Cargo.toml

Polyfill adapter for preview1-using wasm modules to call preview2 functions. - preview2-prototyping/Cargo.toml at main · bytecodealliance/preview2-prototyping

view this post on Zulip bachrc (Feb 22 2023 at 00:55):

Well I see here (https://bytecodealliance.zulipchat.com/#narrow/stream/327223-wit-bindgen/topic/.5Brust.5D.20wasmtime.20.26.20custom.20wit.20type.20.28record.29) that i should maybe import wasi_cap_sync from the std!

view this post on Zulip Giom (Feb 22 2023 at 15:58):

Hey i managed to get it working by adding the following line to my cargo.toml of the host project:
wasi-cap-std-sync = { git = "https://github.com/bytecodealliance/preview2-prototyping", rev = "7736fd0" }

Then i was able to use the WasiCtxBuilder.

view this post on Zulip bachrc (Feb 23 2023 at 21:56):

Yeah, to make this work, I was forced to clone locally the preview2-prototyping, and remove the [links] section.

view this post on Zulip Notification Bot (Feb 23 2023 at 21:57):

bachrc has marked this topic as resolved.

view this post on Zulip Elia Bieri (Mar 05 2023 at 12:50):

Could you send me the example you used to get it working?


Last updated: Oct 23 2024 at 20:03 UTC