Stream: general

Topic: wasi vector usage


view this post on Zulip Evgeny (May 06 2020 at 22:05):

Hi there, here is a newbie question if you don't mind

I built a simple wasm with exported function which was build with wasm32-wasi target, now I a modified hello example from wasmtime and it works fine.. until I start using vector in my exported function: I receive "wrong number of imports provided, 0 != 1"; the problem disappears when I build wasm with wasm32-unknown-unknown target; wasm compilation works fine in all these cases btw

view this post on Zulip Yury Delendik (May 06 2020 at 22:08):

wasm32-unknown-unknown is silent on panics, wasm32-wasi don't

view this post on Zulip Yury Delendik (May 06 2020 at 22:09):

Vec operations may panic

view this post on Zulip Yury Delendik (May 06 2020 at 22:09):

@Evgeny can you check wasm module and tell which wasi function it requires?

view this post on Zulip Evgeny (May 06 2020 at 22:11):

sure if you could tell me how to do that, btw here is a full source:
#[no_mangle]
pub extern "C" fn hello() -> i32 {
let a = vec![322];
1337
}

view this post on Zulip Yury Delendik (May 06 2020 at 22:12):

wasm2wat cli normally tell

view this post on Zulip Yury Delendik (May 06 2020 at 22:12):

lazy to install -> https://wasdk.github.io/wasmcodeexplorer/

view this post on Zulip Evgeny (May 06 2020 at 22:13):

(import "wasi_snapshot_preview1" "fd_write" (func $wasi::lib_generated::wasi_snapshot_preview1::fd_write::h4660e0082b9356a7 (type 10)))
if I got right

view this post on Zulip Yury Delendik (May 06 2020 at 22:14):

yep, "fd_write" probably is used to write panic message to stderr

view this post on Zulip Evgeny (May 06 2020 at 22:18):

Can https://github.com/bytecodealliance/wasmtime/blob/9364eb1d98d4b82d30ce72ec1e46ee72a1ea6a0c/examples/wasi/main.rs help with setting this import ?

Standalone JIT-style runtime for WebAssembly, using Cranelift - bytecodealliance/wasmtime

view this post on Zulip Evgeny (May 06 2020 at 22:18):

I'm not sure how to provide this fd_write

view this post on Zulip Yury Delendik (May 06 2020 at 22:19):

wasmtime supports wasi, so yes

view this post on Zulip Yury Delendik (May 06 2020 at 22:19):

the example above does just that

view this post on Zulip Evgeny (May 06 2020 at 22:20):

thank you for your help!

view this post on Zulip Yury Delendik (May 06 2020 at 22:20):

wasi.get_export(import.name()) will find "fd_write" if it is present


Last updated: Nov 22 2024 at 17:03 UTC