Skip to content

Commit 634087a

Browse files
authored
add build-pgo make target (#741)
1 parent 3a9c162 commit 634087a

File tree

2 files changed

+47
-8
lines changed

2 files changed

+47
-8
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ jobs:
160160
python-version: ${{ matrix.python-version }}
161161

162162
- run: pip install -r tests/requirements.txt
163-
- run: pip install -e . --config-settings=build-args='--profile dev'
163+
- run: make build-dev
164164

165165
- run: pip freeze
166166
- run: pytest
@@ -202,7 +202,7 @@ jobs:
202202
- run: pip install -r tests/requirements-linting.txt
203203
if: steps.cache-py.outputs.cache-hit != 'true'
204204

205-
- run: pip install .
205+
- run: make build-dev
206206

207207
- run: pip freeze
208208

Makefile

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ black = black python/pydantic_core tests generate_self_schema.py wasm-preview/ru
33
ruff = ruff python/pydantic_core tests generate_self_schema.py wasm-preview/run_tests.py
44
mypy-stubtest = python -m mypy.stubtest pydantic_core._pydantic_core --allowlist .mypy-stubtest-allowlist
55

6+
# using pip install cargo (via maturin via pip) doesn't get the tty handle
7+
# so doesn't render color without some help
8+
export CARGO_TERM_COLOR=$(shell (test -t 0 && echo "always") || echo "auto")
9+
# maturin develop only makes sense inside a virtual env, is otherwise
10+
# more or less equivalent to pip install -e just a little nicer
11+
USE_MATURIN = $(shell [ "$$VIRTUAL_ENV" != "" ] && (which maturin))
12+
613
.PHONY: install
714
install:
815
pip install -U pip wheel pre-commit
@@ -16,23 +23,55 @@ install-rust-coverage:
1623
cargo install rustfilt coverage-prepare
1724
rustup component add llvm-tools-preview
1825

26+
.PHONY: install-pgo
27+
rustup component add llvm-tools-preview
28+
1929
.PHONY: build-dev
2030
build-dev:
2131
@rm -f python/pydantic_core/*.so
22-
cargo build --features extension-module
23-
@rm -f target/debug/lib_pydantic_core.d
24-
@rm -f target/debug/lib_pydantic_core.rlib
25-
@mv target/debug/lib_pydantic_core.* python/pydantic_core/_pydantic_core.so
32+
ifneq ($(USE_MATURIN),)
33+
maturin develop
34+
else
35+
pip install -v -e . --config-settings=build-args='--profile dev'
36+
endif
2637

2738
.PHONY: build-prod
2839
build-prod:
2940
@rm -f python/pydantic_core/*.so
41+
ifneq ($(USE_MATURIN),)
3042
maturin develop --release
43+
else
44+
pip install -v -e .
45+
endif
3146

3247
.PHONY: build-coverage
3348
build-coverage:
34-
rm -f python/pydantic_core/*.so
35-
maturin develop -- -C instrument-coverage
49+
@rm -f python/pydantic_core/*.so
50+
ifneq ($(USE_MATURIN),)
51+
RUSTFLAGS='-C instrument-coverage' maturin develop --release
52+
else
53+
RUSTFLAGS='-C instrument-coverage' pip install -v -e .
54+
endif
55+
56+
.PHONY: build-pgo
57+
build-pgo:
58+
@rm -f python/pydantic_core/*.so
59+
$(eval PROFDATA := $(shell mktemp -d))
60+
ifneq ($(USE_MATURIN),)
61+
RUSTFLAGS='-Cprofile-generate=$(PROFDATA)' maturin develop --release
62+
else
63+
RUSTFLAGS='-Cprofile-generate=$(PROFDATA)' pip install -v -e .
64+
endif
65+
pytest tests/benchmarks
66+
$(eval LLVM_PROFDATA := $(shell rustup run stable bash -c 'echo $$RUSTUP_HOME/toolchains/$$RUSTUP_TOOLCHAIN/lib/rustlib/$$(rustc -Vv | grep host | cut -d " " -f 2)/bin/llvm-profdata'))
67+
$(LLVM_PROFDATA) merge -o $(PROFDATA)/merged.profdata $(PROFDATA)
68+
ifneq ($(USE_MATURIN),)
69+
RUSTFLAGS='-Cprofile-use=$(PROFDATA)/merged.profdata' maturin develop --release
70+
else
71+
RUSTFLAGS='-Cprofile-use=$(PROFDATA)/merged.profdata' pip install -v -e .
72+
endif
73+
@rm -rf $(PROFDATA)
74+
3675

3776
.PHONY: build-wasm
3877
build-wasm:

0 commit comments

Comments
 (0)