Skip to content

Conversation

@RagnarGrootKoerkamp
Copy link

@RagnarGrootKoerkamp RagnarGrootKoerkamp commented Nov 21, 2025

This PR fixes #1571: currently, dist always passes a RUSTFLAGS variable to cargo that 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 RUSTFLAGS environment variable is set, and if not, it then uses cargo_config2 to read the rustflags variable.

Probably some test should be added:

  • to check that an explicitly empty RUSTFLAGS is propagated,
  • to check that an unset RUSTFLAGS indeed makes it fall back to .cargo/config.toml
  • to check that it works for both [build] rustflags = ... and [target.<cfg/triple>] rustflags = ...,
  • to check whether anything needs to be done with quoted values in a 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 rustflags are needed (because these cases seem rare), and then just not pass the RUSTFLAGS environment variable to cargo at 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 rustflags for bad defaults, and let users update .cargo/config.toml themselves. Specifically: any binary that is distributed via both cargo-dist and another platform with its own build pipeline should likely set these flags anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dist seems to ignore environmnet variables configured in .cargo/config.toml

1 participant