Skip to content

How to restrict import of unused features required by string type? #433

@XX

Description

@XX

When I make a simple .wit using the string type, like this:

package component:add;

world example {
    export add: func(x: string, y: u8) -> string;
}

after building and running I get a request to add a bunch of additional interfaces:

$ wasm-tools component wit ./target/wasm32-wasip1/release/add.wasm 
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 add: func(x: string, y: u8) -> string;
...

In particular, after running:

$ cargo run -p host -- 2 3 target/wasm32-wasip1/release/add.wasm
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.83s
     Running `target/debug/host 2 3 target/wasm32-wasip1/release/add.wasm`
Error: Failed to instantiate the example world

Caused by:
    0: component imports instance `wasi:cli/environment@0.2.0`, but a matching implementation was not found in the linker
    1: instance export `get-environment` has the wrong type
    2: function implementation is missing

But my component should not have the right to get environment variables and do other things. How can I do this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions