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

As a developer, I want to be able to customize the code generated by didc so that I don't have to do so with a sed script. #473

Open
bitdivine opened this issue Oct 5, 2023 · 5 comments
Labels
enhancement New feature or request

Comments

@bitdivine
Copy link
Member

bitdivine commented Oct 5, 2023

Is your feature request related to a problem? Please describe.
Currently I have to post-process the Rust code generated by .didc. The changes include:

  • Make types and their fields public, otherwise they cannot be used!
  • Comment out the header; I often use different imports and need different clippy rules.
  • Customize the list of traits applied to every struct.
  • ... and many other things.

Describe the solution you'd like
Rather than making a huge long list of customizations, I would like to suggest that to start with we introduce a structure for managing customizations.

In particular I would like to propose an options file that could be called like this:

didc bind --target rs --options optfile.did somefile.candid

or

didc bind --target rs --options <( echo stuff) somefile.candid

That options file could then, for example, contain record{ rust = record {header=false}} to suppress printing the Rust header.

Describe alternatives you've considered

  • Having a bunch of flags. I think this could get unwieldy.
  • Having an implicit location for an options file. We could do this but then we would still want an override.

Additional context

Note: If approved in principle I would be happy to implement this and then make further proposals, one for every option.

@bitdivine bitdivine added the enhancement New feature or request label Oct 5, 2023
@chenyan-dfinity
Copy link
Contributor

We are certainly working on this direction! Note that there is an ruditemary Config option for Rust codegen: https://github.com/dfinity/candid/blob/master/rust/candid/src/bindings/rust.rs#L16. It's not exposed in didc yet, as I feel it's not mature enough.

Make types and their fields public, otherwise they cannot be used!

This should already be fixed in the latest didc.

Customize the list of traits applied to every struct.

There is a config option to do this already.

@bitdivine
Copy link
Member Author

Cool, thank you for the information. I'll look at the latest didc and give it a spin.

@bitdivine
Copy link
Member Author

Would it be an option to expose the config option via a hidden flag? Hidden in the sense that didc --help does not show it? That way we can test the config in some real-world use cases without committing to it? Regardless, please consider us as willing testers for this!

@bitdivine
Copy link
Member Author

bitdivine commented Oct 17, 2023

@chenyan-dfinity Regarding pub, it looks as if fields are still private for didc version 0.3.5:

max@sinkpad:~/dfn/nns-dapp/branches/no-pub-no-more (7:21)$ didc --version
didc 0.3.5
max@sinkpad:~/dfn/nns-dapp/branches/no-pub-no-more (7:37)$ didc bind --target rs declarations/sns_ledger/sns_ledger.did  | grep -A5 -m1 struct
pub struct Account { owner: Principal, subaccount: Option<Subaccount> }
                     ^ owner is private

Are they pub on an unreleased head of main? Let me check.... Yes, head of master works. I'll wait for your next release! :-)

@chenyan-dfinity
Copy link
Contributor

I think the latest release already has this: https://github.com/dfinity/candid/releases/tag/2023-09-27. I'm bad at bumping versions, didc may still report version 0.3.5 for the new release :(

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

No branches or pull requests

2 participants