Skip to content

Commit 70ba2a2

Browse files
committed
doc: add release notes to standalone doc bundle
This is a workaround for #101714 on top of being a useful addition in its own right. It is intended to change the "canonical URL" for viewing the release notes from GitHub, which is relatively slow, to a pre-rendered HTML file that loads from the same CDN as the standard library docs. It also means you get a copy of the release notes when installing the rust-docs with rustup.
1 parent 85b8450 commit 70ba2a2

File tree

4 files changed

+113
-9
lines changed

4 files changed

+113
-9
lines changed

src/bootstrap/src/core/build_steps/doc.rs

+102-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
//! Everything here is basically just a shim around calling either `rustbook` or
88
//! `rustdoc`.
99
10-
use std::fs;
10+
use std::{fs, mem};
11+
use std::io::{self, Write};
1112
use std::path::{Path, PathBuf};
1213

1314
use crate::core::build_steps::compile;
@@ -388,6 +389,106 @@ impl Step for Standalone {
388389
}
389390
}
390391

392+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
393+
pub struct Releases {
394+
compiler: Compiler,
395+
target: TargetSelection,
396+
}
397+
398+
impl Step for Releases {
399+
type Output = ();
400+
const DEFAULT: bool = true;
401+
402+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
403+
let builder = run.builder;
404+
run.path("RELEASES.md").alias("releases").default_condition(builder.config.docs)
405+
}
406+
407+
fn make_run(run: RunConfig<'_>) {
408+
run.builder.ensure(Releases {
409+
compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
410+
target: run.target,
411+
});
412+
}
413+
414+
/// Generates all standalone documentation as compiled by the rustdoc in `stage`
415+
/// for the `target` into `out`.
416+
///
417+
/// This will list all of `src/doc` looking for markdown files and appropriately
418+
/// perform transformations like substituting `VERSION`, `SHORT_HASH`, and
419+
/// `STAMP` along with providing the various header/footer HTML we've customized.
420+
///
421+
/// In the end, this is just a glorified wrapper around rustdoc!
422+
fn run(self, builder: &Builder<'_>) {
423+
let target = self.target;
424+
let compiler = self.compiler;
425+
let _guard = builder.msg_doc(compiler, "releases", target);
426+
let out = builder.doc_out(target);
427+
t!(fs::create_dir_all(&out));
428+
429+
builder.ensure(Standalone {
430+
compiler: builder.compiler(builder.top_stage, builder.config.build),
431+
target,
432+
});
433+
434+
let version_info = builder.ensure(SharedAssets { target: self.target }).version_info;
435+
436+
let favicon = builder.src.join("src/doc/favicon.inc");
437+
let footer = builder.src.join("src/doc/footer.inc");
438+
let full_toc = builder.src.join("src/doc/full-toc.inc");
439+
440+
let html = out.join("releases.html");
441+
let tmppath = out.join("releases.md");
442+
let inpath = builder.src.join("RELEASES.md");
443+
let rustdoc = builder.rustdoc(compiler);
444+
if !up_to_date(&inpath, &html)
445+
|| !up_to_date(&footer, &html)
446+
|| !up_to_date(&favicon, &html)
447+
|| !up_to_date(&full_toc, &html)
448+
|| !(builder.config.dry_run() || up_to_date(&version_info, &html))
449+
|| !(builder.config.dry_run() || up_to_date(&rustdoc, &html))
450+
{
451+
let mut tmpfile = t!(fs::File::create(&tmppath));
452+
t!(tmpfile.write_all(b"% Rust Release Notes\n\n"));
453+
t!(io::copy(&mut t!(fs::File::open(&inpath)), &mut tmpfile));
454+
mem::drop(tmpfile);
455+
let mut cmd = builder.rustdoc_cmd(compiler);
456+
457+
// Needed for --index-page flag
458+
cmd.arg("-Z").arg("unstable-options");
459+
460+
cmd.arg("--html-after-content")
461+
.arg(&footer)
462+
.arg("--html-before-content")
463+
.arg(&version_info)
464+
.arg("--html-in-header")
465+
.arg(&favicon)
466+
.arg("--markdown-no-toc")
467+
.arg("--markdown-css")
468+
.arg("rust.css")
469+
.arg("--index-page")
470+
.arg(&builder.src.join("src/doc/index.md"))
471+
.arg("--markdown-playground-url")
472+
.arg("https://play.rust-lang.org/")
473+
.arg("-o")
474+
.arg(&out)
475+
.arg(&tmppath);
476+
477+
if !builder.config.docs_minification {
478+
cmd.arg("--disable-minification");
479+
}
480+
481+
builder.run(&mut cmd);
482+
}
483+
484+
// We open doc/RELEASES.html as the default if invoked as `x.py doc --open RELEASES.md`
485+
// with no particular explicit doc requested (e.g. library/core).
486+
if builder.was_invoked_explicitly::<Self>(Kind::Doc) {
487+
builder.open_in_browser(&html);
488+
}
489+
}
490+
}
491+
391492
#[derive(Debug, Clone)]
392493
pub struct SharedAssetsPaths {
393494
pub version_info: PathBuf,

src/bootstrap/src/core/builder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,7 @@ impl<'a> Builder<'a> {
810810
doc::StyleGuide,
811811
doc::Tidy,
812812
doc::Bootstrap,
813+
doc::Releases,
813814
),
814815
Kind::Dist => describe!(
815816
dist::Docs,

src/doc/index.md

+6-8
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@
44
nav {
55
display: none;
66
}
7-
body {
8-
font-family: serif;
9-
}
10-
h1, h2, h3, h4, h5, h6 {
11-
font-family: sans-serif;
12-
}
137
h3 {
148
font-size: 1.35rem;
159
}
@@ -119,10 +113,14 @@ documentation for your project _and_ all its dependencies in their correct
119113
version, and open it in your browser. Add the flag `--document-private-items` to
120114
also show items not marked `pub`.
121115

122-
### The Edition Guide
116+
### Rust Version History
117+
118+
[The Release Notes](releases.html) describes the change history of the Rust
119+
toolchain and language.
123120

124121
[The Edition Guide](edition-guide/index.html) describes the Rust editions and
125-
their differences.
122+
their differences. The latest version of the toolchain supports all
123+
historical editions.
126124

127125
### The `rustc` Book
128126

src/doc/rust.css

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* General structure */
22

33
body {
4+
font-family: serif;
45
margin: 0 auto;
56
padding: 0 15px;
67
font-size: 18px;
@@ -17,6 +18,9 @@ body {
1718
}
1819
}
1920

21+
h1, h2, h3, h4, h5, h6 {
22+
font-family: sans-serif;
23+
}
2024
h2, h3, h4, h5, h6 {
2125
font-weight: 400;
2226
line-height: 1.1;

0 commit comments

Comments
 (0)