Skip to content

Commit d378f19

Browse files
committed
add pgo builds for release artifacts on ubuntu
1 parent fb3daeb commit d378f19

File tree

1 file changed

+100
-17
lines changed

1 file changed

+100
-17
lines changed

.github/workflows/ci.yml

Lines changed: 100 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -288,19 +288,32 @@ jobs:
288288
jobs: ${{ toJSON(needs) }}
289289
allowed-failures: coverage
290290

291+
build-sdist:
292+
name: build sdist
293+
runs-on: ubuntu-latest
294+
steps:
295+
- uses: actions/checkout@v3
296+
- uses: PyO3/maturin-action@v1
297+
with:
298+
command: sdist
299+
args: --out dist
300+
rust-toolchain: stable
301+
- uses: actions/upload-artifact@v3
302+
with:
303+
name: pypi_files
304+
path: dist
305+
291306
build:
292307
name: build on ${{ matrix.platform || matrix.os }} (${{ matrix.target }} - ${{ matrix.manylinux || 'auto' }})
293308
# only run on push to main and on release
294-
if: "success() && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main' || contains(github.event.pull_request.labels.*.name, 'Full Build'))"
309+
if: startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main' || contains(github.event.pull_request.labels.*.name, 'Full Build')
295310
strategy:
296311
fail-fast: false
297312
matrix:
298313
os: [ubuntu, macos, windows]
299314
target: [x86_64, aarch64]
300315
manylinux: [auto]
301316
include:
302-
- os: ubuntu
303-
platform: linux
304317
- os: windows
305318
ls: dir
306319
interpreter: 3.7 3.8 3.9 3.10 3.11 pypy3.8 pypy3.9
@@ -346,6 +359,11 @@ jobs:
346359
container: messense/manylinux_2_24-cross:s390x
347360
interpreter: 3.7 3.8 3.9 3.10 3.11
348361
exclude:
362+
# Optimized PGO builds for manylinux follow a different matrix, maybe in future
363+
# maturin-action can support this automatically
364+
- os: ubuntu
365+
target: x86_64
366+
manylinux: auto
349367
# Windows on arm64 only supports Python 3.11+
350368
- os: windows
351369
target: aarch64
@@ -360,18 +378,11 @@ jobs:
360378
python-version: '3.11'
361379
architecture: ${{ matrix.python-architecture || 'x64' }}
362380

363-
- run: pip install -U twine 'black>=22.3.0,<23' typing_extensions
381+
- run: pip install -U 'black>=22.3.0,<23' typing_extensions
382+
364383
# generate self-schema now, so we don't have to do so inside docker in maturin build
365384
- run: python generate_self_schema.py
366385

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-
375386
- name: build wheels
376387
uses: PyO3/maturin-action@v1
377388
with:
@@ -383,15 +394,87 @@ jobs:
383394

384395
- run: ${{ matrix.ls || 'ls -lh' }} dist/
385396

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

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

393476
inspect-pypi-assets:
394-
needs: [build]
477+
needs: [build, build-sdist, build-pgo]
395478
runs-on: ubuntu-latest
396479

397480
steps:
@@ -475,7 +558,7 @@ jobs:
475558
476559
test-builds-os:
477560
name: test build on ${{ matrix.os }}
478-
needs: [build]
561+
needs: [build, build-pgo]
479562

480563
strategy:
481564
fail-fast: false
@@ -504,8 +587,8 @@ jobs:
504587
- run: pytest --ignore=tests/test_docstrings.py
505588

506589
release:
507-
needs: [test-builds-arch, test-builds-os, check]
508-
if: "success() && startsWith(github.ref, 'refs/tags/')"
590+
needs: [test-builds-arch, test-builds-os, build-sdist, check]
591+
if: success() && startsWith(github.ref, 'refs/tags/')
509592
runs-on: ubuntu-latest
510593

511594
steps:

0 commit comments

Comments
 (0)