-
Couldn't load subscription status.
- Fork 2.7k
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
rustflagsbefore 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).