cargo-component icon indicating copy to clipboard operation
cargo-component copied to clipboard

Some wasi imports added per default into wit

Open elwerene opened this issue 9 months ago • 2 comments

If I create a new component, it contains some imports which are not used. How can these be disabled? I searched all code and documentation and could not find any resources on how to accomplish that.

❯ cargo component --version
cargo-component-component 0.11.0 (wasi:040ec92)
❯ cargo component new --lib bla 
    Creating library `bla` package
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
     Updated manifest of package `bla`
   Generated source file `src/lib.rs`
❯ cd bla
❯ cargo component build --release
  Generating bindings for bla (src/bindings.rs)
   Compiling wit-bindgen-rt v0.24.0
   Compiling bitflags v2.5.0
   Compiling bla v0.1.0 (/home/rene/Downloads/bla)
    Finished `release` profile [optimized] target(s) in 0.29s
    Creating component target/wasm32-wasi/release/bla.wasm
❯ wasm-tools --version
wasm-tools 1.206.0
❯ wasm-tools component wit target/wasm32-wasi/release/bla.wasm 
package root:component;

world root {
  import wasi:cli/[email protected];
  import wasi:cli/[email protected];
  import wasi:io/[email protected];
  import wasi:io/[email protected];
  import wasi:cli/[email protected];
  import wasi:cli/[email protected];
  import wasi:cli/[email protected];
  import wasi:clocks/[email protected];
  import wasi:filesystem/[email protected];
  import wasi:filesystem/[email protected];

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

elwerene avatar May 07 '24 14:05 elwerene

If you pass --target wasm32-unknown-unknown to cargo component the component will not import any WASI interfaces.

fibonacci1729 avatar May 07 '24 17:05 fibonacci1729

❯ cargo component build --release --target wasm32-unknown-unknown
   Compiling wit-bindgen-rt v0.24.0
   Compiling bitflags v2.5.0
   Compiling bla v0.1.0 (/home/rene/Downloads/bla)
    Finished `release` profile [optimized] target(s) in 0.17s
    Creating component target/wasm32-unknown-unknown/release/bla.wasm

❯ wasm-tools component wit target/wasm32-unknown-unknown/release/bla.wasm 
package root:component;

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

correct. Thanks :)

Maybe this can be added to the Readme? Is there a way to set the default target of cargo-component? Setting the target in .cargo/config.toml did not help.

elwerene avatar May 08 '24 06:05 elwerene