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

cargo-build-sbf: Use metadata.solana.tools-version in Cargo.toml #2914

Merged
merged 6 commits into from
Oct 8, 2024

Conversation

joncinque
Copy link

Problem

It's possible to specify the version of the platform-tools version using
the --tools-version, but most people aren't aware of the different
versions of the compiler, or that they can use the flag.

Summary of changes

Allow cargo-build-sbf to read from the metadata section of a package
or workspace Cargo.toml. The concept is similar to
rust-toolchain.toml, where cargo finds the right version of Rust. For
cargo-build-sbf, it can read:

[package.metadata.solana]
tools-version = "v1.43"

Or

[workspace.metadata.solana]
tools-version = "v1.43"

To go with this change, since I often forget leading "v" in the version
string, the version parsing now allows for omitting the leading "v", so
you can specify --tools-version 1.43.

As follow-up work, I would like to make cargo build-sbf --version show
the appropriate version based on the Cargo.toml / --tools-version arg,
same as cargo does.

cc @lorisleiva and @febo

let package_tools_version = package.metadata.get("solana").and_then(|v| v.get("tools-version")).and_then(|v| v.as_str());
match (workspace_tools_version, package_tools_version) {
(Some(workspace_version), Some(package_version)) => {
if workspace_version != package_version {
Copy link

Choose a reason for hiding this comment

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

Nice! I was going to ask if there was a precedence between the versions.

@LucasSte
Copy link

The PR looks good. Should we have a test for this new behavior?

@joncinque
Copy link
Author

The PR looks good. Should we have a test for this new behavior?

Sure! I added a test for the package version and the workspace version, let me know how it looks.

#### Problem

It's possible to specify the version of the platform-tools version using
the `--tools-version`, but most people aren't aware of the different
versions of the compiler, or that they can use the flag.

#### Summary of changes

Allow `cargo-build-sbf` to read from the metadata section of a package
or workspace Cargo.toml. The concept is similar to
`rust-toolchain.toml`, where cargo finds the right version of Rust. For
cargo-build-sbf, it can read:

```toml
[package.metadata.solana]
tools-version = "v1.43"
```

Or

```toml
[workspace.metadata.solana]
tools-version = "v1.43"
```

To go with this change, since I often forget leading "v" in the version
string, the version parsing now allows for omitting the leading "v", so
you can specify `--tools-version 1.43`.
@joncinque joncinque added the automerge automerge Merge this Pull Request automatically once CI passes label Oct 8, 2024
@joncinque joncinque merged commit f1b3856 into anza-xyz:master Oct 8, 2024
52 checks passed
@joncinque joncinque deleted the toolstoml branch October 8, 2024 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge automerge Merge this Pull Request automatically once CI passes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants