Skip to content

Commit b6433f3

Browse files
committed
set up cibuildwheel
1 parent 7b69f35 commit b6433f3

File tree

8 files changed

+186
-7
lines changed

8 files changed

+186
-7
lines changed

.github/workflows/ci-cmake_tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
name: Tests and Codecov
22
on:
3-
pull_request:
4-
branches:
5-
- master
63
workflow_dispatch:
74
jobs:
85
BuildAndTest:

.github/workflows/clang-format-check.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
name: clang-format Check
22
on:
3-
pull_request:
43
workflow_dispatch:
54
jobs:
65
formatting-check:

.github/workflows/conda_build.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ on:
44
push:
55
branches:
66
- master
7-
pull_request:
8-
branches:
9-
- master
107
workflow_dispatch:
118

129
jobs:

.github/workflows/release_pypi.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Release to PyPI
2+
3+
on:
4+
pull_request:
5+
workflow_dispatch:
6+
7+
jobs:
8+
BuildWheel:
9+
name: BuildWheel-${{ matrix.os }}
10+
runs-on: ${{ matrix.os }}
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
os: [ubuntu-latest, macos-14, macos-15-intel]
15+
# os: [ubuntu-latest]
16+
defaults:
17+
run:
18+
shell: bash -l {0}
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
25+
# When re-running a PR job, GitHub Actions uses the merge commit created at
26+
# the time of the original run, not a fresh merge with the latest target branch.
27+
# This step ensures we always test against the most recent target branch.
28+
- name: Merge with latest target branch (pull_request only)
29+
if: github.event_name == 'pull_request'
30+
run: |
31+
git fetch origin ${{ github.event.pull_request.base.ref }}
32+
git merge --no-edit origin/${{ github.event.pull_request.base.ref }}
33+
34+
- name: Cache Ccache Directory (pull_request)
35+
if: ${{ github.event_name == 'pull_request' }}
36+
uses: actions/cache@v4
37+
with:
38+
path: |
39+
~/.ccache
40+
key: ccache-${{ runner.os }}-${{ github.event.pull_request.head.ref }}-${{ github.sha }}
41+
restore-keys: |
42+
ccache-${{ runner.os }}-${{ github.event.pull_request.head.ref }}-
43+
ccache-${{ runner.os }}-${{ github.event.pull_request.base.ref }}-
44+
45+
- name: Set Ccache Directory
46+
run: |
47+
echo "Start building---------------------------------"
48+
export CCACHE_DIR="${HOME}/.ccache"
49+
50+
- name: Setup macOS
51+
if: matrix.os == 'macos-15-intel' || matrix.os == 'macos-14'
52+
run: |
53+
if [[ ${{ matrix.os }} == 'macos-15-intel' ]]; then
54+
echo "MACOSX_DEPLOYMENT_TARGET=15.0" >> "$GITHUB_ENV"
55+
elif [[ ${{ matrix.os }} == 'macos-14' ]]; then
56+
echo "MACOSX_DEPLOYMENT_TARGET=14.0" >> "$GITHUB_ENV"
57+
fi
58+
59+
- name: Build Wheels
60+
uses: pypa/cibuildwheel@v3.3.0
61+
env:
62+
CMAKE_C_COMPILER_LAUNCHER: ccache
63+
CMAKE_CXX_COMPILER_LAUNCHER: ccache
64+
CMAKE_CUDA_COMPILER_LAUNCHER: ccache
65+
# DO NOT enable this line because the script for conda build is not
66+
# executed in a interactive shell, and "~" will not be expanded to the
67+
# home directory. Export CCACHE_DIR in the run command instead.
68+
# CCACHE_DIR: ~/.ccache
69+
CCACHE_MAXSIZE: 1G # The limit of actions/cache is 10GB
70+
# Pass environment variables into cibuildwheel build environments
71+
# This is only needed on Linux becuase the wheels are built in docker
72+
# images only on Linux.
73+
CIBW_ENVIRONMENT_PASS_LINUX: CMAKE_C_COMPILER_LAUNCHER CMAKE_CXX_COMPILER_LAUNCHER CMAKE_CUDA_COMPILER_LAUNCHER CCACHE_MAXSIZE
74+
75+
- uses: actions/upload-artifact@v4
76+
with:
77+
name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
78+
path: ./wheelhouse/*.whl

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,14 @@ if(USE_CUDA)
191191
set(CMAKE_CUDA_USE_RESPONSE_FILE_FOR_OBJECTS 0)
192192
endif()
193193

194+
195+
# Print all environment variables for debugging
196+
message(STATUS "==================== Environment Variables ====================")
197+
execute_process(COMMAND ${CMAKE_COMMAND} -E environment
198+
OUTPUT_VARIABLE ENV_OUTPUT)
199+
message(STATUS "${ENV_OUTPUT}")
200+
message(STATUS "================================================================")
201+
194202
# C++ uses link-time optimization anyway; this enables additionally -flto=auto,
195203
# for parallel compilation
196204
# It cannot enable on MacOS since it causes building errors when linking the library libcytnx.a.

pyproject.toml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ cmake.args = [
4343
# conflicts against the build process of HPTT.
4444
"-G Unix Makefiles",
4545
]
46+
# Force the build directory to be "build" instead of a random temp folder. This helps
47+
# ccache caches the compiler outputs successfully.
48+
build-dir = "build/{wheel_tag}"
49+
# cp39-cp39-macosx_14_0_arm64
4650

4751
[tool.scikit-build.metadata.version]
4852
provider = "scikit_build_core.metadata.regex"
@@ -53,3 +57,28 @@ set\(\w+?VERSION_MINOR\s+(?P<minor>\d+)\)
5357
set\(\w+?VERSION_PATCH\s+(?P<patch>\d+)\)
5458
'''
5559
result = "{major}.{minor}.{patch}"
60+
61+
[tool.cibuildwheel]
62+
# The image used to build wheels for x86_64 on Linux is manylinux_2_28, which supports
63+
# older version of Linux than manylinux_2_34. However, manylinux_2_28 is AlmaLinux 8
64+
# based and AlmaLinux 8 ships Boost v1.66. The Boost's CMake configuration files are only
65+
# available since v1.70, so AlmaLinux 9 based manylinux_2_34 is picked here.
66+
# There is a caveat for manylinux_2_34. manylinux_2_34 assume the machines use x86-64-v2
67+
# architecture which is an extension of x86_64, so the wheels built with manylinux_2_34
68+
# may not support older machines. See https://github.com/pypa/manylinux?tab=readme-ov-file#manylinux_2_34-almalinux-9-based---alpha
69+
# for more information.
70+
manylinux-x86_64-image = "manylinux_2_34"
71+
72+
[tool.cibuildwheel.linux]
73+
# before-all = "apt-get install -y arpack boost ccache libomp openblas"
74+
before-all = "bash ./tools/cibuildwheel_before_all.sh"
75+
76+
[tool.cibuildwheel.macos]
77+
before-all = "brew update; brew install arpack boost ccache libomp openblas"
78+
environment = { CMAKE_PREFIX_PATH = "$(brew --prefix arpack):$(brew --prefix boost):$(brew --prefix libomp):$(brew --prefix openblas)", PATH = "$(brew --prefix ccache)/libexec:$PATH" }
79+
80+
# [tool.cibuildwheel]
81+
# before-build = "bash {project}/tools/cibuildwheel_before_build.sh"
82+
# # environment = { CMAKE_PREFIX_PATH = "$(brew --prefix openblas)", PATH = "$(brew --prefix ccache)/libexec:$PATH" }
83+
# # Alternative static configuration for macOS:
84+
# environment = { CMAKE_PREFIX_PATH = "/opt/homebrew/opt/openblas", PATH = "/opt/homebrew/opt/ccache/libexec:$PATH" }

tools/cibuildwheel_before_all.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
set -xe
2+
3+
yum search lapack
4+
yum --showduplicates list "lapack*"
5+
# yum install -y arpack-devel boost-devel ccache lapack-devel libomp-devel openblas-devel
6+
yum install -y arpack-devel boost-devel ccache libomp-devel openblas-devel
7+
# On Red Hat/CentOS systems (which manylinux images are based on), the lapack-devel
8+
# package typically provides the Fortran bindings and miss the C-interface header, so
9+
# use lapacke.h shipped with openblas instead.
10+
ls /usr/include
11+
ln -s /usr/include/openblas/lapacke.h /usr/include/lapacke.h
12+
ln -s /usr/include/openblas/lapack.h /usr/include/lapack.h
13+
ls /usr/include/openblas
14+
# boost1.78-devel
15+
# ls /usr/include/boost | head
16+
# ls /usr/lib64/libboost_*.so

tools/cibuildwheel_before_build.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
set -xe
2+
3+
# Install OpenBLAS
4+
# python -m pip install scipy-openblas64
5+
# blas_lib_dir=$(python -c "import scipy_openblas64; print(scipy_openblas64.get_lib_dir())")
6+
# blas_lib_name=$(python -c "import scipy_openblas64; print(scipy_openblas64.get_library())")
7+
# # This handles different extensions (.so on Linux, .dylib on macOS)
8+
# blas_lib_file=$(find "$blas_lib_dir" -name "*${blas_lib_name}.*" -type f | head -n 1)
9+
# export BLAS_LIBRARIES="$blas_lib_file"
10+
11+
# # Verify BLAS_LIBRARIES points to an existing file
12+
# if [ -f "$BLAS_LIBRARIES" ]; then
13+
# echo "✓ BLAS_LIBRARIES points to existing file: $BLAS_LIBRARIES"
14+
# else
15+
# echo "✗ ERROR: BLAS_LIBRARIES does not point to a valid file: $BLAS_LIBRARIES"
16+
# exit 1
17+
# fi
18+
19+
# BLA_SIZEOF_INTEGER=8 matches the ILP64 openblas64_ interface
20+
# that scipy-openblas64 provides; this avoids CMake thinking
21+
# it found a 32-bit BLAS.
22+
# export BLA_SIZEOF_INTEGER=8
23+
24+
25+
uname -s
26+
# Set up Homebrew for Linux
27+
# Homebrew was removed from PATH on Linux:
28+
# https://github.com/actions/runner-images/issues/6283
29+
if [[ "$(uname -s)" == "Linux" ]]; then
30+
# Find linuxbrew from root folder recursively
31+
# Common locations: /home/linuxbrew/.linuxbrew, /home/*/linuxbrew/.linuxbrew
32+
# brew_find=$(find / -name "*linuxbrew*" -type d 2>/dev/null)
33+
# linuxbrew_bin=$(echo $brew_find | head -n 1)
34+
# if [ -n "$linuxbrew_bin" ] && [ -d "$linuxbrew_bin/bin" ]; then
35+
# echo "Found linuxbrew at: $linuxbrew_bin"
36+
# export PATH="$linuxbrew_bin/bin:$PATH"
37+
# else
38+
# echo "Warning: linuxbrew not found, trying default path"
39+
# export PATH="/home/linuxbrew/.linuxbrew/bin:$PATH"
40+
# fi
41+
export PATH="/host/home/linuxbrew/.linuxbrew/bin:$PATH"
42+
fi
43+
44+
# Install boost, ccache and arpack-ng
45+
# All Ubuntu and macOS GitHub action runners have Homebrew installed.
46+
brew install boost ccache arpack openblas
47+
48+
brew --prefix openblas
49+
ls $(brew --prefix openblas)
50+
brew --prefix ccache
51+
ls $(brew --prefix ccache)
52+
brew --prefix arpack
53+
ls $(brew --prefix arpack)
54+
brew --prefix boost
55+
ls $(brew --prefix boost)

0 commit comments

Comments
 (0)