From c394f1085d16881291003a0aae7413de11dc0aff Mon Sep 17 00:00:00 2001 From: icp Date: Fri, 13 Jan 2023 22:21:19 +0530 Subject: [PATCH] Enable usage of rust-sccache for cargo builds --- common/build-helper/rust.sh | 4 ++++ common/environment/build-style/cargo.sh | 7 +++++++ common/xbps-src/shutils/chroot.sh | 4 ++-- etc/defaults.conf | 6 ++++++ xbps-src | 10 +++++++++- 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/common/build-helper/rust.sh b/common/build-helper/rust.sh index 272d03f52607..e5261a7e7cdf 100644 --- a/common/build-helper/rust.sh +++ b/common/build-helper/rust.sh @@ -30,6 +30,10 @@ else unset CARGO_BUILD_TARGET fi +if [ -n "$XBPS_SCCACHE" ]; then + export RUSTC_WRAPPER="/usr/bin/sccache" +fi + # For cross-compiling rust -sys crates export PKG_CONFIG_ALLOW_CROSS=1 diff --git a/common/environment/build-style/cargo.sh b/common/environment/build-style/cargo.sh index 473750c7a359..4f9e00f47f23 100644 --- a/common/environment/build-style/cargo.sh +++ b/common/environment/build-style/cargo.sh @@ -4,6 +4,13 @@ if ! [[ "$pkgname" =~ ^cargo-auditable(-bootstrap)?$ ]]; then hostmakedepends+=" cargo-auditable" fi +if [ -n "$XBPS_SCCACHE" ] && [ "$pkgname" != "rust-sccache" ]; then + case "$XBPS_MACHINE" in + x86_64*|i686*|arm*|aarch64*) hostmakedepends+=" rust-sccache" ;; + *) ;; + esac +fi + if [ "$CROSS_BUILD" ]; then makedepends+=" rust-std" fi diff --git a/common/xbps-src/shutils/chroot.sh b/common/xbps-src/shutils/chroot.sh index 823705030b97..0708e571558b 100644 --- a/common/xbps-src/shutils/chroot.sh +++ b/common/xbps-src/shutils/chroot.sh @@ -88,8 +88,8 @@ PATH=/void-packages:/usr/bin exec env -i -- SHELL=/bin/sh PATH="\$PATH" DISTCC_HOSTS="\$XBPS_DISTCC_HOSTS" DISTCC_DIR="/host/distcc" \ ${XBPS_ARCH+XBPS_ARCH=$XBPS_ARCH} ${XBPS_CHECK_PKGS+XBPS_CHECK_PKGS=$XBPS_CHECK_PKGS} \ - CCACHE_DIR="/host/ccache" IN_CHROOT=1 LC_COLLATE=C LANG=en_US.UTF-8 TERM=linux HOME="/tmp" \ - PS1="[\u@$XBPS_MASTERDIR \W]$ " /bin/bash +h + CCACHE_DIR="/host/ccache" SCCACHE_DIR="/host/sccache" IN_CHROOT=1 LC_COLLATE=C LANG=en_US.UTF-8 \ + TERM=linux HOME="/tmp" PS1="[\u@$XBPS_MASTERDIR \W]$ " /bin/bash +h _EOF chmod 755 $XBPS_MASTERDIR/bin/xbps-shell diff --git a/etc/defaults.conf b/etc/defaults.conf index f70e4ea3d006..422f85113625 100644 --- a/etc/defaults.conf +++ b/etc/defaults.conf @@ -55,6 +55,12 @@ XBPS_SUCMD="sudo /bin/sh -c" # #XBPS_CCACHE=yes +# [OPTIONAL] +# Enable or disable sccache when building packages. The sccache directory +# is stored in the hostdir, i.e hostdir/sccache. +# +#XBPS_SCCACHE=yes + # [OPTIONAL] # Enable or disable distcc when building packages. The distcc directory # is stored in the hostdir, i.e hostdir/distcc. diff --git a/xbps-src b/xbps-src index cdb5f8c6d643..aeed206b8949 100755 --- a/xbps-src +++ b/xbps-src @@ -658,7 +658,7 @@ export XBPS_SHUTILSDIR XBPS_CROSSPFDIR XBPS_TRIGGERSDIR \ XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_BUILDSTYLEDIR \ XBPS_CPPFLAGS XBPS_CFLAGS XBPS_CXXFLAGS XBPS_FFLAGS XBPS_LDFLAGS \ XBPS_MAKEJOBS XBPS_BUILD_FORCEMODE XBPS_USE_GIT_REVS XBPS_DEBUG_PKGS \ - XBPS_CHECK_PKGS XBPS_CCACHE XBPS_DISTCC XBPS_DISTCC_HOSTS XBPS_SKIP_DEPS \ + XBPS_CHECK_PKGS XBPS_SCCACHE XBPS_CCACHE XBPS_DISTCC XBPS_DISTCC_HOSTS XBPS_SKIP_DEPS \ XBPS_SKIP_REMOTEREPOS XBPS_CROSS_BUILD XBPS_ARG_PKG_OPTIONS XBPS_CONFIG_FILE \ XBPS_KEEP_ALL XBPS_HOSTDIR XBPS_MASTERDIR XBPS_SRC_VERSION \ XBPS_DESTDIR XBPS_MACHINE XBPS_TEMP_MASTERDIR XBPS_BINPKG_EXISTS \ @@ -702,6 +702,14 @@ if [ "$XBPS_CCACHE" ]; then mkdir -p $CCACHE_DIR fi +# +# Set up sccache +# +if [ "$XBPS_SCCACHE" ]; then + export SCCACHE_DIR="$XBPS_HOSTDIR/sccache" + mkdir -p $SCCACHE_DIR +fi + # # Set up distcc #