cross/crossdirect: improve rust handling
I'm suggesting this as a temporary solution for the current issues with cross-compiling Rust programs. Most big Rust projects use proc-macro
crates such as serde_derive, which currently make the rustc wrapper fall back to compiling everything in QEMU (resulting in a slow build).
These changes remove the need for the QEMU+rustc fallback in the wrapper. This works because Cargo's cross-compiling logic can be enabled even when using the same target architecture as the host architecture. Cargo will then pass a --target
argument to rustc for all crates that are not going to be used on the host. If the library paths are adjusted accordingly, the native rustc will produce correct results with the arguments provided by Cargo, i.e. working native build scripts and macro crates when called without --target
.
Please note that this also causes Cargo build scripts to be built for and run on the native architecture, which means that any libraries they require must be present in the native chroot. This might require a change in pmbootstrap such as this one:
--- a/pmb/build/init.py
+++ b/pmb/build/init.py
@@ -108,6 +108,6 @@ def init_compiler(args, depends, cross, arch):
if cross == "crossdirect":
cross_pkgs += ["crossdirect"]
if "rust" in depends or "cargo" in depends:
- cross_pkgs += ["rust"]
+ cross_pkgs += depends
pmb.chroot.apk.install(args, cross_pkgs)