Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Build scripts only get RUSTFLAGS when not passing --target #14046

Closed
nilfit opened this issue Jun 11, 2024 · 2 comments
Closed

Build scripts only get RUSTFLAGS when not passing --target #14046

nilfit opened this issue Jun 11, 2024 · 2 comments
Labels
A-rustflags Area: rustflags C-bug Category: bug S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request. Z-target-applies-to-host Nightly: target-applies-to-host

Comments

@nilfit
Copy link

nilfit commented Jun 11, 2024

Problem

When passing RUSTFLAGS=-Dwarnings to upgrade compiler warnings to errors, the flags are sometimes present in the rustc invocation for the build script and sometimes not.

Steps

  1. Set up a crate that produces a warning when compiling the build script.
  2. RUSTFLAGS=-Dwarnings cargo check -v produces an error for the build script. -Dwarnings is visible on the the Running command line for the build script.
  3. RUSTFLAGS=-Dwarnings cargo check -v --target x86_64-unknown-linux-gnu produces a warning for the build script. -Dwarnings is absent from the command line for the build script and present on the command line for the main build.

I expected step 3 to behave like step 2.

Possible Solution(s)

No response

Notes

  • Replacing RUSTFLAGS with CARGO_ENCODED_RUSTFLAGS gave the same results.
  • Setting the build.target in .cargo/config.toml has the same effect as passing --target.
  • Reproducible with cargo 1.81.0-nightly (b1feb75d0 2024-06-07).

Version

cargo 1.78.0 (54d8815d0 2024-03-26)
release: 1.78.0
commit-hash: 54d8815d04fa3816edc207bbc4dd36bf18014dbc
commit-date: 2024-03-26
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/1.1.1w)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: Arch Linux [64-bit]
@nilfit nilfit added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Jun 11, 2024
@weihanglo
Copy link
Member

Your observation exactly matches what is documented in build.rustflags section in The Cargo Book:

If the --target flag (or build.target) is used, then the flags will only be passed to the compiler for the target. Things being built for the host, such as build scripts or proc macros, will not receive the args.

This is a behavior people relying on under some circumstances, such as when using address sanitizer. One alternative solution to this is target-applies-to-host unstable feature. See the tracking issue: #9453.

Besides it being a behavior by-design (but not great), is there any issue other than target-applies-to-host trying to resolve?

@weihanglo weihanglo added S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request. A-rustflags Area: rustflags Z-target-applies-to-host Nightly: target-applies-to-host and removed S-triage Status: This issue is waiting on initial triage. labels Jun 11, 2024
@nilfit
Copy link
Author

nilfit commented Jun 11, 2024

Your observation exactly matches what is documented in build.rustflags section in The Cargo Book

Oh, I hadn't seen that.

is there any issue other than target-applies-to-host trying to resolve?

I'm trying to consistently apply deny warnings in CI across a cortex-m embedded codebase. Removing cross-compilation-by-default (through .cargo/config.toml) to get the desired warnings-to-errors behavior would break the build.

I only see target-applies-to-host solving the confusion, but the related host-config seems like it would allow the configuration I'm looking for.

While I would love to have an easier way to do all this than through RUSTFLAGS, #8424 covers that better.

Then everything in this issue is covered by others (I guess that makes it a duplicate). Thanks for clearing things up!

@nilfit nilfit closed this as not planned Won't fix, can't repro, duplicate, stale Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustflags Area: rustflags C-bug Category: bug S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request. Z-target-applies-to-host Nightly: target-applies-to-host
Projects
None yet
Development

No branches or pull requests

2 participants