Skip to content

Sync Cargo.toml dependencies when generating code#70

Merged
lorisleiva merged 1 commit intomainfrom
12-01-sync_cargo.toml_when_generating_code
Feb 17, 2026
Merged

Sync Cargo.toml dependencies when generating code#70
lorisleiva merged 1 commit intomainfrom
12-01-sync_cargo.toml_when_generating_code

Conversation

@lorisleiva
Copy link
Member

@lorisleiva lorisleiva commented Dec 1, 2025

This PR adds 2 new options to the renderer which enable the Cargo.toml of the generated client to be created and/or updated such that its dependencies match what the generated code expect.

These options are:

  • syncCargoToml: Whether or not we should update the existing Cargo.toml if some of its dependencies are falling behind or create a new Cargo.toml if missing (default: false). Note that this requires the existing crateFolder option to be provided for this to work as, otherwise, we won't know where to look for the Cargo.toml. A warning message is logged if this is not the case.
  • dependencyVersions: A Record<string, CargoDependency> such that keys are the name of external dependencies — e.g. solana-pubkey — and the values are the version ranges we want to support — e.g. ^3.0 — or the equivalent dependency object — e.g. { version: "^3.0" }. The renderer offer default values for all external dependencies it relies on but this option may be used to override some of these values or add new ones.

Additionally, even when the syncCargoToml option is false, if the crateFolder is provided and there is an existing Cargo.toml, the renderer will go through its dependencies and check if any are missing or out of date for the generated code. A warning message will be logged if that's the case.

Note, when bumping the Rust renderer to the next major version (v2), we can make sure the required path is not the path to the generated folder but the crate folder instead. That way, we can make the syncCargoToml option default to true. This would mean crateFolder would be replaced by generatedFolder and would default to src/generated.

@changeset-bot
Copy link

changeset-bot bot commented Dec 1, 2025

🦋 Changeset detected

Latest commit: e86900a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@codama/renderers-rust Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Member Author

lorisleiva commented Dec 1, 2025

@lorisleiva lorisleiva force-pushed the 12-01-sync_cargo.toml_when_generating_code branch from 8e32350 to 15517a1 Compare December 1, 2025 16:25
Comment on lines 41 to 60
export const DEFAULT_DEPENDENCY_VERSIONS: CargoDependencies = {
'anchor-lang': '~0.31',
borsh: '^0.10',
kaigan: '0.2.6',
'num-derive': '^0.4',
'num-traits': '^0.2',
serde: '^1.0',
'serde-big-array': '^0.5',
serde_with: '^3.0',
'solana-account': '~2.2',
'solana-account-info': '~2.3',
'solana-client': '~2.2',
'solana-cpi': '~2.2',
'solana-decode-error': '~2.3',
'solana-instruction': '~2.3',
'solana-program-error': '~2.2',
'solana-pubkey': '~2.3',
'solana-sdk': '~2.3',
thiserror: '^1.0',
};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section requires extra attention when reviewing. It defines the default version requirements for the generated code. Note that if the user uses stricter or newer versions for some of these, they will not be updated.

@lorisleiva lorisleiva marked this pull request as ready for review December 1, 2025 16:36
@lorisleiva lorisleiva requested a review from febo December 1, 2025 16:37
@lorisleiva lorisleiva changed the title Sync Cargo.toml when generating code Sync Cargo.toml when generating code Dec 1, 2025
@lorisleiva lorisleiva changed the title Sync Cargo.toml when generating code Sync Cargo.toml dependencies when generating code Dec 1, 2025
@lorisleiva lorisleiva force-pushed the 12-01-sync_cargo.toml_when_generating_code branch 3 times, most recently from 52967b6 to 45f11ba Compare December 2, 2025 17:39
@lorisleiva lorisleiva requested a review from stegaBOB December 4, 2025 10:06
@lorisleiva lorisleiva force-pushed the 12-01-sync_cargo.toml_when_generating_code branch 3 times, most recently from cfc7371 to 5fdbdfd Compare December 11, 2025 14:13
@lorisleiva lorisleiva force-pushed the 12-01-sync_cargo.toml_when_generating_code branch from 5fdbdfd to def218c Compare February 13, 2026 23:53
@lorisleiva lorisleiva force-pushed the 12-01-sync_cargo.toml_when_generating_code branch from def218c to e86900a Compare February 13, 2026 23:57
@lorisleiva lorisleiva merged commit f0fbbb0 into main Feb 17, 2026
5 checks passed
@github-actions github-actions bot mentioned this pull request Feb 17, 2026
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