From 59c01feaea6e3a41060f42ca8ace15cfceb3edc9 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sun, 19 Sep 2021 21:49:09 +0200 Subject: [PATCH] github: Use ccache for CI runners --- .github/workflows/analysis.yml | 9 ++++++ .github/workflows/build.yml | 58 ++++++++++++++++++++++++++++------ dist/Brewfile | 1 + dist/get_deps_debian.sh | 1 + dist/get_deps_msys2.sh | 1 + 5 files changed, 61 insertions(+), 9 deletions(-) diff --git a/.github/workflows/analysis.yml b/.github/workflows/analysis.yml index 4e9a25b96..e329b6b8c 100644 --- a/.github/workflows/analysis.yml +++ b/.github/workflows/analysis.yml @@ -29,6 +29,14 @@ jobs: with: languages: 'cpp' + - name: 📜 Restore cache + uses: actions/cache@v2 + with: + path: | + ~/.ccache + .flatpak-builder + key: ${{ runner.os }}-build + - name: ⬇️ Install dependencies run: | sudo apt update @@ -41,6 +49,7 @@ jobs: CC=gcc-10 CXX=g++-10 cmake \ -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ -DCMAKE_INSTALL_PREFIX="$PWD/install" \ + -D CMAKE_C_COMPILER_LAUNCHER=ccache -D CMAKE_CXX_COMPILER_LAUNCHER=ccache \ .. make -j 4 install diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index adc0819b5..a183ca67f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,6 +19,15 @@ jobs: with: fetch-depth: 0 submodules: recursive + + - name: 📜 Restore cache + uses: actions/cache@v2 + with: + path: | + ~/.ccache + .flatpak-builder + key: ${{ runner.os }}-build-${{ github.run_id }} + restore-keys: ${{ runner.os }}-build- - name: ⬇️ Install dependencies run: | @@ -27,11 +36,12 @@ jobs: - name: 🛠️ Build run: | - mkdir build + mkdir -p build cd build CC=gcc-10 CXX=g++-10 cmake \ -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ -DCMAKE_INSTALL_PREFIX="$PWD/install" \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ .. make -j 4 install @@ -41,7 +51,7 @@ jobs: flatpak --user remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo flatpak --user install -y flathub org.freedesktop.Platform//20.08 flatpak --user install -y flathub org.freedesktop.Sdk//20.08 - flatpak-builder --repo=imhex _flatpak dist/net.werwolv.ImHex.yaml + flatpak-builder --repo=imhex _flatpak dist/net.werwolv.ImHex.yaml --ccache --keep-build-dirs flatpak build-bundle imhex imhex.flatpak net.werwolv.ImHex stable - name: ⬆️ Upload ELF @@ -64,21 +74,42 @@ jobs: defaults: run: shell: msys2 {0} + env: + CCACHE_DIR: "${{ github.workspace }}/.ccache" + CCACHE_MAXSIZE: "1000M" + CCACHE_COMPRESS: "true" steps: - name: 🧰 Checkout uses: actions/checkout@v2 with: fetch-depth: 0 submodules: recursive + - name: 🟦 Install msys2 uses: msys2/setup-msys2@v2 + - name: ⬇️ Install dependencies run: | - bash dist/get_deps_msys2.sh + bash dist/get_deps_msys2.sh + + - name: 📜 Prepare Cache + id: prep-ccache + shell: bash + run: | + mkdir -p "${CCACHE_DIR}" + echo "::set-output name=dir::$CCACHE_DIR" + + - name: 📜 Restore Cache + uses: actions/cache@v1 + id: cache-ccache + with: + path: ${{ steps.prep-ccache.outputs.dir }} + key: ${{ runner.os }}-build-${{ github.run_id }} + restore-keys: ${{ runner.os }}-build- - name: 🛠️ Build run: | - mkdir build + mkdir -p build cd build # Get path to mingw python library PYTHON_LIB_NAME=$(pkg-config --libs-only-l python3 | sed 's/^-l//' | sed 's/ //') @@ -89,11 +120,11 @@ jobs: -DCMAKE_INSTALL_PREFIX="$PWD/install" \ -DCREATE_PACKAGE=ON \ -DPython_LIBRARY="$PYTHON_LIB_PATH" \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ .. - mingw32-make -j4 - mingw32-make install + mingw32-make -j4 install cpack - + - name: ⬆️ Upload Portable ZIP uses: actions/upload-artifact@v2 with: @@ -124,9 +155,17 @@ jobs: run: | brew bundle --no-lock --file dist/Brewfile + - name: 📜 Restore cache + uses: actions/cache@v2 + with: + path: | + ~/.ccache + key: ${{ runner.os }}-build-${{ github.run_id }} + restore-keys: ${{ runner.os }}-build- + - name: 🛠️ Build run: | - mkdir build + mkdir -p build cd build CC=$(brew --prefix llvm)/bin/clang \ CXX=$(brew --prefix llvm)/bin/clang++ \ @@ -136,8 +175,9 @@ jobs: -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ -DCREATE_BUNDLE=ON \ -DCREATE_PACKAGE=ON \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ .. - make -j 4 package + make -j4 package - name: ⬆️ Upload DMG uses: actions/upload-artifact@v2 diff --git a/dist/Brewfile b/dist/Brewfile index d80c4798d..a2bc5b94e 100644 --- a/dist/Brewfile +++ b/dist/Brewfile @@ -3,6 +3,7 @@ brew "mbedtls" brew "capstone" brew "nlohmann-json" brew "cmake" +brew "ccache" brew "python3" brew "freetype2" brew "libmagic" diff --git a/dist/get_deps_debian.sh b/dist/get_deps_debian.sh index 9119e7fd2..5e5e4ca6f 100755 --- a/dist/get_deps_debian.sh +++ b/dist/get_deps_debian.sh @@ -17,6 +17,7 @@ apt install -y \ ${PKGCONF:-} \ cmake \ make \ + ccache \ libglfw3-dev \ libglm-dev \ libmagic-dev \ diff --git a/dist/get_deps_msys2.sh b/dist/get_deps_msys2.sh index 9a0a81c9d..70b286f75 100755 --- a/dist/get_deps_msys2.sh +++ b/dist/get_deps_msys2.sh @@ -4,6 +4,7 @@ pacman -S --needed --noconfirm \ mingw-w64-x86_64-gcc \ mingw-w64-x86_64-cmake \ mingw-w64-x86_64-make \ + mingw-w64-x86_64-ccache \ mingw-w64-x86_64-capstone \ mingw-w64-x86_64-glfw \ mingw-w64-x86_64-file \