Skip to content

Commit 8ef5de6

Browse files
committed
add pgo builds for release artifacts on ubuntu
1 parent d2d6c48 commit 8ef5de6

File tree

1 file changed

+98
-15
lines changed

1 file changed

+98
-15
lines changed

.github/workflows/ci.yml

+98-15
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,25 @@ jobs:
287287
jobs: ${{ toJSON(needs) }}
288288
allowed-failures: coverage
289289

290+
build-sdist:
291+
name: build sdist
292+
runs-on: ubuntu-latest
293+
steps:
294+
- uses: actions/checkout@v3
295+
- uses: PyO3/maturin-action@v1
296+
with:
297+
command: sdist
298+
args: --out dist
299+
rust-toolchain: stable
300+
- uses: actions/upload-artifact@v3
301+
with:
302+
name: pypi_files
303+
path: dist
304+
290305
build:
291306
name: build on ${{ matrix.platform || matrix.os }} (${{ matrix.target }} - ${{ matrix.manylinux || 'auto' }})
292307
# only run on push to main and on release
293-
if: "success() && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main' || contains(github.event.pull_request.labels.*.name, 'Full Build'))"
308+
if: startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main' || contains(github.event.pull_request.labels.*.name, 'Full Build')
294309
strategy:
295310
fail-fast: false
296311
matrix:
@@ -345,6 +360,11 @@ jobs:
345360
container: messense/manylinux_2_24-cross:s390x
346361
interpreter: 3.7 3.8 3.9 3.10 3.11
347362
exclude:
363+
# Optimized PGO builds for manylinux follow a different matrix, maybe in future
364+
# maturin-action can support this automatically
365+
- os: ubuntu
366+
target: x86_64
367+
manylinux: auto
348368
# Windows on arm64 only supports Python 3.11+
349369
- os: windows
350370
target: aarch64
@@ -359,19 +379,11 @@ jobs:
359379
python-version: '3.11'
360380
architecture: ${{ matrix.python-architecture || 'x64' }}
361381

362-
- run: pip install -U twine 'black>=22.3.0,<23' typing_extensions
382+
- run: pip install -U 'black>=22.3.0,<23' typing_extensions
363383

364384
# generate self-schema now, so we don't have to do so inside docker in maturin build
365385
- run: python generate_self_schema.py
366386

367-
- name: build sdist
368-
if: ${{ matrix.os == 'ubuntu' && matrix.target == 'x86_64' && matrix.manylinux == 'auto' }}
369-
uses: PyO3/maturin-action@v1
370-
with:
371-
command: sdist
372-
args: --out dist
373-
rust-toolchain: stable
374-
375387
- name: build wheels
376388
uses: PyO3/maturin-action@v1
377389
with:
@@ -384,15 +396,86 @@ jobs:
384396

385397
- run: ${{ matrix.ls || 'ls -lh' }} dist/
386398

387-
- run: twine check --strict dist/*
399+
- uses: actions/upload-artifact@v3
400+
with:
401+
name: pypi_files
402+
path: dist
403+
404+
build-pgo:
405+
name: build pgo-optimized on ${{ matrix.platform || matrix.os }} (${{ matrix.interpreter}} - ${{ matrix.target }} - ${{ matrix.manylinux || 'auto' }})
406+
# only run on push to main and on release
407+
if: startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main' || contains(github.event.pull_request.labels.*.name, 'Full Build')
408+
strategy:
409+
fail-fast: false
410+
matrix:
411+
os: [ubuntu]
412+
platform: [linux]
413+
target: [x86_64]
414+
manylinux: [auto]
415+
interpreter: ["3.7", "3.8", "3.9", "3.10", "3.11", "pypy3.7", "pypy3.8", "pypy3.9"]
416+
417+
runs-on: ${{ matrix.os }}-latest
418+
steps:
419+
- uses: actions/checkout@v3
420+
421+
- name: set up python
422+
uses: actions/setup-python@v4
423+
with:
424+
python-version: ${{ matrix.interpreter }}
425+
architecture: ${{ matrix.python-architecture || 'x64' }}
426+
427+
- name: install rust stable
428+
id: rust-toolchain
429+
uses: dtolnay/rust-toolchain@stable
430+
with:
431+
components: llvm-tools
432+
433+
- run: pip install -U 'black>=22.3.0,<23' typing_extensions
434+
435+
# generate self-schema now, so we don't have to do so inside docker in maturin build
436+
- run: python generate_self_schema.py
437+
438+
- name: build initial wheel
439+
uses: PyO3/maturin-action@v1
440+
with:
441+
target: ${{ matrix.target }}
442+
manylinux: ${{ matrix.manylinux || 'auto' }}
443+
args: >
444+
--release
445+
--out pgo-wheel
446+
--interpreter ${{ matrix.interpreter }}
447+
-- -Cprofile-generate=${{ github.workspace }}/profdata
448+
rust-toolchain: stable
449+
450+
- name: generate pgo data
451+
run: |
452+
pip install -U pip
453+
pip install -r tests/requirements.txt
454+
pip install pydantic-core --no-index --no-deps --find-links pgo-wheel --force-reinstall
455+
pytest
456+
rustup run stable bash -c '$RUSTUP_HOME/toolchains/$RUSTUP_TOOLCHAIN/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-profdata merge -o ${{ github.workspace }}/merged.profdata ${{ github.workspace }}/profdata'
457+
458+
- name: build pgo-optimized wheel
459+
uses: PyO3/maturin-action@v1
460+
with:
461+
target: ${{ matrix.target }}
462+
manylinux: ${{ matrix.manylinux || 'auto' }}
463+
args: >
464+
--release
465+
--out dist
466+
--interpreter ${{ matrix.interpreter }}
467+
-- -Cprofile-use=${{ github.workspace }}/merged.profdata
468+
rust-toolchain: stable
469+
470+
- run: ${{ matrix.ls || 'ls -lh' }} dist/
388471

389472
- uses: actions/upload-artifact@v3
390473
with:
391474
name: pypi_files
392475
path: dist
393476

394477
inspect-pypi-assets:
395-
needs: [build]
478+
needs: [build, build-sdist, build-pgo]
396479
runs-on: ubuntu-latest
397480

398481
steps:
@@ -474,7 +557,7 @@ jobs:
474557
475558
test-builds-os:
476559
name: test build on ${{ matrix.os }}
477-
needs: [build]
560+
needs: [build, build-pgo]
478561

479562
strategy:
480563
fail-fast: false
@@ -502,8 +585,8 @@ jobs:
502585
- run: pytest --ignore=tests/test_docstrings.py
503586

504587
release:
505-
needs: [test-builds-arch, test-builds-os, check]
506-
if: "success() && startsWith(github.ref, 'refs/tags/')"
588+
needs: [test-builds-arch, test-builds-os, build-sdist, check]
589+
if: success() && startsWith(github.ref, 'refs/tags/')
507590
runs-on: ubuntu-latest
508591

509592
steps:

0 commit comments

Comments
 (0)