pmaports/cross/crossdirect/rustc.sh
Oliver Smith d9830c6304
cross/crossdirect: partially use sccache for rust (MR 4310)
Wrap rustc commands with sccache when building native build scripts.
More interesting will be using sscache for compiling for the target
architecture, but sccache currently refuses to cache with --sysroot.
This can be optimized further later on, get some initial support for
sccache in here first.

While at it, tweak the -vV logic to also support -V, start using semver
with this and add myself as maintainer of the package.

[ci:skip-build]: already built successfully in CI
2023-09-05 08:45:41 +02:00

38 lines
1.2 KiB
Bash

#!/bin/sh -e
if [ -n "$CROSSDIRECT_DEBUG" ]; then
set -x
fi
# return the correct host architecture when cargo requests it
if [ "$*" = "-vV" ] || [ "$*" = "-V" ]; then
exec /usr/bin/rustc "$*"
fi
# pmbootstrap installs sccache when building a rust program, unless --no-ccache
# is set. In that case it also sets CCACHE_DISABLE.
SCCACHE=/native/usr/bin/sccache
if ! [ -e "$SCCACHE" ] || [ -n "$CCACHE_DISABLE" ]; then
SCCACHE=""
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
# Not using sccache when building for foreign architecture, as it
# doesn't cache the output with "Non-cacheable reasons: --sysroot"
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 \
$SCCACHE \
/native/usr/bin/rustc \
-Clink-arg=-Wl,-rpath,/native/lib:/native/usr/lib \
"$@"
fi