Skip to content

Commit

Permalink
Update and simplify cmake (#495)
Browse files Browse the repository at this point in the history
* cmake build system revamped completely, more modern practices.
  It auto selects compiler flags based on the supported ones on all operating systems.
  Added support for Windows (llvm, msvc), Linux (llvm, gcc) and MacOS (llvm, gcc).
* cmake support for both ducc0 and fftw
* cmake adding nvcc and msvc optimization flags
* updated CI to test multiple combinations of ffts, os, compilers
  • Loading branch information
DiamonDinoia authored Jul 31, 2024
1 parent 4e89cf9 commit 4a176c4
Show file tree
Hide file tree
Showing 17 changed files with 914 additions and 578 deletions.
100 changes: 28 additions & 72 deletions .github/workflows/cmake_ci.yml
Original file line number Diff line number Diff line change
@@ -1,101 +1,57 @@
name: cmake ci linux macos windows
on:
push:
release:
types: [published]

on: [push, pull_request]

jobs:
prepare:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.generate_matrix.outputs.matrix }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Generate matrix
id: generate_matrix
run: |
echo "MACOSX_DEPLOYMENT_TARGET=11.0" >> $GITHUB_ENV
MATRIX=$(python3 ${{ github.workspace }}/.github/workflows/generate_cmake_matrix.py)
echo "matrix=$MATRIX" >> $GITHUB_OUTPUT
cmake-ci:
runs-on: ${{ matrix.os }}
needs: prepare
strategy:
fail-fast: false
matrix:
os:
- windows-2022
- ubuntu-22.04
- macos-13
compiler:
- llvm
- gcc-12
# you can specify the version after `-` like `llvm-13.0.0`.
generator:
- "Ninja"
build_type:
- Release
finufft_static_linking:
- ON
include:
- os: "windows-2022"
compiler: "msvc"
generator: "Ninja"
build_type: "Release"
finufft_static_linking: "OFF"
exclude:
- os: "windows-2022"
compiler: "gcc-12"
generator: "Ninja"
build_type: "Release"
matrix: ${{ fromJSON(needs.prepare.outputs.matrix) }}
steps:
- uses: actions/checkout@v4

- name: Unlink gcc
if: runner.os == 'macOS'
run: |
brew unlink gcc
continue-on-error: true

- name: Checkout code
uses: actions/checkout@v4
- name: Setup Cpp
uses: aminya/setup-cpp@v1
with:
compiler: ${{ matrix.compiler }}
compiler: ${{ matrix.toolchain }}
vcvarsall: ${{ contains(matrix.os, 'windows') }}
cmake: true
ninja: true
vcpkg: false
cppcheck: false
clangtidy: false

- name: Install macOS dependencies
- name: Set min macOS version and install fftw
if: runner.os == 'macOS'
run: |
brew install fftw
- name: Install fftw
if: runner.os == 'linux'
run: |
sudo apt update
sudo apt install -y libfftw3-dev
- name: Configure Cmake
run: |
cmake -S . -B ./build -G "${{matrix.generator}}" -DCMAKE_BUILD_TYPE:STRING=${{matrix.build_type}} -DFINUFFT_BUILD_TESTS=ON -DFINUFFT_STATIC_LINKING=${{matrix.finufft_static_linking}}
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 }}
- name: Build
run: |
cmake --build ./build --config ${{matrix.build_type}}
- name: Test
working-directory: ./build
run: |
ctest -C ${{matrix.build_type}}
# may change to cpack and action-gh-release later
- name: Upload static and shared lib
uses: actions/upload-artifact@v4
with:
name: ${{matrix.os}}-${{matrix.compiler}}-finufft-lib
path: ${{runner.workspace}}/finufft/build/*finufft*

- name: Pack For Release
if: startsWith(github.ref, 'refs/tags/') && github.event_name == 'release' && github.event.action == 'published'
shell: bash
run: |
cd build
if [[ "${{ matrix.os }}" == "windows-2022" ]]
then
7z a ../${{matrix.os}}-${{matrix.compiler}}-finufft-lib.zip *finufft*
else
tar czvf ../${{matrix.os}}-${{matrix.compiler}}-finufft-lib.tar.gz *finufft*
fi
cd -
- name: Publish
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/') && github.event_name == 'release' && github.event.action == 'published'
with:
files: |
*-finufft-lib*
ctest -C ${{matrix.build_type}} --output-on-failure
76 changes: 76 additions & 0 deletions .github/workflows/generate_cmake_matrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import json

matrix = {
"include": []
}

static_linking = ["On", "Off"]

combinations = [
("ubuntu-22.04", {
"build_type": ["Release", "Debug"],
"toolchain": ["llvm", "gcc"],
"arch_flags": ["-march=native", "-march=x86-64", "native"],
"ducc_fft": ["On", "Off"]
}),
("windows-2022", {
"build_type": ["Release", "Debug"],
"toolchain": ["msvc"],
"arch_flags": ["/arch:AVX2", "/arch:SSE2", "native"],
"ducc_fft": ["On", "Off"]
}),
("windows-2022", {
"build_type": ["Release"],
"toolchain": ["llvm"],
"arch_flags": ["-march=native", "-march=x86-64", "native"],
"ducc_fft": ["On", "Off"]
}),
("macos-13", {
"build_type": ["Release", "Debug"],
"toolchain": ["llvm", "gcc-14"],
"arch_flags": ["-march=native", "-march=x86-64", "native"],
"ducc_fft": ["On", "Off"]
})
]


def get_c_compiler(toolchain):
if "gcc" in toolchain:
return "gcc"
elif toolchain == "llvm":
return "clang"
elif toolchain == "msvc":
return "cl"
else:
raise ValueError(f"Unknown toolchain: {toolchain}")


def get_cxx_compiler(toolchain):
if "gcc" in toolchain:
return "g++"
elif toolchain == "llvm":
return "clang++"
elif toolchain == "msvc":
return "cl"
else:
raise ValueError(f"Unknown toolchain: {toolchain}")


for platform, value in combinations:
for toolchain in value["toolchain"]:
for arch_flag in value["arch_flags"]:
for linking in static_linking:
for build in value["build_type"]:
for ducc in value["ducc_fft"]:
matrix["include"].append({
"os": platform,
"toolchain": toolchain,
"arch_flags": arch_flag,
"finufft_static_linking": linking,
"build_type": build,
"c_compiler": get_c_compiler(toolchain),
"cxx_compiler": get_cxx_compiler(toolchain),
"ducc_fft": ducc
})
json_str = json.dumps(matrix, ensure_ascii=False)
print(json_str)
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,11 @@ repos:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/cheshirekow/cmake-format-precommit
rev: v0.6.13
hooks:
- id: cmake-format
additional_dependencies: [pyyaml]
args: [--line-width=180]
types: [file]
files: (\.cmake|CMakeLists.txt)(.in)?$
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ V 2.3.0beta (7/24/24)
any 32-bit integers to 64-bit when calling cufinufft(f)_setpts. Note that
internally, 32-bit integers are still used, so calling cufinufft with more
than 2e9 points will fail. This restriction may be lifted in the future.
* cmake build system revamped completely, more modern practices.
It auto selects compiler flags based on the supported ones on all operating systems.
Added support for Windows (llvm, msvc), Linux (llvm, gcc) and MacOS (llvm, gcc).
* cmake support for both ducc0 and fftw
* cmake adding nvcc and msvc optimization flags

V 2.2.0 (12/12/23)

Expand Down
Loading

0 comments on commit 4a176c4

Please sign in to comment.