Skip to content

feat: interproject linking — document a project without its dependencies - #396

Open
kim-em wants to merge 2 commits into
leanprover:mainfrom
kim-em:interproject-linking
Open

kim-em wants to merge 2 commits into
leanprover:mainfrom
kim-em:interproject-linking

Conversation

@kim-em

@kim-em kim-em commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

By default doc-gen4 documents a library together with its entire import closure, so a project built on top of a large dependency such as Mathlib regenerates the dependency's documentation too — often several GB, and close to the GitHub Pages ~1 GB artifact limit. This PR adds an opt-in mode that generates pages for only the project's own modules and links references to its dependencies out to their already-published documentation.

Three environment variables control it (in the spirit of the existing DOCGEN_SRC):

  • DOCGEN_LOCAL_MODULE_ROOTS — a comma-separated list of the top-level module namespaces that belong to your project (e.g. MyProject). A module whose root is not listed is treated as external, and its pages are not generated.
  • DOCGEN_DEPS_DOCS_URL — an optional fallback base URL for external dependency documentation, e.g. https://leanprover-community.github.io/mathlib4_docs.
  • DOCGEN_DEPS_DOCS_URLS — optional comma-separated per-root overrides of the form Root=URL, e.g. Mathlib=https://.../mathlib4_docs,Batteries=https://.../batteries_docs. List multiple roots separately when one dependency owns multiple top-level namespaces.

For each external module, a per-root entry takes precedence over the fallback URL. A reference to an external declaration links to the selected site's /find resolver (…/find/?pattern=<decl>#doc), which looks the declaration up by name and so tolerates the dependency's docs being built from a slightly different revision than the one being linked against; module-level links point directly at the corresponding page. Every external module root must have either a per-root entry or a fallback, and doc-gen4 reports a configuration error rather than producing broken local links when a mapping is missing.

The excluded modules stay in the linking context so cross-references still resolve. When DOCGEN_LOCAL_MODULE_ROOTS is unset, the behaviour is unchanged.

The change is localized to the two link builders (moduleNameToLink / declNameToLink), dependency-URL selection and validation, and a render-set filter in fromDb, with the configuration read in getSimpleBaseContext. The README documents the variables. The multi-library regression test now also covers distinct dependency sites, fallback links, trailing-slash normalization, omitted dependency pages, and incomplete-configuration errors.

Validated end-to-end against Tau Ceti, a ~580-module Mathlib-downstream library: with DOCGEN_LOCAL_MODULE_ROOTS=TauCeti, only the 581 TauCeti pages are generated (no Mathlib/Init/Std/… trees), references to Mathlib declarations link to mathlib4_docs, and there are no broken local links — cutting the output from ~963 MB to tens of MB.

@cursor

cursor Bot commented Jul 21, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

By default doc-gen4 documents a library together with its entire import closure, so a
project built on Mathlib regenerates all of Mathlib's documentation (often several GB).
Add two environment variables that instead generate pages for only the project's own
modules and link references to its dependencies out to their hosted documentation:

- DOCGEN_LOCAL_MODULE_ROOTS: comma-separated local module namespaces. A module whose root
  is not listed is treated as external, and its pages are not generated.
- DOCGEN_DEPS_DOCS_URL: base URL of the dependencies' documentation site, e.g.
  https://leanprover-community.github.io/mathlib4_docs.

References to a declaration in an external module link to that site's /find resolver, which
looks the declaration up by name and so tolerates the dependency's docs being built from a
slightly different revision; module-level links point directly at the corresponding page.
When DOCGEN_LOCAL_MODULE_ROOTS is unset the behaviour is unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@kim-em
kim-em force-pushed the interproject-linking branch from b65d39c to 4cac5a7 Compare July 21, 2026 19:49
kim-em added a commit to TauCetiProject/TauCeti that referenced this pull request Jul 21, 2026
…docs (#1092)

Switch the /docs build to doc-gen4 with interproject linking
(leanprover/doc-gen4#396, pinned to the fork until it
lands upstream): render pages for only the TauCeti.* modules and link references
to Mathlib and Lean core out to the hosted mathlib4_docs, instead of rendering
the whole import closure locally. The published artifact drops from ~960 MB to
~33 MB, so deploys are fast and stay well under the GitHub Pages size limit as
the library grows. docbuild now pins the fork's v4.32.0 revision, matching the
repository toolchain.


Claude-Session: https://claude.ai/code/session_01YNbagXozDSSffYZhLxvd98

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Vtec234

Vtec234 commented Jul 28, 2026

Copy link
Copy Markdown
Member

Would this be hard to generalize to per-dependency URLs?

@kim-em

kim-em commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

Would this be hard to generalize to per-dependency URLs?

Done.

@BorisTheBrave

Copy link
Copy Markdown

A reference to an external declaration links to the selected site's /find resolver

I note that this adds a bit of latency to actually navigating the docs. An alternative is to link to the exact url. header-data.bmp contains the necessary indexing for this.

@kim-em

kim-em commented Sep 22, 2026

Copy link
Copy Markdown
Contributor Author

A reference to an external declaration links to the selected site's /find resolver

I note that this adds a bit of latency to actually navigating the docs. An alternative is to link to the exact url. header-data.bmp contains the necessary indexing for this.

Yes, but header-data.bmp won't work reliably if there is any version skew between the docs sites, while /find copes pretty well. Happy if someone wants to investigate this as a follow-up, but I propose that it is out of scope for this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants