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

Rust bindgen possibility for PocketIC #547

Open
edwardoranj opened this issue Jan 15, 2025 · 2 comments
Open

Rust bindgen possibility for PocketIC #547

edwardoranj opened this issue Jan 15, 2025 · 2 comments

Comments

@edwardoranj
Copy link

It would be great if we have PocketIC value in this enum to generate PocketIC compatible client.

pub enum Target {
CanisterCall,
Agent,
CanisterStub,
}

@lwshang
Copy link
Contributor

lwshang commented Jan 16, 2025

Let me start with some clarification on what is ic-cdk-bindgen.

The code you linked above was mostly copied and simplified from https://github.com/dfinity/candid/blob/master/rust/candid_parser/src/bindings/rust.rs

And there is some unfinished experiment on the next generation of ic-cdk-bindgen in bindgen_next branch: https://github.com/dfinity/cdk-rs/tree/bindgen_next/src/ic-cdk-bindgen

There was a debate on where should such bindgen tool live.
My opinion is that, the bindgen tool should live in the same place as where it is used.
ic-cdk-bindgen should only be in responsible for generating the bindings for Rust CDK usage (not Rust Agent or something else).
Keeping ic-cdk and ic-cdk-bindgen in the same codebase is the only way to guarantee that they work together.
That's the reason of moving the CanisterCall bindgen from the candid repository to this cdk-rs repository.


Then let's talk about PocketIC bindgen.

What kind of code do you want to generate?

PocketIC is mostly used for test canisters end-to-end. Do you want to generate some testing code for you canisters?
Because the generated code will be deeply coupled with the PocketIC API, it's better to have the bindgen logic next to the PocketIC code.

Then it is out of the scope of this repository.


In the bindgen_next branch, I changed the Target definition to:

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum Target {
Consumer,
Provider,
Type,
}

So you can generate bindings containing the Rust types only. The types would already be useful for testing.

@edwardoranj
Copy link
Author

Hi @lwshang,

Thank you for sharing your thoughts. I will test your updates on the bindgen_next branch. I believe this is the best place to discuss this, as ic-cdk-bindgen generates Rust types from the DID file. Regarding PocketIC, as you know, it is used to test canisters end-to-end, and we need to have a Rust client for the canister in the PocketIC environment. I believe this can be generated from the bindgen, as it already has the capability to generate Rust types.

While I agree with you about the location of the code, generating such canister clients in PocketIC using ic-cdk-bindgen will save a lot of time on writing integration tests. These are my honest thoughts.

I hope there will be active discussion on this topic, thanks!

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

2 participants