Skip to content

Commit eb5fb58

Browse files
committed
Filter doc deps based on public-dependency
Fixes #2025 When public-dependency is enabled, only document direct deps and their public deps. Skips transitive private deps.
1 parent e456e09 commit eb5fb58

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/cargo/core/compiler/unit_dependencies.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,16 @@ fn compute_deps_doc(
637637
// built. If we're documenting *all* libraries, then we also depend on
638638
// the documentation of the library being built.
639639
let mut ret = Vec::new();
640+
let is_root = state.ws.is_member(&unit.pkg);
641+
642+
// Check if public-dependency feature is enabled
643+
let public_deps_enabled = state.gctx.cli_unstable().public_dependency
644+
|| unit
645+
.pkg
646+
.manifest()
647+
.unstable_features()
648+
.is_enabled(Feature::public_dependency());
649+
640650
for (id, deps) in state.deps(unit, unit_for) {
641651
let Some(dep_lib) = calc_artifact_deps(unit, unit_for, id, &deps, state, &mut ret)? else {
642652
continue;
@@ -657,7 +667,20 @@ fn compute_deps_doc(
657667
IS_NO_ARTIFACT_DEP,
658668
)?;
659669
ret.push(lib_unit_dep);
660-
if dep_lib.documented() && state.intent.wants_deps_docs() {
670+
671+
// Decide whether to document this dependency.
672+
// When public-dependency is enabled, only document:
673+
// - Direct dependencies of workspace members
674+
// - Public dependencies (recursively)
675+
// This dramatically speeds up documentation builds by excluding indirect
676+
// private dependencies that cannot be used by readers of the docs.
677+
let should_doc_dep = if public_deps_enabled && !is_root {
678+
state.resolve().is_public_dep(unit.pkg.package_id(), id)
679+
} else {
680+
true
681+
};
682+
683+
if dep_lib.documented() && state.intent.wants_deps_docs() && should_doc_dep {
661684
// Document this lib as well.
662685
let doc_unit_dep = new_unit_dep(
663686
state,

0 commit comments

Comments
 (0)