Skip to content

Commit d0ffd36

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 ee91f40 commit d0ffd36

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

src/cargo/core/compiler/unit_dependencies.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,17 @@ 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+
.require(Feature::public_dependency())
649+
.is_ok();
650+
640651
for (id, deps) in state.deps(unit, unit_for) {
641652
let Some(dep_lib) = calc_artifact_deps(unit, unit_for, id, &deps, state, &mut ret)? else {
642653
continue;
@@ -657,7 +668,20 @@ fn compute_deps_doc(
657668
IS_NO_ARTIFACT_DEP,
658669
)?;
659670
ret.push(lib_unit_dep);
660-
if dep_lib.documented() && state.intent.wants_deps_docs() {
671+
672+
// Decide whether to document this dependency.
673+
// When public-dependency is enabled, only document:
674+
// - Direct dependencies of workspace members
675+
// - Public dependencies (recursively)
676+
// This dramatically speeds up documentation builds by excluding indirect
677+
// private dependencies that cannot be used by readers of the docs.
678+
let should_doc_dep = if public_deps_enabled {
679+
is_root || state.resolve().is_public_dep(unit.pkg.package_id(), id)
680+
} else {
681+
true
682+
};
683+
684+
if dep_lib.documented() && state.intent.wants_deps_docs() && should_doc_dep {
661685
// Document this lib as well.
662686
let doc_unit_dep = new_unit_dep(
663687
state,

0 commit comments

Comments
 (0)