Skip to content

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

Closed
@petrochenkov

Description

@petrochenkov

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-configurationArea: cargo config files and env varsA-rustflagsArea: rustflagsC-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions