Skip to content

refactor: split BuildOptions and BuildContext into logical sub-groups#3098

Merged
messense merged 6 commits into
PyO3:mainfrom
messense:refactor/split-build-options-and-context
Mar 22, 2026
Merged

refactor: split BuildOptions and BuildContext into logical sub-groups#3098
messense merged 6 commits into
PyO3:mainfrom
messense:refactor/split-build-options-and-context

Conversation

@messense

@messense messense commented Mar 21, 2026

Copy link
Copy Markdown
Member
  • Move CargoOptions and TargetTriple into dedicated src/cargo_options.rs.
  • Refactor BuildOptions using clap's #[command(flatten)] to group Python, Platform, and Output options.
  • Partition the 28-field BuildContext into ProjectContext, ArtifactContext, and PythonContext for better modularity.
  • Update over 130 references across the codebase to use the new context structures.

- Move CargoOptions and TargetTriple into dedicated src/cargo_options.rs.
- Refactor BuildOptions using clap's #[command(flatten)] to group Python, Platform, and Output options.
- Partition the 28-field BuildContext into ProjectContext, ArtifactContext, and PythonContext for better modularity.
- Update over 130 references across the codebase to use the new context structures.
- Maintain public API compatibility via re-exports in src/lib.rs.
…level functions

- Group remaining BuildContext fields into ProjectContext and ArtifactContext.
- Move bridge() and get_platform_tag() methods to ProjectContext.
- Refactor generate_sbom_data, write_sboms, and source_distribution to accept modular contexts.
- Update PythonInterpreter::get_tag to take &ProjectContext.
- Update all references across the codebase to the new nested structure.
- Remove unused imports and clean up SdistContext fields.
…ping

- Explain the build lifecycle: Input (Project) → Constraints (Python) → Output (Artifact).
- Detail the role of each sub-context struct in both BuildContext and BuildOptions.
- Update field references in integration and unit tests to use new modular structures.
- Fix BuildOptions construction in test suites.
- Update CLI test snapshots to reflect new clap option ordering.
Comment thread src/build_context/repair.rs Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors maturin’s build configuration and runtime build context into smaller logical sub-groups (Cargo/Target, Python, Platform, Output) to reduce the size/complexity of BuildOptions and BuildContext, while keeping the public API stable via re-exports.

Changes:

  • Introduces src/cargo_options.rs and moves CargoOptions/TargetTriple into it.
  • Refactors BuildOptions into flattened sub-structs: PythonOptions, PlatformOptions, and OutputOptions.
  • Splits BuildContext into ProjectContext, PythonContext, and ArtifactContext, updating call sites and CLI/help snapshots accordingly.

Reviewed changes

Copilot reviewed 27 out of 27 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/run/sdist.rs Updates test build options initialization to use output.out.
tests/common/other.rs Updates test helpers to use OutputOptions/PlatformOptions and new context nesting.
tests/common/integration.rs Adjusts integration tests for build_context.project/build_context.python nesting.
tests/cmd/publish.stdout Updates CLI help snapshot reflecting option regrouping/order.
tests/cmd/build.stdout Updates CLI help snapshot reflecting option regrouping/order.
src/source_distribution/pyproject.rs Switches sdist codepaths from BuildContext to ProjectContext access.
src/source_distribution/mod.rs Splits sdist entrypoints to accept ProjectContext + ArtifactContext.
src/sbom.rs Refactors SBOM generation/writing to accept ProjectContext + ArtifactContext.
src/python_interpreter/mod.rs Updates tag computation to depend on ProjectContext rather than BuildContext.
src/project_layout.rs Uses CargoOptions::cargo_metadata_args() from the new module.
src/pgo.rs Updates PGO logic to use build_context.project.* nesting.
src/module_writer/mock_writer.rs Updates dist-info writing to use nested project context fields.
src/main.rs Updates CLI wiring to use OutputOptions and nested build context fields.
src/lib.rs Re-exports new context structs/options and exposes cargo_options module.
src/develop/mod.rs Updates develop flow to construct BuildOptions using new grouped option structs.
src/compile.rs Updates compilation pipeline to use nested context fields (project/python/artifact).
src/cargo_options.rs New module containing CargoOptions/TargetTriple and associated helpers/tests.
src/build_options.rs Introduces PythonOptions/PlatformOptions/OutputOptions and flattens them into BuildOptions.
src/build_context/wheels.rs Updates wheel build pipeline for nested contexts and new SBOM API shape.
src/build_context/repair.rs Updates auditwheel/repair logic to use nested contexts.
src/build_context/mod.rs Defines ProjectContext/PythonContext/ArtifactContext and restructures BuildContext.
src/build_context/builder.rs Populates new sub-context structs from BuildOptions and resolved metadata.
src/binding_generator/uniffi_binding.rs Updates generator paths/fields for nested project context.
src/binding_generator/pyo3_binding.rs Updates generator paths/fields for nested project context.
src/binding_generator/mod.rs Switches binding generation logic to nested project/artifact fields.
src/binding_generator/cffi_binding.rs Updates generator paths/fields for nested project context.
src/binding_generator/bin_binding.rs Updates WASI detection to use project.target.

Comment thread src/build_context/wheels.rs Outdated
Comment thread src/build_context/wheels.rs Outdated
Comment thread src/develop/mod.rs Outdated
- Restore contextual error messages to compile() calls in BuildContext::build_wheels.
- Fix regression where maturin develop ignored user-provided compression settings.
- Update test snapshots and field references in test suite to match new modular context structure.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 27 out of 27 changed files in this pull request and generated 2 comments.

Comment thread src/build_context/mod.rs
Comment thread src/python_interpreter/mod.rs
@messense messense merged commit ee4701b into PyO3:main Mar 22, 2026
49 checks passed
@messense messense deleted the refactor/split-build-options-and-context branch March 22, 2026 01:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants