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

Cargo concatenates rustflags from .cargo/configss in reversed order #8128

Closed
petrochenkov opened this issue Apr 17, 2020 · 1 comment · Fixed by #12515
Closed

Cargo concatenates rustflags from .cargo/configss in reversed order #8128

petrochenkov opened this issue Apr 17, 2020 · 1 comment · Fixed by #12515
Labels
A-configuration Area: cargo config files and env vars A-rustflags Area: rustflags C-bug Category: bug

Comments

@petrochenkov
Copy link
Contributor

Consider this setup:

outer
├── .cargo
│   └── config
└── inner
    ├── .cargo
    │   └── config
    ├── Cargo.toml
    └── src
        └── main.rs

Less specific outer/.cargo/config contains

[build]
rustflags = ["-Ccodegen-units=1"]

More specific outer/inner/.cargo/config contains

[build]
rustflags = ["-Ccodegen-units=2"]

The compiler's command line in this case is

rustc --crate-name inner --edition=2018 'src\main.rs' ... -Ccodegen-units=2 -Ccodegen-units=1

rustc like many other tools prefers the last specified value for the given option to support hierarchical build systems.
With Cargo's flag concatenation behavior this means that less specific flags override more specific flags, which is not a correct behavior.

cc rust-lang/rust#70729 (comment)

@ehuss
Copy link
Contributor

ehuss commented Aug 17, 2023

@petrochenkov (or anyone following this issue), we are looking to change the order of how arrays get merged in #12515. Do you have a sense of the risk that might pose in breaking existing environments?

@bors bors closed this as completed in 2cc50bc Aug 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-configuration Area: cargo config files and env vars A-rustflags Area: rustflags C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants