Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse the WIT binary from the Wasm component and store in the Miden package #364

Open
Tracked by #354
greenhat opened this issue Dec 23, 2024 · 0 comments
Open
Tracked by #354
Milestone

Comments

@greenhat
Copy link
Contributor

greenhat commented Dec 23, 2024

Why

To use the Miden package (i.e. account) as a dependency in a Rust project (i.e. note script), we need to store the WIT binary in the Miden package so that cargo-miden could generate the WIT file(s) for the Rust project (i.e. note script) compilation.

How

The WIT binary is stored in the custom section of the core Wasm binary. When the cargo-component generates a Wasm component, it strips the custom section from the core Wasm binary so that Wasm component binary parsed by the frontend does not have it anymore and instead encoded as component imports and exports.

Option 1

Re-create the WIT binary from the component imports and exports using the wit-component crate. This implemented in the wasm-tools component wasm [WASM_COMPONENT_FILE] command at https://github.com/bytecodealliance/wasm-tools/blob/main/src/bin/wasm-tools/component.rs#L824-L835
The difficulty with this approach is that wit-component needs a lot more than parsed component imports/exports, but since we plan to revamp the Wasm component parsing to avoid the inlining phase we might end up having all needed pieces in place.

Option 2

Parse the Wasm component binary with wit-parser to get everything needed for the wit-component to re-create the WIT binary. This implemented in the wasm-tools component wasm [WASM_COMPONENT_FILE] command at https://github.com/bytecodealliance/wasm-tools/blob/main/src/bin/wasm-tools/component.rs#L684-L725
The downside of this approach is that we parse the Wasm component binary twice.

I lean towards Option 1. After revamping the frontend to get rid of the inlining phase, we can assess what's missing for the Option 1 and go with Option 2 if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant