-
Notifications
You must be signed in to change notification settings - Fork 0
237 lines (213 loc) · 8.86 KB
/
release.yml
File metadata and controls
237 lines (213 loc) · 8.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
name: release
on:
push:
tags:
- "v*"
workflow_dispatch:
jobs:
sdist:
name: Build sdist
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Build source distribution
run: |
python -m pip install -U pip build
python -m build -s
- name: Upload sdist
uses: actions/upload-artifact@v4
with:
name: dist-sdist
path: dist/*
if-no-files-found: error
# ----- Linux (native x86_64 + native aarch64) -----
wheels-linux:
name: Build Linux wheels (${{ matrix.arch }})
strategy:
fail-fast: false
matrix:
include:
- arch: x86_64
runner: ubuntu-latest
image_var: CIBW_MANYLINUX_X86_64_IMAGE
- arch: aarch64
runner: ubuntu-24.04-arm
image_var: CIBW_MANYLINUX_AARCH64_IMAGE
runs-on: ${{ matrix.runner }}
permissions:
contents: read
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Restore ccache
uses: actions/cache@v4
with:
path: .ccache
key: ccache-linux-${{ matrix.arch }}-${{ hashFiles('**/CMakeLists.txt', '**/*.cmake', '**/*.cpp', '**/*.h', 'pyproject.toml') }}
- name: Build wheels with cibuildwheel (${{ matrix.arch }})
uses: pypa/cibuildwheel@v2.21.3
env:
CIBW_BUILD: cp310-* cp311-* cp312-*
CIBW_SKIP: pp* *-musllinux_*
CIBW_ARCHS_LINUX: ${{ matrix.arch }}
${{ matrix.image_var }}: manylinux_2_28
# Install build tools + FFTW + Boost headers; robust ccache fallback (pkg -> prebuilt -> source)
CIBW_BEFORE_ALL_LINUX: |
set -eux
pm_install() {
if command -v dnf >/dev/null 2>&1; then
dnf -y install pkgconfig ninja-build unzip make which curl ca-certificates xz tar gzip cmake gcc-c++ fftw fftw-devel boost-devel libzstd libzstd-devel || true
elif command -v yum >/dev/null 2>&1; then
yum -y install pkgconfig ninja-build unzip make which curl ca-certificates xz tar gzip cmake gcc-c++ fftw fftw-devel boost-devel libzstd libzstd-devel || true
elif command -v microdnf >/dev/null 2>&1; then
microdnf -y install pkgconfig ninja-build unzip make which curl ca-certificates xz tar gzip cmake gcc-c++ fftw fftw-devel boost-devel libzstd libzstd-devel || true
elif command -v apt-get >/dev/null 2>&1; then
apt-get update -y
apt-get install -y --no-install-recommends \
pkg-config ninja-build unzip make curl ca-certificates xz-utils tar gzip cmake g++ \
libfftw3-3 libfftw3-dev libboost-all-dev zstd libzstd-dev
else
echo "No supported package manager found" >&2
exit 1
fi
}
install_ccache() {
# 1) Try package manager
if command -v dnf >/devnull 2>&1; then dnf -y install ccache || true; fi
if command -v yum >/devnull 2>&1; then yum -y install ccache || true; fi
if command -v microdnf >/devnull 2>&1; then microdnf -y install ccache || true; fi
if command -v apt-get >/devnull 2>&1; then apt-get install -y --no-install-recommends ccache || true; fi
if command -v ccache >/dev/null 2>&1; then return 0; fi
# 2) Try official prebuilt tarball
ver="4.11.3"
arch="$(uname -m)"
url="https://github.com/ccache/ccache/releases/download/v${ver}/ccache-${ver}-linux-${arch}.tar.xz"
if curl -fsSL "$url" -o /tmp/ccache.tar.xz; then
mkdir -p /usr/local/ccache
tar -xJf /tmp/ccache.tar.xz -C /usr/local/ccache --strip-components=1
ln -sf /usr/local/ccache/bin/ccache /usr/local/bin/ccache
fi
if command -v ccache >/dev/null 2>&1; then return 0; fi
# 3) Build from source with CMake (last resort)
src="4.11.3"
tmpd="$(mktemp -d)"
curl -fsSL "https://github.com/ccache/ccache/releases/download/v${src}/ccache-${src}.tar.gz" -o "${tmpd}/ccache.tar.gz"
tar -xzf "${tmpd}/ccache.tar.gz" -C "${tmpd}"
cmake -S "${tmpd}/ccache-${src}" -B "${tmpd}/build" -DCMAKE_BUILD_TYPE=Release
cmake --build "${tmpd}/build" -j"$(nproc)"
cmake --install "${tmpd}/build"
ln -sf /usr/local/bin/ccache /usr/local/ccache/bin/ccache || true
}
pm_install
install_ccache
command -v ccache >/dev/null || { echo "ccache still missing"; exit 1; }
CIBW_ENVIRONMENT_LINUX: >
CC=gcc
CXX=g++
CCACHE_DIR=/project/.ccache
CMAKE_ARGS="-G Ninja -DHF_USE_OPENMP=ON -DHF_USE_FFTW_THREADS=ON -DBOOST_INCLUDEDIR=/usr/include -DCMAKE_CXX_COMPILER_LAUNCHER=ccache"
CMAKE_BUILD_PARALLEL_LEVEL=$(nproc)
CIBW_REPAIR_WHEEL_COMMAND_LINUX: >
bash -lc 'auditwheel repair -w {dest_dir} {wheel}'
CIBW_TEST_REQUIRES: numpy
CIBW_TEST_COMMAND: |
python - <<'PY'
import numpy as np, cpp_hf
nk,d=4,2
w=np.ones((nk,nk))*((2/nk)*(2/nk)/(2*np.pi)**2)
H=np.zeros((nk,nk,d,d),np.complex128)
K=np.linspace(-1,1,nk)
V=(1.0/np.sqrt((K[:,None]**2+K[None,:]**2)+0.2)).astype(np.complex128)[...,None,None]
P0=np.zeros_like(H)
ne=0.5*d*w.sum()
P,F,E,mu,n=cpp_hf.hartreefock_iteration_cpp(w,H,V,P0,ne,0.2,1,1e-2,2,1.0)
print("wheel ok", int(n), float(mu))
PY
- name: Upload Linux ${{ matrix.arch }} wheels
uses: actions/upload-artifact@v4
with:
name: dist-wheels-linux-${{ matrix.arch }}
path: wheelhouse/*
if-no-files-found: error
# ----- macOS (Intel/Apple Silicon) -----
wheels-macos:
name: Build macOS wheels (Intel/Apple Silicon)
strategy:
fail-fast: false
matrix:
runner: [macos-13, macos-14]
runs-on: ${{ matrix.runner }}
env:
MACOSX_DEPLOYMENT_TARGET: ${{ matrix.runner == 'macos-14' && '14.0' || '13.0' }}
permissions:
contents: read
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Homebrew deps
env:
HOMEBREW_NO_AUTO_UPDATE: "1"
run: |
rm -f "$HOME/Library/Caches/Homebrew/downloads/"*libomp* || true
brew install fftw libomp boost cmake ninja || true
- name: Build wheels with cibuildwheel
uses: pypa/cibuildwheel@v2.21.3
env:
CIBW_BUILD: cp310-* cp311-* cp312-*
CIBW_SKIP: pp*
CIBW_ARCHS_MACOS: native
CIBW_ENVIRONMENT_MACOS: >
PKG_CONFIG_PATH=/opt/homebrew/lib/pkgconfig:/usr/local/lib/pkgconfig
CMAKE_ARGS="-DHF_USE_OPENMP=ON -DHF_USE_FFTW_THREADS=ON -DCMAKE_OSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET}"
CIBW_REPAIR_WHEEL_COMMAND_MACOS: >
bash -lc 'delocate-listdeps -d {wheel} || true; MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET} delocate-wheel -L /opt/homebrew/lib -L /usr/local/lib --require-archs {delocate_archs} -w {dest_dir} -v {wheel}'
CIBW_TEST_REQUIRES: numpy
CIBW_TEST_COMMAND: |
python - <<'PY'
import numpy as np, cpp_hf
nk,d=4,2
w=np.ones((nk,nk))*((2/nk)*(2/nk)/(2*np.pi)**2)
H=np.zeros((nk,nk,d,d),np.complex128)
K=np.linspace(-1,1,nk)
V=(1.0/np.sqrt((K[:,None]**2+K[None,:]**2)+0.2)).astype(np.complex128)[...,None,None]
P0=np.zeros_like(H)
ne=0.5*d*w.sum()
P,F,E,mu,n=cpp_hf.hartreefock_iteration_cpp(w,H,V,P0,ne,0.2,1,1e-2,2,1.0)
print("wheel ok", int(n), float(mu))
PY
- name: Upload macOS wheels
uses: actions/upload-artifact@v4
with:
name: dist-wheels-${{ matrix.runner }}
path: wheelhouse/*
if-no-files-found: error
# ----- Publish to PyPI -----
publish:
name: Publish to PyPI
needs: [sdist, wheels-linux, wheels-macos]
runs-on: ubuntu-latest
environment: cpp_hf_env
permissions:
contents: read
id-token: write
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
pattern: dist-*
merge-multiple: true
path: dist
- name: Publish to PyPI via OIDC (Trusted Publisher)
if: startsWith(github.ref, 'refs/tags/v')
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist/