Skip to content

Commit ee6df13

Browse files
committed
rustbuild: Move rustbook to a src/tools directory
We've actually got quite a few tools that are compiled as part of our build, let's start housing them all in a `tools` directory.
1 parent 4d3d29d commit ee6df13

File tree

21 files changed

+55
-56
lines changed

21 files changed

+55
-56
lines changed

mk/crates.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ TOOL_DEPS_error_index_generator := rustdoc syntax serialize
125125
TOOL_SOURCE_compiletest := $(S)src/compiletest/compiletest.rs
126126
TOOL_SOURCE_rustdoc := $(S)src/driver/driver.rs
127127
TOOL_SOURCE_rustc := $(S)src/driver/driver.rs
128-
TOOL_SOURCE_rustbook := $(S)src/rustbook/main.rs
128+
TOOL_SOURCE_rustbook := $(S)src/tools/rustbook/main.rs
129129
TOOL_SOURCE_error_index_generator := $(S)src/error_index_generator/main.rs
130130

131131
ONLY_RLIB_core := 1

src/bootstrap/build/compile.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,3 +298,28 @@ fn add_to_sysroot(out_dir: &Path, sysroot_dst: &Path) {
298298
sysroot_dst.join(path.file_name().unwrap())));
299299
}
300300
}
301+
302+
/// Build a tool in `src/tools`
303+
///
304+
/// This will build the specified tool with the specified `host` compiler in
305+
/// `stage` into the normal cargo output directory.
306+
pub fn tool(build: &Build, stage: u32, host: &str, tool: &str) {
307+
println!("Building stage{} tool {} ({})", stage, tool, host);
308+
309+
let compiler = Compiler::new(stage, host);
310+
311+
// FIXME: need to clear out previous tool and ideally deps, may require
312+
// isolating output directories or require a pseudo shim step to
313+
// clear out all the info.
314+
//
315+
// Maybe when libstd is compiled it should clear out the rustc of the
316+
// corresponding stage?
317+
// let out_dir = build.cargo_out(stage, &host, Mode::Librustc, target);
318+
// build.clear_if_dirty(&out_dir, &libstd_shim(build, stage, &host, target));
319+
320+
let mut cargo = build.cargo(stage, &compiler, Mode::Tool, None, "build");
321+
cargo.arg("--manifest-path")
322+
.arg(build.src.join(format!("src/tools/{}/Cargo.toml", tool)));
323+
build.run(&mut cargo);
324+
}
325+

src/bootstrap/build/mod.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ impl Build {
165165
Rustc { stage } => {
166166
compile::assemble_rustc(self, stage, target.target);
167167
}
168+
ToolRustbook { stage } => {
169+
compile::tool(self, stage, target.target, "rustbook");
170+
}
168171
DocBook { stage } => {
169172
doc::rustbook(self, stage, target.target, "book", &doc_out);
170173
}
@@ -303,15 +306,9 @@ impl Build {
303306

304307
/// Get the specified tool next to the specified compiler
305308
fn tool(&self, compiler: &Compiler, tool: &str) -> PathBuf {
306-
if compiler.is_snapshot(self) {
307-
assert!(tool == "rustdoc", "no tools other than rustdoc in stage0");
308-
let mut rustdoc = self.rustc.clone();
309-
rustdoc.pop();
310-
rustdoc.push(exe("rustdoc", &self.config.build));
311-
return rustdoc
312-
}
313-
let (stage, host) = (compiler.stage, compiler.host);
314-
self.cargo_out(stage - 1, host, false, host).join(exe(tool, host))
309+
self.stage_out(compiler.stage, compiler.host, false)
310+
.join(self.cargo_dir())
311+
.join(exe(tool, compiler.host))
315312
}
316313

317314
/// Get a `Command` which is ready to run `tool` in `stage` built for
@@ -322,8 +319,8 @@ impl Build {
322319
let host = compiler.host;
323320
let stage = compiler.stage;
324321
let paths = vec![
325-
self.cargo_out(stage - 1, host, true, host).join("deps"),
326-
self.cargo_out(stage - 1, host, false, host).join("deps"),
322+
self.cargo_out(stage, host, true, host).join("deps"),
323+
self.cargo_out(stage, host, false, host).join("deps"),
327324
];
328325
add_lib_path(paths, &mut cmd);
329326
return cmd
@@ -354,7 +351,6 @@ impl Build {
354351
}
355352
if stage > 0 {
356353
features.push_str(" rustdoc");
357-
features.push_str(" rustbook");
358354
}
359355
return features
360356
}

src/bootstrap/build/step.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ macro_rules! targets {
4545
host: &'a str
4646
}),
4747

48+
// Various tools that we can build as part of the build.
49+
(tool_rustbook, ToolRustbook { stage: u32 }),
50+
4851
// Steps for long-running native builds. Ideally these wouldn't
4952
// actually exist and would be part of build scripts, but for now
5053
// these are here.
@@ -255,7 +258,9 @@ impl<'a> Step<'a> {
255258
}
256259
Source::DocBook { stage } |
257260
Source::DocNomicon { stage } |
258-
Source::DocStyle { stage } |
261+
Source::DocStyle { stage } => {
262+
vec![self.tool_rustbook(stage)]
263+
}
259264
Source::DocStandalone { stage } => {
260265
vec![self.rustc(stage)]
261266
}
@@ -269,6 +274,8 @@ impl<'a> Step<'a> {
269274
}
270275
Source::Check { stage, compiler: _ } => {
271276
vec![]
277+
Source::ToolRustbook { stage } => {
278+
vec![self.librustc(stage, self.compiler(stage))]
272279
}
273280
}
274281
}

src/rustbook/Cargo.toml

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/rustc/Cargo.lock

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/rustc/Cargo.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ path = "rustc.rs"
1111
name = "rustdoc"
1212
path = "rustdoc.rs"
1313

14-
[[bin]]
15-
name = "rustbook"
16-
path = "rustbook.rs"
17-
1814
[profile.release]
1915
opt-level = 2
2016

@@ -27,7 +23,6 @@ debug-assertions = false
2723
# All optional dependencies so the features passed to this Cargo.toml select
2824
# what should actually be built.
2925
[dependencies]
30-
rustbook = { path = "../rustbook", optional = true }
3126
rustc_back = { path = "../librustc_back" }
3227
rustc_driver = { path = "../librustc_driver" }
3328
rustdoc = { path = "../librustdoc", optional = true }

src/rustc/rustbook.rs

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/tools/rustbook/Cargo.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tools/rustbook/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
authors = ["The Rust Project Developers"]
3+
name = "rustbook"
4+
version = "0.0.0"
5+
6+
[[bin]]
7+
name = "rustbook"
8+
path = "main.rs"
File renamed without changes.

src/rustbook/build.rs renamed to src/tools/rustbook/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ fn render(book: &Book, tgt: &Path) -> CliResult<()> {
160160

161161
// Copy js for playpen
162162
let mut playpen = try!(File::create(tgt.join("playpen.js")));
163-
let js = include_bytes!("../librustdoc/html/static/playpen.js");
163+
let js = include_bytes!("../../librustdoc/html/static/playpen.js");
164164
try!(playpen.write_all(js));
165165
Ok(())
166166
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)