Always read from all CFLAGS
-style flags
#1401
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Reading from just one of these means that users setting different environment variables in different parts of the build process would not get flags from the other parts.
This tripped me up in rust-lang/rust#133092 / rust-lang/rust#136984, where I thought that since I was extending
CFLAGS_*
instead of overwriting it, I was allowingcc-rs
to also read fromCFLAGS
.Instead, we now read all of the flags, but in order such that more specific flags override less specific ones.
So e.g. when users set
CFLAGS=-flag1 CFLAGS_aarch64_apple_darwin=-flag2 cargo build
, we end up passing-flag1 -flag2
to the compiler (in that order specifically).NOTE: This has the slight chance of breaking builds where users assume that
CFLAGS_$TARGET
overwritesCFLAGS
. I will argue that that is likely to be the minority, relative to users that do want flags from allCFLAGS*
env vars.To fix such cases, users should pass the negative flag in
CFLAGS_$TARGET
that they don't wantCFLAGS
to set (e.g. ifCFLAGS
contains-pthread
, users should passCFLAGS_$TARGET=-no-pthread
).