Description
Problem
When using a global target directory, after first install, cargo ignores the --rev
option; once you've installed a binary once, it seems impossible to update to the latest version with cargo install -f --git --rev [new version]
.
Steps
- Set a global target directory in
~/.cargo/config.toml
:
[build]
target-dir = "/home/oatman/GLOBAL_TARGET_DIR/"
- Install a package specifying a previous git revision:
cargo install -f --git https://github.com/mfontanini/presenterm.git --rev dbe172
- Try to install a different revision:
cargo install -f --git https://github.com/mfontanini/presenterm.git --rev c4b66c1
- Observe that cargo compiles nothing, and lies to us about replacing
dbe172
withc4b66c1
cargo install -f --git https://github.com/mfontanini/presenterm.git --rev c4b66c1
Updating git repository `https://github.com/mfontanini/presenterm.git`
Installing presenterm v0.14.0 (https://github.com/mfontanini/presenterm.git?rev=c4b66c1#c4b66c18)
Updating crates.io index
Locking 158 packages to latest compatible versions
Adding bincode v1.3.3 (available: v2.0.1)
Finished `release` profile [optimized] target(s) in 0.29s
Replacing /home/oatman/.cargo/bin/presenterm
Replaced package `presenterm v0.14.0 (https://github.com/mfontanini/presenterm.git?rev=dbe172#dbe172dc)` with `presenterm v0.14.0 (https://github.com/mfontanini/presenterm.git?rev=c4b66c1#c4b66c18)` (executable `presenterm`)
This returns in ~300ms for me, clearly using some kind of cache?
Possible Solution(s)
Removing the global target-dir
from ~/.cargo/config.toml
fixes this.
Something about the default cargo settings seems to not trigger this bug, as if you set a specific dir with cargo install --target-dir=/tmp/presenterm
, it also exhibits this behaviour.
I am working around this is my own scripts by setting a specific target-dir
for my git-installed packages, and deleting that target director before subsequent installs. Not ideal, as build artefacts can't be reused, but at least it installs the version I want!
Notes
I believe that something in cargo's cache freshness checking is bypassing the --rev
option? Perhaps as the crate version doesn't change in presenterm
?
Cargo is correctly checking for valid revisions, it just ignores them if an existing git-installed version exists:
❯ : cargo install -f --git https://github.com/mfontanini/presenterm.git --rev BADID
Updating git repository `https://github.com/mfontanini/presenterm.git`
error: revspec 'BADID' not found; class=Reference (4); code=NotFound (-3)
Version
cargo 1.89.0-nightly (2251525ae 2025-06-16)
release: 1.89.0-nightly
commit-hash: 2251525ae503fa196f6d7f9ce6d32eccb2d5f044
commit-date: 2025-06-16
host: x86_64-unknown-linux-gnu
libgit2: 1.9.0 (sys:0.20.2 vendored)
libcurl: 8.12.1-DEV (sys:0.4.80+curl-8.12.1 vendored ssl:OpenSSL/3.5.0)
ssl: OpenSSL 3.5.0 8 Apr 2025
os: NixOS 24.11.0 [64-bit]