refactor: split BuildOptions and BuildContext into logical sub-groups#3098
Merged
messense merged 6 commits intoMar 22, 2026
Merged
Conversation
- 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.
messense
commented
Mar 21, 2026
Contributor
There was a problem hiding this comment.
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.rsand movesCargoOptions/TargetTripleinto it. - Refactors
BuildOptionsinto flattened sub-structs:PythonOptions,PlatformOptions, andOutputOptions. - Splits
BuildContextintoProjectContext,PythonContext, andArtifactContext, 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. |
- 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CargoOptionsandTargetTripleinto dedicatedsrc/cargo_options.rs.BuildOptionsusing clap's#[command(flatten)]to group Python, Platform, and Output options.BuildContextintoProjectContext,ArtifactContext, andPythonContextfor better modularity.