bytecodealliance / bytecodealliance/wasmtime

Bindgen! gives weird name to an interface well-named in WIT file

Open
#9,774 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
18.6k
Forks
1.8k
Avg merge
1d 18h
Merged PRs (30d)
126

Description

I don't know whether this is a bug or expected. I personally would consider it as a minor bug, but I leave it as a feature request.

#### Feature

I'd like `bindgen!` generates a sensible name for the bindings of interfaces in a WIT file.

I have this WIT file. It exports an interface called `add` that contains only one function `add`.
```
package component: interfaced-adder;

// See https://github.com/bytecodealliance/cargo-component/issues/360 for why this is needed
// Also according to https://component-model.bytecodealliance.org/creating-and-consuming/composing.html, "Composition happens at the level of interfaces"

interface add {
add: func(a: s32, b: s32) -> s32;
}

world adder {
export add;
}

```

In my Rust host, I need to run an `adder` component, so I write the host code like

```rust
bindgen!({
path: "../wit-files/interfaced-adder.wit",
world: "adder",
});

pub fn run_adder_sync(engine: &Engine) {
let (component, linker, mut store) = get_component_linker_store(
engine,
"./target/wasm32-wasip2/release/guest_interfaced_adder_rs.wasm",
"../target/wasm32-wasip2/release/guest_interfaced_adder_rs.wasm",
);
let bindings = Adder::instantiate(&mut store, &component, &linker).unwrap();
let a = 1;
let b = 2;
// TODO: interface0 seems weird, file an issue
let result = bindings.interface0.call_add(&mut store, a, b).unwrap();
assert_eq!(result, 3);
}
```

Instead of a meaningful name like `"add"`, `bindgen!` somehow generate the binding for interface `add` with the name `"interface0"`. This seems weird to me. And I don't see why it can't be named as the same as the interface name. `bindings.add.call_add` seems more natural to me.

#### Benefit

The current naming is bad for readability and understanding, as no one can see from `interface0` that it has any relation to the interface `add`. `interface0` means just the first interface.

Changing the naming can improve readability, understanding and code writing.

#### Implementation

No, I am not very familiar with bindgen internals.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.