-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Closed
Labels
C-bugCategory: bugCategory: bugS-triageStatus: This issue is waiting on initial triage.Status: This issue is waiting on initial triage.
Description
Problem
When cargo install fails to compile the requested binary, it prints the following message:
error: could not compile `[package name]` (bin "[binary name]")
[…]
error: failed to compile `[package name] v[package version] ([package source path if `--path` provided])`, intermediate artifacts can be found at `[target directory path]`.
To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path.
This suggestion is incorrect in the case when a custom build.build-dir path – distinct from the target directory path – is configured, either in a .cargo/config.toml file (local or global) or using the CARGO_BUILD_BUILD_DIR environment variable. The substance of the suggestion and the use of the term “intermediate artifacts” indicate that it's the build.build-dir path and CARGO_BUILD_BUILD_DIR environment variable that should be printed here.
Steps
mkdir -p issue_16622/src
cd issue_16622
cat > Cargo.toml << 'EOF'
[package]
name = "issue-16622"
EOF
touch src/main.rs
CARGO_BUILD_BUILD_DIR=./build cargo install --path .Output:
Installing issue-16622 v0.0.0 ([…]/issue_16622)
Compiling issue-16622 v0.0.0 ([…]/issue_16622)
error[E0601]: `main` function not found in crate `issue_16622`
|
= note: consider adding a `main` function to `src/main.rs`
For more information about this error, try `rustc --explain E0601`.
error: could not compile `issue-16622` (bin "issue-16622") due to 1 previous error
error: failed to compile `issue-16622 v0.0.0 ([…]/issue_16622)`, intermediate artifacts can be found at `[…]/issue_16622/target`.
To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path.
Possible Solution(s)
Desired output:
Installing issue-16622 v0.0.0 ([…]/issue_16622)
Compiling issue-16622 v0.0.0 ([…]/issue_16622)
error[E0601]: `main` function not found in crate `issue_16622`
|
= note: consider adding a `main` function to `src/main.rs`
For more information about this error, try `rustc --explain E0601`.
error: could not compile `issue-16622` (bin "issue-16622") due to 1 previous error
error: failed to compile `issue-16622 v0.0.0 ([…]/issue_16622)`, intermediate artifacts can be found at `[…]/issue_16622/build`.
To reuse those artifacts with a future compilation, set the environment variable `CARGO_BUILD_BUILD_DIR` to that path.
Notes
No response
Version
cargo 1.95.0-nightly (fe2f314ae 2026-01-30)
release: 1.95.0-nightly
commit-hash: fe2f314aef06e688a9517da1ac0577bb1854d01f
commit-date: 2026-01-30
host: aarch64-apple-darwin
libgit2: 1.9.2 (sys:0.20.3 vendored)
libcurl: 8.7.1 (sys:0.4.83+curl-8.15.0 system ssl:(SecureTransport) LibreSSL/3.3.6)
ssl: OpenSSL 3.5.4 30 Sep 2025
os: Mac OS 26.2.0 [64-bit]
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
C-bugCategory: bugCategory: bugS-triageStatus: This issue is waiting on initial triage.Status: This issue is waiting on initial triage.