dfinity / cdk-rs

Rust canister development kit for the Internet Computer.
Apache License 2.0
201 stars 90 forks source link

feat!: ic-cdk-bindgen rewrite #486

Closed lwshang closed 7 months ago

lwshang commented 7 months ago

SDK-1622

Description

The current API of ic-cdk-bindgen crate exposes many types from the dependency candid_parser.

This rewrite is necessary for the upcoming "Trait-Bound Canister Development" feature. which will need Candid to Rust bindgen for various targets.

The targets will be supported:

Now, the main entry point to the ic-cdk-bindgen library is ic_cdk_bindgen::Builder.

This PR focuses on changing the existing bindgen for inter-canister calls. In the context of Rust CDK, such usage is named consumer.

// build.rs
fn main() {
    ic_cdk_bindgen::Builder::new("profile_rs")
        .generate_consumer()
        .unwrap();
}

Then in lib.rs of the consumer canister:

mod profile_rs {
    include!(concat!(env!("OUT_DIR"), "/consumer/profile_rs.rs"));
}
use profile_rs::{profile_rs, Profile};

#[update(name = "getSelf")]
async fn get_self() -> Profile {
    profile_rs.get_self().await.unwrap().0
}

Note

This PR is just a intermediate state of the "Trait-Bound Canister Development" feature. The base branch of this PR is not main but a dedicated bindgen_next branch.

Support for provider and type will be implemented in the following PRs.

Docs and Changelog will be added when this overall feature is completed and before merge into the main branch.

How Has This Been Tested?

examples: counter, profile

Checklist: