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

Use Kani's Cargo when calling cargo metadata #3972

Closed
wants to merge 1 commit into from

Conversation

clubby789
Copy link

@clubby789 clubby789 commented Apr 1, 2025

When Kani is installed normally, use the Cargo binary from the linked Rust toolchain when calling cargo metadata.
If a rust-toolchain.toml is present, or the toolchain has been manually overridden with cargo +1.xx kani an older version of cargo metadata can be used, which causes incompatible package IDs to be passed.

Resolves #3967

Tested by installing and verifying that cargo +1.76 kani no longer produces an error.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

@clubby789 clubby789 requested a review from a team as a code owner April 1, 2025 10:18
@zjp-CN
Copy link

zjp-CN commented Apr 2, 2025

Since kani relies on pinned toolchain for analyzing Rust code through rustc, is it a good practice to run cargo +1.76 kani when you're using incompatible toolchain?
Why not just run cargo +nightly-xxxx-xx-xx kani where nightly-xxxx-xx-xx is required by kani?

@clubby789
Copy link
Author

This was motivated by running Kani in an existing repo with an old rust-toolchain.toml and getting a very obscure error that took several hours to track down - +1.76 is just for ease of testing.
I also experimented with trying to translate old-format IDs to new-format, but given that the format is unspecified I'm not confident in being able to write a reliable solution there

@zjp-CN
Copy link

zjp-CN commented Apr 2, 2025

I think cargo +nightly-xxxx-xx-xx kani is more reliable, because

  • +nightly-xxxx-xx-xx is precedent to rust-toolchain.toml by rustup
  • you'll need nightly-xxxx-xx-xx toolchain anyways to make kani really work to do analysis

@clubby789
Copy link
Author

clubby789 commented Apr 9, 2025

Unless I'm mistaken, Kani always uses its linked nightly-xxxx toolchain (unless built in a dev environment) for everything else - this fixes the inconsistency here by also using it for cargo metadata, which was a bit of a beginner papercut when trying to use the tool initially

@carolynzech
Copy link
Contributor

Thanks for the PR! This cargo +1.76 kani invocation pattern is not something we'd like to support--for a given version of Kani, we only support it working with its rust-toolchain.toml version. I worry that this PR will lead users into thinking that Kani is accepting their 1.76 override, which IMO is more confusing than just failing loudly when they try to override the toolchain. One thing we could do is try to detect if someone is overriding the toolchain version and error with a message about that, since I agree that the current cargo metadata related error message is quite obscure.

I'm curious about this comment:

This was motivated by running Kani in an existing repo with an old rust-toolchain.toml and getting a very obscure error that took several hours to track down - +1.76 is just for ease of testing.

Can you post a follow up in #3967 elaborating more on what happened here? You should be able to invoke Kani in a repo that has a different rust-toolchain.toml file. If there are papercuts with using the tool, we would very much like to know about them (and fix them).

I'm going to close this PR, but please do follow up in #3967 if you have the bandwidth--if something took hours of debugging, we would like to improve on that.

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.

Kani doesn't work with Rust versions below 1.77
3 participants