Skip to content

fix(package): Allow packaging of self-cycles with -Zpackage-workspace #15626

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/cargo/ops/cargo_package/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,11 @@ fn local_deps<T>(packages: impl Iterator<Item = (Package, T)>) -> LocalDependenc
continue;
};

// We don't care about cycles
if dep.source_id() == pkg.package_id().source_id() {
Copy link
Member

@weihanglo weihanglo Jun 4, 2025

Choose a reason for hiding this comment

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

It is a bit unintuitive, as comparing source_id doesn't generally imply they are cyclic. However, given we filtered in local packages earlier (which source ID contains path to package root as the unique identifer), it makes sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, in general this code assumes that the source_id is unique and looks up a package id by the source id. I could move this into the following if so we can then compare package ids. That won't make a practical differende but maybe it makes the intent clearer?

continue;
}

if let Some(dep_pkg) = source_to_pkg.get(&dep.source_id()) {
graph.link(pkg.package_id(), *dep_pkg);
}
Expand Down
33 changes: 33 additions & 0 deletions tests/testsuite/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7560,6 +7560,39 @@ fn unpublished_cyclic_dev_dependencies() {
);
}

#[cargo_test]
fn unpublished_cyclic_dev_dependencies_nightly() {
registry::init();
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
edition = "2015"
authors = []
license = "MIT"
description = "foo"
documentation = "foo"

[dev-dependencies]
foo = { path = ".", version = "0.0.1" }
"#,
)
.file("src/lib.rs", "")
.build();

p.cargo("package --no-verify --exclude-lockfile -Zpackage-workspace")
.masquerade_as_nightly_cargo(&["package-workspace"])
.with_stderr_data(str![[r#"
[PACKAGING] foo v0.0.1 ([ROOT]/foo)
[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)

"#]])
.run();
}

// A failing case from <https://github.com/rust-lang/cargo/issues/15059>
#[cargo_test]
fn unpublished_dependency() {
Expand Down