Stream: wasm

Topic: wit-bindgen and wizer mapdir


view this post on Zulip Ramon Klass (Jul 25 2023 at 15:00):

to make sure it isn't my code, I compiled a minimal wasi component that only tries to list files in /usr/ during wizer.initialize and ran the wizer release binary, I can't get this to work, am I doing something wrong? The directory exists

./wizer-v3.0.1-x86_64-linux/wizer --allow-wasi --mapdir "/usr::usr/" --wasm-bulk-memory true ../target/wasm32-wasi/release/wasi_runtime.wasm -o initialized.wasm
thread '<unnamed>' panicked at 'called Result::unwrap() on an Err value: Custom { kind: Uncategorized, error: "failed to find a pre-opened file descriptor through which \"/usr\" could be opened" }', wasi_runtime/src/lib.rs:28:43

view this post on Zulip Ramon Klass (Jul 25 2023 at 15:47):

(I didn't know you can't edit initial messages) I compiled a minimal wasi module, not component

view this post on Zulip Ramon Klass (Jul 26 2023 at 22:54):

I've narrowed it down, calling the wit_bindgen::generate! macro breaks wizer's mapdir, if the wasm file has no component exports I can read files from the mapped dir, but when I add anything componentish it's as if I didn't provide mapdir

how can I further debug this?

even just adding the bindgen macro without actually implementing or exporting the component causes it to break

view this post on Zulip Joel Dice (Jul 26 2023 at 23:11):

My only guess is that wit-bindgen is using https://github.com/bytecodealliance/wit-bindgen/blob/bc4fcebd2805d28ab513806b22483b5f8a0232b3/crates/guest-rust/src/lib.rs#L25 to invoke __wasm_call_ctors, which tells wasm-ld not to insert calls automatically into all exports. Therefore your init function won't call it and thus won't initialize the preopen state. Try adding this to the start of your init function:

                extern "C" {
                    fn __wasm_call_ctors();
                }
                __wasm_call_ctors();

view this post on Zulip Joel Dice (Jul 26 2023 at 23:12):

(you'll need to wrap that in an unsafe block, I imagine)

view this post on Zulip Ramon Klass (Jul 27 2023 at 00:02):

I'll try that next, right now I'm trying to figure out your commits from earlier today ;) world_exports seems to be rejected by the macro though, I think I'll downgrade for now to test your suggestion

view this post on Zulip Joel Dice (Jul 27 2023 at 00:08):

Oops, sorry -- I didn't update the commit message to reflect the syntax we settled on: https://github.com/bytecodealliance/wit-bindgen/pull/604#discussion_r1268189438 plus https://github.com/bytecodealliance/wit-bindgen/pull/604#discussion_r1269806777

This also provides stubs for the Java, Go, and Markdown generators. In addition to resource support, I've changed how the Rust guest generator handles exports per a conversation with Alex. Instead...
This also provides stubs for the Java, Go, and Markdown generators. In addition to resource support, I've changed how the Rust guest generator handles exports per a conversation with Alex. Instead...

view this post on Zulip Ramon Klass (Jul 27 2023 at 00:24):

@Joel Dice your assumption was correct, wasm_call_ctors got me further, I'll now try if the resulting wasm can be adapted into a working component and probably make an example since I can't be the only one who wants to initialize a component :)


Last updated: Dec 23 2024 at 12:05 UTC