feat: Use cargo-config2 to read rustflags from the config to append to
#2202
+34
−1
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.
This PR fixes #1571: currently,
distalways passes aRUSTFLAGSvariable tocargothat is based on the current environment variable (possibly empty), with possibly some target-specific values appended.As noted in #1571, this causes issues when e.g.
rustflags = "-C target-cpu=native"is set in.cargo/config.toml.This PR first checks if the
RUSTFLAGSenvironment variable is set, and if not, it then usescargo_config2to read therustflagsvariable.Probably some test should be added:
RUSTFLAGSis propagated,RUSTFLAGSindeed makes it fall back to.cargo/config.toml[build] rustflags = ...and[target.<cfg/triple>] rustflags = ...,rustflags=[...]array. I'm not sure if simply concatenating is always valid?An alternative, simpler solution could be to detect when the environment variable is not set and also no modifications to
rustflagsare needed (because these cases seem rare), and then just not pass theRUSTFLAGSenvironment variable tocargoat all, so that it does its usual thing.See https://github.com/RagnarGrootKoerkamp/cargo-dist/tree/rustflags-optional for how that could look.
Yes another (surely controversial) solution could be to simply not manually override
rustflagsfor bad defaults, and let users update.cargo/config.tomlthemselves. Specifically: any binary that is distributed via bothcargo-distand another platform with its own build pipeline should likely set these flags anyway.