Skip to content

Commit cc66550

Browse files
committed
add build-pgo make target
1 parent d08d269 commit cc66550

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

Makefile

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ 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+
610
.PHONY: install
711
install:
812
pip install -U pip wheel pre-commit
@@ -16,23 +20,35 @@ install-rust-coverage:
1620
cargo install rustfilt coverage-prepare
1721
rustup component add llvm-tools-preview
1822

23+
.PHONY: install-pgo
24+
rustup component add llvm-tools-preview
25+
1926
.PHONY: build-dev
2027
build-dev:
2128
@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
29+
pip install -v -e . --config-settings=build-args='--profile dev'
2630

2731
.PHONY: build-prod
2832
build-prod:
2933
@rm -f python/pydantic_core/*.so
30-
maturin develop --release
34+
pip install -v -e .
3135

3236
.PHONY: build-coverage
3337
build-coverage:
34-
rm -f python/pydantic_core/*.so
35-
maturin develop -- -C instrument-coverage
38+
@rm -f python/pydantic_core/*.so
39+
RUSTFLAGS='-C instrument-coverage' pip install -v -e .
40+
41+
.PHONY: build-pgo
42+
build-pgo:
43+
@rm -f python/pydantic_core/*.so
44+
$(eval PROFDATA := $(shell mktemp -d))
45+
RUSTFLAGS='-Cprofile-generate=$(PROFDATA)' pip install -v -e .
46+
pytest tests/benchmarks
47+
$(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'))
48+
$(LLVM_PROFDATA) merge -o $(PROFDATA)/merged.profdata $(PROFDATA)
49+
RUSTFLAGS='-Cprofile-use=$(PROFDATA)/merged.profdata' pip install -v -e .
50+
@rm -rf $(PROFDATA)
51+
3652

3753
.PHONY: build-wasm
3854
build-wasm:

0 commit comments

Comments
 (0)