Skip to content

Commit 46d324f

Browse files
committed
Enable ccache for packages build (#6)
1 parent d0e1018 commit 46d324f

File tree

5 files changed

+85
-0
lines changed

5 files changed

+85
-0
lines changed

.github/scripts/build-package.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@ ARGUMENTS="--syncdeps \
2020
$([ "$CLEAN_BUILD" = 1 ] && echo "--cleanbuild" || echo "") \
2121
$([ "$INSTALL_PACKAGE" = 1 ] && echo "--install" || echo "")"
2222

23+
ccache -svv || true
24+
2325
if [[ "$PACKAGE_REPOSITORY" == *MINGW* ]]; then
2426
makepkg-mingw $ARGUMENTS --skippgpcheck
2527
else
2628
makepkg $ARGUMENTS
2729
fi
30+
31+
ccache -svv || true

.github/scripts/enable-ccache.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
set -e # exit on error
4+
set -x # echo on
5+
set -o pipefail # fail of any command in pipeline is an error
6+
7+
DIR="`dirname ${BASH_SOURCE[0]}`/../.."
8+
DIR=`realpath $DIR`
9+
if [[ -n "$GITHUB_WORKSPACE" ]]; then
10+
echo "CCACHE_DIR=$DIR/ccache" >> "$GITHUB_ENV"
11+
echo timestamp=$(date -u --iso-8601=seconds) >> "$GITHUB_OUTPUT"
12+
fi
13+
14+
pushd /
15+
echo "::group::/etc/makepkg.conf"
16+
patch -p1 -b -i "$DIR/patches/ccache/0001-makepkg.patch"
17+
cat /etc/makepkg.conf
18+
echo "::endgroup::"
19+
20+
echo "::group::/etc/makepkg_mingw.conf"
21+
patch -p1 -b -i "$DIR/patches/ccache/0002-makepkg-mingw.patch"
22+
cat /etc/makepkg_mingw.conf
23+
echo "::endgroup::"
24+
popd

.github/workflows/build-package.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ jobs:
4848
mingw-w64-x86_64-github-cli \
4949
mingw-w64-x86_64-jq \
5050
base-devel \
51+
${{ contains(inputs.packages_repository, 'MINGW') && 'mingw-w64-cross-gcc mingw-w64-x86_64-ccache' || ' ccache' }} \
5152
${{ inputs.dependencies }}
5253
5354
- name: Download artifacts
@@ -73,10 +74,31 @@ jobs:
7374
sparse-checkout: ${{ inputs.package_name }}
7475
path: ${{ github.workspace }}/packages
7576

77+
- name: Enable Ccache
78+
id: enable-ccache
79+
run: |
80+
`cygpath "${{ github.workspace }}"`/.github/scripts/enable-ccache.sh
81+
82+
- name: Restore Ccache
83+
uses: actions/cache/restore@v4
84+
with:
85+
path: ${{ github.workspace }}/ccache
86+
key: main-ccache-${{ steps.enable-ccache.outputs.timestamp }}
87+
restore-keys: main-ccache-
88+
7689
- name: Build ${{ inputs.package_name }}
7790
working-directory: ${{ github.workspace }}/packages/${{ inputs.package_name }}
7891
run: |
92+
ccache -svv || true
7993
`cygpath "${{ github.workspace }}"`/.github/scripts/build-package.sh ${{ inputs.packages_repository }}
94+
ccache -svv || true
95+
96+
- name: Save Ccache
97+
if: always()
98+
uses: actions/cache/save@v4
99+
with:
100+
path: ${{ github.workspace }}/ccache
101+
key: main-ccache-${{ steps.enable-ccache.outputs.timestamp }}
80102

81103
- name: Upload ${{ inputs.package_name }}
82104
uses: actions/upload-artifact@v4

patches/ccache/0001-makepkg.patch

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--- a/etc/makepkg.conf
2+
+++ b/etc/makepkg.conf
3+
@@ -63,7 +63,7 @@
4+
#-- check: Run the check() function if present in the PKGBUILD
5+
#-- sign: Generate PGP signature file
6+
#
7+
-BUILDENV=(!distcc color !ccache check !sign)
8+
+BUILDENV=(!distcc color ccache check !sign)
9+
#
10+
#-- If using DistCC, your MAKEFLAGS will also need modification. In addition,
11+
#-- specify a space-delimited list of hosts running in the DistCC cluster.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--- a/etc/makepkg_mingw.conf
2+
+++ b/etc/makepkg_mingw.conf
3+
@@ -137,7 +137,7 @@
4+
#-- check: Run the check() function if present in the PKGBUILD
5+
#-- sign: Generate PGP signature file
6+
#
7+
-BUILDENV=(!distcc color !ccache check !sign)
8+
+BUILDENV=(!distcc color ccache check !sign)
9+
#
10+
#-- If using DistCC, your MAKEFLAGS will also need modification. In addition,
11+
#-- specify a space-delimited list of hosts running in the DistCC cluster.
12+
--- a/usr/share/makepkg/buildenv/compiler.sh
13+
+++ b/usr/share/makepkg/buildenv/compiler.sh
14+
@@ -34,8 +34,8 @@
15+
16+
buildenv_ccache() {
17+
if check_buildoption "ccache" "y"; then
18+
- if [ -d /usr/lib/ccache/bin ]; then
19+
- export PATH="/usr/lib/ccache/bin:$PATH"
20+
+ if [ -d ${MINGW_PREFIX:-/usr}/lib/ccache/bin ]; then
21+
+ export PATH="${MINGW_PREFIX:-/usr}/lib/ccache/bin:$PATH"
22+
using_ccache=1
23+
fi
24+
fi

0 commit comments

Comments
 (0)