Hi, new to rust->wasm component develoment.
Trying to understand this. If I build a new component following the rust component docs cargo component new --reactor add
, then I extract the .wit
file from the generated wasm, I see a very simple:
package root:component;
world root {
export add: func(x: s32, y: s32) -> s32;
}
But if I now change the component to return a string
rather than an s32
, then I build the component with a new wit file:
package component:add;
world example {
export add: func(x: s32, y: s32) -> string;
}
extracting the .wit
file from the resulting components shows a new interface that includes all wasi imports:
package root:component;
world root {
import wasi:cli/environment@0.2.0-rc-2023-12-05;
import wasi:cli/exit@0.2.0-rc-2023-12-05;
import wasi:io/error@0.2.0-rc-2023-11-10;
import wasi:io/streams@0.2.0-rc-2023-11-10;
import wasi:cli/stdin@0.2.0-rc-2023-12-05;
import wasi:cli/stdout@0.2.0-rc-2023-12-05;
import wasi:cli/stderr@0.2.0-rc-2023-12-05;
import wasi:clocks/wall-clock@0.2.0-rc-2023-11-10;
import wasi:filesystem/types@0.2.0-rc-2023-11-10;
import wasi:filesystem/preopens@0.2.0-rc-2023-11-10;
export add: func(x: s32, y: s32) -> string;
}
Is this expected? If so, why?
My guess would be that the bindings generated to marshal the string pull in the panic infrastructure from the Rust standard library, which will call the WASI preview1 versions of things like getting environment variables, printing to the console, and exiting. cargo-component
will automatically adapt the stdlib's preview1 calls to preview2
Interesting, thanks
James Mart has marked this topic as resolved.
Last updated: Nov 25 2024 at 19:03 UTC