Skip to content

Commit 64ede94

Browse files
authored
More binary builds v2 (#582)
* More binary builds v2 * fix version * fix archs * lets see what happens * fix cd script * typo * wut * ok, need true platform * comment and fix * fix builds * more fix * better test * fix test * fix win * try again * safer * add pushd * cannot install deps with no-index * maybe like this * had an extta popd * sod it * comments * try windows test
1 parent 9a9f7a7 commit 64ede94

File tree

3 files changed

+122
-82
lines changed

3 files changed

+122
-82
lines changed

.github/workflows/cd.yml

Lines changed: 65 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
# Github Actions script to produce binary wheels.
2+
#
3+
# Note that a lot of the cibuildwheel config is in pyproject.toml.
4+
#
5+
# We perform one build for each wheel that we generate, i.e. one per architecture.
6+
# In download_wgpu_native.py, we detect CIBW_PLATFORM and CIBW_ARCHS to determine
7+
# the required binary from wgpu-native.
8+
#
9+
# If https://github.com/pypa/cibuildwheel/issues/944 gets implemented, we can build more wheels per build.
10+
#
11+
# Also includes the sdist build that does not include a binary.
12+
13+
114
name: CD
215

316
on:
@@ -11,70 +24,75 @@ on:
1124

1225
jobs:
1326

14-
# The release builds are done for the platforms that we want to build wheels for.
15-
# We build wheels, test them, and then upload the wheel as an artifact.
1627
release-builds:
17-
name: Build wheels on ${{ matrix.os }}
28+
name: Build wheel for ${{ matrix.platform }} ${{ matrix.arch }}
1829
timeout-minutes: 10
1930
runs-on: ${{ matrix.os }}
2031
strategy:
2132
fail-fast: false
2233
matrix:
23-
os: [ubuntu-latest, windows-latest, macos-latest]
34+
include:
35+
- platform: windows
36+
arch: AMD64
37+
os: windows-latest
38+
testable: true
39+
- platform: windows
40+
arch: ARM64
41+
os: windows-latest
42+
- platform: windows
43+
arch: x86
44+
os: windows-latest
45+
- platform: macos
46+
arch: arm64
47+
os: macos-latest
48+
testable: true
49+
- platform: macos
50+
arch: x86_64
51+
os: macos-13 # last Intel MacOS
52+
cibw_version: '==2.16' # delocation does not work for later versions
53+
- platform: linux
54+
arch: x86_64
55+
os: ubuntu-latest
56+
testable: true
57+
- platform: linux
58+
arch: aarch64
59+
os: ubuntu-latest
2460
steps:
2561
- uses: actions/checkout@v4
26-
- name: Set up Python
27-
uses: actions/setup-python@v5
62+
- name: Set up QEMU
63+
if: matrix.platform == 'linux' && matrix.arch == 'aarch64'
64+
uses: docker/setup-qemu-action@v3
2865
with:
29-
python-version: '3.9'
66+
platforms: arm64
3067
- name: Install dev dependencies
3168
run: |
32-
python -m pip install --upgrade pip wheel setuptools twine
69+
python -m pip install --upgrade pip wheel setuptools twine cibuildwheel${{ matrix.cibw_version}}
3370
- name: Build wheels
34-
# Use v2.16, v2.20 fails the osx builds
35-
uses: pypa/[email protected]
71+
run: python -m cibuildwheel --output-dir dist
3672
env:
37-
CIBW_MANYLINUX_X86_64_IMAGE: quay.io/pypa/manylinux_2_28_x86_64
38-
CIBW_ARCHS_LINUX: x86_64
39-
CIBW_SKIP: cp39-musllinux_x86_64
40-
with:
41-
output-dir: dist
73+
CIBW_PLATFORM: ${{ matrix.platform }}
74+
CIBW_ARCHS: ${{ matrix.arch }}
4275
- name: Twine check
4376
run: |
4477
twine check dist/*
78+
- name: Test wheel
79+
if: matrix.testable
80+
shell: bash
81+
run: |
82+
rm -rf ./wgpu
83+
filename=$(ls dist/*.whl)
84+
pip install $filename
85+
pushd $HOME
86+
python -c 'import wgpu.backends.wgpu_native; print(wgpu.backends.wgpu_native._ffi.lib_path)'
87+
popd
88+
pip uninstall -y wgpu
89+
git reset --hard HEAD
4590
- name: Upload distributions
4691
uses: actions/upload-artifact@v4
4792
with:
4893
path: dist
49-
name: ${{ matrix.os }}-build
94+
name: ${{ matrix.platform }}-${{ matrix.arch }}-build
5095

51-
# These release builds uses QEMU so that we can build wheels for arm64.
52-
# We build wheels and upload the wheel as an artifact, but we don't test them here.
53-
qemu-release-builds:
54-
name: Build wheels on ubuntu-latest with QEMU
55-
timeout-minutes: 10
56-
runs-on: ubuntu-latest
57-
strategy:
58-
fail-fast: false
59-
steps:
60-
- uses: actions/checkout@v4
61-
- name: Set up QEMU
62-
uses: docker/setup-qemu-action@v3
63-
with:
64-
platforms: arm64
65-
- name: Build wheels
66-
uses: pypa/[email protected]
67-
env:
68-
CIBW_MANYLINUX_AARCH64_IMAGE: quay.io/pypa/manylinux_2_28_aarch64
69-
CIBW_ARCHS_LINUX: aarch64
70-
CIBW_SKIP: cp39-musllinux_aarch64
71-
with:
72-
output-dir: dist
73-
- name: Upload distributions
74-
uses: actions/upload-artifact@v4
75-
with:
76-
path: dist
77-
name: qemu-build
7896

7997
sdist-build:
8098
name: Build sdist
@@ -99,9 +117,8 @@ jobs:
99117
shell: bash
100118
run: |
101119
rm -rf ./wgpu
102-
pushd $HOME
103-
pip install $GITHUB_WORKSPACE/dist/*.tar.gz
104-
popd
120+
filename=$(ls dist/*.tar.gz)
121+
pip install $filename
105122
# don't run tests, we just want to know if the sdist can be installed
106123
pip uninstall -y wgpu
107124
git reset --hard HEAD
@@ -114,10 +131,11 @@ jobs:
114131
path: dist
115132
name: sdist-build
116133

134+
117135
publish:
118136
name: Publish to Github and Pypi
119137
runs-on: ubuntu-latest
120-
needs: [release-builds, qemu-release-builds, sdist-build]
138+
needs: [release-builds, sdist-build]
121139
if: success() && startsWith(github.ref, 'refs/tags/v')
122140
steps:
123141
- uses: actions/checkout@v4

download-wgpu-native.py

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ def extract_file(zip_filename, member, path):
6666

6767

6868
def get_os_string():
69-
if sys.platform.startswith("win"):
69+
if os.environ.get("CIBUILDWHEEL") == "1" and os.getenv("CIBW_PLATFORM"):
70+
return os.getenv("CIBW_PLATFORM")
71+
elif sys.platform.startswith("win"):
7072
return "windows"
7173
elif sys.platform.startswith("darwin"):
7274
return "macos"
@@ -84,24 +86,46 @@ def get_arch():
8486
is_64_bit = sys.maxsize > 2**32
8587
machine = platform.machine()
8688

87-
# See if this is run by cibuildwheel and check to see if ARCHFLAGS is
88-
# specified (only done on macOS). This allows to select the proper binaries.
89-
# For specifics of CIBUILDWHEEL and macOS build envs, see:
90-
# https://github.com/pypa/cibuildwheel/blob/4307b52ff28b631519d38bfa0dd09d6a9b39a81e/cibuildwheel/macos.py#L277
91-
if os.environ.get("CIBUILDWHEEL") == "1" and "ARCHFLAGS" in os.environ:
92-
archflags = os.environ["ARCHFLAGS"]
93-
return "aarch64" if "arm64" in archflags else "x86_64"
94-
9589
if machine == "armv7l":
9690
# Raspberry pi
97-
return "armv7"
91+
detected_arch = "armv7"
9892
elif is_64_bit and machine.startswith(("arm", "aarch64")):
9993
# Includes MacOS M1, arm linux, ...
100-
return "aarch64"
94+
detected_arch = "aarch64"
10195
elif is_64_bit:
102-
return "x86_64"
96+
detected_arch = "x86_64"
10397
else:
104-
return "i686"
98+
detected_arch = "i686"
99+
100+
if os.environ.get("CIBUILDWHEEL") == "1":
101+
# When running in cibuildwheel, we derive the intended arch from
102+
# an env var (the same one that cibuildwheel uses) that we set in cd.yml.
103+
cibw_arch = os.getenv("CIBW_ARCHS") # must be singular
104+
if not cibw_arch:
105+
# Linux builds run on Docker, so env is not visible
106+
cibw_arch = detected_arch
107+
elif "," in cibw_arch:
108+
raise RuntimeError("CIBW_ARCHS must have a single arch")
109+
arch_map = {
110+
"windows": {
111+
"AMD64": "x86_64",
112+
"ARM64": "aarch64",
113+
"x86": "i686",
114+
},
115+
"macos": {
116+
"arm64": "aarch64",
117+
"x86_64": "x86_64",
118+
},
119+
"linux": {
120+
"x86_64": "x86_64",
121+
"aarch64": "aarch64",
122+
"i868": "i686",
123+
},
124+
}
125+
maps_for_os = arch_map[get_os_string()]
126+
return maps_for_os[cibw_arch]
127+
128+
return detected_arch
105129

106130

107131
def main(version, os_string, arch, upstream):

pyproject.toml

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,31 @@
11
[build-system]
2-
requires = [
3-
"setuptools>=42",
4-
]
2+
requires = ["setuptools>=42"]
53
build-backend = "setuptools.build_meta"
64

5+
76
[tool.cibuildwheel]
87
# we only build on one python version since the wheels are not bound to it
9-
build = "cp39-*"
10-
11-
# we can't list requests under build-system.requires because
12-
# that step happens _after_ the before-build command
8+
build = "cp312-*"
9+
# Print system info before build
10+
before-all = "uname -a"
11+
# Can't list requests under build-system.requires because that step happens _after_ the before-build command
1312
before-build = "pip install requests && python download-wgpu-native.py"
14-
15-
# this is sufficient to trigger an install of the built wheel
13+
# This is sufficient to trigger an install of the built wheel
1614
test-command = "echo Wheel installed"
1715

18-
# this is the minimum supported manylinux version
19-
manylinux-x86_64-image = "manylinux_2_24"
20-
manylinux-i686-image = "manylinux_2_24"
21-
manylinux-aarch64-image = "manylinux_2_24"
22-
manylinux-ppc64le-image = "manylinux_2_24"
23-
manylinux-s390x-image = "manylinux_2_24"
24-
manylinux-pypy_x86_64-image = "manylinux_2_24"
25-
manylinux-pypy_i686-image = "manylinux_2_24"
26-
manylinux-pypy_aarch64-image = "manylinux_2_24"
16+
[tool.cibuildwheel.windows]
17+
# Only for local use, overridden in cd.yml
18+
archs = ["amd64"]
2719

2820
[tool.cibuildwheel.macos]
29-
# also create apple silicon wheels
30-
archs = ["x86_64", "arm64"]
21+
# Only for local use, overridden in cd.yml
22+
archs = ["arm64"]
3123

32-
# the upstream binaries are not universal yet
33-
# archs = ["x86_64", "universal2", "arm64"]
24+
[tool.cibuildwheel.linux]
25+
# wgpu-native does not build for musllinux yet
26+
skip = "*musllinux*"
27+
# Use custom images, with minimal version that matches wgpu-native
28+
manylinux-x86_64-image = "quay.io/pypa/manylinux_2_28_x86_64"
29+
manylinux-aarch64-image = "quay.io/pypa/manylinux_2_28_aarch64"
30+
manylinux-i686-image = "quay.io/pypa/manylinux_2_28_i686"
31+
manylinux-ppc64le-image = "quay.io/pypa/manylinux_2_28_ppc64le"

0 commit comments

Comments
 (0)