f0286576e7
Add a cargo wrapper which appends a --target argument to the command line. This makes cargo pass the --target argument to rustc for crates being built for the target architecture, even if the target is the same as the host. It will omit the --target argument for build scripts and crates used in macros. Check for this --target argument in the rustc wrapper and adjust the library paths depending on its presence. The fallback that runs rustc under qemu is no longer needed because macros are now built for the native architecture and can be loaded into the native compiler without any problems. Also check if the arguments passed to rustc are "-vV". If this is the case, we still need to fall back to the target rustc because the native rustc will return the wrong architecture. If the wrong host architecture is passed to a build script, it might try to look for a cross-compiler or do something else that doesn't work. [ci:skip-build]: already built successfully in CI
26 lines
848 B
Bash
26 lines
848 B
Bash
#!/bin/sh -e
|
|
|
|
if [ -n "$CROSSDIRECT_DEBUG" ]; then
|
|
set -x
|
|
fi
|
|
|
|
# return the correct host architecture when cargo requests it
|
|
if [ "$*" = "-vV" ]; then
|
|
exec /usr/bin/rustc -vV
|
|
fi
|
|
|
|
# We expect the right target to be set in the arguments if compiling for the
|
|
# target architecture. Our cargo wrapper passes the right "--target" argument
|
|
# automatically. If no target is provided, this is probably a macro or a
|
|
# build script, so it should be compiled for the native architecture.
|
|
if echo "$*" | grep -qFe "--target"; then
|
|
LD_LIBRARY_PATH=/native/lib:/native/usr/lib /native/usr/bin/rustc \
|
|
-Clinker=/native/usr/lib/crossdirect/rust-qemu-linker \
|
|
--sysroot=/usr \
|
|
"$@"
|
|
else
|
|
PATH=/native/usr/bin:/native/bin LD_LIBRARY_PATH=/native/lib:/native/usr/lib \
|
|
/native/usr/bin/rustc \
|
|
-Clink-arg=-Wl,-rpath,/native/lib:/native/usr/lib \
|
|
"$@"
|
|
fi
|