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

feat!: ic-cdk-bindgen rewrite #486

Merged
merged 6 commits into from
May 1, 2024
Merged

Conversation

lwshang
Copy link
Contributor

@lwshang lwshang commented May 1, 2024

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:

  • Consumer
  • Provider
  • Type

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:

  • The title of this PR complies with Conventional Commits.
  • I have edited the CHANGELOG accordingly.
  • I have made corresponding changes to the documentation.

@lwshang lwshang marked this pull request as ready for review May 1, 2024 15:43
@lwshang lwshang requested a review from a team as a code owner May 1, 2024 15:43
@lwshang lwshang merged commit ca5e603 into bindgen_next May 1, 2024
19 of 20 checks passed
@lwshang lwshang deleted the lwshang/rewrite_bindgen branch May 1, 2024 18:06
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

Successfully merging this pull request may close these issues.

1 participant