Description
Problem
If a target directory already exists, even if empty, cargo will not create CACHEDIR.TAG in it.
This will break any tools that depend on CACHEDIR.TAG being in there.
This fails for both the default ./target dir as well as custom --target-dir.
EDIT:
Here's our specific case where this fails all the time:
When I don't have the target dir created and first open my project in VSCode it's setup to re-route all rust-analyzer target dirs to stop the RA builds & checks and regular builds constantly trampling on each other like so in settings.json
:
"rust-analyzer.check.extraArgs": ["--target-dir=target/rust-analyzer"],
"rust-analyzer.cargo.buildScripts.overrideCommand": ["cargo", "check", "--quiet", "--workspace", "--message-format=json", "--all-targets", "--target-dir=target/rust-analyzer"],
So when RA runs, it creates the ./target/rust-analyzer
dir, which means that the next time that cargo
runs it doesn't create the CACHEDIR.TAG because /target
already exists...
Steps
- Pick any cargo project (just the default init crate should do)
- Create the target dir manually, or delete it's contents after a build manually
- Build
- Observe lack of CACHEDIR.TAG
Possible Solution(s)
If there's no specific reason for this just make sure to create CACHEDIR.TAG if it doesn't exist already.
Notes
We currently use this to find the target directory of the root package when a subpackage is being built. We need to get some version info from there so that we can download the matching C libraries dependencies. Is there a better way to do this than scanning up the tree for a known file such as CACHEDIR.TAG?
Version
cargo 1.71.0 (cfd3bbd8f 2023-06-08)
release: 1.71.0
commit-hash: cfd3bbd8fe4fd92074dfad04b7eb9a923646839f
commit-date: 2023-06-08
host: aarch64-apple-darwin
libgit2: 1.6.4 (sys:0.17.1 vendored)
libcurl: 7.88.1 (sys:0.4.61+curl-8.0.1 system ssl:(SecureTransport) LibreSSL/3.3.6)
ssl: OpenSSL 1.1.1t 7 Feb 2023
os: Mac OS 13.4.0 [64-bit]