Skip to content

cargo build and run use inconsistent debug flags for proc-macro crates #12457

@ilammy

Description

@ilammy

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

  1. cargo build --verbose
  2. 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

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]

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bugS-propose-closeStatus: A team member has nominated this for closing, pending further input from the team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions