refactor: decouple build orchestration from BuildContext#3100
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors maturin’s build pipeline by moving the high-level “build verbs” (wheel/sdist orchestration, tagging, SBOM generation) out of BuildContext into a new BuildOrchestrator, keeping BuildContext primarily as a data container plus lower-level helpers.
Changes:
- Added
BuildOrchestratorand migrated wheel/sdist build orchestration (including SBOM generation/writing and tag selection) into it. - Updated CLI commands and test helpers to use
BuildOrchestratorinstead of calling orchestration methods onBuildContext. - Reshaped
BuildContextto expose narrowerpub(crate)repair helpers and movedfilter_cargo_targetsintocompile.rs.
Reviewed changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/run/sdist.rs | Switch sdist tests to build via BuildOrchestrator. |
| tests/common/other.rs | Switch common test helpers to build wheels/sdists via BuildOrchestrator. |
| tests/common/integration.rs | Switch integration tests to build wheels via BuildOrchestrator. |
| tests/common/errors.rs | Switch error-path tests to build wheels via BuildOrchestrator. |
| src/sbom.rs | Moves SBOM generation/writing out; keeps include-path resolution and SBOM data type. |
| src/pgo.rs | Refactors PGO pipeline to orchestrate via BuildOrchestrator helpers. |
| src/module_writer/mock_writer.rs | Uses BuildOrchestrator::tags_from_bridge() for dist-info generation in tests. |
| src/lib.rs | Exposes BuildOrchestrator publicly and adds module. |
| src/develop/mod.rs | Uses BuildOrchestrator for wheel builds in develop. |
| src/compile.rs | Adds filter_cargo_targets here (moved from build_context builder). |
| src/commands/utils.rs | Uses BuildOrchestrator for building sdists used by other commands. |
| src/commands/sdist.rs | Uses BuildOrchestrator to build the sdist. |
| src/commands/publish.rs | Uses BuildOrchestrator to build wheels before upload. |
| src/commands/pep517.rs | Uses BuildOrchestrator for PEP517 operations; subcommand naming changed. |
| src/commands/mod.rs | Narrows command module visibility to pub(crate) and adds tracing instrumentation. |
| src/commands/develop.rs | Adds tracing instrumentation. |
| src/commands/build.rs | Uses BuildOrchestrator for wheel builds; adds tracing instrumentation. |
| src/build_orchestrator.rs | New orchestrator module containing the migrated build pipeline. |
| src/build_context/wheels.rs | Deleted (logic migrated into BuildOrchestrator). |
| src/build_context/repair.rs | Renames/opens up repair helpers for orchestrator use. |
| src/build_context/mod.rs | Removes orchestration methods; keeps wrappers for repair helpers used by orchestrator. |
| src/build_context/builder.rs | Uses compile::filter_cargo_targets after moving it. |
…GO orchestration to BuildOrchestrator - Make internal build methods (compile_cdylib, build_cffi_wheel, build_uniffi_wheel, build_bin_wheel, get_universal_tag) private or pub(crate) to avoid leaking internals in the public API. - Move SBOM generation and writing logic from BuildOrchestrator into SbomData::generate() and SbomData::write() in sbom.rs, keeping separation of concerns. - Move PGO build loops into BuildOrchestrator and reduce PgoContext to profiling environment management (paths, instrumentation, merging).
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.
Summary
BuildContexthad grown into a monolith that mixed data (configuration, interpreter lists, paths) with behavior (wheel building, PGO loops, SBOM generation, target filtering). This PR extracts the orchestration logic into dedicated types, leavingBuildContextas a pure data container.What changed
New
BuildOrchestrator— owns the high-level build flow (wheel building, PGO loops, sdist creation, tag computation). Takes a&BuildContextreference and coordinates the build pipeline without owning any state.PgoContextnarrowed to profiling concerns — manages the profdata directory,llvm-profdataresolution, instrumentation execution, and profile merging. The three-phase PGO build loops now live inBuildOrchestrator.SbomDatagainedgenerate()andwrite()— SBOM generation and wheel-writing logic moved from the orchestrator intosbom.rs, keeping CycloneDX serialization details out of the build pipeline.Target filtering moved to
compile.rs—filter_cargo_targets()extracted as a free function, removing workspace/metadata logic fromBuildContext.Cleanup:
packagesreferences from bridge detectioncompile_cdylib,build_cffi_wheel,build_uniffi_wheel,build_bin_wheel,get_universal_tag) are now private orpub(crate)src/build_context/wheels.rs(531 lines) — logic moved toBuildOrchestratorArchitecture