You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: text/0000-mergeable-rustdoc-cross-crate-info.md
+9-16Lines changed: 9 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,12 +5,14 @@
5
5
6
6
# Summary
7
7
8
-
Mergeable cross-crate information in rustdoc. Facilitates the generation of documentation indexes in environments with many crates by allowing each crate to write to an independent output directory. Final documentation is rendered with a lightweight merge step. Configurable with command-line flags, this proposal writes a `doc.parts` directory to hold pre-merge cross-crate information. Currently, rustdoc requires global mutable access to a single output directory to generate cross-crate information, which is an obstacle to integrating rustdoc in build systems that make build actions independent.
8
+
Mergeable cross-crate information in rustdoc. Facilitates the generation of documentation indexes in workspaces with many crates by allowing each crate to write to an independent output directory. Final documentation is rendered with a lightweight merge step. Configurable with command-line flags, this proposal writes a `doc.parts` directory to hold pre-merge cross-crate information. Currently, rustdoc requires global mutable access to a single output directory to generate cross-crate information, which is an obstacle to integrating rustdoc in build systems that make build actions independent.
9
9
10
10
# Motivation
11
11
12
12
The main goal of this proposal is to facilitate users producing a documentation bundle of every crate in a large environment. When a crate needs to be re-documented, only a relatively lightweight merge step will be needed to produce a complete documentation bundle. This proposal is to facilitate the creation and updating of these bundles.
13
13
14
+
This proposal also targets documenting individual crates and their dependencies in non-cargo build systems. As will be explained, doc targets in non-cargo build systems often do not support cross-crate information.
15
+
14
16
There are some files in the rustdoc output directory that are read and overwritten during every invocation of rustdoc. This proposal refers to these files as **cross-crate information**, or **CCI**, as in <https://rustc-dev-guide.rust-lang.org/rustdoc.html#multiple-runs-same-output-directory>.
15
17
16
18
Build systems may run build actions in a distributed environment across separate logical filesystems. It might also be desirable to run rustdoc in a lock-free parallel mode, where every rustdoc process writes to a disjoint set of files.
Document `s` and `t` independently, providing `--write-rendered-cci=false`, `--read-rendered-cci=false`, and `--parts-out-dir=<crate name>/target/doc.parts`
50
52
@@ -76,9 +78,6 @@ In general, instead of two crates in the environment (`s` and `t`) you could hav
76
78
$ tree . -a
77
79
.
78
80
├── i
79
-
│ ├── Cargo.lock
80
-
│ ├── Cargo.toml
81
-
│ ├── .gitignore
82
81
│ ├── src
83
82
│ │ └── lib.rs
84
83
│ └── target
@@ -217,9 +216,6 @@ $ tree . -a
217
216
│ ├── sidebar-items.js
218
217
│ └── trait.T.html
219
218
├── s
220
-
│ ├── Cargo.lock
221
-
│ ├── Cargo.toml
222
-
│ ├── .gitignore
223
219
│ ├── src
224
220
│ │ └── lib.rs
225
221
│ └── target
@@ -245,9 +241,6 @@ $ tree . -a
245
241
│ │ └── type-impl
246
242
│ └── libs.rmeta
247
243
└── t
248
-
├── Cargo.lock
249
-
├── Cargo.toml
250
-
├── .gitignore
251
244
├── src
252
245
│ └── lib.rs
253
246
└── target
@@ -310,7 +303,7 @@ This part is the crate name.
310
303
311
304
*`<parts out dir>/<crate name>/crates-index`: for`doc/crates.js`, `doc/index.html`
312
305
313
-
This part is the also crate name. It represents a different kind of CCI because it is written to a `doc/index.html`, and rendered as an HTML document instead as JSON. In principal, we could use this part to add more information to the crates index `doc/index.html` (the first line of the top level crate documentation, for example).
306
+
This part is also the crate name. It represents a different kind of CCI because it is written to a `doc/index.html`, and rendered as an HTML document instead as JSON. In principal, we could use this part to add more information to the crates index `doc/index.html` (the first line of the top level crate documentation, for example).
314
307
315
308
*`<parts out dir>/<crate name>/type-impl`: for`doc/type.impl/**/*.js`
316
309
@@ -362,13 +355,13 @@ The WIP may change the sorting order of the elements in the CCI. It does not cha
362
355
363
356
# Rationale and alternatives
364
357
365
-
Running rustdoc in parallel is essential in enabling the tool to scale to large projects. The approach implemented by Cargo is to run rustdoc in parallel by locking the CCI files. There are some environments where having synchronized access to the CCI is impossible. This proposal implements a reasonable approach to shared rustdoc, because it cleanly enables the addition of new kinds of CCI without changing existing documentation.
358
+
Running rustdoc in parallel is essential in enabling the tool to scale to large projects. The approach implemented by Cargo is to run rustdoc in parallel by locking the CCI files. There are some workspaces where having synchronized access to the CCI is impossible. This proposal implements a reasonable approach to shared rustdoc, because it cleanly enables the addition of new kinds of CCI without changing existing documentation.
366
359
367
360
# Prior art
368
361
369
362
Prior art for linking and merging independently generated documentation was **not** identified in Javadoc, Godoc, Doxygen, Sphinx (intersphinx), nor any documentation system for other languages. Analogs of cross-crate information were not found, but a more thorough investigation or experience with other systems may be needed.
370
363
371
-
However, the issues presented here have been encountered in multiple build systems that interact with rustdoc. They limit the usefulness of rustdoc in large environments.
364
+
However, the issues presented here have been encountered in multiple build systems that interact with rustdoc. They limit the usefulness of rustdoc in large workspaces.
372
365
373
366
## Bazel
374
367
@@ -377,7 +370,7 @@ Bazel has `rules_rust` for building Rust targets and rustdoc documentation.
It does not document crates' dependencies. `search-index.js`, for example, is both a dependency and an output file for rustdoc in multi-crate documentation environments. If it is declared as a dependency in this way, Bazel could not build docs for the members of an environment in parallel with a single output directory, as it strictly enforces hermiticity. For a recursive, parallel rustdoc to ever serve as a first-class citizen in Bazel, changes similar to the ones described in this proposal would be needed.
373
+
It does not document crates' dependencies. `search-index.js`, forexample, is both a dependency and an output file for rustdocin multi-crate documentation workspaces. If it is declared as a dependency in this way, Bazel could not build docs forthe members of an environmentin parallel with a single output directory, as it strictly enforces hermiticity. For a recursive, parallel rustdoc to ever serve as a first-class citizen in Bazel, changes similar to the ones described in this proposal would be needed.
381
374
382
375
There is an [open issue](https://github.com/bazelbuild/rules_rust/issues/1837) raised about the fact that Bazel does not document crates dependencies. The comments in the issue discuss a pull request on Bazel that documents each crates dependencies in a separate output directory. It is noted in the discussion that this solution, being implemented under the current rustdoc, "doesn't scale well and it should be implemented in a different manner long term." In order to get CCI in a mode like this, rustdoc would need to adopt changes, like the ones in this proposal, for merging cross-crate information.
383
376
@@ -403,7 +396,7 @@ It has a subtarget, `[doc]`, for generating rustdoc for a crate.
403
396
404
397
You can provide a coarse-grained `extern-html-root-url`for all dependencies. You could document all crates independently, but no cross-crate information would be shared.
405
398
406
-
It does not document crates' dependencies for the same reason that Bazel does not.
399
+
buck2 does not natively merge rustdoc from separate targets. The buck2 maintainers have a [proprietary search backend](https://rust-lang.zulipchat.com/#narrow/stream/266220-t-rustdoc/topic/mergable.20rustdoc.20proposal/near/445952204) that merges and parses `search-index.js` files from separately documented crates. Their proprietary tooling does not handle cross-crate trait implementations from upstream crates. By implementing this merging directly in rustdoc, we could avoid fragmentation and bring cross-crate information to more consumers.
0 commit comments