diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d04f7a9..057f79f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,6 +13,11 @@ jobs: working-directory: ./src/spice2x steps: - uses: actions/checkout@v4 + - name: Set ccache environment variables + run: | + echo "CCACHE_DIR=${{ github.workspace }}/src/spice2x/.ccache" >> $GITHUB_ENV + - name: Install ccache + uses: hendrikmuhs/ccache-action@v1.2 - name: Calculate commit SHA id: vars run: | diff --git a/src/spice2x/.dockerignore b/src/spice2x/.dockerignore index 852f8ce..e2cfd15 100644 --- a/src/spice2x/.dockerignore +++ b/src/spice2x/.dockerignore @@ -2,3 +2,4 @@ bin/** dist/** docker/** cmake-build* +.ccache/** \ No newline at end of file diff --git a/src/spice2x/.gitignore b/src/spice2x/.gitignore index f4f6b25..fa14a9b 100644 --- a/src/spice2x/.gitignore +++ b/src/spice2x/.gitignore @@ -16,4 +16,6 @@ build_docker.local.sh bin/* dist/* -external/cv2pdb/* \ No newline at end of file +external/cv2pdb/* + +.ccache/* \ No newline at end of file diff --git a/src/spice2x/Dockerfile b/src/spice2x/Dockerfile index fc0e36a..6472577 100644 --- a/src/spice2x/Dockerfile +++ b/src/spice2x/Dockerfile @@ -4,4 +4,4 @@ WORKDIR /src COPY --from=gitroot . /src/.git COPY . /src/src/spice2x WORKDIR /src/src/spice2x -CMD ["./build_all.sh"] +ENTRYPOINT ["./build_all.sh"] diff --git a/src/spice2x/build_all.sh b/src/spice2x/build_all.sh index 522a19f..825ac92 100755 --- a/src/spice2x/build_all.sh +++ b/src/spice2x/build_all.sh @@ -19,6 +19,25 @@ function trap_error_exit { trap trap_error_dbg DEBUG trap trap_error_exit EXIT +IGNORE_CACHE=0 + +# Parse options +while getopts "ih" opt; do + case $opt in + i) IGNORE_CACHE=1 ;; + h) + echo "Usage: $0 [-i]" + echo " -i: Ignore build cache" + echo " -h: Show this help" + exit 0 + ;; + \?) + echo "Invalid option: -$OPTARG" >&2 + exit 1 + ;; + esac +done + # settings GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD 2> /dev/null || echo "none") GIT_HEAD=$(git rev-parse HEAD || echo "none") @@ -74,6 +93,15 @@ echo "Build Type: $BUILD_TYPE" echo "Cores: $CORES" echo "" +if ((IGNORE_CACHE > 0)) +then + echo "Ignoring build cache..." +else + export CCACHE_DIR="$(pwd)/.ccache" + export CMAKE_CXX_COMPILER_LAUNCHER=ccache + export CMAKE_C_COMPILER_LAUNCHER=ccache +fi + time ( # 32 bit echo "Building 32bit targets..." diff --git a/src/spice2x/build_docker.bat b/src/spice2x/build_docker.bat index 8cbec15..7072a75 100644 --- a/src/spice2x/build_docker.bat +++ b/src/spice2x/build_docker.bat @@ -1,6 +1,6 @@ docker build --pull external/docker -t spicetools/deps -docker build --build-context gitroot=%cd%/../../.git . -t spicetools/spice --no-cache -docker run --rm -it -v %cd%/dist:/src/src/spice2x/dist -v %cd%/bin:/src/src/spice2x/bin spicetools/spice +docker build --build-context gitroot=%cd%/../../.git . -t spicetools/spice +docker run --rm -it -v %cd%/dist:/src/src/spice2x/dist -v %cd%/bin:/src/src/spice2x/bin -v %cd%/.ccache:/src/src/spice2x/.ccache spicetools/spice %* @REM to generate PDBs, set DEBUG to 1 in build_all.sh, place cv2pdb in external\cv2pdb, and run below @REM external\cv2pdb\cv2pdb.exe bin\spice2x\spicecfg.exe bin\spice2x\spicecfg-pdb.exe bin\spice2x\spicecfg-pdb.pdb @REM external\cv2pdb\cv2pdb.exe bin\spice2x\spice.exe bin\spice2x\spice-pdb.exe bin\spice2x\spice-pdb.pdb diff --git a/src/spice2x/build_docker.sh b/src/spice2x/build_docker.sh index 9147847..f47ca69 100755 --- a/src/spice2x/build_docker.sh +++ b/src/spice2x/build_docker.sh @@ -1,4 +1,4 @@ #!/bin/bash docker build --pull $PWD/external/docker -t spicetools/deps --platform linux/x86_64 -docker build --build-context gitroot=$PWD/../../.git . -t spicetools/spice:latest --no-cache -docker run --rm -v $PWD/dist:/src/src/spice2x/dist -v $PWD/bin:/src/src/spice2x/bin spicetools/spice +docker build --build-context gitroot=$PWD/../../.git . -t spicetools/spice:latest +docker run --rm -v $PWD/dist:/src/src/spice2x/dist -v $PWD/bin:/src/src/spice2x/bin -v $PWD/.ccache:/src/src/spice2x/.ccache spicetools/spice "$@" diff --git a/src/spice2x/external/docker/Dockerfile b/src/spice2x/external/docker/Dockerfile index 1ef70c4..4c5db15 100644 --- a/src/spice2x/external/docker/Dockerfile +++ b/src/spice2x/external/docker/Dockerfile @@ -11,6 +11,7 @@ RUN pacman --noconfirm -Syu git \ mingw-w64-winpthreads \ mingw-w64-gcc \ mingw-w64-headers \ - mingw-w64-binutils + mingw-w64-binutils \ + ccache RUN useradd user -m && echo "ALL ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers RUN su user -c "cd /tmp/ && git clone https://aur.archlinux.org/yay-bin.git --depth=1 && cd yay-bin && makepkg --noconfirm -si && yay --noconfirm -S mingw-w64-cmake"