I'm writing, in Rust, a wasm+wasi (wasm32-wasi) module that's run with wasmtime
. In this module, I'd like to use https://docs.wasmtime.dev/api/wasmtime_wasi/preview2/command/sync/wasi/sockets/ip_name_lookup/index.html. Where in the wasm book, examples, or elsewhere most closely demonstrates how? The main disconnect I have is, how do I 'use' wasi API in Rust code that'll itself become wasm+wasi.
*wasmtime book. I attempted to edit my original message however that doesn't appear to be allowed.
(I think you can edit your messages for a few minutes and then they become locked, general Zulip feature)
I'm not entirely sure what you mean with wasm+wasi
Well, wasm that uses wasi API
in general you just use the libc functions, as in, rust's builtin name lookup calls, wasi translates that to use wasi_sockets and then the runtime either allows the calls or blocks them
I haven't worked with wasi_sockets at all yet, so I can't help with specifics
Makes sense! I'll try that, thank you :-)
@Ramon Klass Which Rust builtin name lookup calls did you have in mind?
Neither wasi-libc
nor the Rust standard library (which is based on wasi-libc
when targeting wasm32-wasi
) have wasi-sockets
support yet. I'm planning to start working on that in a few weeks if nobody beats me to it.
Meanwhile, you could consider calling the wasi-sockets
host functions directly using bindings generated by wit-bindgen
; I haven't tried that myself, though.
@Joel Dice Oh and so there's no Rust API available, whether in std or a crate, to perform host name resolving to addresses in a wasm module? The wit-bindgen bindings are currently the only possible option?
To my knowledge, yes, that's correct. wasi-sockets
is quite new, and the infrastructure and implementations are still being built.
Would you happen to know if that approach is documented somewhere, say, in the wasmtime book?
I'm not aware of any docs specific to wasi-sockets
, but there is general documentation about importing host interfaces with wit-bindgen
/cargo-component
at https://component-model.bytecodealliance.org/language-support/rust.html#importing-an-interface-with-cargo-component. In this case, you'll want to copy the WIT files from the crates/wasi/wit directory of the version of Wasmtime you plan to use. You'll want to make sure it's the exact same (and fairly recent) version since the interfaces have not yet stabilized and have changed from version to version.
Thank you for the helpful primer
Last updated: Nov 22 2024 at 17:03 UTC