Skip to content

Commit

Permalink
Always build PGO using RUSTFLAGS
Browse files Browse the repository at this point in the history
There are many ways to pass flags to rustc:

* `cargo rustc`, which only affects your crate and not its dependencies.
* `RUSTFLAGS` environment variable, which affects dependencies as well.

See https://stackoverflow.com/a/38040431

In this case I think `RUSTFLAGS` is a better choice.
  • Loading branch information
messense committed Jul 4, 2023
1 parent 5c696e5 commit dadbc62
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,10 @@ jobs:
--release
--out pgo-wheel
--interpreter ${{ matrix.maturin-interpreter || matrix.interpreter }}
-- -Cprofile-generate=${{ github.workspace }}/profdata
rust-toolchain: stable
docker-options: -e CI
env:
RUSTFLAGS: "-Cprofile-generate=${{ github.workspace }}/profdata"

- name: detect rust host
run: echo RUST_HOST=$(rustc -Vv | grep host | cut -d ' ' -f 2) >> "$GITHUB_ENV"
Expand All @@ -468,10 +469,9 @@ jobs:
pip install -r tests/requirements.txt
pip install pydantic-core --no-index --no-deps --find-links pgo-wheel --force-reinstall
pytest tests/benchmarks
rustup run stable bash -c 'echo LLVM_PROFDATA=$RUSTUP_HOME/toolchains/$RUSTUP_TOOLCHAIN/lib/rustlib/${{ env.RUST_HOST }}/bin/llvm-profdata >> "$GITHUB_ENV"'
- name: merge pgo data
run: ${{ env.LLVM_PROFDATA }} merge -o ${{ github.workspace }}/merged.profdata ${{ github.workspace }}/profdata
run: rustup run stable llvm-profdata merge -o ${{ github.workspace }}/merged.profdata ${{ github.workspace }}/profdata

- name: build pgo-optimized wheel
uses: PyO3/maturin-action@v1
Expand All @@ -482,9 +482,10 @@ jobs:
--release
--out dist
--interpreter ${{ matrix.maturin-interpreter || matrix.interpreter }}
-- -Cprofile-use=${{ github.workspace }}/merged.profdata
rust-toolchain: stable
docker-options: -e CI
env:
RUSTFLAGS: "-Cprofile-use=${{ github.workspace }}/merged.profdata"

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

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codspeed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
run: pytest tests/benchmarks

- name: Prepare merged pgo data
run: 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'
run: rustup run stable llvm-profdata merge -o ${{ github.workspace }}/merged.profdata ${{ github.workspace }}/profdata

- name: Compile pydantic-core for benchmarking
# --no-default-features to avoid using mimalloc
Expand Down

0 comments on commit dadbc62

Please sign in to comment.