Skip to content

Conversation

ziyao233
Copy link
Contributor

An explicitly-specified target may simplify the dependency graph, i.e. crates unused on the target may be omitted. Cargo-fetch does this type of simplification and may pull fewer packages with --target argument.

maturin build doesn't pass the specified triple to cargo-metadata currently as --target isn't supported in cargo-metadata. When building reproducibly with cargo-fetch and --frozen argument, this could ultimately lead to a confusing and annoying dependency that cannot be resolved offline, since cargo-metadata has no idea about the target and cannot just drop the unnecessary dependency.

However, cargo-metadata does support --filter-platform since Cargo 1.40, which plays basically the same role as --target during dependency resolving. Let's translate --target to --filter-platform when calling cargo-metadata to handle the case.

Closes: #2561


This is the first time that I play with Rust, thanks for your patience and guide.

An explicitly-specified target may simplify the dependency graph, i.e.
crates unused on the target may be omitted. Cargo-fetch does this type
of simplification and may pull fewer packages with --target argument.

maturin build doesn't pass the specified triple to cargo-metadata
currently as --target isn't supported in cargo-metadata. When building
reproducibly with cargo-fetch and --frozen argument, this could
ultimately lead to a confusing and annoying dependency that cannot be
resolved offline, since cargo-metadata has no idea about the target and
cannot just drop the unnecessary dependency.

However, cargo-metadata does support --filter-platform since Cargo 1.40,
which plays basically the same role as --target during dependency
resolving. Let's translate --target to --filter-platform when calling
cargo-metadata to handle the case.

Closes: PyO3#2561
Signed-off-by: Yao Zi <ziyao@disroot.org>
@ziyao233 ziyao233 force-pushed the convert-triple-to-filter-platform branch from 270b2cc to 042e292 Compare April 20, 2025 17:25
@ziyao233
Copy link
Contributor Author

ziyao233 commented Apr 21, 2025

The failed test seems to be caused by some random network issues

Copy link
Member

@messense messense left a comment

Choose a reason for hiding this comment

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

LGTM

@messense messense merged commit df35a39 into PyO3:main Apr 21, 2025
75 of 76 checks passed
konstin added a commit that referenced this pull request May 9, 2025
#2562 introduced a regression breaking publishing maturin (https://github.com/PyO3/maturin/actions/runs/14923136319/job/41923286669). This PR moves the target triple type from a String to an enum, forcing all consumers to handle the virtual universal2 target themselves.

I tested this as far as possible on Linux, but it's missing real macOS testing (there are two different error messages for universal2 build before and after the regression and it's now back to the "good" error message).
messense pushed a commit that referenced this pull request May 9, 2025
#2562 introduced a regression breaking publishing maturin
(https://github.com/PyO3/maturin/actions/runs/14923136319/job/41923286669).
This PR moves the target triple type from a String to an enum, forcing
all consumers to handle the virtual universal2 target themselves.

I tested this as far as possible on Linux, but it's missing real macOS
testing (there are two different error messages for universal2 build
before and after the regression and it's now back to the "good" error
message).
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.

cargo-metadata invoked by maturin resolves dependencies differently from cargo fetch with --target specified
2 participants