Skip to content

Cargo should accumulate rustflags from all sources, rather than from only one source #6338

Closed
@infinity0

Description

In Debian Rust package builds we would like to apply e.g. -C linker and --remap-path-prefix in all situations. We currently do this by setting CARGO_HOME to point to a directory containing a config file with contents similar to the following:

[source.crates-io]
replace-with = "dh-cargo-registry"

[source.dh-cargo-registry]
directory = "$PWD/vendor" # or /usr/share/cargo/registry

[build]
rustflags = [... "-C", "linker=arm-linux-gnueabi-gcc", "-C", "link-arg=-Wl,-z,relro", "--remap-path-prefix", "$PWD=/usr/share/cargo/registry/cargo-0.31.0"]

However if RUSTFLAGS is set (e.g. to empty) in the environment, the above build.rustflags will be totally ignored.

The only method we have currently, to absolutely ensure that certain flags are set, is to append to RUSTFLAGS itself, but this is ugly because it does not support escaping of spaces.

The proposal here is to change env_args to instead use all the sources listed there, in order of priority - that is, set the effective rust flags to be config/build.rustflags + Cargo.toml/target.rustflags + RUSTFLAGS, with later flags taking precedence.

Metadata

Assignees

No one assigned

    Labels

    A-configurationArea: cargo config files and env varsA-rustflagsArea: rustflagsC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions