Stream: wasi

Topic: ✔ Disable importing of packages wasi:cli, wasi:io etc


view this post on Zulip lkjhaisduhjfkxcjvbnis (Aug 06 2024 at 12:45):

I am trying to build a very simple application with components that does not depend on any other packages. just some functions. When I compile my guest project to a core wasm module everything seems to be working just fine, with the output of wasm-tools component wit <core.wasm> being

package root:root {
  world root {
    export hello-world: func() -> string;
  }
}


package component:sus {
  world example {
    export hello-world: func() -> string;
  }
}

However when i convert the core module to a component with
wasm-tools component new --adapt wasi_snapshot_preview1=latest_wasi_snapshot_preview1.reactor.wasm <core.wasm> -o component.wasm
It adds dependencies on a bunch of standard packages:

...

package root:component {
  world root {
    import wasi:cli/environment@0.2.0;
    import wasi:cli/exit@0.2.0;
    import wasi:io/error@0.2.0;
    import wasi:io/streams@0.2.0;
    import wasi:cli/stdin@0.2.0;
    import wasi:cli/stdout@0.2.0;
    import wasi:cli/stderr@0.2.0;
    import wasi:clocks/wall-clock@0.2.0;
    import wasi:filesystem/types@0.2.0;
    import wasi:filesystem/preopens@0.2.0;

    export hello-world: func() -> string;
  }
}

I do not want to support these packages on my host so how can i avoid importing these?

view this post on Zulip Alex Crichton (Aug 06 2024 at 12:47):

If you're using Rust as a source language you can use the wasm32-unknown-unknown target for this

view this post on Zulip lkjhaisduhjfkxcjvbnis (Aug 06 2024 at 12:47):

oh great let me try that. is there documentation on this? i have only ever seen the wasm32-wasip1 target in use

view this post on Zulip Alex Crichton (Aug 06 2024 at 12:49):

No documentation I know of myself, but the workflow should be the same (note that things like println in the standard library won't work)

view this post on Zulip lkjhaisduhjfkxcjvbnis (Aug 06 2024 at 12:51):

Ok so do i understand this correctly that the wasm32-wasip1 requires these core packages to be present to make the std lib work and wasm32-unknown-unknown does not and hence does not support the stdlib?

view this post on Zulip Alex Crichton (Aug 06 2024 at 13:04):

more or less yeah

view this post on Zulip lkjhaisduhjfkxcjvbnis (Aug 06 2024 at 13:06):

It works! Thank you so much for your help!

view this post on Zulip Notification Bot (Aug 06 2024 at 13:15):

lkjhaisduhjfkxcjvbnis has marked this topic as resolved.


Last updated: Dec 23 2024 at 13:07 UTC