Skip to content

Commit a82f934

Browse files
committed
add pgo builds for release artifacts on ubuntu
1 parent 5c05380 commit a82f934

File tree

1 file changed

+99
-17
lines changed

1 file changed

+99
-17
lines changed

.github/workflows/ci.yml

Lines changed: 99 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,19 +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
364382

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

368-
- name: build sdist
369-
if: ${{ matrix.os == 'ubuntu' && matrix.target == 'x86_64' && matrix.manylinux == 'auto' }}
370-
uses: PyO3/maturin-action@v1
371-
with:
372-
command: sdist
373-
args: --out dist
374-
rust-toolchain: stable
375-
376386
- name: build wheels
377387
uses: PyO3/maturin-action@v1
378388
with:
@@ -385,15 +395,87 @@ jobs:
385395

386396
- run: ${{ matrix.ls || 'ls -lh' }} dist/
387397

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

390472
- uses: actions/upload-artifact@v3
391473
with:
392474
name: pypi_files
393475
path: dist
394476

395477
inspect-pypi-assets:
396-
needs: [build]
478+
needs: [build, build-sdist, build-pgo]
397479
runs-on: ubuntu-latest
398480

399481
steps:
@@ -477,7 +559,7 @@ jobs:
477559
478560
test-builds-os:
479561
name: test build on ${{ matrix.os }}
480-
needs: [build]
562+
needs: [build, build-pgo]
481563

482564
strategy:
483565
fail-fast: false
@@ -506,8 +588,8 @@ jobs:
506588
- run: pytest --ignore=tests/test_docstrings.py
507589

508590
release:
509-
needs: [test-builds-arch, test-builds-os, check]
510-
if: "success() && startsWith(github.ref, 'refs/tags/')"
591+
needs: [test-builds-arch, test-builds-os, build-sdist, check]
592+
if: success() && startsWith(github.ref, 'refs/tags/')
511593
runs-on: ubuntu-latest
512594

513595
steps:

0 commit comments

Comments
 (0)