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

[1/x] feature(cargo-miden): support building Wasm component from a Cargo project #329

Merged
merged 13 commits into from
Oct 28, 2024

Conversation

greenhat
Copy link
Contributor

@greenhat greenhat commented Sep 19, 2024

Close #90
Close #117
Close #308
Close #334

This PR adds support to the cargo-miden to use cargo-component library to build Wasm component Rust projects. The existing cargo-miden ability to build core Wasm module Rust projects is preserved.

The Miden SDK and intrinsics are pulled through the Wasm CM as an imported interface (see miden-core-import.wit). The Miden SDK types are defined in WIT (see miden.wit) and remapped to the miden-sdk crate types at cargo-component library invocation in cargo-miden along with the skip list for function bindings generation at

package.metadata.section.bindings.with = [
("miden:base/core-types@1.0.0/felt", "miden_sdk::Felt"),
("miden:base/core-types@1.0.0/word", "miden_sdk::Word"),
("miden:base/core-types@1.0.0/core-asset", "miden_sdk::CoreAsset"),
("miden:base/core-types@1.0.0/account-id", "miden_sdk::AccountId"),
("miden:base/core-types@1.0.0/tag", "miden_sdk::Tag"),
("miden:base/core-types@1.0.0/note-type", "miden_sdk::NoteType"),
("miden:base/core-types@1.0.0/recipient", "miden_sdk::Recipient"),
]
.into_iter()
.map(|(k, v)| (k.to_string(), v.to_string()))
.collect();
// skip functions that are provided by the Miden SDK and/or intrinsics
// only function names (no CM path)
package.metadata.section.bindings.skip = vec![
// Our function names can clash with user's function names leading to
// skipping the bindings generation of the user's function names
// see https://github.com/0xPolygonMiden/compiler/issues/341
"remove-asset",
"create-note",
"heap-base",
"hash-one-to-one",
"hash-two-to-one",
"add-asset",
"add",
]
.into_iter()
.map(|s| s.to_string())
.collect();

Then, when translating Wasm component the original(linkable) MASM module and function names are recovered at the core Wasm module and the component level by https://github.com/0xPolygonMiden/compiler/blob/fe28b1cffef6a15b02f8e86fadce9c14263281cb/frontend-wasm/src/miden_abi/mod.rs#L61-L111

See test/rust-apps-wasm/rust-sdk/basic-wallet/ test project for an example and rust_sdk_basic_wallet() test.

To not grow this PR any bigger, #341 and #342 are created to fix the introduced quick-and-dirty ways for function generation skipping and MASM module and function names recovery.

@greenhat greenhat force-pushed the greenhat/i90-wasm-cm-cargo-miden branch 3 times, most recently from a9e4fcc to a876d8b Compare September 25, 2024 14:20
@greenhat greenhat force-pushed the greenhat/i90-wasm-cm-cargo-miden branch 2 times, most recently from 6dfa67a to 58b8dcf Compare October 1, 2024 13:59
@greenhat greenhat force-pushed the greenhat/i90-wasm-cm-cargo-miden branch from 58b8dcf to 02f855d Compare October 1, 2024 14:01
@greenhat greenhat force-pushed the greenhat/i90-wasm-cm-cargo-miden branch from 6a1ba88 to 45df95c Compare October 10, 2024 15:28
SDK functions that were renamed to satisfy the Wasm Component Model
requirements and remove Wasm component imports for the intrinsics that
were converted to IR ops.
@greenhat greenhat force-pushed the greenhat/i90-wasm-cm-cargo-miden branch from 45df95c to 2a83384 Compare October 10, 2024 15:36
@greenhat greenhat force-pushed the greenhat/i90-wasm-cm-cargo-miden branch from e1796ab to 97b92ae Compare October 11, 2024 13:42
@greenhat greenhat marked this pull request as ready for review October 11, 2024 13:55
@greenhat greenhat requested a review from bitwalker October 11, 2024 13:56
@greenhat greenhat force-pushed the greenhat/i90-wasm-cm-cargo-miden branch from 2802aa7 to 787f4e3 Compare October 14, 2024 09:40
@greenhat greenhat force-pushed the greenhat/i90-wasm-cm-cargo-miden branch from 787f4e3 to 6a59e3d Compare October 14, 2024 12:28
@bitwalker
Copy link
Contributor

Just wanted to follow up and let you know I've started reviewing, but haven't finished just yet, I'll try to get my review wrapped up today (Tuesday).

@greenhat
Copy link
Contributor Author

I forgot to address the provisioning of the WIT interface for the Miden SDK. I made #343 for it.

@greenhat greenhat changed the title feature(cargo-miden): support building Wasm component from a Cargo project [1/1] feature(cargo-miden): support building Wasm component from a Cargo project Oct 16, 2024
@greenhat greenhat changed the title [1/1] feature(cargo-miden): support building Wasm component from a Cargo project [1/2] feature(cargo-miden): support building Wasm component from a Cargo project Oct 16, 2024
@greenhat greenhat changed the title [1/2] feature(cargo-miden): support building Wasm component from a Cargo project [1/x] feature(cargo-miden): support building Wasm component from a Cargo project Oct 22, 2024
@bitwalker bitwalker merged commit c201bf6 into next Oct 28, 2024
5 checks passed
@bitwalker bitwalker deleted the greenhat/i90-wasm-cm-cargo-miden branch October 28, 2024 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants