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.
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.
11 //! Documentation generation for rustbuilder.
13 //! This module implements generation for all bits and pieces of documentation
14 //! for the Rust project. This notably includes suites like the rust book, the
15 //! nomicon, rust by example, standalone documentation, etc.
17 //! Everything here is basically just a shim around calling either `rustbook` or
20 use std::collections::HashSet;
23 use std::path::{PathBuf, Path};
26 use build_helper::up_to_date;
28 use crate::util::symlink_dir;
29 use crate::builder::{Builder, Compiler, RunConfig, ShouldRun, Step};
30 use crate::tool::{self, prepare_tool_cargo, Tool, SourceType};
32 use crate::cache::{INTERNER, Interned};
33 use crate::config::Config;
36 ($($name:ident, $path:expr, $book_name:expr;)+) => {
38 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
40 target: Interned<String>,
45 const DEFAULT: bool = true;
47 fn should_run(run: ShouldRun) -> ShouldRun {
48 let builder = run.builder;
49 run.path($path).default_condition(builder.config.docs)
52 fn make_run(run: RunConfig) {
53 run.builder.ensure($name {
58 fn run(self, builder: &Builder) {
59 builder.ensure(Rustbook {
61 name: INTERNER.intern_str($book_name),
70 Nomicon, "src/doc/nomicon", "nomicon";
71 Reference, "src/doc/reference", "reference";
72 EditionGuide, "src/doc/edition-guide", "edition-guide";
73 RustdocBook, "src/doc/rustdoc", "rustdoc";
74 RustcBook, "src/doc/rustc", "rustc";
75 RustByExample, "src/doc/rust-by-example", "rust-by-example";
78 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
80 target: Interned<String>,
81 name: Interned<String>,
84 impl Step for Rustbook {
87 // rustbook is never directly called, and only serves as a shim for the nomicon and the
89 fn should_run(run: ShouldRun) -> ShouldRun {
93 /// Invoke `rustbook` for `target` for the doc book `name`.
95 /// This will not actually generate any documentation if the documentation has
96 /// already been generated.
97 fn run(self, builder: &Builder) {
98 let src = builder.src.join("src/doc");
99 builder.ensure(RustbookSrc {
102 src: INTERNER.intern_path(src),
107 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
108 pub struct UnstableBook {
109 target: Interned<String>,
112 impl Step for UnstableBook {
114 const DEFAULT: bool = true;
116 fn should_run(run: ShouldRun) -> ShouldRun {
117 let builder = run.builder;
118 run.path("src/doc/unstable-book").default_condition(builder.config.docs)
121 fn make_run(run: RunConfig) {
122 run.builder.ensure(UnstableBook {
127 fn run(self, builder: &Builder) {
128 builder.ensure(UnstableBookGen {
131 builder.ensure(RustbookSrc {
133 name: INTERNER.intern_str("unstable-book"),
134 src: builder.md_doc_out(self.target),
139 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
140 pub struct CargoBook {
141 target: Interned<String>,
142 name: Interned<String>,
145 impl Step for CargoBook {
147 const DEFAULT: bool = true;
149 fn should_run(run: ShouldRun) -> ShouldRun {
150 let builder = run.builder;
151 run.path("src/tools/cargo/src/doc/book").default_condition(builder.config.docs)
154 fn make_run(run: RunConfig) {
155 run.builder.ensure(CargoBook {
157 name: INTERNER.intern_str("cargo"),
161 fn run(self, builder: &Builder) {
162 let target = self.target;
163 let name = self.name;
164 let src = builder.src.join("src/tools/cargo/src/doc");
166 let out = builder.doc_out(target);
167 t!(fs::create_dir_all(&out));
169 let out = out.join(name);
171 builder.info(&format!("Cargo Book ({}) - {}", target, name));
173 let _ = fs::remove_dir_all(&out);
175 builder.run(builder.tool_cmd(Tool::Rustbook)
183 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
185 target: Interned<String>,
186 name: Interned<String>,
187 src: Interned<PathBuf>,
190 impl Step for RustbookSrc {
193 fn should_run(run: ShouldRun) -> ShouldRun {
197 /// Invoke `rustbook` for `target` for the doc book `name` from the `src` path.
199 /// This will not actually generate any documentation if the documentation has
200 /// already been generated.
201 fn run(self, builder: &Builder) {
202 let target = self.target;
203 let name = self.name;
205 let out = builder.doc_out(target);
206 t!(fs::create_dir_all(&out));
208 let out = out.join(name);
209 let src = src.join(name);
210 let index = out.join("index.html");
211 let rustbook = builder.tool_exe(Tool::Rustbook);
212 let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
213 if up_to_date(&src, &index) && up_to_date(&rustbook, &index) {
216 builder.info(&format!("Rustbook ({}) - {}", target, name));
217 let _ = fs::remove_dir_all(&out);
218 builder.run(rustbook_cmd
226 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
229 target: Interned<String>,
233 impl Step for TheBook {
235 const DEFAULT: bool = true;
237 fn should_run(run: ShouldRun) -> ShouldRun {
238 let builder = run.builder;
239 run.path("src/doc/book").default_condition(builder.config.docs)
242 fn make_run(run: RunConfig) {
243 run.builder.ensure(TheBook {
244 compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
250 /// Build the book and associated stuff.
252 /// We need to build:
254 /// * Book (first edition)
255 /// * Book (second edition)
256 /// * Version info and CSS
259 fn run(self, builder: &Builder) {
260 let compiler = self.compiler;
261 let target = self.target;
262 let name = self.name;
265 builder.ensure(Rustbook {
267 name: INTERNER.intern_string(name.to_string()),
270 // building older edition redirects
272 let source_name = format!("{}/first-edition", name);
273 builder.ensure(Rustbook {
275 name: INTERNER.intern_string(source_name),
278 let source_name = format!("{}/second-edition", name);
279 builder.ensure(Rustbook {
281 name: INTERNER.intern_string(source_name),
284 let source_name = format!("{}/2018-edition", name);
285 builder.ensure(Rustbook {
287 name: INTERNER.intern_string(source_name),
290 // build the version info page and CSS
291 builder.ensure(Standalone {
296 // build the redirect pages
297 builder.info(&format!("Documenting book redirect pages ({})", target));
298 for file in t!(fs::read_dir(builder.src.join("src/doc/book/redirects"))) {
300 let path = file.path();
301 let path = path.to_str().unwrap();
303 invoke_rustdoc(builder, compiler, target, path);
308 fn invoke_rustdoc(builder: &Builder, compiler: Compiler, target: Interned<String>, markdown: &str) {
309 let out = builder.doc_out(target);
311 let path = builder.src.join("src/doc").join(markdown);
313 let favicon = builder.src.join("src/doc/favicon.inc");
314 let footer = builder.src.join("src/doc/footer.inc");
315 let version_info = out.join("version_info.html");
317 let mut cmd = builder.rustdoc_cmd(compiler.host);
319 let out = out.join("book");
321 cmd.arg("--html-after-content").arg(&footer)
322 .arg("--html-before-content").arg(&version_info)
323 .arg("--html-in-header").arg(&favicon)
324 .arg("--markdown-no-toc")
325 .arg("--markdown-playground-url")
326 .arg("https://play.rust-lang.org/")
329 .arg("--markdown-css")
332 builder.run(&mut cmd);
335 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
336 pub struct Standalone {
338 target: Interned<String>,
341 impl Step for Standalone {
343 const DEFAULT: bool = true;
345 fn should_run(run: ShouldRun) -> ShouldRun {
346 let builder = run.builder;
347 run.path("src/doc").default_condition(builder.config.docs)
350 fn make_run(run: RunConfig) {
351 run.builder.ensure(Standalone {
352 compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
357 /// Generates all standalone documentation as compiled by the rustdoc in `stage`
358 /// for the `target` into `out`.
360 /// This will list all of `src/doc` looking for markdown files and appropriately
361 /// perform transformations like substituting `VERSION`, `SHORT_HASH`, and
362 /// `STAMP` along with providing the various header/footer HTML we've customized.
364 /// In the end, this is just a glorified wrapper around rustdoc!
365 fn run(self, builder: &Builder) {
366 let target = self.target;
367 let compiler = self.compiler;
368 builder.info(&format!("Documenting standalone ({})", target));
369 let out = builder.doc_out(target);
370 t!(fs::create_dir_all(&out));
372 let favicon = builder.src.join("src/doc/favicon.inc");
373 let footer = builder.src.join("src/doc/footer.inc");
374 let full_toc = builder.src.join("src/doc/full-toc.inc");
375 t!(fs::copy(builder.src.join("src/doc/rust.css"), out.join("rust.css")));
377 let version_input = builder.src.join("src/doc/version_info.html.template");
378 let version_info = out.join("version_info.html");
380 if !builder.config.dry_run && !up_to_date(&version_input, &version_info) {
381 let info = t!(fs::read_to_string(&version_input))
382 .replace("VERSION", &builder.rust_release())
383 .replace("SHORT_HASH", builder.rust_info.sha_short().unwrap_or(""))
384 .replace("STAMP", builder.rust_info.sha().unwrap_or(""));
385 t!(fs::write(&version_info, &info));
388 for file in t!(fs::read_dir(builder.src.join("src/doc"))) {
390 let path = file.path();
391 let filename = path.file_name().unwrap().to_str().unwrap();
392 if !filename.ends_with(".md") || filename == "README.md" {
396 let html = out.join(filename).with_extension("html");
397 let rustdoc = builder.rustdoc(compiler.host);
398 if up_to_date(&path, &html) &&
399 up_to_date(&footer, &html) &&
400 up_to_date(&favicon, &html) &&
401 up_to_date(&full_toc, &html) &&
402 up_to_date(&version_info, &html) &&
403 (builder.config.dry_run || up_to_date(&rustdoc, &html)) {
407 let mut cmd = builder.rustdoc_cmd(compiler.host);
408 cmd.arg("--html-after-content").arg(&footer)
409 .arg("--html-before-content").arg(&version_info)
410 .arg("--html-in-header").arg(&favicon)
411 .arg("--markdown-no-toc")
412 .arg("--index-page").arg(&builder.src.join("src/doc/index.md"))
413 .arg("--markdown-playground-url")
414 .arg("https://play.rust-lang.org/")
418 if filename == "not_found.md" {
419 cmd.arg("--markdown-css")
420 .arg("https://doc.rust-lang.org/rust.css");
422 cmd.arg("--markdown-css").arg("rust.css");
424 builder.run(&mut cmd);
429 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
432 pub target: Interned<String>,
437 const DEFAULT: bool = true;
439 fn should_run(run: ShouldRun) -> ShouldRun {
440 let builder = run.builder;
441 run.all_krates("std").default_condition(builder.config.docs)
444 fn make_run(run: RunConfig) {
445 run.builder.ensure(Std {
446 stage: run.builder.top_stage,
451 /// Compile all standard library documentation.
453 /// This will generate all documentation for the standard library and its
454 /// dependencies. This is largely just a wrapper around `cargo doc`.
455 fn run(self, builder: &Builder) {
456 let stage = self.stage;
457 let target = self.target;
458 builder.info(&format!("Documenting stage{} std ({})", stage, target));
459 let out = builder.doc_out(target);
460 t!(fs::create_dir_all(&out));
461 let compiler = builder.compiler(stage, builder.config.build);
462 let compiler = if builder.force_use_stage1(compiler, target) {
463 builder.compiler(1, compiler.host)
468 builder.ensure(compile::Std { compiler, target });
469 let out_dir = builder.stage_out(compiler, Mode::Std)
470 .join(target).join("doc");
472 // Here what we're doing is creating a *symlink* (directory junction on
473 // Windows) to the final output location. This is not done as an
474 // optimization but rather for correctness. We've got three trees of
475 // documentation, one for std, one for test, and one for rustc. It's then
476 // our job to merge them all together.
478 // Unfortunately rustbuild doesn't know nearly as well how to merge doc
479 // trees as rustdoc does itself, so instead of actually having three
480 // separate trees we just have rustdoc output to the same location across
483 // This way rustdoc generates output directly into the output, and rustdoc
484 // will also directly handle merging.
485 let my_out = builder.crate_doc_out(target);
486 t!(symlink_dir_force(&builder.config, &my_out, &out_dir));
487 t!(fs::copy(builder.src.join("src/doc/rust.css"), out.join("rust.css")));
489 let run_cargo_rustdoc_for = |package: &str| {
490 let mut cargo = builder.cargo(compiler, Mode::Std, target, "rustdoc");
491 compile::std_cargo(builder, &compiler, target, &mut cargo);
493 // Keep a whitelist so we do not build internal stdlib crates, these will be
494 // build by the rustc step later if enabled.
495 cargo.arg("-Z").arg("unstable-options")
496 .arg("-p").arg(package);
497 // Create all crate output directories first to make sure rustdoc uses
499 // FIXME: Cargo should probably do this itself.
500 t!(fs::create_dir_all(out_dir.join(package)));
502 .arg("--markdown-css").arg("rust.css")
503 .arg("--markdown-no-toc")
504 .arg("--index-page").arg(&builder.src.join("src/doc/index.md"));
506 builder.run(&mut cargo);
507 builder.cp_r(&my_out, &out);
509 for krate in &["alloc", "core", "std"] {
510 run_cargo_rustdoc_for(krate);
515 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
518 target: Interned<String>,
523 const DEFAULT: bool = true;
525 fn should_run(run: ShouldRun) -> ShouldRun {
526 let builder = run.builder;
527 run.krate("test").default_condition(builder.config.docs)
530 fn make_run(run: RunConfig) {
531 run.builder.ensure(Test {
532 stage: run.builder.top_stage,
537 /// Compile all libtest documentation.
539 /// This will generate all documentation for libtest and its dependencies. This
540 /// is largely just a wrapper around `cargo doc`.
541 fn run(self, builder: &Builder) {
542 let stage = self.stage;
543 let target = self.target;
544 builder.info(&format!("Documenting stage{} test ({})", stage, target));
545 let out = builder.doc_out(target);
546 t!(fs::create_dir_all(&out));
547 let compiler = builder.compiler(stage, builder.config.build);
548 let compiler = if builder.force_use_stage1(compiler, target) {
549 builder.compiler(1, compiler.host)
554 // Build libstd docs so that we generate relative links
555 builder.ensure(Std { stage, target });
557 builder.ensure(compile::Test { compiler, target });
558 let out_dir = builder.stage_out(compiler, Mode::Test)
559 .join(target).join("doc");
561 // See docs in std above for why we symlink
562 let my_out = builder.crate_doc_out(target);
563 t!(symlink_dir_force(&builder.config, &my_out, &out_dir));
565 let mut cargo = builder.cargo(compiler, Mode::Test, target, "doc");
566 compile::test_cargo(builder, &compiler, target, &mut cargo);
568 cargo.arg("--no-deps").arg("-p").arg("test");
570 builder.run(&mut cargo);
571 builder.cp_r(&my_out, &out);
575 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
576 pub struct WhitelistedRustc {
578 target: Interned<String>,
581 impl Step for WhitelistedRustc {
583 const DEFAULT: bool = true;
584 const ONLY_HOSTS: bool = true;
586 fn should_run(run: ShouldRun) -> ShouldRun {
587 let builder = run.builder;
588 run.krate("rustc-main").default_condition(builder.config.docs)
591 fn make_run(run: RunConfig) {
592 run.builder.ensure(WhitelistedRustc {
593 stage: run.builder.top_stage,
598 /// Generate whitelisted compiler crate documentation.
600 /// This will generate all documentation for crates that are whitelisted
601 /// to be included in the standard documentation. This documentation is
602 /// included in the standard Rust documentation, so we should always
603 /// document it and symlink to merge with the rest of the std and test
604 /// documentation. We don't build other compiler documentation
605 /// here as we want to be able to keep it separate from the standard
606 /// documentation. This is largely just a wrapper around `cargo doc`.
607 fn run(self, builder: &Builder) {
608 let stage = self.stage;
609 let target = self.target;
610 builder.info(&format!("Documenting stage{} whitelisted compiler ({})", stage, target));
611 let out = builder.doc_out(target);
612 t!(fs::create_dir_all(&out));
613 let compiler = builder.compiler(stage, builder.config.build);
614 let compiler = if builder.force_use_stage1(compiler, target) {
615 builder.compiler(1, compiler.host)
620 // Build libstd docs so that we generate relative links
621 builder.ensure(Std { stage, target });
623 builder.ensure(compile::Rustc { compiler, target });
624 let out_dir = builder.stage_out(compiler, Mode::Rustc)
625 .join(target).join("doc");
627 // See docs in std above for why we symlink
628 let my_out = builder.crate_doc_out(target);
629 t!(symlink_dir_force(&builder.config, &my_out, &out_dir));
631 let mut cargo = builder.cargo(compiler, Mode::Rustc, target, "doc");
632 compile::rustc_cargo(builder, &mut cargo);
634 // We don't want to build docs for internal compiler dependencies in this
635 // step (there is another step for that). Therefore, we whitelist the crates
636 // for which docs must be built.
637 cargo.arg("--no-deps");
638 for krate in &["proc_macro"] {
639 cargo.arg("-p").arg(krate);
642 builder.run(&mut cargo);
643 builder.cp_r(&my_out, &out);
647 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
650 target: Interned<String>,
653 impl Step for Rustc {
655 const DEFAULT: bool = true;
656 const ONLY_HOSTS: bool = true;
658 fn should_run(run: ShouldRun) -> ShouldRun {
659 let builder = run.builder;
660 run.krate("rustc-main").default_condition(builder.config.docs)
663 fn make_run(run: RunConfig) {
664 run.builder.ensure(Rustc {
665 stage: run.builder.top_stage,
670 /// Generate compiler documentation.
672 /// This will generate all documentation for compiler and dependencies.
673 /// Compiler documentation is distributed separately, so we make sure
674 /// we do not merge it with the other documentation from std, test and
675 /// proc_macros. This is largely just a wrapper around `cargo doc`.
676 fn run(self, builder: &Builder) {
677 let stage = self.stage;
678 let target = self.target;
679 builder.info(&format!("Documenting stage{} compiler ({})", stage, target));
681 // This is the intended out directory for compiler documentation.
682 let out = builder.compiler_doc_out(target);
683 t!(fs::create_dir_all(&out));
685 // Get the correct compiler for this stage.
686 let compiler = builder.compiler(stage, builder.config.build);
687 let compiler = if builder.force_use_stage1(compiler, target) {
688 builder.compiler(1, compiler.host)
693 if !builder.config.compiler_docs {
694 builder.info("\tskipping - compiler/librustdoc docs disabled");
699 builder.ensure(compile::Rustc { compiler, target });
701 // We do not symlink to the same shared folder that already contains std library
702 // documentation from previous steps as we do not want to include that.
703 let out_dir = builder.stage_out(compiler, Mode::Rustc).join(target).join("doc");
704 t!(symlink_dir_force(&builder.config, &out, &out_dir));
706 // Build cargo command.
707 let mut cargo = builder.cargo(compiler, Mode::Rustc, target, "doc");
708 cargo.env("RUSTDOCFLAGS", "--document-private-items");
709 compile::rustc_cargo(builder, &mut cargo);
711 // Only include compiler crates, no dependencies of those, such as `libc`.
712 cargo.arg("--no-deps");
714 // Find dependencies for top level crates.
715 let mut compiler_crates = HashSet::new();
716 for root_crate in &["rustc_driver", "rustc_codegen_llvm", "rustc_codegen_ssa"] {
717 let interned_root_crate = INTERNER.intern_str(root_crate);
718 find_compiler_crates(builder, &interned_root_crate, &mut compiler_crates);
721 for krate in &compiler_crates {
722 // Create all crate output directories first to make sure rustdoc uses
724 // FIXME: Cargo should probably do this itself.
725 t!(fs::create_dir_all(out_dir.join(krate)));
726 cargo.arg("-p").arg(krate);
729 builder.run(&mut cargo);
733 fn find_compiler_crates(
735 name: &Interned<String>,
736 crates: &mut HashSet<Interned<String>>
738 // Add current crate.
739 crates.insert(*name);
741 // Look for dependencies.
742 for dep in builder.crates.get(name).unwrap().deps.iter() {
743 if builder.crates.get(dep).unwrap().is_local(builder) {
744 find_compiler_crates(builder, dep, crates);
749 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
752 target: Interned<String>,
755 impl Step for Rustdoc {
757 const DEFAULT: bool = true;
758 const ONLY_HOSTS: bool = true;
760 fn should_run(run: ShouldRun) -> ShouldRun {
761 run.krate("rustdoc-tool")
764 fn make_run(run: RunConfig) {
765 run.builder.ensure(Rustdoc {
766 stage: run.builder.top_stage,
771 /// Generate compiler documentation.
773 /// This will generate all documentation for compiler and dependencies.
774 /// Compiler documentation is distributed separately, so we make sure
775 /// we do not merge it with the other documentation from std, test and
776 /// proc_macros. This is largely just a wrapper around `cargo doc`.
777 fn run(self, builder: &Builder) {
778 let stage = self.stage;
779 let target = self.target;
780 builder.info(&format!("Documenting stage{} rustdoc ({})", stage, target));
782 // This is the intended out directory for compiler documentation.
783 let out = builder.compiler_doc_out(target);
784 t!(fs::create_dir_all(&out));
786 // Get the correct compiler for this stage.
787 let compiler = builder.compiler(stage, builder.config.build);
788 let compiler = if builder.force_use_stage1(compiler, target) {
789 builder.compiler(1, compiler.host)
794 if !builder.config.compiler_docs {
795 builder.info("\tskipping - compiler/librustdoc docs disabled");
799 // Build rustc docs so that we generate relative links.
800 builder.ensure(Rustc { stage, target });
803 builder.ensure(tool::Rustdoc { host: compiler.host });
805 // Symlink compiler docs to the output directory of rustdoc documentation.
806 let out_dir = builder.stage_out(compiler, Mode::ToolRustc)
809 t!(fs::create_dir_all(&out_dir));
810 t!(symlink_dir_force(&builder.config, &out, &out_dir));
812 // Build cargo command.
813 let mut cargo = prepare_tool_cargo(
824 // Only include compiler crates, no dependencies of those, such as `libc`.
825 cargo.arg("--no-deps");
826 cargo.arg("-p").arg("rustdoc");
828 cargo.env("RUSTDOCFLAGS", "--document-private-items");
829 builder.run(&mut cargo);
833 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
834 pub struct ErrorIndex {
835 target: Interned<String>,
838 impl Step for ErrorIndex {
840 const DEFAULT: bool = true;
841 const ONLY_HOSTS: bool = true;
843 fn should_run(run: ShouldRun) -> ShouldRun {
844 let builder = run.builder;
845 run.path("src/tools/error_index_generator").default_condition(builder.config.docs)
848 fn make_run(run: RunConfig) {
849 run.builder.ensure(ErrorIndex {
854 /// Generates the HTML rendered error-index by running the
855 /// `error_index_generator` tool.
856 fn run(self, builder: &Builder) {
857 let target = self.target;
859 builder.info(&format!("Documenting error index ({})", target));
860 let out = builder.doc_out(target);
861 t!(fs::create_dir_all(&out));
862 let mut index = builder.tool_cmd(Tool::ErrorIndex);
864 index.arg(out.join("error-index.html"));
866 // FIXME: shouldn't have to pass this env var
867 index.env("CFG_BUILD", &builder.config.build)
868 .env("RUSTC_ERROR_METADATA_DST", builder.extended_error_dir());
870 builder.run(&mut index);
874 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
875 pub struct UnstableBookGen {
876 target: Interned<String>,
879 impl Step for UnstableBookGen {
881 const DEFAULT: bool = true;
882 const ONLY_HOSTS: bool = true;
884 fn should_run(run: ShouldRun) -> ShouldRun {
885 let builder = run.builder;
886 run.path("src/tools/unstable-book-gen").default_condition(builder.config.docs)
889 fn make_run(run: RunConfig) {
890 run.builder.ensure(UnstableBookGen {
895 fn run(self, builder: &Builder) {
896 let target = self.target;
898 builder.ensure(compile::Std {
899 compiler: builder.compiler(builder.top_stage, builder.config.build),
903 builder.info(&format!("Generating unstable book md files ({})", target));
904 let out = builder.md_doc_out(target).join("unstable-book");
905 builder.create_dir(&out);
906 builder.remove_dir(&out);
907 let mut cmd = builder.tool_cmd(Tool::UnstableBookGen);
908 cmd.arg(builder.src.join("src"));
911 builder.run(&mut cmd);
915 fn symlink_dir_force(config: &Config, src: &Path, dst: &Path) -> io::Result<()> {
919 if let Ok(m) = fs::symlink_metadata(dst) {
920 if m.file_type().is_dir() {
921 fs::remove_dir_all(dst)?;
923 // handle directory junctions on windows by falling back to
925 fs::remove_file(dst).or_else(|_| {
931 symlink_dir(config, src, dst)