Skip to content

Commit 848e785

Browse files
committed
rustbuild: Add rustbook/standalone doc support
This commit implements documentation generation of the nomicon, the book, the style guide, and the standalone docs. New steps were added for each one as well as appropriate makefile targets for each one as well.
1 parent 7ce4afb commit 848e785

File tree

5 files changed

+157
-1
lines changed

5 files changed

+157
-1
lines changed

src/bootstrap/build/doc.rs

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use std::path::Path;
12+
use std::fs::{self, File};
13+
use std::io::prelude::*;
14+
15+
use build::{Build, Compiler};
16+
use build::util::up_to_date;
17+
18+
pub fn rustbook(build: &Build, stage: u32, host: &str, name: &str, out: &Path) {
19+
t!(fs::create_dir_all(out));
20+
21+
let out = out.join(name);
22+
let compiler = Compiler::new(stage, host);
23+
let src = build.src.join("src/doc").join(name);
24+
let index = out.join("index.html");
25+
let rustbook = build.tool(&compiler, "rustbook");
26+
if up_to_date(&src, &index) && up_to_date(&rustbook, &index) {
27+
return
28+
}
29+
println!("Rustbook stage{} ({}) - {}", stage, host, name);
30+
let _ = fs::remove_dir_all(&out);
31+
build.run(build.tool_cmd(&compiler, "rustbook")
32+
.arg("build")
33+
.arg(&src)
34+
.arg(out));
35+
}
36+
37+
pub fn standalone(build: &Build, stage: u32, host: &str, out: &Path) {
38+
println!("Documenting stage{} standalone ({})", stage, host);
39+
t!(fs::create_dir_all(out));
40+
41+
let compiler = Compiler::new(stage, host);
42+
43+
let favicon = build.src.join("src/doc/favicon.inc");
44+
let footer = build.src.join("src/doc/footer.inc");
45+
let full_toc = build.src.join("src/doc/full-toc.inc");
46+
t!(fs::copy(build.src.join("src/doc/rust.css"), out.join("rust.css")));
47+
48+
let version_input = build.src.join("src/doc/version_info.html.template");
49+
let version_info = out.join("version_info.html");
50+
51+
if !up_to_date(&version_input, &version_info) {
52+
let mut info = String::new();
53+
t!(t!(File::open(&version_input)).read_to_string(&mut info));
54+
let blank = String::new();
55+
let short = build.short_ver_hash.as_ref().unwrap_or(&blank);
56+
let hash = build.ver_hash.as_ref().unwrap_or(&blank);
57+
let info = info.replace("VERSION", &build.release)
58+
.replace("SHORT_HASH", short)
59+
.replace("STAMP", hash);
60+
t!(t!(File::create(&version_info)).write_all(info.as_bytes()));
61+
}
62+
63+
for file in t!(fs::read_dir(build.src.join("src/doc"))) {
64+
let file = t!(file);
65+
let path = file.path();
66+
let filename = path.file_name().unwrap().to_str().unwrap();
67+
if !filename.ends_with(".md") || filename == "README.md" {
68+
continue
69+
}
70+
71+
let html = out.join(filename).with_extension("html");
72+
let rustdoc = build.tool(&compiler, "rustdoc");
73+
if up_to_date(&path, &html) &&
74+
up_to_date(&footer, &html) &&
75+
up_to_date(&favicon, &html) &&
76+
up_to_date(&full_toc, &html) &&
77+
up_to_date(&version_info, &html) &&
78+
up_to_date(&rustdoc, &html) {
79+
continue
80+
}
81+
82+
let mut cmd = build.tool_cmd(&compiler, "rustdoc");
83+
cmd.arg("--html-after-content").arg(&footer)
84+
.arg("--html-before-content").arg(&version_info)
85+
.arg("--html-in-header").arg(&favicon)
86+
.arg("--markdown-playground-url")
87+
.arg("https://play.rust-lang.org/")
88+
.arg("-o").arg(out)
89+
.arg(&path);
90+
91+
if filename == "reference.md" {
92+
cmd.arg("--html-in-header").arg(&full_toc);
93+
}
94+
95+
if filename == "not_found.md" {
96+
cmd.arg("--markdown-no-toc")
97+
.arg("--markdown-css")
98+
.arg("https://doc.rust-lang.org/rust.css");
99+
} else {
100+
cmd.arg("--markdown-css").arg("rust.css");
101+
}
102+
build.run(&mut cmd);
103+
}
104+
}

src/bootstrap/build/mod.rs

