Skip to content

Use single multi-target compilation for universal2#571

Closed
jakelishman wants to merge 2 commits intoPyO3:mainfrom
jakelishman:multi-target
Closed

Use single multi-target compilation for universal2#571
jakelishman wants to merge 2 commits intoPyO3:mainfrom
jakelishman:multi-target

Conversation

@jakelishman
Copy link

@jakelishman jakelishman commented Feb 17, 2026

As of Rust 1.61, it is possible to compile for more than one --target with a single compilation command. This commit refactors the build logic to avail itself of this functionality when doing the only multiple-target compilation we support, which is to make the combined universal2 wheels for macOS.

The combination of the multiple build artifacts into one universal2-compatible artifact is now done as part of the general artifact-path handling, which means we no longer have to sort out the configuration environment twice for the same system, and we no longer rely on cargo returning information about the built artifacts in the same order between two separate compilations.

Beyond the immediate benefit of isolating the "create binary artifacts" logic into only a single place, this commit is intended to be a refactor along the path towards support for extracting non-binary artifacts that are side-effects of particular RustExtension's build scripts.


This is a potential implementation of #563 (comment).

Warning: I don't think this should merge as-is. It breaks the ability to:

  • pass --crate-type=cdylib
  • use RustExtension.rustc_args

when in universal2 mode. I think we could get round the --crate-type problem by patching Cargo.toml into a temporary directory, but breaking rustc_args in the name of a refactor sounds to me to be fatal to this approach.

I'm putting this up just to demonstrate the principle of what I was up to. I think I can rescue a fair amount of the refactor in this PR into something that still helps isolate the multi-target logic, but doesn't come with the caveats of doing a true multi-target build.

jakelishman and others added 2 commits February 17, 2026 15:46
As of Rust 1.61, it is possible to compile for more than one `--target`
with a single compilation command.  This commit refactors the build
logic to avail itself of this functionality when doing the only
multiple-target compilation we support, which is to make the combined
`universal2` wheels for macOS.

The combination of the multiple build artifacts into one
universal2-compatible artifact is now done as part of the general
artifact-path handling, which means we no longer have to sort out the
configuration environment twice for the same system, and we no longer
rely on `cargo` returning information about the built artifacts in the
same order between two separate compilations.

Beyond the immediate benefit of isolating the "create binary artifacts"
logic into only a single place, this commit is intended to be a refactor
along the path towards support for extracting non-binary artifacts that
are side-effects of particular `RustExtension`'s build scripts.
@jakelishman
Copy link
Author

I'll just close this one - it turned out to be easier to produce the superseding #572 than I expected, and the structure of them is almost identical.

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.

1 participant

Comments