vm-hpe
February 6, 2024, 11:09am
11
Well, as expected, this issue has been reported by many people in same case as like this.. i.e. build-arch==target-arch.
Relevant ones and supposed to be fixed by:
opened 06:05AM - 30 Nov 16 UTC
closed 08:31PM - 01 Jun 21 UTC
A-linkage
A-configuration
C-feature-request
A-build-scripts
My interest is in this is for Yocto. For Yocto the `--build` and `--target` are … different but they're the same for Rust (I'm using x86_64 Ubuntu and building an x86_64 Yocto image). So what that means is that Yocto uses the distro compiler to produce a build sysroot using the triple `x86_64-linux` and the target sysroot uses the triple `x86_64-poky-linux`. A binary built for the build sysroot needs different libraries and a different rpath then what a binary built for the target sysroot. Now the Rust built-in target that would match both of these would be `x86_64-unknown-linux-gnu` and that's where the problem lies. Since these need different sysroots and rpath's then I need to be able to pass flags to the linker (or what I really use is a custom linker that's a wrapper to provide the right args). Now gcc-rs has the ability to pass `HOST_CC` and `TARGET_CC` along with other HOST_ and TARGET_ options but Cargo does not. Now if I built from x86_64 for an arm target and have the following config:
```
[target.x86_64-unknown-linux-gnu]
linker = "custom-build-linker"
[target.aarch64-unknown-linux-gnu]
linker = "custom-target-linker"
```
Cargo will build `build-script-build` with the `custom-build-linker` but when I'm building from x86_64 for x86_64 then there's no way for me to supply two different linkers. I focused my examples on linkers here but rustflags work the same way as well.
I propose adding support to Cargo to read a `[host]` section that would behave like a `[target]` section but instead would be used for any items that Cargo needs to build to run on the build machine (e.g. compiler plugins?). It would look something like:
```
[host]
linker = "custom-build-linker"
[target.aarch64-unknown-linux-gnu]
linker = "custom-target-linker"
```
rust-lang:master
← jameshilliard:split-host
opened 04:37AM - 02 Apr 21 UTC
This prevents target configs from accidentally being picked up when cross compil… ing from hosts that have the same architecture as their targets.
closes #3349