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
(I didn't know you can't edit initial messages) I compiled a minimal wasi module, not component
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
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();
(you'll need to wrap that in an unsafe
block, I imagine)
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
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
@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