Skip to content

Commit 39b492c

Browse files
authored
In package-workspace, keep dev-dependencies if they have a version (#15470)
Fixes #15412
2 parents 6ee6027 + faf7329 commit 39b492c

File tree

2 files changed

+89
-14
lines changed

2 files changed

+89
-14
lines changed

src/cargo/ops/cargo_package/mod.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -239,18 +239,17 @@ fn do_package<'a>(
239239
let deps = local_deps(pkgs.iter().map(|(p, f)| ((*p).clone(), f.clone())));
240240
let just_pkgs: Vec<_> = pkgs.iter().map(|p| p.0).collect();
241241

242-
// The publish registry doesn't matter unless there are local dependencies,
243-
// so only try to get one if we need it. If they explicitly passed a
244-
// registry on the CLI, we check it no matter what.
245-
let sid = if deps.has_no_dependencies() && opts.reg_or_index.is_none() {
246-
None
247-
} else {
248-
let sid = get_registry(ws.gctx(), &just_pkgs, opts.reg_or_index.clone())?;
249-
debug!("packaging for registry {}", sid);
250-
Some(sid)
251-
};
252-
253242
let mut local_reg = if ws.gctx().cli_unstable().package_workspace {
243+
// The publish registry doesn't matter unless there are local dependencies,
244+
// so only try to get one if we need it. If they explicitly passed a
245+
// registry on the CLI, we check it no matter what.
246+
let sid = if deps.has_no_dependencies() && opts.reg_or_index.is_none() {
247+
None
248+
} else {
249+
let sid = get_registry(ws.gctx(), &just_pkgs, opts.reg_or_index.clone())?;
250+
debug!("packaging for registry {}", sid);
251+
Some(sid)
252+
};
254253
let reg_dir = ws.build_dir().join("package").join("tmp-registry");
255254
sid.map(|sid| TmpRegistry::new(ws.gctx(), reg_dir, sid))
256255
.transpose()?
@@ -407,9 +406,14 @@ fn local_deps<T>(packages: impl Iterator<Item = (Package, T)>) -> LocalDependenc
407406
for (pkg, _payload) in packages.values() {
408407
graph.add(pkg.package_id());
409408
for dep in pkg.dependencies() {
410-
// Ignore local dev-dependencies because they aren't needed for intra-workspace
411-
// lockfile generation or verification as they get stripped on publish.
412-
if dep.kind() == DepKind::Development || !dep.source_id().is_path() {
409+
// We're only interested in local (i.e. living in this workspace) dependencies.
410+
if !dep.source_id().is_path() {
411+
continue;
412+
}
413+
414+
// If local dev-dependencies don't have a version specified, they get stripped
415+
// on publish so we should ignore them.
416+
if dep.kind() == DepKind::Development && !dep.specified_req() {
413417
continue;
414418
};
415419

tests/testsuite/package.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5806,6 +5806,77 @@ features = ["foo"]
58065806
);
58075807
}
58085808

5809+
#[cargo_test]
5810+
fn workspace_with_local_dev_deps() {
5811+
let crates_io = registry::init();
5812+
let p = project()
5813+
.file(
5814+
"Cargo.toml",
5815+
r#"
5816+
[workspace]
5817+
members = ["main", "dev_dep"]
5818+
resolver = "3"
5819+
5820+
[workspace.dependencies]
5821+
dev_dep = { path = "dev_dep", version = "0.0.1" }
5822+
"#,
5823+
)
5824+
.file(
5825+
"main/Cargo.toml",
5826+
r#"
5827+
[package]
5828+
name = "main"
5829+
version = "0.0.1"
5830+
edition = "2024"
5831+
authors = []
5832+
license = "MIT"
5833+
description = "main"
5834+
5835+
[dev-dependencies]
5836+
dev_dep.workspace = true
5837+
"#,
5838+
)
5839+
.file(
5840+
"dev_dep/Cargo.toml",
5841+
r#"
5842+
[package]
5843+
name = "dev_dep"
5844+
version = "0.0.1"
5845+
edition = "2024"
5846+
authors = []
5847+
license = "MIT"
5848+
description = "main"
5849+
"#,
5850+
)
5851+
.file("main/src/lib.rs", "")
5852+
.file("dev_dep/src/lib.rs", "")
5853+
.build();
5854+
5855+
p.cargo("package -Zpackage-workspace")
5856+
.masquerade_as_nightly_cargo(&["package-workspace"])
5857+
.replace_crates_io(crates_io.index_url())
5858+
.with_stdout_data("")
5859+
.with_stderr_data(str![[r#"
5860+
[WARNING] manifest has no documentation, homepage or repository.
5861+
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
5862+
[PACKAGING] dev_dep v0.0.1 ([ROOT]/foo/dev_dep)
5863+
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
5864+
[WARNING] manifest has no documentation, homepage or repository.
5865+
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
5866+
[PACKAGING] main v0.0.1 ([ROOT]/foo/main)
5867+
[UPDATING] crates.io index
5868+
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
5869+
[VERIFYING] dev_dep v0.0.1 ([ROOT]/foo/dev_dep)
5870+
[COMPILING] dev_dep v0.0.1 ([ROOT]/foo/target/package/dev_dep-0.0.1)
5871+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
5872+
[VERIFYING] main v0.0.1 ([ROOT]/foo/main)
5873+
[COMPILING] main v0.0.1 ([ROOT]/foo/target/package/main-0.0.1)
5874+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
5875+
5876+
"#]])
5877+
.run();
5878+
}
5879+
58095880
fn workspace_with_local_deps_packaging_one_fails_project() -> Project {
58105881
project()
58115882
.file(

0 commit comments

Comments
 (0)