Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions guide/src/local_development.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ Options:

[possible values: pyo3, pyo3-ffi, cffi, uniffi, bin]

--pgo
Build with Profile-Guided Optimization (PGO).

Requires `pgo-command` to be set in `[tool.maturin]` in pyproject.toml. This performs a three-phase build: instrumented build, profile training, and optimized rebuild.

Implies `--release` unless `--profile` is specified.

--strip
Strip the library for minimum file size

Expand Down
16 changes: 16 additions & 0 deletions src/develop/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ pub struct DevelopOptions {
/// Pass --release to cargo
#[arg(short = 'r', long, help_heading = heading::COMPILATION_OPTIONS, conflicts_with = "profile")]
pub release: bool,
/// Build with Profile-Guided Optimization (PGO).
///
/// Requires `pgo-command` to be set in `[tool.maturin]` in pyproject.toml.
/// This performs a three-phase build: instrumented build, profile training,
/// and optimized rebuild.
///
/// Implies `--release` unless `--profile` is specified.
#[arg(long)]
pub pgo: bool,
/// Strip the library for minimum file size
#[arg(long)]
pub strip: bool,
Expand Down Expand Up @@ -324,6 +333,7 @@ pub fn develop(develop_options: DevelopOptions, venv_dir: &Path) -> Result<()> {
let DevelopOptions {
bindings,
release,
pgo,
strip,
extras,
group,
Expand All @@ -340,6 +350,11 @@ pub fn develop(develop_options: DevelopOptions, venv_dir: &Path) -> Result<()> {
if release {
cargo_options.profile = Some("release".to_string());
}
// PGO-optimizing a debug build makes no sense, so `--pgo` implies the
// release profile unless another profile was requested explicitly
if pgo && cargo_options.profile.is_none() {
cargo_options.profile = Some("release".to_string());
}

let mut target_triple = cargo_options.target.clone();
let target = Target::from_target_triple(cargo_options.target.as_ref())?;
Expand Down Expand Up @@ -385,6 +400,7 @@ pub fn develop(develop_options: DevelopOptions, venv_dir: &Path) -> Result<()> {
.into_build_context()
.strip(if strip { Some(true) } else { None })
.editable(true)
.pgo(pgo)
.build()?;

// Ensure that version information is present, https://github.com/PyO3/maturin/issues/2416
Expand Down
8 changes: 8 additions & 0 deletions tests/cmd/develop.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ Options:

[possible values: pyo3, pyo3-ffi, cffi, uniffi, bin]

--pgo
Build with Profile-Guided Optimization (PGO).

Requires `pgo-command` to be set in `[tool.maturin]` in pyproject.toml. This performs a
three-phase build: instrumented build, profile training, and optimized rebuild.

Implies `--release` unless `--profile` is specified.

--strip
Strip the library for minimum file size

Expand Down
1 change: 1 addition & 0 deletions tests/common/develop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ pub fn test_develop(case: &DevelopCase<'_>) -> Result<()> {
let develop_options = DevelopOptions {
bindings: case.bindings.map(|binding| binding.to_owned()),
release: false,
pgo: false,
strip: false,
extras: Vec::new(),
group: Vec::new(),
Expand Down
Loading