Skip to content

Commit 1c77007

Browse files
committed
Add "-Zpublic-dependency" for public-dependency feature
1 parent c061bfb commit 1c77007

File tree

22 files changed

+152
-139
lines changed

22 files changed

+152
-139
lines changed

src/cargo/core/compiler/mod.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ use crate::core::compiler::future_incompat::FutureIncompatReport;
8989
pub use crate::core::compiler::unit::{Unit, UnitInterner};
9090
use crate::core::manifest::TargetSourcePath;
9191
use crate::core::profiles::{PanicStrategy, Profile, StripInner};
92-
use crate::core::{Feature, PackageId, Target, Verbosity};
92+
use crate::core::{PackageId, Target, Verbosity};
9393
use crate::util::errors::{CargoResult, VerboseError};
9494
use crate::util::interning::InternedString;
9595
use crate::util::machine_message::{self, Message};
@@ -1437,14 +1437,7 @@ pub fn extern_args(
14371437
|dep: &UnitDep, extern_crate_name: InternedString, noprelude: bool| -> CargoResult<()> {
14381438
let mut value = OsString::new();
14391439
let mut opts = Vec::new();
1440-
if unit
1441-
.pkg
1442-
.manifest()
1443-
.unstable_features()
1444-
.require(Feature::public_dependency())
1445-
.is_ok()
1446-
&& !dep.public
1447-
&& unit.target.is_lib()
1440+
if !dep.public && unit.target.is_lib() && cx.bcx.config.cli_unstable().public_dependency
14481441
{
14491442
opts.push("priv");
14501443
*unstable_opts = true;

src/cargo/core/features.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,7 @@ unstable_cli_options!(
764764
panic_abort_tests: bool = ("Enable support to run tests with -Cpanic=abort"),
765765
precise_pre_release: bool = ("Enable pre-release versions to be selected with `update --precise`"),
766766
profile_rustflags: bool = ("Enable the `rustflags` option in profiles in .cargo/config.toml file"),
767+
public_dependency: bool = ("Respect a dependency's `public` field in Cargo.toml to control public/private dependencies"),
767768
publish_timeout: bool = ("Enable the `publish.timeout` key in .cargo/config.toml file"),
768769
rustdoc_map: bool = ("Allow passing external documentation mappings to rustdoc"),
769770
rustdoc_scrape_examples: bool = ("Allows Rustdoc to scrape code examples from reverse-dependencies"),
@@ -1140,6 +1141,7 @@ impl CliUnstable {
11401141
"mtime-on-use" => self.mtime_on_use = parse_empty(k, v)?,
11411142
"no-index-update" => self.no_index_update = parse_empty(k, v)?,
11421143
"panic-abort-tests" => self.panic_abort_tests = parse_empty(k, v)?,
1144+
"public-dependency" => self.public_dependency = parse_empty(k, v)?,
11431145
"profile-rustflags" => self.profile_rustflags = parse_empty(k, v)?,
11441146
"precise-pre-release" => self.precise_pre_release = parse_empty(k, v)?,
11451147
"trim-paths" => self.trim_paths = parse_empty(k, v)?,

src/cargo/core/workspace.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,6 @@ impl<'cfg> Workspace<'cfg> {
449449
// NOTE: Since we use ConfigRelativePath, this root isn't used as
450450
// any relative paths are resolved before they'd be joined with root.
451451
Path::new("unused-relative-path"),
452-
self.unstable_features(),
453452
/* kind */ None,
454453
)
455454
})

src/cargo/ops/cargo_package.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use crate::core::compiler::{BuildConfig, CompileMode, DefaultExecutor, Executor}
1010
use crate::core::manifest::Target;
1111
use crate::core::resolver::CliFeatures;
1212
use crate::core::{registry::PackageRegistry, resolver::HasDevUnits};
13-
use crate::core::{Feature, Shell, Verbosity, Workspace};
1413
use crate::core::{Package, PackageId, PackageSet, Resolve, SourceId};
14+
use crate::core::{Shell, Verbosity, Workspace};
1515
use crate::sources::PathSource;
1616
use crate::util::cache_lock::CacheLockMode;
1717
use crate::util::config::JobsConfig;
@@ -911,12 +911,7 @@ fn run_verify(
911911
let pkg_fingerprint = hash_all(&dst)?;
912912
let ws = Workspace::ephemeral(new_pkg, config, None, true)?;
913913

914-
let rustc_args = if pkg
915-
.manifest()
916-
.unstable_features()
917-
.require(Feature::public_dependency())
918-
.is_ok()
919-
{
914+
let rustc_args = if ws.config().cli_unstable().public_dependency {
920915
// FIXME: Turn this on at some point in the future
921916
//Some(vec!["-D exported_private_dependencies".to_string()])
922917
Some(vec![])

src/cargo/util/toml/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,6 @@ pub fn to_real_manifest(
678678
nested_paths: &mut nested_paths,
679679
config,
680680
warnings: &mut warnings,
681-
features: &features,
682681
platform: None,
683682
root: package_root,
684683
};
@@ -1153,7 +1152,6 @@ fn to_virtual_manifest(
11531152
config,
11541153
warnings: &mut warnings,
11551154
platform: None,
1156-
features: &features,
11571155
root,
11581156
};
11591157
(replace(&me, &mut cx)?, patch(&me, &mut cx)?)
@@ -1302,7 +1300,6 @@ struct Context<'a, 'b> {
13021300
warnings: &'a mut Vec<String>,
13031301
platform: Option<Platform>,
13041302
root: &'a Path,
1305-
features: &'a Features,
13061303
}
13071304

13081305
fn verify_lints(lints: Option<manifest::TomlLints>) -> CargoResult<Option<manifest::TomlLints>> {
@@ -1709,7 +1706,6 @@ pub(crate) fn to_dependency<P: ResolveToPath + Clone>(
17091706
warnings: &mut Vec<String>,
17101707
platform: Option<Platform>,
17111708
root: &Path,
1712-
features: &Features,
17131709
kind: Option<DepKind>,
17141710
) -> CargoResult<Dependency> {
17151711
dep_to_dependency(
@@ -1723,7 +1719,6 @@ pub(crate) fn to_dependency<P: ResolveToPath + Clone>(
17231719
warnings,
17241720
platform,
17251721
root,
1726-
features,
17271722
},
17281723
kind,
17291724
)
@@ -1944,13 +1939,18 @@ fn detailed_dep_to_dependency<P: ResolveToPath + Clone>(
19441939
}
19451940

19461941
if let Some(p) = orig.public {
1947-
cx.features.require(Feature::public_dependency())?;
1948-
19491942
if dep.kind() != DepKind::Normal {
19501943
bail!("'public' specifier can only be used on regular dependencies, not {:?} dependencies", dep.kind());
19511944
}
19521945

1953-
dep.set_public(p);
1946+
if !cx.config.cli_unstable().public_dependency {
1947+
cx.warnings.push(format!(
1948+
"{name} uses 'public' specifier, pass `-Zpublic-dependency` to enable support for it",
1949+
name = dep.name_in_toml(),
1950+
))
1951+
} else {
1952+
dep.set_public(p);
1953+
}
19541954
}
19551955

19561956
if let (Some(artifact), is_lib, target) = (

src/doc/src/reference/unstable.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,9 @@ The 'public-dependency' feature allows marking dependencies as 'public'
296296
or 'private'. When this feature is enabled, additional information is passed to rustc to allow
297297
the 'exported_private_dependencies' lint to function properly.
298298

299-
This requires the appropriate key to be set in `cargo-features`:
299+
Pass `-Zpublic-dependency` to cargo to enable support for it.
300300

301301
```toml
302-
cargo-features = ["public-dependency"]
303-
304302
[dependencies]
305303
my_dep = { version = "1.2.3", public = true }
306304
private_dep = "2.0.0" # Will be 'private' by default

tests/testsuite/cargo/z_help/stdout.log

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Available unstable (nightly-only) flags:
2525
-Z panic-abort-tests Enable support to run tests with -Cpanic=abort
2626
-Z precise-pre-release Enable pre-release versions to be selected with `update --precise`
2727
-Z profile-rustflags Enable the `rustflags` option in profiles in .cargo/config.toml file
28+
-Z public-dependency Respect a dependency's `public` field in Cargo.toml to control public/private dependencies
2829
-Z publish-timeout Enable the `publish.timeout` key in .cargo/config.toml file
2930
-Z rustdoc-map Allow passing external documentation mappings to rustdoc
3031
-Z rustdoc-scrape-examples Allows Rustdoc to scrape code examples from reverse-dependencies
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
cargo-features = ["public-dependency"]
21
[package]
32
name = "bar"
43
version = "0.0.0"

tests/testsuite/cargo_add/detect_workspace_inherit_public/out/primary/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
cargo-features = ["public-dependency"]
21
[package]
32
name = "bar"
43
version = "0.0.0"

tests/testsuite/cargo_add/no_public/in/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
cargo-features = ["public-dependency"]
21
[workspace]
32

43
[package]

tests/testsuite/cargo_add/no_public/out/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
cargo-features = ["public-dependency"]
21
[workspace]
32

43
[package]

tests/testsuite/cargo_add/overwrite_no_public/in/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
cargo-features = ["public-dependency"]
21
[workspace]
32

43
[package]

tests/testsuite/cargo_add/overwrite_no_public/out/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
cargo-features = ["public-dependency"]
21
[workspace]
32

43
[package]

tests/testsuite/cargo_add/overwrite_no_public_with_public/in/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
cargo-features = ["public-dependency"]
21
[workspace]
32

43
[package]

tests/testsuite/cargo_add/overwrite_no_public_with_public/out/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
cargo-features = ["public-dependency"]
21
[workspace]
32

43
[package]

tests/testsuite/cargo_add/overwrite_public/in/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
cargo-features = ["public-dependency"]
21
[workspace]
32

43
[package]

tests/testsuite/cargo_add/overwrite_public/out/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
cargo-features = ["public-dependency"]
21
[workspace]
32

43
[package]

tests/testsuite/cargo_add/overwrite_public_with_no_public/in/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
cargo-features = ["public-dependency"]
21
[workspace]
32

43
[package]

tests/testsuite/cargo_add/overwrite_public_with_no_public/out/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
cargo-features = ["public-dependency"]
21
[workspace]
32

43
[package]

tests/testsuite/cargo_add/public/in/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
cargo-features = ["public-dependency"]
21
[workspace]
32

43
[package]

tests/testsuite/cargo_add/public/out/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
cargo-features = ["public-dependency"]
21
[workspace]
32

43
[package]

0 commit comments

Comments
 (0)