|
1 | | -name: publish-sdist |
| 1 | +name: release |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
5 | 5 | tags: |
6 | 6 | - "v*" |
| 7 | + workflow_dispatch: |
7 | 8 |
|
8 | 9 | jobs: |
9 | | - publish: |
| 10 | + sdist: |
| 11 | + name: Build sdist |
10 | 12 | runs-on: ubuntu-latest |
11 | 13 | permissions: |
12 | 14 | contents: read |
13 | | - id-token: write |
14 | 15 | steps: |
15 | 16 | - uses: actions/checkout@v4 |
16 | 17 |
|
17 | 18 | - uses: actions/setup-python@v5 |
18 | 19 | with: |
19 | 20 | python-version: "3.12" |
20 | 21 |
|
21 | | - - name: Install system deps |
| 22 | + - name: Build source distribution |
22 | 23 | run: | |
23 | | - sudo apt-get update |
24 | | - sudo apt-get install -y libfftw3-dev cmake ninja-build pkg-config |
| 24 | + python -m pip install -U pip build |
| 25 | + python -m build -s |
| 26 | +
|
| 27 | + - name: Upload sdist |
| 28 | + uses: actions/upload-artifact@v4 |
| 29 | + with: |
| 30 | + name: dist-sdist |
| 31 | + path: dist/* |
| 32 | + |
| 33 | + wheels-linux: |
| 34 | + name: Build Linux wheels (x86_64, aarch64) |
| 35 | + runs-on: ubuntu-latest |
| 36 | + permissions: |
| 37 | + contents: read |
| 38 | + steps: |
| 39 | + - uses: actions/checkout@v4 |
| 40 | + |
| 41 | + - name: Build wheels with cibuildwheel |
| 42 | + uses: pypa/cibuildwheel@v2.21.3 |
| 43 | + env: |
| 44 | + # CPython versions to build (match CI tests) |
| 45 | + CIBW_BUILD: cp310-* cp311-* cp312-* |
| 46 | + CIBW_SKIP: pp* *-musllinux_* |
| 47 | + CIBW_ARCHS_LINUX: x86_64 aarch64 |
| 48 | + # Build FFTW from source and stage Boost headers for CMake |
| 49 | + CIBW_BEFORE_ALL_LINUX: | |
| 50 | + set -eux |
| 51 | + # Ensure pkg-config is present in the manylinux container |
| 52 | + if command -v yum >/dev/null 2>&1; then |
| 53 | + yum -y install pkgconfig || true |
| 54 | + fi |
| 55 | + FFTW_V=3.3.10 |
| 56 | + curl -fsSL -o fftw.tar.gz http://www.fftw.org/fftw-${FFTW_V}.tar.gz |
| 57 | + tar -xzf fftw.tar.gz |
| 58 | + pushd fftw-${FFTW_V} |
| 59 | + ./configure --prefix=/opt/fftw --enable-shared --enable-threads |
| 60 | + make -j"$(nproc)" |
| 61 | + make install |
| 62 | + popd |
| 63 | +
|
| 64 | + # Boost headers (header-only; no build needed) |
| 65 | + BOOST_V=1_84_0 |
| 66 | + curl -fsSL -o boost.tar.bz2 https://boostorg.jfrog.io/artifactory/main/release/1.84.0/source/boost_${BOOST_V}.tar.bz2 |
| 67 | + tar -xjf boost.tar.bz2 |
| 68 | + mkdir -p /opt/boost/include |
| 69 | + cp -r boost_${BOOST_V}/boost /opt/boost/include/ |
| 70 | +
|
| 71 | + # Help CMake find FFTW via pkg-config and Boost headers via define |
| 72 | + CIBW_ENVIRONMENT_LINUX: > |
| 73 | + PKG_CONFIG_PATH=/opt/fftw/lib/pkgconfig |
| 74 | + CMAKE_PREFIX_PATH=/opt/fftw |
| 75 | + CMAKE_ARGS="-DHF_USE_OPENMP=ON -DHF_USE_FFTW_THREADS=ON -DBOOST_INCLUDE_DIR=/opt/boost/include" |
| 76 | +
|
| 77 | + # Quick import + tiny run test inside the wheel env |
| 78 | + CIBW_TEST_COMMAND: > |
| 79 | + python - <<'PY' |
| 80 | + import numpy as np, cpp_hf |
| 81 | + nk,d=4,2 |
| 82 | + w=np.ones((nk,nk))*((2/nk)*(2/nk)/(2*np.pi)**2) |
| 83 | + H=np.zeros((nk,nk,d,d),np.complex128) |
| 84 | + K=np.linspace(-1,1,nk) |
| 85 | + V=(1.0/np.sqrt((K[:,None]**2+K[None,:]**2)+0.2)).astype(np.complex128)[...,None,None] |
| 86 | + P0=np.zeros_like(H) |
| 87 | + ne=0.5*d*w.sum() |
| 88 | + P,F,E,mu,n=cpp_hf.hartreefock_iteration_cpp(w,H,V,P0,ne,0.2,1,1e-2,2,1.0) |
| 89 | + print("wheel ok", int(n), float(mu)) |
| 90 | + PY |
| 91 | +
|
| 92 | + - name: Upload Linux wheels |
| 93 | + uses: actions/upload-artifact@v4 |
| 94 | + with: |
| 95 | + name: dist-wheels-linux |
| 96 | + path: wheelhouse/* |
| 97 | + if-no-files-found: error |
25 | 98 |
|
26 | | - - name: Build distribution (sdist) |
| 99 | + wheels-macos: |
| 100 | + name: Build macOS wheels (Intel/Apple Silicon) |
| 101 | + strategy: |
| 102 | + fail-fast: false |
| 103 | + matrix: |
| 104 | + runner: [macos-13, macos-14] |
| 105 | + runs-on: ${{ matrix.runner }} |
| 106 | + permissions: |
| 107 | + contents: read |
| 108 | + steps: |
| 109 | + - uses: actions/checkout@v4 |
| 110 | + |
| 111 | + - name: Install Homebrew deps |
27 | 112 | run: | |
28 | | - python -m pip install -U pip build numpy scikit-build-core |
29 | | - python -m build -s |
| 113 | + brew update |
| 114 | + brew install fftw libomp boost cmake ninja pkg-config || true |
| 115 | +
|
| 116 | + - name: Build wheels with cibuildwheel |
| 117 | + uses: pypa/cibuildwheel@v2.21.3 |
| 118 | + env: |
| 119 | + CIBW_BUILD: cp310-* cp311-* cp312-* |
| 120 | + CIBW_SKIP: pp* |
| 121 | + # Let cibuildwheel build for the host arch on each runner |
| 122 | + CIBW_ARCHS_MACOS: native |
| 123 | + # Ensure pkg-config sees Homebrew's .pc files across both arch locations |
| 124 | + CIBW_ENVIRONMENT_MACOS: > |
| 125 | + PKG_CONFIG_PATH=/opt/homebrew/lib/pkgconfig:/usr/local/lib/pkgconfig |
| 126 | + CMAKE_ARGS="-DHF_USE_OPENMP=ON -DHF_USE_FFTW_THREADS=ON" |
| 127 | + CIBW_TEST_COMMAND: > |
| 128 | + python - <<'PY' |
| 129 | + import numpy as np, cpp_hf |
| 130 | + nk,d=4,2 |
| 131 | + w=np.ones((nk,nk))*((2/nk)*(2/nk)/(2*np.pi)**2) |
| 132 | + H=np.zeros((nk,nk,d,d),np.complex128) |
| 133 | + K=np.linspace(-1,1,nk) |
| 134 | + V=(1.0/np.sqrt((K[:,None]**2+K[None,:]**2)+0.2)).astype(np.complex128)[...,None,None] |
| 135 | + P0=np.zeros_like(H) |
| 136 | + ne=0.5*d*w.sum() |
| 137 | + P,F,E,mu,n=cpp_hf.hartreefock_iteration_cpp(w,H,V,P0,ne,0.2,1,1e-2,2,1.0) |
| 138 | + print("wheel ok", int(n), float(mu)) |
| 139 | + PY |
| 140 | +
|
| 141 | + - name: Upload macOS wheels |
| 142 | + uses: actions/upload-artifact@v4 |
| 143 | + with: |
| 144 | + name: dist-wheels-${{ matrix.runner }} |
| 145 | + path: wheelhouse/* |
| 146 | + if-no-files-found: error |
| 147 | + |
| 148 | + publish: |
| 149 | + name: Publish to PyPI |
| 150 | + needs: [sdist, wheels-linux, wheels-macos] |
| 151 | + runs-on: ubuntu-latest |
| 152 | + permissions: |
| 153 | + contents: read |
| 154 | + id-token: write |
| 155 | + steps: |
| 156 | + - name: Download all artifacts |
| 157 | + uses: actions/download-artifact@v4 |
| 158 | + with: |
| 159 | + pattern: dist-* |
| 160 | + merge-multiple: true |
| 161 | + path: dist |
30 | 162 |
|
31 | 163 | - name: Publish to PyPI via OIDC (Trusted Publisher) |
32 | 164 | uses: pypa/gh-action-pypi-publish@release/v1 |
|
0 commit comments