-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Open
Labels
A-configurationArea: cargo config files and env varsArea: cargo config files and env varsA-environment-variablesArea: environment variablesArea: environment variablesA-rustflagsArea: rustflagsArea: rustflagsC-bugCategory: bugCategory: bugS-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
Description
The .cargo/config
file, through its build.rustflags
key, allows you to add arbitrary compiler flags, which are appended to those passed by Cargo at build-time. These flags, however, are not parsed or evaluated in any way, which means that no environment information can be used in these flags.
Steps
- Create a new Cargo binary project:
cargo new --bin test-case
- Insert into .cargo/config:
[build]
rustflags = ["-C", "link-arg=-Wl,--defsym=FOO=${BAR}"]
- Export BAR:
export BAR=0
- Build the binary:
cargo build
- Note the output of the error, which shows that the
${BAR}
variable was not expanded:
= note: /usr/bin/ld:--defsym:1: ignoring invalid character `{' in expression
/usr/bin/ld:--defsym:1: syntax error
collect2: error: ld returned 1 exit status
Possible Solution(s)
There are two obvious solutions to this:
- Expand
rustflags
before passing them to the compiler. - Allow build.rs to override arbitrary compiler flags.
Notes
Output of cargo version
: cargo 1.39.0-nightly (fe0e5a4 2019-09-04)
The original issue that prompted this is that there is no way to pass the Cargo output directory as a part of the -Map
linker flag, which means that the map file is always generated in the source directory (highly undesirable).
Metadata
Metadata
Assignees
Labels
A-configurationArea: cargo config files and env varsArea: cargo config files and env varsA-environment-variablesArea: environment variablesArea: environment variablesA-rustflagsArea: rustflagsArea: rustflagsC-bugCategory: bugCategory: bugS-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.