Skip to content
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

Support public dependency configuration with workspace deps #12817

Merged
merged 1 commit into from
Oct 13, 2023
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
9 changes: 8 additions & 1 deletion src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2080,6 +2080,7 @@ pub struct TomlWorkspaceDependency {
#[serde(rename = "default_features")]
default_features2: Option<bool>,
optional: Option<bool>,
public: Option<bool>,
/// This is here to provide a way to see the "unused manifest keys" when deserializing
#[serde(skip_serializing)]
#[serde(flatten)]
Expand Down Expand Up @@ -2114,11 +2115,12 @@ impl TomlWorkspaceDependency {
if let Some(false) = self.default_features.or(self.default_features2) {
default_features_msg(name, None, cx);
}
if self.optional.is_some() || self.features.is_some() {
if self.optional.is_some() || self.features.is_some() || self.public.is_some() {
TomlDependency::Detailed(DetailedTomlDependency {
version: Some(s),
optional: self.optional,
features: self.features.clone(),
public: self.public,
..Default::default()
})
} else {
Expand Down Expand Up @@ -2150,6 +2152,11 @@ impl TomlWorkspaceDependency {
}
_ => {}
}
// Inherit the workspace configuration for `public` unless
// it's explicitly specified for this dependency.
if let Some(public) = self.public {
d.public = Some(public);
}
d.add_features(self.features.clone());
d.update_optional(self.optional);
TomlDependency::Detailed(d)
Expand Down
49 changes: 49 additions & 0 deletions tests/testsuite/pub_priv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,52 @@ Caused by:
)
.run()
}

#[cargo_test(nightly, reason = "exported_private_dependencies lint is unstable")]
fn workspace_dep_made_public() {
Package::new("foo1", "0.1.0")
.file("src/lib.rs", "pub struct FromFoo;")
.publish();
Package::new("foo2", "0.1.0")
.file("src/lib.rs", "pub struct FromFoo;")
.publish();
Package::new("foo3", "0.1.0")
.file("src/lib.rs", "pub struct FromFoo;")
.publish();

let p = project()
.file(
"Cargo.toml",
r#"
cargo-features = ["public-dependency"]

[package]
name = "foo"
version = "0.0.1"

[workspace.dependencies]
foo1 = "0.1.0"
foo2 = { version = "0.1.0", public = true }
foo3 = { version = "0.1.0", public = false }

[dependencies]
foo1 = { workspace = true, public = true }
foo2 = { workspace = true }
foo3 = { workspace = true, public = true }
"#,
)
.file(
"src/lib.rs",
"
#![deny(exported_private_dependencies)]
pub fn use_priv1(_: foo1::FromFoo) {}
pub fn use_priv2(_: foo2::FromFoo) {}
pub fn use_priv3(_: foo3::FromFoo) {}
",
)
.build();

p.cargo("check")
.masquerade_as_nightly_cargo(&["public-dependency"])
.run()
}