Skip to content

Commit 946149d

Browse files
authored
Faster CI builds (#614)
* Using sccache to speedup compilation * using github cache to save cmake dependencies * fixed issue of python always running
1 parent 2f3e745 commit 946149d

File tree

4 files changed

+86
-12
lines changed

4 files changed

+86
-12
lines changed

.github/workflows/cmake_ci.yml

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on: [push, pull_request]
44

55
jobs:
66
prepare:
7-
runs-on: ubuntu-latest
7+
runs-on: ubuntu-22.04
88
outputs:
99
matrix: ${{ steps.generate_matrix.outputs.matrix }}
1010
steps:
@@ -13,18 +13,71 @@ jobs:
1313
- name: Generate matrix
1414
id: generate_matrix
1515
run: |
16-
echo "MACOSX_DEPLOYMENT_TARGET=11.0" >> $GITHUB_ENV
1716
MATRIX=$(python3 ${{ github.workspace }}/.github/workflows/generate_cmake_matrix.py)
1817
echo "matrix=$MATRIX" >> $GITHUB_OUTPUT
18+
cache:
19+
strategy:
20+
matrix:
21+
os:
22+
- ubuntu-22.04
23+
- windows-2022
24+
runs-on: ${{ matrix.os }}
25+
steps:
26+
- name: Checkout code
27+
uses: actions/checkout@v4
28+
- name: create cache directory
29+
run: |
30+
mkdir -p cpm
31+
- name: Setup Cpp
32+
if: steps.cache.outputs.cache-hit != 'true'
33+
uses: aminya/setup-cpp@v1
34+
with:
35+
cmake : true
36+
- name: Download dependencies in cache linux
37+
if: steps.cache.outputs.cache-hit != 'true' && runner.os == 'Linux'
38+
run: |
39+
cmake -S . -B ./build
40+
rm -rf build
41+
cmake -S . -B ./build -DFINUFFT_USE_DUCC0=ON
42+
env:
43+
CPM_SOURCE_CACHE: cpm
44+
- name: Download dependencies in cache windows
45+
if: steps.cache.outputs.cache-hit != 'true' && runner.os != 'Linux'
46+
run: |
47+
cmake -S . -B build
48+
rm build -r -force
49+
cmake -S . -B build -DFINUFFT_USE_DUCC0=ON
50+
env:
51+
CPM_SOURCE_CACHE: cpm
52+
- name: Cache dependencies
53+
uses: actions/cache/save@v4
54+
with:
55+
key: cpm-cache-00-${{ hashFiles('CMakeLists.txt', 'cmake/*') }}
56+
enableCrossOsArchive: true
57+
path: cpm
1958
cmake-ci:
2059
runs-on: ${{ matrix.os }}
21-
needs: prepare
60+
needs: [prepare, cache]
2261
strategy:
2362
fail-fast: false
2463
matrix: ${{ fromJSON(needs.prepare.outputs.matrix) }}
2564
steps:
2665
- name: Checkout code
2766
uses: actions/checkout@v4
67+
- name: Restore Cache
68+
uses: actions/cache/restore@v4
69+
with:
70+
key: cpm-cache-00-${{ hashFiles('CMakeLists.txt', 'cmake/*') }}
71+
enableCrossOsArchive: true
72+
path: cpm
73+
- name: Run sccache-cache only on non-release runs
74+
if: github.event_name != 'release' && github.event_name != 'workflow_dispatch'
75+
uses: mozilla-actions/[email protected]
76+
- name: Set caching env vars only on non-release runs
77+
if: github.event_name != 'release' && github.event_name != 'workflow_dispatch'
78+
run: |
79+
echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV
80+
echo "SCCACHE_GHA_VERSION=0" >> $GITHUB_ENV
2881
- name: Setup Cpp
2982
uses: aminya/setup-cpp@v1
3083
with:
@@ -46,7 +99,9 @@ jobs:
4699
sudo apt install -y libfftw3-dev
47100
- name: Configure Cmake
48101
run: |
49-
cmake -S . -B ./build -G Ninja -DCMAKE_BUILD_TYPE:STRING=${{matrix.build_type}} -DFINUFFT_ARCH_FLAGS=${{ matrix.arch_flags }} -DFINUFFT_BUILD_TESTS=ON -DFINUFFT_STATIC_LINKING=${{matrix.finufft_static_linking}} -DFINUFFT_USE_DUCC0=${{ matrix.ducc_fft }}
102+
cmake -S . -B ./build -G Ninja -DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache -DCMAKE_BUILD_TYPE:STRING=${{matrix.build_type}} -DFINUFFT_ARCH_FLAGS=${{ matrix.arch_flags }} -DFINUFFT_BUILD_TESTS=ON -DFINUFFT_STATIC_LINKING=${{matrix.finufft_static_linking}} -DFINUFFT_USE_DUCC0=${{ matrix.ducc_fft }}
103+
env:
104+
CPM_SOURCE_CACHE: cpm
50105
- name: Build
51106
run: |
52107
cmake --build ./build --config ${{matrix.build_type}}
@@ -57,31 +112,34 @@ jobs:
57112
ctest -C ${{matrix.build_type}} --output-on-failure
58113
59114
- name: Set up Python
60-
if: matrix.finufft_static_linking
115+
if: matrix.finufft_static_linking == 'off'
61116
uses: actions/setup-python@v5
62117
with:
63118
python-version: '3.10'
64119

65120
- name: Build Python wheels
66-
if: matrix.finufft_static_linking
121+
if: matrix.finufft_static_linking == 'off'
67122
env:
68123
MACOSX_DEPLOYMENT_TARGET: 13
124+
CPM_SOURCE_CACHE: cpm
69125
shell: bash
70126
run: |
71127
python3 -m pip install \
72128
--verbose \
73129
-C cmake.define.CMAKE_BUILD_TYPE=${{ matrix.build_type }} \
74130
-C cmake.define.FINUFFT_ARCH_FLAGS=${{ matrix.arch_flags }} \
75131
-C cmake.define.FINUFFT_USE_DUCC0=${{ matrix.ducc_fft }} \
132+
-C cmake.define.CMAKE_CXX_COMPILER_LAUNCHER=sccache \
133+
-C cmake.define.CMAKE_C_COMPILER_LAUNCHER=sccache \
76134
python/finufft
77135
78136
- name: Install pytest
79-
if: matrix.finufft_static_linking
137+
if: matrix.finufft_static_linking == 'off'
80138
run: |
81139
python3 -m pip install --upgrade pip
82140
python3 -m pip install pytest
83141
84142
- name: Test Python package
85-
if: matrix.finufft_static_linking
143+
if: matrix.finufft_static_linking == 'off'
86144
run: |
87145
python3 -m pytest python/finufft/test

.github/workflows/generate_cmake_matrix.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
})
3434
]
3535

