I am trying to export a wasi-http incoming-handler from my component. I have copied Wasmtime's version of the WASI wit files into a deps/
directory alongside the definition of my world (in both the guest and host crates), and that seems to be enough to make cargo-component
happy (able to resolve references to WASI stuff). However, the Wasmtime side of things using component::bindgen!
is not so happy:
error: failed to find package `wasi:http` in `deps` directory
--> /home/jeff/aaa/wit/deps/job-server.wit:7:12
|
7 | export wasi:http/incoming-handler
| ^--------
--> src/main.rs:7:1
|
7 | wasmtime::component::bindgen!("job-server" in "wit/deps");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `wasmtime::component::bindgen` (in Nightly builds, run with -Z macro-backtrace for more info)
I can't find any options on the component::bindgen!
macro to tell it how to resolve dependencies referenced in my world definition.
Here is my component world:
package jeffparsons:job-server
world job-server {
export hello-world: func() -> string
export wasi:http/incoming-handler
}
And here's what my host's wit/
dir looks like:
~/Projects/aaa took 5s> find -L wit
wit
wit/deps
wit/deps/wasi
wit/deps/wasi/filesystem
wit/deps/wasi/filesystem/world.wit
wit/deps/wasi/filesystem/types.wit
wit/deps/wasi/filesystem/preopens.wit
wit/deps/wasi/logging
wit/deps/wasi/logging/logging.wit
wit/deps/wasi/clocks
wit/deps/wasi/clocks/timezone.wit
wit/deps/wasi/clocks/monotonic-clock.wit
wit/deps/wasi/clocks/wall-clock.wit
wit/deps/wasi/io
wit/deps/wasi/io/streams.wit
wit/deps/wasi/poll
wit/deps/wasi/poll/poll.wit
wit/deps/wasi/random
wit/deps/wasi/random/insecure-seed.wit
wit/deps/wasi/random/insecure.wit
wit/deps/wasi/random/random.wit
wit/deps/wasi/cli
wit/deps/wasi/cli/command.wit
wit/deps/wasi/cli/run.wit
wit/deps/wasi/cli/stdio.wit
wit/deps/wasi/cli/terminal.wit
wit/deps/wasi/cli/reactor.wit
wit/deps/wasi/cli/environment.wit
wit/deps/wasi/cli/exit.wit
wit/deps/wasi/http
wit/deps/wasi/http/proxy.wit
wit/deps/wasi/http/types.wit
wit/deps/wasi/http/incoming-handler.wit
wit/deps/wasi/http/outgoing-handler.wit
wit/deps/wasi/sockets
wit/deps/wasi/sockets/tcp-create-socket.wit
wit/deps/wasi/sockets/udp-create-socket.wit
wit/deps/wasi/sockets/ip-name-lookup.wit
wit/deps/wasi/sockets/tcp.wit
wit/deps/wasi/sockets/udp.wit
wit/deps/wasi/sockets/network.wit
wit/deps/wasi/sockets/instance-network.wit
wit/deps/job-server.wit
Is this something that is meant to be possible (yet)? Hopefully I've just missed something simple!
From my Cargo.lock
:
[[package]]
name = "wasmtime"
version = "13.0.0"
source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=release-13.0.0#d57fc24b5370e05697d718ff1e8412acd04e7bc4"
Thanks! :bow:
(P.S. I'm not sure if this is the right venue for these sorts of end-user questions — please point me in the right direction if not!)
this is a totally fine venue for these questions
i think you just need to move the contents of wit/deps/wasi to wit/deps
Thanks! I eventually got this working by structuring my wit/
dir like this:
wit/job-server.wit
wit/deps
wit/deps/filesystem
wit/deps/filesystem/world.wit
And invoking the bindgen!
macro like this:
wasmtime::component::bindgen!("jeffparsons:job-server/job-server");
I think my mental model of how it would be looking for *.wit
files was just wrong; I expected it to be looking for files from some common root, rather than always looking for dependencies beneath a deps/
directory as a sibling of the package you're generating bindings for.
I've started using wit-deps
to manage this dir, so in practice the wit/job-server.wit
listed above is actually a symlink to wit/deps/job-server/world.wit
. It feels a bit weird, but it works!!
Last updated: Nov 22 2024 at 16:03 UTC