feat: add support for ccache

This introduces basic support for ccache, during packaging builds.

If you are building many packages, it is recommended to manually
increase the maximum size of the ccache cache. This is typically
achieved by modifying `~/.ccache/ccache.conf` and adjusting the
`max_size` setting.

Signed-off-by: Joseph Benden <joe@benden.us>
This commit is contained in:
Joseph Benden 2019-07-20 01:14:20 +00:00 committed by Natanael Copa
parent 9be3a6c6a0
commit b1b47140ea
3 changed files with 33 additions and 5 deletions

View File

@ -9,6 +9,9 @@ export MAKEFLAGS=-j$JOBS
# remove line below to disable colors # remove line below to disable colors
USE_COLORS=1 USE_COLORS=1
# uncomment line below to enable ccache support.
#USE_CCACHE=1
SRCDEST=/var/cache/distfiles SRCDEST=/var/cache/distfiles
# uncomment line below to store built packages in other location # uncomment line below to store built packages in other location

View File

@ -26,6 +26,8 @@ fi
: ${APK:="apk"} : ${APK:="apk"}
: ${ADDUSER:="abuild-adduser"} : ${ADDUSER:="abuild-adduser"}
: ${ADDGROUP:="abuild-addgroup"} : ${ADDGROUP:="abuild-addgroup"}
: ${CC:="gcc"}
: ${CXX:="g++"}
apk_opt_wait="--wait 30" apk_opt_wait="--wait 30"
@ -2054,6 +2056,9 @@ builddeps() {
mhd=$(get_missing_deps "--root $CBUILDROOT --arch $CTARGET_ARCH" $hostdeps) || return 1 mhd=$(get_missing_deps "--root $CBUILDROOT --arch $CTARGET_ARCH" $hostdeps) || return 1
missing=$(echo $mbd $mhd) missing=$(echo $mbd $mhd)
# shall ccache be added?
[ -n "$USE_CCACHE" ] && missing="$missing ccache"
if [ -z "$install_deps" ]; then if [ -z "$install_deps" ]; then
# if we dont have any missing deps we are done now # if we dont have any missing deps we are done now
[ -z "$missing" ] && return 0 [ -z "$missing" ] && return 0
@ -2138,6 +2143,7 @@ rootbld() {
"$BUILD_ROOT/$SRCDEST" "$BUILD_ROOT/$REPODEST" \ "$BUILD_ROOT/$SRCDEST" "$BUILD_ROOT/$REPODEST" \
"$BUILD_ROOT/tmp/pkg" "$BUILD_ROOT/tmp/src" \ "$BUILD_ROOT/tmp/pkg" "$BUILD_ROOT/tmp/src" \
"$BUILD_ROOT/usr/bin" "$pkgbasedir" "$REPODEST" \ "$BUILD_ROOT/usr/bin" "$pkgbasedir" "$REPODEST" \
"$BUILD_ROOT/$HOME/.ccache" \
"$srcdir" "$srcdir"
cp /etc/abuild.conf /etc/group /etc/passwd "$BUILD_ROOT/etc" cp /etc/abuild.conf /etc/group /etc/passwd "$BUILD_ROOT/etc"
@ -2170,7 +2176,7 @@ rootbld() {
calcdeps calcdeps
$SUDO_APK add --initdb --root "$BUILD_ROOT" --update \ $SUDO_APK add --initdb --root "$BUILD_ROOT" --update \
abuild alpine-base build-base git $hostdeps $builddeps abuild alpine-base build-base git ccache $hostdeps $builddeps
local bwrap_opts="" local bwrap_opts=""
options_has "net" || bwrap_opts="$bwrap_opts --unshare-net" options_has "net" || bwrap_opts="$bwrap_opts --unshare-net"
@ -2181,6 +2187,7 @@ rootbld() {
--bind "$BUILD_ROOT/$HOME" "$HOME" \ --bind "$BUILD_ROOT/$HOME" "$HOME" \
--ro-bind "$HOME/.abuild" "$HOME/.abuild" \ --ro-bind "$HOME/.abuild" "$HOME/.abuild" \
--ro-bind "$aportsgit" "$aportsgit" \ --ro-bind "$aportsgit" "$aportsgit" \
--bind "$HOME/.ccache" "$HOME/.ccache" \
--bind "$SRCDEST" "$SRCDEST" \ --bind "$SRCDEST" "$SRCDEST" \
--bind "$BUILD_ROOT/tmp" /tmp \ --bind "$BUILD_ROOT/tmp" /tmp \
--bind "$BUILD_ROOT/tmp/src" "$srcdir" \ --bind "$BUILD_ROOT/tmp/src" "$srcdir" \
@ -2491,6 +2498,24 @@ if [ $(id -u) -eq 0 ] && [ -z "$FAKEROOTKEY" ]; then
FAKEROOT= FAKEROOT=
fi fi
# check for ccache presence and maybe export its path
if [ -n "$USE_CCACHE" ]; then
if ! command -v ccache >/dev/null; then
die "Ccache is enabled; however, the binary can not be found."
fi
if [ ! -d "$HOME/.ccache" ]; then
die "Ccache is enabled; however, the user cache directory is not found."
fi
if [ ! -f "$HOME/.ccache/ccache.conf" ]; then
die "Ccache is enabled; however, the ccache configuration file is not found."
fi
# prepend ccache path
export PATH="/usr/lib/ccache/bin:$PATH"
fi
# find startdir # find startdir
[ -f "$APKBUILD" ] || die "Could not find $APKBUILD (PWD=$PWD)" [ -f "$APKBUILD" ] || die "Could not find $APKBUILD (PWD=$PWD)"
APKBUILD=$(readlink -f "$APKBUILD") APKBUILD=$(readlink -f "$APKBUILD")
@ -2509,9 +2534,7 @@ SRCDEST=${SRCDEST:-$startdir}
BUILD_ROOT= BUILD_ROOT=
# set a default CC export CC CXX
: ${CC:=gcc}
export CC
cd "$startdir" || die cd "$startdir" || die
. "$APKBUILD" . "$APKBUILD"

View File

@ -55,7 +55,7 @@ hostspec_to_libc() {
readconfig() { readconfig() {
local _APORTSDIR _BUILDDIR _PKGDEST _SRCPKGDEST _REPODEST _SRCDEST local _APORTSDIR _BUILDDIR _PKGDEST _SRCPKGDEST _REPODEST _SRCDEST
local _CARCH _CHOST _CTARGET _CPPFLAGS _CFLAGS _CXXFLAGS _LDFLAGS local _CARCH _CHOST _CTARGET _CPPFLAGS _CFLAGS _CXXFLAGS _LDFLAGS
local _JOBS _MAKEFLAGS _PACKAGER _USE_COLORS local _JOBS _MAKEFLAGS _PACKAGER _USE_COLORS _USE_CCACHE
local gitbase= local gitbase=
[ -n "${APORTSDIR+x}" ] && _APORTSDIR=$APORTSDIR [ -n "${APORTSDIR+x}" ] && _APORTSDIR=$APORTSDIR
[ -n "${BUILDDIR+x}" ] && _BUILDDIR=$BUILDDIR [ -n "${BUILDDIR+x}" ] && _BUILDDIR=$BUILDDIR
@ -74,6 +74,7 @@ readconfig() {
[ -n "${MAKEFLAGS+x}" ] && _MAKEFLAGS=$MAKEFLAGS [ -n "${MAKEFLAGS+x}" ] && _MAKEFLAGS=$MAKEFLAGS
[ -n "${PACKAGER+x}" ] && _PACKAGER=$PACKAGER [ -n "${PACKAGER+x}" ] && _PACKAGER=$PACKAGER
[ -n "${USE_COLORS+x}" ] && _USE_COLORS="$USE_COLORS" [ -n "${USE_COLORS+x}" ] && _USE_COLORS="$USE_COLORS"
[ -n "${USE_CCACHE+x}" ] && _USE_CCACHE="$USE_CCACHE"
: ${ABUILD_CONF:=$sysconfdir/abuild.conf} : ${ABUILD_CONF:=$sysconfdir/abuild.conf}
: ${ABUILD_USERDIR:=$HOME/.abuild} : ${ABUILD_USERDIR:=$HOME/.abuild}
: ${ABUILD_USERCONF:=$ABUILD_USERDIR/abuild.conf} : ${ABUILD_USERCONF:=$ABUILD_USERDIR/abuild.conf}
@ -114,6 +115,7 @@ readconfig() {
MAKEFLAGS=${_MAKEFLAGS-$MAKEFLAGS} MAKEFLAGS=${_MAKEFLAGS-$MAKEFLAGS}
PACKAGER=${_PACKAGER-$PACKAGER} PACKAGER=${_PACKAGER-$PACKAGER}
USE_COLORS=${_USE_COLORS-$USE_COLORS} USE_COLORS=${_USE_COLORS-$USE_COLORS}
USE_CCACHE=${_USE_CCACHE-$USE_CCACHE}
[ -z "$CBUILD" ] && CBUILD="$(gcc -dumpmachine)" [ -z "$CBUILD" ] && CBUILD="$(gcc -dumpmachine)"
[ -z "$CHOST" ] && CHOST="$CBUILD" [ -z "$CHOST" ] && CHOST="$CBUILD"