-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
Problem
cargo build
passes debuginfo flags to rustc when compiling proc-macro crates in dev
profile, while cargo run
does not.
Different flags cause unnecessary recompilation, since crate compilations have different metadata hashes. For example, if a workspace has a custom derive macros defined and a lot a binaries, it is not possible to run cargo build
to compile all the binaries first, then run them as needed using cargo run
without recompiling everything.
I'd expect cargo build
and cargo run
to use the same rustc flags for crates when compiling with the same profile.
Steps
Use the attached cargo-example.zip
cargo build --verbose
cargo run --bin foo --verbose
Look for -C debuginfo=2
Possible Solution(s)
As a workaround, I disable debuginfo for build dependencies explicitly:
[profile.dev.build-override]
debug = false
With this, proc-macro crates are consistently built without debuginfo in dev
profile and do not cause recompilation.
Notes
Reproduces since nightly-2023-02-09
Appears to be related to
- Turn off debuginfo for build dependencies v2 #11252
- Inconsistent handling of debug = 0 vs debug = false in profiles #12163
- Procedural macros are rebuilding all dependencies rust-playground#928
- Excessive rebuilding when nothing changed quickwit-oss/quickwit#3346
Version
cargo 1.71.1 (7f1d04c00 2023-07-29)
release: 1.71.1
commit-hash: 7f1d04c0053083b98fa50b69b6f56e339b0556a8
commit-date: 2023-07-29
host: x86_64-apple-darwin
libgit2: 1.6.4 (sys:0.17.1 vendored)
libcurl: 7.79.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 12.5.0 [64-bit]