-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
Problem
Setting the CARGO_TARGET_<triple>_LINKER
environment variable has no affect on cargo build
.
I am targeting x86_64-unknown-linux-musl
and I need to be able to build on both macOS (for development) and Linux (for CI). The linker is named differently on the two platforms: x86_64-linux-musl-gcc
on macOS and musl-gcc
on Linux (which is the what rustc
expects by default). I would like to be able to the CARGO_TARGET__LINKER environment variable to override the default on macOS only.
Steps (macOS)
rustup default stable
(fails for nightly too)rustup target add x86_64-unknown-linux-musl
brew install filosottile/musl-cross/musl-cross
cargo new envtest
cd envtest
export CARGO_TARGET_x86_64_unknown_linux_musl_LINKER=x86_64-linux-musl-gcc
cargo build --target x86_64-unknown-linux-musl
Result: error: linking with ``cc`` failed: exit code: 1
Expected Result: a binary linked with x86_64-linux-musl-gcc
Suggested Fix
Rather than just being able to specify target specific configurations in .cargo/config
, it would be nice to be able to specify configurations by target and host combinations.
For example I want this rule to only apply when building for the musl target on macOS:
[target.x86_64-unknown-linux-musl]
linker = "x86_64-linux-musl-gcc"
If narrow this rule by host would be amazing. Something like:
[target.x86_64-unknown-linux-musl.cfg(host_os = "macos")]
linker = "x86_64-linux-musl-gcc"
That said, being able to use the CARGO_TARGET_<triple>_LINKER
environment variable is more than enough for my needs. Thank you.
Notes
Output of cargo version
: cargo 1.43.0 (2cbe904 2020-05-03)
Release channels tested:
- stable-x86_64-apple-darwin unchanged - rustc 1.43.1 (8d69840ab 2020-05-04)
- nightly-x86_64-apple-darwin unchanged - rustc 1.45.0-nightly (a74d1862d 2020-05-14)
OSes tested on:
- macOS Catalina 10.15.5 Beta (19F83c)
- debian buster -- from the official rust:latest docker image