36-
3736
def get_c_compiler(toolchain):
3837
if "gcc" in toolchain:
3938
return "gcc"
@@ -70,7 +69,7 @@ def get_cxx_compiler(toolchain):
7069
"build_type": build,
7170
"c_compiler": get_c_compiler(toolchain),
7271
"cxx_compiler": get_cxx_compiler(toolchain),
73-
"ducc_fft": ducc
72+
"ducc_fft": ducc,
7473
})
7574
json_str = json.dumps(matrix, ensure_ascii=False)
7675
print(json_str)

CHANGELOG

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ List of features / changes made / release notes, in reverse chronological order.
22
If not stated, FINUFFT is assumed (cuFINUFFT <=1.3 is listed separately).
33

44
Master, using release name V 2.4.0 (1/7/25)
5-
5+
* PR614: Added support for sccache in github actions.
6+
Caching cmake dependencies so to avoid downloading fftw, xsimd, etc. every time.
67
* fully removed chkbnds option (opts and spreadopts) (Barnett)
78
* classic GNU makefile settings make.inc.* tidied to make-platforms/ (Barnett)
89
* unified separate-dim arrays (eg X,Y,Z->XYZ), simplifiying core (Reinecke #592)

CMakeLists.txt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,26 @@ set(FINUFFT_CXX_FLAGS_DEBUG
7979
-g3
8080
-ggdb
8181
-ggdb3
82-
/Zi
8382
-Wall
8483
-Wno-sign-compare
8584
-Wno-unknown-pragmas)
85+
86+
if(DEFINED ENV{GITHUB_ACTIONS})
87+
if($ENV{GITHUB_ACTIONS} STREQUAL "true")
88+
message("CMake is being executed inside a GitHub workflow")
89+
# if msvc use FS flag
90+
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND NOT CMAKE_BUILD_TYPE STREQUAL
91+
"Release")
92+
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT
93+
"$<$<CONFIG:Debug,RelWithDebInfo>:Embedded>")
94+
message("CMAKE_MSVC_DEBUG_INFORMATION_FORMAT TO Embedded")
95+
endif()
96+
endif()
97+
else()
98+
message("CMake is NOT being executed inside a GitHub workflow")
99+
# env variable is:
100+
message(STATUS "ENV{GITHUB_ACTIONS}: $ENV{GITHUB_ACTIONS}")
101+
endif()
86102
filter_supported_compiler_flags(FINUFFT_CXX_FLAGS_DEBUG FINUFFT_CXX_FLAGS_DEBUG)
87103
message(STATUS "FINUFFT Debug flags: ${FINUFFT_CXX_FLAGS_DEBUG}")
88104
list(APPEND FINUFFT_CXX_FLAGS_RELWITHDEBINFO ${FINUFFT_CXX_FLAGS_RELEASE}

0 commit comments

Comments
 (0)