Skip to content

Strip excluded cargo targets in sdist - #2964

Merged
messense merged 3 commits into
PyO3:mainfrom
messense:sdist-targets-excludes
Feb 6, 2026
Merged

Strip excluded cargo targets in sdist#2964
messense merged 3 commits into
PyO3:mainfrom
messense:sdist-targets-excludes

Conversation

@messense

@messense messense commented Feb 5, 2026

Copy link
Copy Markdown
Member

Closes #2955

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

This PR fixes issue #2955 where maturin fails to strip excluded cargo build targets from source distributions, causing build failures. Since Cargo 1.80, Cargo consistently strips excluded build targets, but maturin was not doing this, resulting in Cargo.toml files referencing source files that don't exist in the sdist.

Changes:

  • Implements automatic stripping of cargo targets (lib, bin, example, test, bench) whose source files are excluded from the sdist
  • Adds comprehensive test coverage for the new functionality with both included and excluded examples and benchmarks

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/source_distribution.rs Adds rewrite_cargo_toml_targets function to strip targets with excluded source files; integrates this into sdist generation workflow
src/module_writer/virtual_writer.rs Changes visibility of exclude method to pub(crate) to support exclusion checks during file filtering
tests/run.rs Updates test expectations to verify that excluded targets are stripped from Cargo.toml while included targets are retained
test-crates/hello-world/Cargo.toml Adds test bench and example target declarations for testing the stripping functionality
test-crates/hello-world/pyproject.toml Configures maturin to exclude specific bench and example files
test-crates/hello-world/benches/*.rs Adds test benchmark files (both included and excluded variants)
test-crates/hello-world/examples/*.rs Adds test example files (both included and excluded variants)
test-crates/pyo3-mixed-workspace/.gitignore Adds standard Rust target/ directory to gitignore
test-crates/pyo3-mixed-src/.gitignore Adds standard Rust target/ directory to gitignore

@messense
messense force-pushed the sdist-targets-excludes branch from c8927be to 56a745a Compare February 5, 2026 12:32

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 12 out of 12 changed files in this pull request and generated no new comments.

@messense
messense force-pushed the sdist-targets-excludes branch from 9b0f2c3 to 34ab8d6 Compare February 5, 2026 23:55
@messense
messense merged commit 786277b into PyO3:main Feb 6, 2026
79 of 84 checks passed
@messense
messense deleted the sdist-targets-excludes branch February 6, 2026 04:51
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.

maturin respects package.include / package.exclude but does not strip build targets, causing build failures

2 participants