Stream: wit-bindgen

Topic: Hashtag in export_name


view this post on Zulip David D. (Mar 14 2023 at 22:30):

When I add interfaces to a wit definition, the export name includes a hashtag. For example:

interface erc20 {
  record state {
    name: option<string>,
    symbol: option<string>,
    balances: list<tuple<string, u64>>
  }
  construct: func(state: state, name: string, symbol: string)
  mint: func(account: string, amount: u64)
  transfer: func(to: string, amount: u64)
}

default world contract {
  export exports: self.erc20
}

...generates a #[export_name = "exports#construct"]. This compiles fine, but wasmtime cannot recognize the function name:

let function = instance .get_func(&mut store, "exports#construct");

...returns a None. If I pull all the names of all exports out of the module, the function name "exports#construct" is in there. I know this is still very much in development, but am I doing anything obviously wrong?

view this post on Zulip Alex Crichton (Mar 14 2023 at 22:44):

Note that the hash there is a core wasm name mangling detail not present in the component itself. With a component you'd extract the instanced named "exports" followed by the function called "construct" from that instance

view this post on Zulip David D. (Mar 15 2023 at 12:13):

Thanks for the insight @Alex Crichton :pray:

For anyone following, I changed:

let function = instance.get_func(&mut store, "exports#construct")?;

to

let function = instance.exports(&mut store).instance("exports")?.func("construct")?;

Last updated: Dec 23 2024 at 12:05 UTC