Problem
Setting build-dir in .cargo/config.toml prevent using cargo command in build.rs
> cargo build
Compiling cargo-build-generated v0.1.0 (/Users/__/work/cargo-build-generated)
Building [========> ] 1/3: cargo-build-generated(build)
And it's halt in deadlock.
-vv shows:
[cargo-build-generated 0.1.0] Blocking waiting for file lock on build directory (/Users/__/work/cargo-build-generated/./target2/build/debug/.cargo-build-lock)
Removing .cargo/config.toml with build.build-dir - fixes the problem.
Steps
- create crate with build.rs that generate rust source and uses cargo to build
- use OUT_DIR to save source
- set build-dir in .cargo/config.toml
- run cargo build
Possible Solution(s)
No response
Notes
MRE: https://github.com/vldm/cargo-build-generated
Workaround
(from comments)
One can set CARGO_BUILD_BUILD_DIR:
Command::new(&cargo)
.arg("build")
.env("CARGO_BUILD_BUILD_DIR", &generated)
Or put custom .cargo/config.toml (with build-dir set to $OUT_DIR/..)
Version
cargo 1.96.0 (30a34c682 2026-05-25)
release: 1.96.0
commit-hash: 30a34c6821b57de0aaec83a901aca39f88f6778c
commit-date: 2026-05-25
host: aarch64-apple-darwin
libgit2: 1.9.2 (sys:0.20.4 vendored)
libcurl: 8.7.1 (sys:0.4.87+curl-8.19.0 system ssl:(SecureTransport) LibreSSL/3.3.6)
ssl: OpenSSL 3.5.4 30 Sep 2025
os: Mac OS 26.5.0 [64-bit]
(but 1.94.0 was affected as well)
Problem
Setting build-dir in .cargo/config.toml prevent using cargo command in build.rs
And it's halt in deadlock.
-vvshows:Removing .cargo/config.toml with
build.build-dir- fixes the problem.Steps
Possible Solution(s)
No response
Notes
MRE: https://github.com/vldm/cargo-build-generated
Workaround
(from comments)
One can set
CARGO_BUILD_BUILD_DIR:Or put custom
.cargo/config.toml(with build-dir set to$OUT_DIR/..)Version