Skip to content

Commit 6d99db2

Browse files
committed
build: use cibuildwheels for PyPi compatible packages
Also use abi3 for producing a wheel that works for Python 3.10+, without having to build different wheels for each Python minor version.
1 parent 219007d commit 6d99db2

File tree

2 files changed

+54
-15
lines changed

2 files changed

+54
-15
lines changed

cloudbuild.yaml

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313
# limitations under the License.
1414

1515
steps:
16-
# 1. Build the distribution (sdist and wheel).
17-
# This uses scikit-build-core as defined in pyproject.toml to compile C++ extensions.
18-
# We set BUILD_TESTING=OFF to ignore tests during the artifact build.
16+
# 1. Build the source distribution (sdist).
1917
- name: 'python:3.10'
20-
id: 'build'
18+
id: 'build-sdist'
2119
entrypoint: 'bash'
2220
args:
2321
- '-c'
@@ -27,27 +25,47 @@ steps:
2725
exit 1
2826
fi
2927
pip install build
30-
31-
echo "Building C++ extensions with editable install..."
32-
# Note: pip install -e . will also respect the build-system requirements
28+
python -m build --sdist
29+
30+
# 2. Build the manylinux wheels using cibuildwheel.
31+
# This step builds for the native architecture of the GCB worker (x86_64 or ARM64).
32+
# Multiple parallel builds on different architectures can safely upload to the same AR repository.
33+
- name: 'python:3.10'
34+
id: 'build-wheels'
35+
entrypoint: 'bash'
36+
args:
37+
- '-c'
38+
- |
39+
# Install cibuildwheel and the docker client
40+
pip install cibuildwheel
41+
apt-get update && apt-get install -y docker.io
42+
43+
echo "Detected architecture: $(uname -m)"
44+
45+
echo "Building C++ extensions with editable install (local check)..."
3346
SKBUILD_CMAKE_ARGS="-DBUILD_TESTING=OFF" pip install -e .
34-
35-
echo "Building sdist and wheel..."
36-
SKBUILD_CMAKE_ARGS="-DBUILD_TESTING=OFF" python -m build
3747
38-
# 2. Upload to internal Artifact Registry (AR) for OSS Exit Gate.
39-
# OSS Exit Gate fetches artifacts from this repository.
48+
echo "Running cibuildwheel..."
49+
# cibuildwheel will build for the native architecture by default
50+
# using the Python version filters defined in pyproject.toml.
51+
cibuildwheel --output-dir dist
52+
volumes:
53+
- name: 'docker-socket'
54+
path: '/var/run/docker.sock'
55+
waitFor: ['build-sdist']
56+
57+
# 3. Upload to internal Artifact Registry (AR) for OSS Exit Gate.
4058
- name: 'python:3.10'
4159
id: 'upload-to-ar'
4260
entrypoint: 'bash'
4361
args:
4462
- '-c'
4563
- |
46-
pip install -U twine keyring keyrings.google-artifactregistry-auth
64+
pip install twine keyring keyrings.google-artifactregistry-auth
4765
twine upload --repository-url https://us-python.pkg.dev/oss-exit-gate-prod/${_PROJECT_NAME}--pypi dist/*
48-
waitFor: ['build']
66+
waitFor: ['build-wheels']
4967

50-
# 3. Create and upload the manifest to GCS to trigger the Exit Gate publication.
68+
# 4. Create and upload the manifest to GCS to trigger the Exit Gate publication.
5169
# The presence of this file in the specific GCS bucket triggers the verification and publishing process.
5270
- name: 'gcr.io/cloud-builders/gcloud'
5371
id: 'trigger-exit-gate'

pyproject.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ build-backend = "scikit_build_core.build"
132132
# Tells scikit-build-core to use setuptools-scm to retrieve the version from git.
133133
metadata.version.provider = "scikit_build_core.metadata.setuptools_scm"
134134

135+
# Enable Stable ABI (abi3) for Python 3.10 and later.
136+
# This produces a single wheel per architecture that works on all future Python versions.
137+
wheel.py-api = "cp310"
138+
135139
# Specifies the minimum version of CMake that must be present on the system.
136140
cmake.version = ">=3.18"
137141

@@ -193,3 +197,20 @@ fail_under = 90
193197
[tool.gcovr]
194198
fail-under-line = "80"
195199
#fail-under-branch = "85"
200+
201+
# ===================================================================
202+
# Tool-specific Configuration for cibuildwheel
203+
# ===================================================================
204+
[tool.cibuildwheel]
205+
# Build only once per architecture (using Python 3.10).
206+
# Because abi3 is enabled, this wheel will work for 3.10, 3.11, 3.12, 3.13, etc.
207+
build = "cp310-*"
208+
# Skip 32-bit builds and musllinux
209+
skip = "*-manylinux_i686 *-musllinux_*"
210+
211+
[tool.cibuildwheel.linux]
212+
# Pass the flag to skip tests during the build inside the container
213+
environment = { SKBUILD_CMAKE_ARGS="-DBUILD_TESTING=OFF" }
214+
# We need to install the build requirements inside the cibuildwheel container
215+
before-build = "pip install pybind11 scikit-build-core cmake ninja setuptools-scm"
216+

0 commit comments

Comments
 (0)