Skip to content

Commit 6f222b3

Browse files
Rollup merge of #146220 - weihanglo:rustdoc-emit, r=GuillaumeGomez
feat(rustdoc): stabilize `--emit` flag ### [---> FCP <---](#146220 (comment)) ## Stabilization Report: `rustdoc --emit` **Feature:** `rustdoc --emit` **Tracking issue:** #83784 **Stabilization PR:** #146220 ### What we are stabilizing This stabilizes the `rustdoc --emit` flag, which controls what types of output rustdoc produces. The flag accepts a comma-separated list of the following emit types: - `html-static-files` --- Shared static files with content-hashed filenames for safe caching. - `html-non-static-files` --- Per-crate documentation files with deterministic filenames. - `dep-info[=<path>]` --- A Makefile-compatible `.d` file listing all source files loaded during documentation generation. Same as rustc's dep-info files. When `--emit` is not specified, the default behavior is `--emit=html-static-files,html-non-static-files` (i.e., full HTML documentation output, no dep-info). ### What we are not stabilizing * Interaction between other unstable options, such as `-Zrustdoc-mergeable-info` and `--output-format=doctest` * Available options and the default options when `--emit` not specified. * Extension of per-type emit paths for options currently missing that. ### Motivation #### Cargo The primary consumer is Cargo, which needs `--emit=dep-info=<path>` to precisely track the input dependencies of a rustdoc invocation (see the [`-Zrustdoc-depinfo`] unstable Cargo feature). Without dep-info, Cargo cannot detect changes to files pulled in via `#[path = "..."]` or similar mechanisms and leads to stale documentation in incremental builds. Cargo also uses the selective emission mechanism (`html-static-files` / `html-non-static-files`) when the unstable [`-Zrustdoc-mergeable-info`] feature is active. It skips writing shared static files and search index during per-crate doc generation and defer them to a final merge phase. Under stable usage, Cargo passes all three emit types together. #### docs.rs docs.rs is the other major consumer. It uses selective emission to avoid redundantly copying toolchain-wide static files for every crate, which has historically been a source of breakage. See the tracking #83784 and the about page for more <https://docs.rs/about/download>. ### Tests - `tests/run-make/emit-shared-files` --- Verifies selective emission of static vs non-static files. - `tests/run-make/rustdoc-dep-info` --- Verifies dep-info generation, including explicit path and `--out-dir` interaction. - `tests/run-make/rustdoc-scrape-examples-dep-info` --- Verifies dep-info works with scrape-examples. - `tests/run-make/rustdoc-default-output/` --- Verifies `--help` output shows `[html-static-files,html-non-static-files,dep-info]` [`-Zrustdoc-depinfo`]: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#rustdoc-depinfo [`-Zrustdoc-mergeable-info`]: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#rustdoc-mergeable-info
2 parents 480d852 + cef0e99 commit 6f222b3

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

src/doc/rustdoc/src/command-line-arguments.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,37 @@ When `rustdoc` receives this flag, it will print an extra "Version (version)" in
440440
the crate root's docs. You can use this flag to differentiate between different versions of your
441441
library's documentation.
442442

443+
## `--emit`: control the types of output for rustdoc to emit
444+
445+
This flag controls the types of output by rustdoc. It accepts a comma-separated
446+
list of values, and may be specified multiple times. The valid emit kinds are:
447+
448+
- `html-static-files` --- Generates shared static files whose contents are
449+
tied to a specific toolchain version. These are written with a filename
450+
that includes a hash of their contents, so they are safe to cache with
451+
the change if the toolchain version or their contents change, or with the
452+
`Cache-Control: immutable` directive.
453+
- `html-non-static-files` --- Generates files based on the crate(s) being
454+
documented. These file names need to be deterministic so there is no
455+
content-hash in their file names.
456+
- `dep-info` --- Generates a file with Makefile syntax that indicates all the
457+
source files that were loaded to document the crate. The default output
458+
filename is `CRATE_NAME.d`. This emit type can can optionally be followed by
459+
`=` to specify an explicit output path, for example,
460+
`--emit=dep-info=/path/to/foo.d`. The output can be sent to stdout by
461+
specifying `-` as the path (e.g., `--emit=dep-info=-`).
462+
463+
Using this flag looks like this:
464+
465+
```bash
466+
$ rustdoc src/lib.rs --emit=html-static-files,html-non-static-files,dep-info=/path/to/build/cache/foo.d
467+
```
468+
469+
If not specified, the default emit types would be
470+
`--emit=html-static-files,html-non-static-files`.
471+
472+
Output files are written to the current directory unless the `--out-dir` flag is used.
473+
443474
## `-`: load source code from the standard input
444475

445476
If you specify `-` as the INPUT on the command line, then `rustdoc` will read the

src/librustdoc/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ fn opts() -> Vec<RustcOptGroup> {
534534
"",
535535
),
536536
opt(
537-
Unstable,
537+
Stable,
538538
Multi,
539539
"",
540540
"emit",

0 commit comments

Comments
 (0)