cargo
cargo copied to clipboard
document external cargo subcommand PATH precedence
Problem
I have encountered an issue with the cargo nextest subcommand where it does not select the expected subcommand's version.
Steps
Here are the details of the problem:
- I have
cargo-nextestin my PATH, located at/nix/store/3yl7vgm2qkp7skr5gskbfd457f6g43cg-cargo-nextest-0.9.66/bin/cargo-nextest, and its version is 0.9.66.
bash-5.2$ which cargo-nextest
/nix/store/3yl7vgm2qkp7skr5gskbfd457f6g43cg-cargo-nextest-0.9.66/bin/cargo-nextest
- Additionally, I have
cargo-nextestinstalled in~/.cargo/bin, and its version is 0.9.59.
bash-5.2$ ~/.cargo/bin/cargo-nextest --version
cargo-nextest 0.9.59
-
Running
~/.cargo/bin/cargo-nextest --versionconfirms that the version installed in~/.cargo/binis indeed 0.9.59. -
However, when I execute
cargo nextest --version, it incorrectly selects version 0.9.59 from~/.cargo/bin, instead of the desired version 0.9.66 from/nix/store/3yl7vgm2qkp7skr5gskbfd457f6g43cg-cargo-nextest-0.9.66/bin/cargo-nextest.
bash-5.2$ cargo nextest --version
cargo-nextest-nextest 0.9.59
This behavior seems inconsistent and unexpected. It would be helpful if the cargo command could prioritize the version in the path /nix/store/3yl7vgm2qkp7skr5gskbfd457f6g43cg-cargo-nextest-0.9.66/bin when invoking the cargo nextest subcommand.
Thank you for your attention to this issue, and please let me know if you need any further information to reproduce or investigate the problem.
Possible Solution(s)
No response
Notes
No response
Version
cargo 1.72.1 (103a7ff2e 2023-08-15)
release: 1.72.1
commit-hash: 103a7ff2ee7678d34f34d778614c5eb2525ae9de
commit-date: 2023-08-15
host: x86_64-unknown-linux-gnu
libgit2: 1.6.4 (sys:0.17.2 vendored)
libcurl: 8.1.2-DEV (sys:0.4.63+curl-8.1.2 vendored ssl:OpenSSL/1.1.1u)
ssl: OpenSSL 1.1.1u 30 May 2023
os: NixOS 24.5.0 [64-bit]
Hello,
cargo-nextest is not the cargo built-in command and this issue may not be related to cargo.
And I see you desired cargo is in /nix/store/..., is there something like .env to activate it ?
This is a concern not with cargo-nextest but with how third-party subcommands are loaded.
On mobile so can't look everything up but cargo intentionally prefers the copy of packages it has installed. You can customize this by putting cargo's bin directory in PATH. If cargo sees it there, it will respect the users precedence.
Thanks for the report! As @epage mentioned, I believe cargo looks at PATH to determine the priority, so you can put ~/.cargo/bin later in the PATH. Closing as a duplicate of #11020 and #6507.
Have we documented this behavior in The Cargo Book? If not, I would like to propose this as a documentation issue.
https://github.com/rust-lang/cargo/blob/363a2d11320faf531f6aacd1ea067c6bc08343b9/src/bin/cargo/main.rs#L247-L270
Updating the documentation sounds good to me!
@rustbot claim
I plan to add this behavior in the custom-subcommands section. (a note block in the last )