bytecodealliance / bytecodealliance/wit-bindgen

Generate component with only specified interfaces

Open
#1,298 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
1.5k
Forks
286
Avg merge
6h 32m
Merged PRs (30d)
19

Description

Hi everyone!

I'm not 100% sure if this is the right place to ask this question or if it maybe is a more of a `rustc` problem.
In any case: I'm trying to generate a component that implements a certain interface and *only* that interface.

Consider this example:

```rust
wit_bindgen::generate!({
inline: r#"
package foo:bar;

world bar {
export baz : interface {
zero: func() -> u32;
}
}
"#
});

struct MyComponent;

impl crate::exports::baz::Guest for MyComponent {
fn zero() -> u32 {
0
}
}

export!(MyComponent);
```

Given this code, I would expect the `wit` embedded in the resulting component to look similar to this

```wit
package root:component;

world root {
export baz: interface {
zero: func() -> u32;
}
}
```

Instead, `wasm-tools component wit target/wasm32-wasip2/debug/super_simplest.wasm` outputs

```wit
package root:component;

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

export baz: interface {
zero: func() -> u32;
}
}

// + all package definitions of imported packages
```

My guess was that these imports are necessary to handle stuff like error messages on panic that the rust compiler might introduce. However, compiling while declaring the ` #![no_std]` (which I assumed to disable these things) at the top of `lib.rs` does not help and the same `wit` is embedded.

Is there a way to *only* generate the interface as specified?

I'm using `wit-bindgen 0.42.1`, `cargo/rustc 1.87.0-nightly`, and `wasm-tools 1.219.1`.

Cheers,
Markus

P.S.: After writing this issue I tried everything out with the code mentioned [here](https://github.com/bytecodealliance/wit-bindgen/blob/main/README.md?plain=1#L186-L260) and have encountered the same problem.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.