Skip to content

cfg(debug_assertions) not working #13525

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
flippette opened this issue Mar 3, 2024 · 1 comment
Closed

cfg(debug_assertions) not working #13525

flippette opened this issue Mar 3, 2024 · 1 comment
Labels
C-bug Category: bug S-triage Status: This issue is waiting on initial triage.

Comments

@flippette
Copy link

flippette commented Mar 3, 2024

Problem

So I have this ~/.cargo/config.toml file:

# wildcard cfg
[target.'cfg(any(test, not(test)))']
linker = "clang"
rustflags = ["-Z", "threads=8"]

[target.'cfg(all(target_arch = "x86_64", target_os = "linux"))']
rustflags = ["-C", "link-arg=-fuse-ld=mold"]

[target.'cfg(debug_assertions)']
rustflags = ["-Z", "codegen-backend=cranelift"]

[profile.inst]
inherits = "release"
codegen-units = 1
strip = true
lto = "thin"

According to my understanding, -Z codegen-backend=cranelift should only be set in debug builds. However:

~ ❯ cargo install -fv cargo-info &| grep codegen | head -n 3
     Running `/home/flippette/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --crate-name build_script_build --edition=2021 /home/flippette/.cargo/registry/src/index.crates.io-6f17d22bba15001f/proc-macro2-1.0.78/build.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debug-assertions=off --cfg 'feature="default"' --cfg 'feature="proc-macro"' -C metadata=b37db54dac17ce9f -C extra-filename=-b37db54dac17ce9f --out-dir /tmp/cargo-installOWdvTA/release/build/proc-macro2-b37db54dac17ce9f -C linker=clang -C strip=debuginfo -L dependency=/tmp/cargo-installOWdvTA/release/deps --cap-lints allow -C link-arg=-fuse-ld=mold -Z threads=8 -Z codegen-backend=cranelift`
     Running `/home/flippette/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --crate-name unicode_ident --edition=2018 /home/flippette/.cargo/registry/src/index.crates.io-6f17d22bba15001f/unicode-ident-1.0.12/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debug-assertions=off -C metadata=854e146bbce61056 -C extra-filename=-854e146bbce61056 --out-dir /tmp/cargo-installOWdvTA/release/deps -C linker=clang -C strip=debuginfo -L dependency=/tmp/cargo-installOWdvTA/release/deps --cap-lints allow -C link-arg=-fuse-ld=mold -Z threads=8 -Z codegen-backend=cranelift`
     Running `/home/flippette/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --crate-name pin_project_lite --edition=2018 /home/flippette/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pin-project-lite-0.2.13/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no -C metadata=1c23ed485efa1b06 -C extra-filename=-1c23ed485efa1b06 --out-dir /tmp/cargo-installOWdvTA/release/deps -C linker=clang -C strip=debuginfo -L dependency=/tmp/cargo-installOWdvTA/release/deps --cap-lints allow -C link-arg=-fuse-ld=mold -Z threads=8 -Z codegen-backend=cranelift`

this is not what's happening. Am I missing something or is this a Cargo bug?

Steps

  1. Set this in ~/.cargo/config.toml
[target.'cfg(debug_assertions)']
rustflags = ["-Z", "codegen-backend=cranelift"]
  1. Perform a Cargo build with -C debug-assertions=off
  2. Observe that Cranelift is still being used (visible in cargo -v output and readelf -p .comment /path/to/binary | grep -i cranelift)

Possible Solution(s)

No response

Notes

No response

Version

~ ❯ cargo -vV
cargo 1.78.0-nightly (f772ec022 2024-03-01)
release: 1.78.0-nightly
commit-hash: f772ec0224d3755ce52ac5128a80319fb2eb45d0
commit-date: 2024-03-01
host: x86_64-unknown-linux-gnu
libgit2: 1.7.2 (sys:0.18.2 vendored)
libcurl: 8.6.0-DEV (sys:0.4.72+curl-8.6.0 vendored ssl:OpenSSL/3.2.1)
ssl: OpenSSL 3.2.1 30 Jan 2024
os: Arch Linux Rolling Release [64-bit]
@flippette flippette added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Mar 3, 2024
@ehuss
Copy link
Contributor

ehuss commented Mar 3, 2024

Thanks for the report! I believe this is a duplicate of #5777 and #8170, so closing in favor of that.

@ehuss ehuss closed this as not planned Won't fix, can't repro, duplicate, stale Mar 3, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-bug Category: bug S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

No branches or pull requests

2 participants