Skip to content

Commit 789b048

Browse files
committed
feat: build windows distributions with cibuildwheel in GH CI
Should avoid maintaining appveyor workflow (and free up appveyor account limitations πŸ˜‰). This also introduces windows aarch64 distributions πŸŽ‰ Lastly, I updated other spots in the GH actions workflow: - upgrade `actions/checkout` to v5 (only breaking changes are internal like upgrade node version used for building their dist) - turn off credential persistence in `actions/checkout` action (only useful if the workflow uses `git push` or similar) - upgrade `actions/download-artifact` to v5 (only breaking changes are internal because this already uses `merge-multiple: true`) - add job to check built distributions for non-tagged commits to default branch. This is meant to highlight any problems with dists' metadata before tagging a release. - add job to build sdist (for sake of completeness)
1 parent d0a1743 commit 789b048

File tree

3 files changed

+105
-3
lines changed

3 files changed

+105
-3
lines changed

β€Ž.github/workflows/wheels.ymlβ€Ž

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,19 @@ jobs:
2121
os: ubuntu-24.04-arm
2222
- name: macos
2323
os: macos-13
24+
- name: windows-x64
25+
os: windows-latest
26+
- name: windows-x86
27+
os: windows-latest
28+
- name: windows-arm64
29+
# https://github.com/actions/partner-runner-images#available-images
30+
os: windows-11-arm
2431

2532
steps:
26-
- uses: actions/checkout@v4
33+
- uses: actions/checkout@v5
34+
with:
35+
# avoid leaking credentials in uploaded artifacts
36+
persist-credentials: false
2737

2838
- uses: actions/setup-python@v6
2939
with:
@@ -33,6 +43,8 @@ jobs:
3343
run: python -m pip install cibuildwheel~=3.1.1
3444

3545
- name: Build wheels
46+
env:
47+
CIBW_ARCHS_WINDOWS: ${{ matrix.name == 'windows-x86' && 'auto32' || 'native' }}
3648
run: python -m cibuildwheel --output-dir wheelhouse
3749

3850
- uses: actions/upload-artifact@v4
@@ -45,7 +57,10 @@ jobs:
4557
runs-on: ubuntu-24.04
4658

4759
steps:
48-
- uses: actions/checkout@v4
60+
- uses: actions/checkout@v5
61+
with:
62+
# avoid leaking credentials in uploaded artifacts
63+
persist-credentials: false
4964

5065
- uses: actions/setup-python@v6
5166
with:
@@ -69,13 +84,50 @@ jobs:
6984
name: wheels-linux-ppc
7085
path: ./wheelhouse/*.whl
7186

87+
sdist:
88+
runs-on: ubuntu-latest
89+
steps:
90+
- uses: actions/checkout@v5
91+
with:
92+
# avoid leaking credentials in uploaded artifacts
93+
persist-credentials: false
94+
95+
- uses: actions/setup-python@v6
96+
with:
97+
python-version: '3.13'
98+
99+
- name: Build sdist
100+
run: pipx run build --sdist --outdir dist
101+
102+
- uses: actions/upload-artifact@v4
103+
with:
104+
name: wheels-sdist
105+
path: dist/*
106+
107+
twine-check:
108+
name: Twine check
109+
# It is good to do this check on non-tagged commits.
110+
# Note, pypa/gh-action-pypi-publish (see job below) does this automatically.
111+
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
112+
needs: [build_wheels, build_wheels_ppc, sdist]
113+
runs-on: ubuntu-latest
114+
115+
steps:
116+
- uses: actions/download-artifact@v5
117+
with:
118+
path: dist
119+
pattern: wheels-*
120+
merge-multiple: true
121+
- name: check distribution files
122+
run: pipx run twine check dist/*
123+
72124
pypi:
73125
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
74126
needs: [build_wheels, build_wheels_ppc]
75127
runs-on: ubuntu-24.04
76128

77129
steps:
78-
- uses: actions/download-artifact@v4
130+
- uses: actions/download-artifact@v5
79131
with:
80132
path: dist
81133
pattern: wheels-*

β€Žbuild.ps1β€Ž

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
if (!(Test-Path -Path "build")) {
2+
# in case the pygit2 package build/ workspace has not been created by cibuildwheel yet
3+
mkdir build
4+
}
5+
if (Test-Path -Path "$env:LIBGIT2_SRC") {
6+
Set-Location "$env:LIBGIT2_SRC"
7+
# for local runs, reuse build/libgit_src if it exists
8+
if (Test-Path -Path build) {
9+
# purge previous build env (likely for a different arch type)
10+
Remove-Item -Recurse -Force build
11+
}
12+
# ensure we are checked out to the right version
13+
git fetch --depth=1 --tags
14+
git checkout "v$env:LIBGIT2_VERSION"
15+
} else {
16+
# from a fresh run (like in CI)
17+
git clone --depth=1 -b "v$env:LIBGIT2_VERSION" https://github.com/libgit2/libgit2.git $env:LIBGIT2_SRC
18+
Set-Location "$env:LIBGIT2_SRC"
19+
}
20+
cmake -B build -S . -DBUILD_TESTS=OFF
21+
cmake --build build/ --config=Release --target install

β€Žpyproject.tomlβ€Ž

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,35 @@ archs = ["universal2"]
2424
environment = {LIBGIT2_VERSION="1.9.1", LIBSSH2_VERSION="1.11.1", OPENSSL_VERSION="3.3.3", LIBGIT2="/Users/runner/work/pygit2/pygit2/ci"}
2525
repair-wheel-command = "DYLD_LIBRARY_PATH=/Users/runner/work/pygit2/pygit2/ci/lib delocate-wheel --require-archs {delocate_archs} -w {dest_dir} {wheel}"
2626

27+
[tool.cibuildwheel.windows]
28+
environment.LIBGIT2_SRC = "build/libgit2_src"
29+
environment.LIBGIT2_VERSION = "1.9.1"
30+
before-all = "powershell -File build.ps1"
31+
32+
[[tool.cibuildwheel.overrides]]
33+
select="*-win_amd64"
34+
inherit.environment="append"
35+
environment.CMAKE_GENERATOR = "Visual Studio 17 2022"
36+
environment.CMAKE_GENERATOR_PLATFORM = "x64"
37+
environment.CMAKE_INSTALL_PREFIX = "C:/libgit2_install_x86_64"
38+
environment.LIBGIT2 = "C:/libgit2_install_x86_64"
39+
40+
[[tool.cibuildwheel.overrides]]
41+
select="*-win32"
42+
inherit.environment="append"
43+
environment.CMAKE_GENERATOR = "Visual Studio 17 2022"
44+
environment.CMAKE_GENERATOR_PLATFORM = "Win32"
45+
environment.CMAKE_INSTALL_PREFIX = "C:/libgit2_install_x86"
46+
environment.LIBGIT2 = "C:/libgit2_install_x86"
47+
48+
[[tool.cibuildwheel.overrides]]
49+
select="*-win_arm64"
50+
inherit.environment="append"
51+
environment.CMAKE_GENERATOR = "Visual Studio 17 2022"
52+
environment.CMAKE_GENERATOR_PLATFORM = "ARM64"
53+
environment.CMAKE_INSTALL_PREFIX = "C:/libgit2_install_arm64"
54+
environment.LIBGIT2 = "C:/libgit2_install_arm64"
55+
2756
[tool.ruff]
2857
extend-exclude = [ ".cache", ".coverage", "build", "site-packages", "venv*"]
2958
target-version = "py310" # oldest supported Python version

0 commit comments

Comments
Β (0)