Stream: wit-bindgen

Topic: bindings imports


view this post on Zulip Yan Ivnitskiy (May 29 2025 at 23:59):

I'm trying to call an imported function in my component; the wit file is herecargo component bindings generates a bindings file successfully and it produces a getrandom() function. I bind an implementation to the linker in my host code and that gets invoked as well. However, when the host implementation returns back to the component, it panics in the component's bindings code, when it unpacks the result/vector by unmarshalling the ptr/size due to unaligned access. Anyone have any pointers to what can be happening? (cc @Alex Crichton )

GitHub Gist: instantly share code, notes, and snippets.

view this post on Zulip Yan Ivnitskiy (May 30 2025 at 00:31):

looks like everything works if getrandom() returns list<u8> instead of result<list<u8>>

view this post on Zulip Lann Martin (May 30 2025 at 12:33):

I don't know what the exact issue is but if you're using cargo component you may have better luck building with cargo component build.

view this post on Zulip Alex Crichton (May 30 2025 at 14:29):

If you're working with WASIp3, which is guest-level async, you'll need to make sure you're using up-to-date tools and everything is still a work-in-progress meaning that it's not a smooth experience at this time.

What you're running into here is that if you build for wasm32-wasip1 that doesn't build a component, it just builds a core module. With wasm32-wasip2 the linker being used by rustc doesn't have async support, so it's failing to recognize the intrinsic.

To build for wasm32-wasip3 right now (which is a target that doesn't exist in rust) you typically need to build for wasm32-wasip1 and manually run wasm-tools component new yourself.

view this post on Zulip Yan Ivnitskiy (May 30 2025 at 17:32):

@Alex Crichton i have been using wasm32-unknown-unknown; it works with my imported function returning list<u8> but not with it wrapped in a result; i wonder if it's a bindgen issue?

view this post on Zulip Alex Crichton (May 30 2025 at 17:34):

Can you confirm you've got the most up-to-date wasm-tools and wit-bindgen deps?

view this post on Zulip Yan Ivnitskiy (May 31 2025 at 17:48):

had an older install of cargo-component; bumped to wit-bindgen 0.41; it works now, thanks


Last updated: Dec 06 2025 at 06:05 UTC