Skip to content

Commit 42ea30c

Browse files
committed
Auto merge of #45692 - steveklabnik:ship-cargo-book, r=alexcrichton
Start shipping the Cargo book Fixes #44910 Fixes #39588 See both of those bugs for more details.
2 parents b8c70b0 + 3b32a3a commit 42ea30c

File tree

2 files changed

+48
-45
lines changed

2 files changed

+48
-45
lines changed

src/bootstrap/doc.rs

+46-45
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,52 @@ impl Step for UnstableBook {
132132
}
133133
}
134134

135+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
136+
pub struct CargoBook {
137+
target: Interned<String>,
138+
name: Interned<String>,
139+
}
140+
141+
impl Step for CargoBook {
142+
type Output = ();
143+
const DEFAULT: bool = true;
144+
145+
fn should_run(run: ShouldRun) -> ShouldRun {
146+
let builder = run.builder;
147+
run.path("src/tools/cargo/src/doc/book").default_condition(builder.build.config.docs)
148+
}
149+
150+
fn make_run(run: RunConfig) {
151+
run.builder.ensure(CargoBook {
152+
target: run.target,
153+
name: INTERNER.intern_str("cargo"),
154+
});
155+
}
156+
157+
fn run(self, builder: &Builder) {
158+
let build = builder.build;
159+
160+
let target = self.target;
161+
let name = self.name;
162+
let src = PathBuf::from("src/tools/cargo/src/doc/book");
163+
164+
let out = build.doc_out(target);
165+
t!(fs::create_dir_all(&out));
166+
167+
let out = out.join(name);
168+
169+
println!("Cargo Book ({}) - {}", target, name);
170+
171+
let _ = fs::remove_dir_all(&out);
172+
173+
build.run(builder.tool_cmd(Tool::Rustbook)
174+
.arg("build")
175+
.arg(&src)
176+
.arg("-d")
177+
.arg(out));
178+
}
179+
}
180+
135181
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
136182
struct RustbookSrc {
137183
target: Interned<String>,
@@ -240,51 +286,6 @@ impl Step for TheBook {
240286
}
241287
}
242288

243-
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
244-
pub struct CargoBook {
245-
target: Interned<String>,
246-
}
247-
248-
impl Step for CargoBook {
249-
type Output = ();
250-
const DEFAULT: bool = true;
251-
252-
fn should_run(run: ShouldRun) -> ShouldRun {
253-
let builder = run.builder;
254-
run.path("src/doc/cargo").default_condition(builder.build.config.docs)
255-
}
256-
257-
fn make_run(run: RunConfig) {
258-
run.builder.ensure(CargoBook {
259-
target: run.target,
260-
});
261-
}
262-
263-
/// Create a placeholder for the cargo documentation so that doc.rust-lang.org/cargo will
264-
/// redirect to doc.crates.io. We want to publish doc.rust-lang.org/cargo in the paper
265-
/// version of the book, but we don't want to rush the process of switching cargo's docs
266-
/// over to mdbook and deploying them. When the cargo book is ready, this implementation
267-
/// should build the mdbook instead of this redirect page.
268-
fn run(self, builder: &Builder) {
269-
let build = builder.build;
270-
let out = build.doc_out(self.target);
271-
272-
let cargo_dir = out.join("cargo");
273-
t!(fs::create_dir_all(&cargo_dir));
274-
275-
let index = cargo_dir.join("index.html");
276-
let redirect_html = r#"
277-
<html>
278-
<head>
279-
<meta http-equiv="refresh" content="0; URL='http://doc.crates.io'" />
280-
</head>
281-
</html>"#;
282-
283-
println!("Creating cargo book redirect page");
284-
t!(t!(File::create(&index)).write_all(redirect_html.as_bytes()));
285-
}
286-
}
287-
288289
fn invoke_rustdoc(builder: &Builder, compiler: Compiler, target: Interned<String>, markdown: &str) {
289290
let build = builder.build;
290291
let out = build.doc_out(target);

src/doc/index.md

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Rust provides a number of book-length sets of documentation, collectively
2828
nicknamed 'The Rust Bookshelf.'
2929

3030
* [The Rust Programming Language][book] teaches you how to program in Rust.
31+
* [The Cargo Book][cargo-book] is a guide to Cargo, Rust's build tool and dependency manager.
3132
* [The Unstable Book][unstable-book] has documentation for unstable features.
3233
* [The Rustonomicon][nomicon] is your guidebook to the dark arts of unsafe Rust.
3334
* [The Reference][ref] is not a formal spec, but is more detailed and comprehensive than the book.
@@ -53,4 +54,5 @@ before this policy was put into place. That work is being tracked
5354
[nomicon]: nomicon/index.html
5455
[unstable-book]: unstable-book/index.html
5556
[rustdoc-book]: rustdoc/index.html
57+
[cargo-book]: cargo/index.html
5658

0 commit comments

Comments
 (0)