+17
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ mod channel;
3333
mod clean;
3434
mod compile;
3535
mod config;
36+
mod doc;
3637
mod flags;
3738
mod native;
3839
mod sanity;
@@ -133,6 +134,7 @@ impl Build {
133134
self.update_submodules();
134135

135136
for target in step::all(self) {
137+
let doc_out = self.out.join(&target.target).join("doc");
136138
match target.src {
137139
Llvm { _dummy } => {
138140
native::llvm(self, target.target);
@@ -149,6 +151,21 @@ impl Build {
149151
Rustc { stage } => {
150152
println!("ok, rustc stage{} in {}", stage, target.target);
151153
}
154+
DocBook { stage } => {
155+
doc::rustbook(self, stage, target.target, "book", &doc_out);
156+
}
157+
DocNomicon { stage } => {
158+
doc::rustbook(self, stage, target.target, "nomicon",
159+
&doc_out);
160+
}
161+
DocStyle { stage } => {
162+
doc::rustbook(self, stage, target.target, "style",
163+
&doc_out);
164+
}
165+
DocStandalone { stage } => {
166+
doc::standalone(self, stage, target.target, &doc_out);
167+
}
168+
Doc { .. } => {} // pseudo-step
152169
}
153170
}
154171
}

src/bootstrap/build/step.rs

+21
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ macro_rules! targets {
2626
(librustc, Librustc { stage: u32, compiler: Compiler<'a> }),
2727
(llvm, Llvm { _dummy: () }),
2828
(compiler_rt, CompilerRt { _dummy: () }),
29+
(doc, Doc { stage: u32 }),
30+
(doc_book, DocBook { stage: u32 }),
31+
(doc_nomicon, DocNomicon { stage: u32 }),
32+
(doc_style, DocStyle { stage: u32 }),
33+
(doc_standalone, DocStandalone { stage: u32 }),
2934
}
3035
}
3136
}
@@ -88,6 +93,7 @@ fn top_level(build: &Build) -> Vec<Step> {
8893
src: Source::Llvm { _dummy: () },
8994
target: &build.config.build,
9095
};
96+
targets.push(t.doc(stage));
9197
for host in build.config.host.iter() {
9298
if !build.flags.host.contains(host) {
9399
continue
@@ -121,6 +127,11 @@ fn add_steps<'a>(build: &'a Build,
121127
"rustc" => targets.push(host.rustc(stage)),
122128
"llvm" => targets.push(target.llvm(())),
123129
"compiler-rt" => targets.push(target.compiler_rt(())),
130+
"doc-style" => targets.push(host.doc_style(stage)),
131+
"doc-standalone" => targets.push(host.doc_standalone(stage)),
132+
"doc-nomicon" => targets.push(host.doc_nomicon(stage)),
133+
"doc-book" => targets.push(host.doc_book(stage)),
134+
"doc" => targets.push(host.doc(stage)),
124135
_ => panic!("unknown build target: `{}`", step),
125136
}
126137
}
@@ -172,6 +183,16 @@ impl<'a> Step<'a> {
172183
vec![self.llvm(()).target(&build.config.build)]
173184
}
174185
Source::Llvm { _dummy } => Vec::new(),
186+
Source::DocBook { stage } |
187+
Source::DocNomicon { stage } |
188+
Source::DocStyle { stage } |
189+
Source::DocStandalone { stage } => {
190+
vec![self.rustc(stage)]
191+
}
192+
Source::Doc { stage } => {
193+
vec![self.doc_book(stage), self.doc_nomicon(stage),
194+
self.doc_style(stage), self.doc_standalone(stage)]
195+
}
175196
}
176197
}
177198
}

src/bootstrap/mk/Makefile.in

+12
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,15 @@ all:
2424

2525
clean:
2626
$(Q)$(BOOTSTRAP) --clean
27+
28+
docs: doc
29+
doc:
30+
$(Q)$(BOOTSTRAP) --step doc
31+
style:
32+
$(Q)$(BOOTSTRAP) --step doc-style
33+
nomicon:
34+
$(Q)$(BOOTSTRAP) --step doc-nomicon
35+
book:
36+
$(Q)$(BOOTSTRAP) --step doc-book
37+
standalone-docs:
38+
$(Q)$(BOOTSTRAP) --step doc-standalone

src/doc/rustc-ux-guidelines.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
% Rustc UX guidelines
2+
13
Don't forget the user. Whether human or another program, such as an IDE, a
24
good user experience with the compiler goes a long way into making developer
35
lives better. We don't want users to be baffled by compiler output or
@@ -70,4 +72,4 @@ understandable compiler scripts.
7072
* The `--verbose` flag is for adding verbose information to `rustc` output
7173
when not compiling a program. For example, using it with the `--version` flag
7274
gives information about the hashes of the code.
73-
* Experimental flags and options must be guarded behind the `-Z unstable-options` flag.
75+
* Experimental flags and options must be guarded behind the `-Z unstable-options` flag.

0 commit comments

Comments
 (0)