bytecodealliance / bytecodealliance/wasmtime
API to access custom sections
- Dominant language
- Rust
- Stars
- 18.6k
- Forks
- 1.8k
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 126
Description
#### Feature
It would be nice if [`Component`](https://docs.rs/wasmtime/latest/wasmtime/component/struct.Component.html) could provide access to custom sections (see [the Javascript API](https://developer.mozilla.org/en-US/docs/WebAssembly/Reference/JavaScript_interface/Module/customSections_static)).
#### Benefit
Allows you to access custom sections. For me specifically, I'm writing a better version of pre-commit using WASI and I'm planning to store metadata about how to run the linter in a custom section.
#### Implementation
I think `wasmtime` uses `wasmparser` which can already parse these, so it just needs to be exposed somehow. I think the biggest question is where the data is stored. I assume `Component` discards all the data it has read after compilation, and it doesn't know in advance whether you want to keep the custom sections or not... I dunno I'm not familiar enough with the implementation to say more.
#### Alternatives
My current solution is to use `wasmparser` to parse the file a second time, but it would be nice to not have to do this:
```
pub fn read_metadata(wasm_path: &Path) -> Result {
let module = std::fs::read(wasm_path)?;
// TODO: Don't read all into memory... but it's probably fine and
// wasmparser doesn't provide a handy parse_reader() method.
let parser = Parser::new(0);
for payload in parser.parse_all(&module) {
match payload? {
Payload::CustomSection(section) if section.name() == "my_metadata" => {
return Ok(serde_json::from_slice::(section.data())?);
}
_ => {}
}
}
bail!("No metadata section found in the wasm file");
}
```
Contributor guide
Assessment
This issue has not been assessed yet.