Stream: jco

Topic: Does jco always add import on wasi_cli terminal-*


view this post on Zulip Tylr (Nov 27 2024 at 22:03):

When I run a built http incoming-request handler component via jco serve there are no errors. But when I attempt to run the same .wasm with wasmtime serve it results in the error

Error: component imports instance `wasi:cli/terminal-input@0.2.2`, but a matching implementation was not found in the linker

Caused by:
    0: instance export `terminal-input` has the wrong type
    1: resource implementation is missing

The part which ties back to this topic title is that I have commented out the terminal imports from the wit files used during the jco componentize.

example;

 rg "import terminal"
deps/wasi_cli@0.2.0.wit
109:  // import terminal-input;
110:  // import terminal-output;
111:  // import terminal-stdin;
112:  // import terminal-stdout;
113:  // import terminal-stderr;
138:  // import terminal-input;
139:  // import terminal-output;
140:  // import terminal-stdin;
141:  // import terminal-stdout;
142:  // import terminal-stderr;

So why is it being imported by the component wasm?

view this post on Zulip Guy Bedford (Nov 27 2024 at 22:45):

Wasmtime doesn't enable the WASI capabilities by default. Perhaps try wasmtime serve -S common? Alternatively you can build a pure server component with Jco using the --disable all flag, since by default we support console logging on the server implementation.

view this post on Zulip Tylr (Nov 27 2024 at 22:51):

adding -S common fixed the error from wasmtime.
But why did I need the terminal-input import? afaik it isnt being used by my component, and is removed from the wit files.
Do I need to run some sort of treeshaking / optimizer like jco opt to have the terminal declarations removed?

view this post on Zulip Guy Bedford (Nov 27 2024 at 22:57):

If you run componentize with disable for all features then you can build a pure component with no WASI imports. By default we use WASI logging to be able to support displaying error messages as well as supporting console.log etc, which is on by default for debugging purposes.

view this post on Zulip Tylr (Nov 27 2024 at 23:14):

Ill play with the options and see what i can glean

view this post on Zulip Cameron Taggart (Dec 02 2024 at 01:59):

Hi all. I'm having trouble getting a JavaScript component to use a Rust component. I put together a minimal project and put all the details in this readme: https://github.com/cataggar/StarlingMonkey15/blob/rs-ts-rs/README.md

https://github.com/bytecodealliance/StarlingMonkey/issues/15 - cataggar/StarlingMonkey15

Last updated: Dec 23 2024 at 13:07 UTC