Skip to content

Commit 4ac1abc

Browse files
committed
🧪 Generalize cibuildwheel config w/ env vars
1 parent d731fa6 commit 4ac1abc

File tree

2 files changed

+68
-58
lines changed

2 files changed

+68
-58
lines changed

‎.github/workflows/ci-cd.yml

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ jobs:
141141
- windows-latest
142142
- macos-latest
143143
tag:
144-
- manylinux
144+
- ''
145145
- 'musllinux'
146146
exclude:
147147
- runner-vm-os: windows-latest
@@ -158,31 +158,40 @@ jobs:
158158
with:
159159
check-name: >-
160160
Build ${{ matrix.tag }} wheels on ${{ matrix.runner-vm-os }}
161-
wheel-tags-to-skip: >-
162-
${{
163-
(github.event_name != 'push' || !contains(github.ref, 'refs/tags/'))
164-
&& '*_i686
165-
*-macosx_universal2
166-
*-musllinux_*
167-
*-win32
168-
pp*'
169-
|| (matrix.tag == 'musllinux') && '*-manylinux_* pp*'
170-
|| '*-musllinux_* pp*'
171-
}}
172161
runner-vm-os: ${{ matrix.runner-vm-os }}
173162
timeout-minutes: 20
174163
source-tarball-name: >-
175164
${{ needs.build-pure-python-dists.outputs.sdist-filename }}
176165
dists-artifact-name: ${{ needs.pre-setup.outputs.dists-artifact-name }}
177-
cython-tracing: >- # Cython line tracing for coverage collection
178-
${{
166+
# CIBW_CONFIG_SETTINGS: `with-cython-tracing` — for coverage collection
167+
# CIBW_CONFIG_SETTINGS: `pure-python` — force C-extensions
168+
environment-variables: |-
169+
CIBW_ARCHS_MACOS=x86_64 arm64 universal2
170+
171+
CIBW_CONFIG_SETTINGS<<EOF
172+
pure-python=false
173+
with-cython-tracing=${{
179174
(
180175
github.event_name == 'push'
181176
&& contains(github.ref, 'refs/tags/')
182177
)
183178
&& 'false'
184179
|| 'true'
185180
}}
181+
EOF
182+
183+
CIBW_SKIP<<EOF
184+
${{
185+
(github.event_name != 'push' || !contains(github.ref, 'refs/tags/'))
186+
&& '*_i686
187+
*-macosx_universal2
188+
*-musllinux_*
189+
*-win32'
190+
|| (matrix.tag == 'musllinux') && '*-manylinux_*'
191+
|| '*-musllinux_*'
192+
}}
193+
pp*
194+
EOF
186195
187196
test:
188197
name: Test
@@ -514,17 +523,36 @@ jobs:
514523
with:
515524
check-name: >-
516525
Build ${{ matrix.tag }} wheels for ${{ matrix.qemu }}
517-
qemu: ${{ matrix.qemu }}
518-
wheel-tags-to-skip: >-
519-
${{
520-
(matrix.tag == 'musllinux')
521-
&& '*-manylinux_* pp*'
522-
|| '*-musllinux_* pp*'
523-
}}
526+
qemu: true
524527
timeout-minutes: 60
525528
source-tarball-name: >-
526529
${{ needs.build-pure-python-dists.outputs.sdist-filename }}
527530
dists-artifact-name: ${{ needs.pre-setup.outputs.dists-artifact-name }}
531+
# CIBW_ARCHS_LINUX: Build emulated architectures if QEMU, else "auto"
532+
# CIBW_CONFIG_SETTINGS: `with-cython-tracing` — for coverage collection
533+
# CIBW_CONFIG_SETTINGS: `pure-python` — force C-extensions
534+
environment-variables: |-
535+
CIBW_ARCHS_LINUX=${{ matrix.qemu }}
536+
537+
CIBW_ARCHS_MACOS=x86_64 arm64 universal2
538+
539+
CIBW_CONFIG_SETTINGS<<EOF
540+
pure-python=false
541+
with-cython-tracing=${{
542+
(
543+
github.event_name == 'push'
544+
&& contains(github.ref, 'refs/tags/')
545+
)
546+
&& 'false'
547+
|| 'true'
548+
}}
549+
EOF
550+
551+
CIBW_SKIP=${{
552+
(matrix.tag == 'musllinux')
553+
&& '*-manylinux_*'
554+
|| '*-musllinux_*'
555+
}} pp*
528556
529557
deploy:
530558
name: Deploy

‎.github/workflows/reusable-cibuildwheel.yml

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,19 @@ on: # yamllint disable-line rule:truthy
1313
description: A custom name for the Checks API-reported status
1414
required: false
1515
type: string
16-
cython-tracing:
17-
description: Whether to build Cython modules with line tracing
18-
default: '0'
16+
environment-variables:
17+
description: >-
18+
A newline-delimited blob of text with environment variables
19+
to be set using `${GITHUB_ENV}`
1920
required: false
2021
type: string
2122
qemu:
22-
description: Emulated QEMU architecture
23-
default: ''
23+
default: false
24+
description: >-
25+
Whether this job needs to configure QEMU to emulate a foreign
26+
architecture before running `cibuildwheel`. Defaults to "false".
2427
required: false
25-
type: string
28+
type: boolean
2629
runner-vm-os:
2730
description: VM OS to use
2831
default: ubuntu-latest
@@ -36,11 +39,6 @@ on: # yamllint disable-line rule:truthy
3639
description: Deadline for the job to complete
3740
required: true
3841
type: number
39-
wheel-tags-to-skip:
40-
description: Wheel tags to skip building
41-
default: ''
42-
required: false
43-
type: string
4442

4543
env:
4644
FORCE_COLOR: "1" # Make tools pretty.
@@ -55,14 +53,21 @@ jobs:
5553
inputs.check-name
5654
&& inputs.check-name
5755
|| format(
58-
'Build wheels on {0} {1}',
56+
'Build wheels on {0}{1}',
5957
inputs.runner-vm-os,
60-
inputs.qemu
58+
inputs.qemu && ' under QEMU' || ''
6159
)
6260
}}
6361
runs-on: ${{ inputs.runner-vm-os }}
6462
timeout-minutes: ${{ fromJSON(inputs.timeout-minutes) }}
6563
steps:
64+
- name: Export requested job-global environment variables
65+
if: inputs.environment-variables != ''
66+
env:
67+
INPUT_ENVIRONMENT_VARIABLES: ${{ inputs.environment-variables }}
68+
run: echo "${INPUT_ENVIRONMENT_VARIABLES}" >> "${GITHUB_ENV}"
69+
shell: bash
70+
6671
- name: Compute GHA artifact name ending
6772
id: gha-artifact-name
6873
run: |
@@ -93,39 +98,16 @@ jobs:
9398
uses: docker/setup-qemu-action@v3
9499
with:
95100
platforms: all
96-
# This should be temporary
97-
# xref https://github.com/docker/setup-qemu-action/issues/188
98-
# xref https://github.com/tonistiigi/binfmt/issues/215
99-
image: tonistiigi/binfmt:qemu-v8.1.5
100-
id: qemu
101-
- name: Prepare emulation
102-
if: inputs.qemu
103-
run: |
104-
# Build emulated architectures only if QEMU is set,
105-
# use default "auto" otherwise
106-
echo "CIBW_ARCHS_LINUX=${{ inputs.qemu }}" >> "${GITHUB_ENV}"
107-
shell: bash
108-
109-
- name: Skip building some wheel tags
110-
if: inputs.wheel-tags-to-skip
111-
run: |
112-
echo "CIBW_SKIP=${{ inputs.wheel-tags-to-skip }}" >> "${GITHUB_ENV}"
113-
shell: bash
114101

115102
- name: Build wheels
116103
uses: pypa/[email protected]
117-
env:
118-
CIBW_ARCHS_MACOS: x86_64 arm64 universal2
119-
CIBW_CONFIG_SETTINGS: >- # Cython line tracing for coverage collection
120-
pure-python=false
121-
with-cython-tracing=${{ inputs.cython-tracing }}
122104

123105
- name: Upload built artifacts for testing and publishing
124106
uses: actions/upload-artifact@v4
125107
with:
126108
name: ${{ inputs.dists-artifact-name }}-
127109
${{ inputs.runner-vm-os }}-
128-
${{ inputs.qemu }}-
110+
${{ inputs.qemu && 'qemu-' || '' }}
129111
${{ steps.gha-artifact-name.outputs.hash }}
130112
path: ./wheelhouse/*.whl
131113

0 commit comments

Comments
 (0)