2016-02-16 12:26:43 -06:00
|
|
|
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2016-05-02 17:16:15 -05:00
|
|
|
//! Documentation generation for rustbuild.
|
|
|
|
//!
|
|
|
|
//! This module implements generation for all bits and pieces of documentation
|
|
|
|
//! for the Rust project. This notably includes suites like the rust book, the
|
|
|
|
//! nomicon, standalone documentation, etc.
|
|
|
|
//!
|
|
|
|
//! Everything here is basically just a shim around calling either `rustbook` or
|
|
|
|
//! `rustdoc`.
|
|
|
|
|
2016-02-16 12:26:43 -06:00
|
|
|
use std::fs::{self, File};
|
|
|
|
use std::io::prelude::*;
|
2017-03-01 17:34:54 -06:00
|
|
|
use std::io;
|
|
|
|
use std::path::Path;
|
2016-03-08 01:11:05 -06:00
|
|
|
use std::process::Command;
|
2016-02-16 12:26:43 -06:00
|
|
|
|
2016-07-05 23:58:20 -05:00
|
|
|
use {Build, Compiler, Mode};
|
2017-03-01 17:34:54 -06:00
|
|
|
use util::{cp_r, symlink_dir};
|
2017-01-31 15:27:51 -06:00
|
|
|
use build_helper::up_to_date;
|
2016-02-16 12:26:43 -06:00
|
|
|
|
2016-05-02 17:16:15 -05:00
|
|
|
/// Invoke `rustbook` as compiled in `stage` for `target` for the doc book
|
|
|
|
/// `name` into the `out` path.
|
|
|
|
///
|
|
|
|
/// This will not actually generate any documentation if the documentation has
|
|
|
|
/// already been generated.
|
2016-12-28 17:01:21 -06:00
|
|
|
pub fn rustbook(build: &Build, target: &str, name: &str) {
|
2016-10-21 15:18:09 -05:00
|
|
|
let out = build.doc_out(target);
|
|
|
|
t!(fs::create_dir_all(&out));
|
2016-02-16 12:26:43 -06:00
|
|
|
|
|
|
|
let out = out.join(name);
|
2016-12-28 17:01:21 -06:00
|
|
|
let compiler = Compiler::new(0, &build.config.build);
|
2016-02-16 12:26:43 -06:00
|
|
|
let src = build.src.join("src/doc").join(name);
|
|
|
|
let index = out.join("index.html");
|
|
|
|
let rustbook = build.tool(&compiler, "rustbook");
|
|
|
|
if up_to_date(&src, &index) && up_to_date(&rustbook, &index) {
|
|
|
|
return
|
|
|
|
}
|
2016-12-28 17:01:21 -06:00
|
|
|
println!("Rustbook ({}) - {}", target, name);
|
2016-02-16 12:26:43 -06:00
|
|
|
let _ = fs::remove_dir_all(&out);
|
|
|
|
build.run(build.tool_cmd(&compiler, "rustbook")
|
|
|
|
.arg("build")
|
|
|
|
.arg(&src)
|
2017-02-07 17:13:57 -06:00
|
|
|
.arg("-d")
|
2016-02-16 12:26:43 -06:00
|
|
|
.arg(out));
|
|
|
|
}
|
|
|
|
|
2017-03-07 14:31:41 -06:00
|
|
|
/// Build the book and associated stuff.
|
|
|
|
///
|
|
|
|
/// We need to build:
|
|
|
|
///
|
|
|
|
/// * Book (first edition)
|
|
|
|
/// * Book (second edition)
|
|
|
|
/// * Index page
|
|
|
|
/// * Redirect pages
|
2017-03-07 13:49:50 -06:00
|
|
|
pub fn book(build: &Build, target: &str, name: &str) {
|
2017-03-07 14:31:41 -06:00
|
|
|
// build book first edition
|
2017-03-07 13:49:50 -06:00
|
|
|
rustbook(build, target, &format!("{}/first-edition", name));
|
2017-03-07 14:31:41 -06:00
|
|
|
|
|
|
|
// build book second edition
|
2017-03-07 13:49:50 -06:00
|
|
|
rustbook(build, target, &format!("{}/second-edition", name));
|
2017-03-07 14:31:41 -06:00
|
|
|
|
|
|
|
// build the index page
|
|
|
|
let index = format!("{}/index.md", name);
|
2017-03-07 15:29:05 -06:00
|
|
|
println!("Documenting book index ({})", target);
|
2017-03-07 14:31:41 -06:00
|
|
|
invoke_rustdoc(build, target, &index);
|
2017-03-07 16:19:25 -06:00
|
|
|
|
2017-03-07 15:07:55 -06:00
|
|
|
// build the redirect pages
|
2017-03-07 15:29:05 -06:00
|
|
|
println!("Documenting book redirect pages ({})", target);
|
2017-03-07 15:07:55 -06:00
|
|
|
for file in t!(fs::read_dir(build.src.join("src/doc/book/redirects"))) {
|
|
|
|
let file = t!(file);
|
|
|
|
let path = file.path();
|
|
|
|
let path = path.to_str().unwrap();
|
|
|
|
|
|
|
|
invoke_rustdoc(build, target, path);
|
|
|
|
}
|
2017-03-07 14:31:41 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn invoke_rustdoc(build: &Build, target: &str, markdown: &str) {
|
|
|
|
let out = build.doc_out(target);
|
|
|
|
|
|
|
|
let compiler = Compiler::new(0, &build.config.build);
|
|
|
|
|
|
|
|
let path = build.src.join("src/doc").join(markdown);
|
|
|
|
|
|
|
|
let rustdoc = build.rustdoc(&compiler);
|
|
|
|
|
|
|
|
let favicon = build.src.join("src/doc/favicon.inc");
|
|
|
|
let footer = build.src.join("src/doc/footer.inc");
|
|
|
|
|
2017-03-07 15:29:05 -06:00
|
|
|
let version_input = build.src.join("src/doc/version_info.html.template");
|
2017-03-07 14:31:41 -06:00
|
|
|
let version_info = out.join("version_info.html");
|
|
|
|
|
2017-03-07 15:29:05 -06:00
|
|
|
if !up_to_date(&version_input, &version_info) {
|
|
|
|
let mut info = String::new();
|
|
|
|
t!(t!(File::open(&version_input)).read_to_string(&mut info));
|
|
|
|
let info = info.replace("VERSION", &build.rust_release())
|
|
|
|
.replace("SHORT_HASH", build.rust_info.sha_short().unwrap_or(""))
|
|
|
|
.replace("STAMP", build.rust_info.sha().unwrap_or(""));
|
|
|
|
t!(t!(File::create(&version_info)).write_all(info.as_bytes()));
|
|
|
|
}
|
|
|
|
|
2017-03-07 14:31:41 -06:00
|
|
|
let mut cmd = Command::new(&rustdoc);
|
|
|
|
|
|
|
|
build.add_rustc_lib_path(&compiler, &mut cmd);
|
|
|
|
|
|
|
|
let out = out.join("book");
|
|
|
|
|
2017-03-07 15:29:05 -06:00
|
|
|
t!(fs::copy(build.src.join("src/doc/rust.css"), out.join("rust.css")));
|
|
|
|
|
2017-03-07 14:31:41 -06:00
|
|
|
cmd.arg("--html-after-content").arg(&footer)
|
|
|
|
.arg("--html-before-content").arg(&version_info)
|
|
|
|
.arg("--html-in-header").arg(&favicon)
|
|
|
|
.arg("--markdown-playground-url")
|
|
|
|
.arg("https://play.rust-lang.org/")
|
|
|
|
.arg("-o").arg(&out)
|
|
|
|
.arg(&path)
|
|
|
|
.arg("--markdown-css")
|
|
|
|
.arg("rust.css");
|
|
|
|
|
|
|
|
build.run(&mut cmd);
|
2017-03-07 13:49:50 -06:00
|
|
|
}
|
|
|
|
|
2016-05-02 17:16:15 -05:00
|
|
|
/// Generates all standalone documentation as compiled by the rustdoc in `stage`
|
|
|
|
/// for the `target` into `out`.
|
|
|
|
///
|
|
|
|
/// This will list all of `src/doc` looking for markdown files and appropriately
|
|
|
|
/// perform transformations like substituting `VERSION`, `SHORT_HASH`, and
|
|
|
|
/// `STAMP` alongw ith providing the various header/footer HTML we've cutomized.
|
|
|
|
///
|
|
|
|
/// In the end, this is just a glorified wrapper around rustdoc!
|
2016-12-30 21:50:57 -06:00
|
|
|
pub fn standalone(build: &Build, target: &str) {
|
|
|
|
println!("Documenting standalone ({})", target);
|
2016-10-21 15:18:09 -05:00
|
|
|
let out = build.doc_out(target);
|
|
|
|
t!(fs::create_dir_all(&out));
|
2016-02-16 12:26:43 -06:00
|
|
|
|
2016-12-30 21:50:57 -06:00
|
|
|
let compiler = Compiler::new(0, &build.config.build);
|
2016-02-16 12:26:43 -06:00
|
|
|
|
|
|
|
let favicon = build.src.join("src/doc/favicon.inc");
|
|
|
|
let footer = build.src.join("src/doc/footer.inc");
|
|
|
|
let full_toc = build.src.join("src/doc/full-toc.inc");
|
|
|
|
t!(fs::copy(build.src.join("src/doc/rust.css"), out.join("rust.css")));
|
|
|
|
|
|
|
|
let version_input = build.src.join("src/doc/version_info.html.template");
|
|
|
|
let version_info = out.join("version_info.html");
|
|
|
|
|
|
|
|
if !up_to_date(&version_input, &version_info) {
|
|
|
|
let mut info = String::new();
|
|
|
|
t!(t!(File::open(&version_input)).read_to_string(&mut info));
|
2017-02-15 17:57:06 -06:00
|
|
|
let info = info.replace("VERSION", &build.rust_release())
|
|
|
|
.replace("SHORT_HASH", build.rust_info.sha_short().unwrap_or(""))
|
|
|
|
.replace("STAMP", build.rust_info.sha().unwrap_or(""));
|
2016-02-16 12:26:43 -06:00
|
|
|
t!(t!(File::create(&version_info)).write_all(info.as_bytes()));
|
|
|
|
}
|
|
|
|
|
|
|
|
for file in t!(fs::read_dir(build.src.join("src/doc"))) {
|
|
|
|
let file = t!(file);
|
|
|
|
let path = file.path();
|
|
|
|
let filename = path.file_name().unwrap().to_str().unwrap();
|
|
|
|
if !filename.ends_with(".md") || filename == "README.md" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
let html = out.join(filename).with_extension("html");
|
2016-03-08 01:11:05 -06:00
|
|
|
let rustdoc = build.rustdoc(&compiler);
|
2016-02-16 12:26:43 -06:00
|
|
|
if up_to_date(&path, &html) &&
|
|
|
|
up_to_date(&footer, &html) &&
|
|
|
|
up_to_date(&favicon, &html) &&
|
|
|
|
up_to_date(&full_toc, &html) &&
|
|
|
|
up_to_date(&version_info, &html) &&
|
|
|
|
up_to_date(&rustdoc, &html) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2016-03-08 01:11:05 -06:00
|
|
|
let mut cmd = Command::new(&rustdoc);
|
2016-03-11 19:30:16 -06:00
|
|
|
build.add_rustc_lib_path(&compiler, &mut cmd);
|
2016-02-16 12:26:43 -06:00
|
|
|
cmd.arg("--html-after-content").arg(&footer)
|
|
|
|
.arg("--html-before-content").arg(&version_info)
|
|
|
|
.arg("--html-in-header").arg(&favicon)
|
|
|
|
.arg("--markdown-playground-url")
|
|
|
|
.arg("https://play.rust-lang.org/")
|
2016-10-21 15:18:09 -05:00
|
|
|
.arg("-o").arg(&out)
|
2016-02-16 12:26:43 -06:00
|
|
|
.arg(&path);
|
|
|
|
|
|
|
|
if filename == "not_found.md" {
|
|
|
|
cmd.arg("--markdown-no-toc")
|
|
|
|
.arg("--markdown-css")
|
|
|
|
.arg("https://doc.rust-lang.org/rust.css");
|
|
|
|
} else {
|
|
|
|
cmd.arg("--markdown-css").arg("rust.css");
|
|
|
|
}
|
|
|
|
build.run(&mut cmd);
|
|
|
|
}
|
|
|
|
}
|
2016-03-08 00:36:21 -06:00
|
|
|
|
2016-05-02 17:16:15 -05:00
|
|
|
/// Compile all standard library documentation.
|
|
|
|
///
|
|
|
|
/// This will generate all documentation for the standard library and its
|
|
|
|
/// dependencies. This is largely just a wrapper around `cargo doc`.
|
2016-10-21 15:18:09 -05:00
|
|
|
pub fn std(build: &Build, stage: u32, target: &str) {
|
2016-04-05 12:01:31 -05:00
|
|
|
println!("Documenting stage{} std ({})", stage, target);
|
2016-10-21 15:18:09 -05:00
|
|
|
let out = build.doc_out(target);
|
|
|
|
t!(fs::create_dir_all(&out));
|
2016-04-05 12:01:31 -05:00
|
|
|
let compiler = Compiler::new(stage, &build.config.build);
|
rustbuild: Compile rustc twice, not thrice
This commit switches the rustbuild build system to compiling the
compiler twice for a normal bootstrap rather than the historical three
times.
Rust is a bootstrapped language which means that a previous version of
the compiler is used to build the next version of the compiler. Over
time, however, we change many parts of compiler artifacts such as the
metadata format, symbol names, etc. These changes make artifacts from
one compiler incompatible from another compiler. Consequently if a
compiler wants to be able to use some artifacts then it itself must have
compiled the artifacts.
Historically the rustc build system has achieved this by compiling the
compiler three times:
* An older compiler (stage0) is downloaded to kick off the chain.
* This compiler now compiles a new compiler (stage1)
* The stage1 compiler then compiles another compiler (stage2)
* Finally, the stage2 compiler needs libraries to link against, so it
compiles all the libraries again.
This entire process amounts in compiling the compiler three times.
Additionally, this process always guarantees that the Rust source tree
can compile itself because the stage2 compiler (created by a freshly
created compiler) would successfully compile itself again. This
property, ensuring Rust can compile itself, is quite important!
In general, though, this third compilation is not required for general
purpose development on the compiler. The third compiler (stage2) can
reuse the libraries that were created during the second compile. In
other words, the second compilation can produce both a compiler and the
libraries that compiler will use. These artifacts *must* be compatible
due to the way plugins work today anyway, and they were created by the
same source code so they *should* be compatible as well.
So given all that, this commit switches the default build process to
only compile the compiler three times, avoiding this third compilation
by copying artifacts from the previous one. Along the way a new entry in
the Travis matrix was also added to ensure that our full bootstrap can
succeed. This entry does not run tests, though, as it should not be
necessary.
To restore the old behavior of a full bootstrap (three compiles) you can
either pass:
./configure --enable-full-bootstrap
or if you're using config.toml:
[build]
full-bootstrap = true
Overall this will hopefully be an easy 33% win in build times of the
compiler. If we do 33% less work we should be 33% faster! This in turn
should affect cycle times and such on Travis and AppVeyor positively as
well as making it easier to work on the compiler itself.
2016-12-25 17:20:33 -06:00
|
|
|
let compiler = if build.force_use_stage1(&compiler, target) {
|
|
|
|
Compiler::new(1, compiler.host)
|
|
|
|
} else {
|
|
|
|
compiler
|
|
|
|
};
|
2016-03-11 19:30:16 -06:00
|
|
|
let out_dir = build.stage_out(&compiler, Mode::Libstd)
|
2016-04-05 12:01:31 -05:00
|
|
|
.join(target).join("doc");
|
2016-03-08 01:11:05 -06:00
|
|
|
let rustdoc = build.rustdoc(&compiler);
|
|
|
|
|
2017-03-01 17:34:54 -06:00
|
|
|
// Here what we're doing is creating a *symlink* (directory junction on
|
|
|
|
// Windows) to the final output location. This is not done as an
|
|
|
|
// optimization but rather for correctness. We've got three trees of
|
|
|
|
// documentation, one for std, one for test, and one for rustc. It's then
|
|
|
|
// our job to merge them all together.
|
|
|
|
//
|
|
|
|
// Unfortunately rustbuild doesn't know nearly as well how to merge doc
|
|
|
|
// trees as rustdoc does itself, so instead of actually having three
|
|
|
|
// separate trees we just have rustdoc output to the same location across
|
|
|
|
// all of them.
|
|
|
|
//
|
|
|
|
// This way rustdoc generates output directly into the output, and rustdoc
|
|
|
|
// will also directly handle merging.
|
|
|
|
let my_out = build.crate_doc_out(target);
|
|
|
|
build.clear_if_dirty(&my_out, &rustdoc);
|
|
|
|
t!(symlink_dir_force(&my_out, &out_dir));
|
2016-03-08 00:36:21 -06:00
|
|
|
|
2016-04-05 12:01:31 -05:00
|
|
|
let mut cargo = build.cargo(&compiler, Mode::Libstd, target, "doc");
|
2016-03-08 00:36:21 -06:00
|
|
|
cargo.arg("--manifest-path")
|
2017-02-15 10:53:18 -06:00
|
|
|
.arg(build.src.join("src/libstd/Cargo.toml"))
|
2017-01-08 13:37:52 -06:00
|
|
|
.arg("--features").arg(build.std_features());
|
|
|
|
|
|
|
|
// We don't want to build docs for internal std dependencies unless
|
|
|
|
// in compiler-docs mode. When not in that mode, we whitelist the crates
|
|
|
|
// for which docs must be built.
|
2017-03-11 20:45:20 -06:00
|
|
|
if !build.config.compiler_docs {
|
2017-01-08 13:37:52 -06:00
|
|
|
cargo.arg("--no-deps");
|
|
|
|
for krate in &["alloc", "collections", "core", "std", "std_unicode"] {
|
|
|
|
cargo.arg("-p").arg(krate);
|
|
|
|
// Create all crate output directories first to make sure rustdoc uses
|
|
|
|
// relative links.
|
|
|
|
// FIXME: Cargo should probably do this itself.
|
|
|
|
t!(fs::create_dir_all(out_dir.join(krate)));
|
|
|
|
}
|
2017-01-05 16:26:04 -06:00
|
|
|
}
|
|
|
|
|
2017-01-08 13:37:52 -06:00
|
|
|
|
2016-03-08 00:36:21 -06:00
|
|
|
build.run(&mut cargo);
|
2017-03-01 17:34:54 -06:00
|
|
|
cp_r(&my_out, &out);
|
2016-03-08 00:36:21 -06:00
|
|
|
}
|
|
|
|
|
2016-05-02 17:16:15 -05:00
|
|
|
/// Compile all libtest documentation.
|
|
|
|
///
|
|
|
|
/// This will generate all documentation for libtest and its dependencies. This
|
|
|
|
/// is largely just a wrapper around `cargo doc`.
|
2016-10-21 15:18:09 -05:00
|
|
|
pub fn test(build: &Build, stage: u32, target: &str) {
|
2016-04-05 12:01:31 -05:00
|
|
|
println!("Documenting stage{} test ({})", stage, target);
|
2016-10-21 15:18:09 -05:00
|
|
|
let out = build.doc_out(target);
|
|
|
|
t!(fs::create_dir_all(&out));
|
2016-04-05 12:01:31 -05:00
|
|
|
let compiler = Compiler::new(stage, &build.config.build);
|
rustbuild: Compile rustc twice, not thrice
This commit switches the rustbuild build system to compiling the
compiler twice for a normal bootstrap rather than the historical three
times.
Rust is a bootstrapped language which means that a previous version of
the compiler is used to build the next version of the compiler. Over
time, however, we change many parts of compiler artifacts such as the
metadata format, symbol names, etc. These changes make artifacts from
one compiler incompatible from another compiler. Consequently if a
compiler wants to be able to use some artifacts then it itself must have
compiled the artifacts.
Historically the rustc build system has achieved this by compiling the
compiler three times:
* An older compiler (stage0) is downloaded to kick off the chain.
* This compiler now compiles a new compiler (stage1)
* The stage1 compiler then compiles another compiler (stage2)
* Finally, the stage2 compiler needs libraries to link against, so it
compiles all the libraries again.
This entire process amounts in compiling the compiler three times.
Additionally, this process always guarantees that the Rust source tree
can compile itself because the stage2 compiler (created by a freshly
created compiler) would successfully compile itself again. This
property, ensuring Rust can compile itself, is quite important!
In general, though, this third compilation is not required for general
purpose development on the compiler. The third compiler (stage2) can
reuse the libraries that were created during the second compile. In
other words, the second compilation can produce both a compiler and the
libraries that compiler will use. These artifacts *must* be compatible
due to the way plugins work today anyway, and they were created by the
same source code so they *should* be compatible as well.
So given all that, this commit switches the default build process to
only compile the compiler three times, avoiding this third compilation
by copying artifacts from the previous one. Along the way a new entry in
the Travis matrix was also added to ensure that our full bootstrap can
succeed. This entry does not run tests, though, as it should not be
necessary.
To restore the old behavior of a full bootstrap (three compiles) you can
either pass:
./configure --enable-full-bootstrap
or if you're using config.toml:
[build]
full-bootstrap = true
Overall this will hopefully be an easy 33% win in build times of the
compiler. If we do 33% less work we should be 33% faster! This in turn
should affect cycle times and such on Travis and AppVeyor positively as
well as making it easier to work on the compiler itself.
2016-12-25 17:20:33 -06:00
|
|
|
let compiler = if build.force_use_stage1(&compiler, target) {
|
|
|
|
Compiler::new(1, compiler.host)
|
|
|
|
} else {
|
|
|
|
compiler
|
|
|
|
};
|
rustbuild: Fix dist for non-host targets
The `rust-std` package that we produce is expected to have not only the standard
library but also libtest for compiling unit tests. Unfortunately this does not
currently happen due to the way rustbuild is structured.
There are currently two main stages of compilation in rustbuild, one for the
standard library and one for the compiler. This is primarily done to allow us to
fill in the sysroot right after the standard library has finished compiling to
continue compiling the rest of the crates. Consequently the entire compiler does
not have to explicitly depend on the standard library, and this also should
allow us to pull in crates.io dependencies into the build in the future because
they'll just naturally build against the std we just produced.
These phases, however, do not represent a cross-compiled build. Target-only
builds also require libtest, and libtest is currently part of the
all-encompassing "compiler build". There's unfortunately no way to learn about
just libtest and its dependencies (in a great and robust fashion) so to ensure
that we can copy the right artifacts over this commit introduces a new build
step, libtest.
The new libtest build step has documentation, dist, and link steps as std/rustc
already do. The compiler now depends on libtest instead of libstd, and all
compiler crates can now assume that test and its dependencies are implicitly
part of the sysroot (hence explicit dependencies being removed). This makes the
build a tad less parallel as in theory many rustc crates can be compiled in
parallel with libtest, but this likely isn't where we really need parallelism
either (all the time is still spent in the compiler).
All in all this allows the `dist-std` step to depend on both libstd and libtest,
so `rust-std` packages produced by rustbuild should start having both the
standard library and libtest.
Closes #32523
2016-03-28 00:28:10 -05:00
|
|
|
let out_dir = build.stage_out(&compiler, Mode::Libtest)
|
2016-04-05 12:01:31 -05:00
|
|
|
.join(target).join("doc");
|
rustbuild: Fix dist for non-host targets
The `rust-std` package that we produce is expected to have not only the standard
library but also libtest for compiling unit tests. Unfortunately this does not
currently happen due to the way rustbuild is structured.
There are currently two main stages of compilation in rustbuild, one for the
standard library and one for the compiler. This is primarily done to allow us to
fill in the sysroot right after the standard library has finished compiling to
continue compiling the rest of the crates. Consequently the entire compiler does
not have to explicitly depend on the standard library, and this also should
allow us to pull in crates.io dependencies into the build in the future because
they'll just naturally build against the std we just produced.
These phases, however, do not represent a cross-compiled build. Target-only
builds also require libtest, and libtest is currently part of the
all-encompassing "compiler build". There's unfortunately no way to learn about
just libtest and its dependencies (in a great and robust fashion) so to ensure
that we can copy the right artifacts over this commit introduces a new build
step, libtest.
The new libtest build step has documentation, dist, and link steps as std/rustc
already do. The compiler now depends on libtest instead of libstd, and all
compiler crates can now assume that test and its dependencies are implicitly
part of the sysroot (hence explicit dependencies being removed). This makes the
build a tad less parallel as in theory many rustc crates can be compiled in
parallel with libtest, but this likely isn't where we really need parallelism
either (all the time is still spent in the compiler).
All in all this allows the `dist-std` step to depend on both libstd and libtest,
so `rust-std` packages produced by rustbuild should start having both the
standard library and libtest.
Closes #32523
2016-03-28 00:28:10 -05:00
|
|
|
let rustdoc = build.rustdoc(&compiler);
|
|
|
|
|
2017-03-01 17:34:54 -06:00
|
|
|
// See docs in std above for why we symlink
|
|
|
|
let my_out = build.crate_doc_out(target);
|
|
|
|
build.clear_if_dirty(&my_out, &rustdoc);
|
|
|
|
t!(symlink_dir_force(&my_out, &out_dir));
|
rustbuild: Fix dist for non-host targets
The `rust-std` package that we produce is expected to have not only the standard
library but also libtest for compiling unit tests. Unfortunately this does not
currently happen due to the way rustbuild is structured.
There are currently two main stages of compilation in rustbuild, one for the
standard library and one for the compiler. This is primarily done to allow us to
fill in the sysroot right after the standard library has finished compiling to
continue compiling the rest of the crates. Consequently the entire compiler does
not have to explicitly depend on the standard library, and this also should
allow us to pull in crates.io dependencies into the build in the future because
they'll just naturally build against the std we just produced.
These phases, however, do not represent a cross-compiled build. Target-only
builds also require libtest, and libtest is currently part of the
all-encompassing "compiler build". There's unfortunately no way to learn about
just libtest and its dependencies (in a great and robust fashion) so to ensure
that we can copy the right artifacts over this commit introduces a new build
step, libtest.
The new libtest build step has documentation, dist, and link steps as std/rustc
already do. The compiler now depends on libtest instead of libstd, and all
compiler crates can now assume that test and its dependencies are implicitly
part of the sysroot (hence explicit dependencies being removed). This makes the
build a tad less parallel as in theory many rustc crates can be compiled in
parallel with libtest, but this likely isn't where we really need parallelism
either (all the time is still spent in the compiler).
All in all this allows the `dist-std` step to depend on both libstd and libtest,
so `rust-std` packages produced by rustbuild should start having both the
standard library and libtest.
Closes #32523
2016-03-28 00:28:10 -05:00
|
|
|
|
2016-04-05 12:01:31 -05:00
|
|
|
let mut cargo = build.cargo(&compiler, Mode::Libtest, target, "doc");
|
rustbuild: Fix dist for non-host targets
The `rust-std` package that we produce is expected to have not only the standard
library but also libtest for compiling unit tests. Unfortunately this does not
currently happen due to the way rustbuild is structured.
There are currently two main stages of compilation in rustbuild, one for the
standard library and one for the compiler. This is primarily done to allow us to
fill in the sysroot right after the standard library has finished compiling to
continue compiling the rest of the crates. Consequently the entire compiler does
not have to explicitly depend on the standard library, and this also should
allow us to pull in crates.io dependencies into the build in the future because
they'll just naturally build against the std we just produced.
These phases, however, do not represent a cross-compiled build. Target-only
builds also require libtest, and libtest is currently part of the
all-encompassing "compiler build". There's unfortunately no way to learn about
just libtest and its dependencies (in a great and robust fashion) so to ensure
that we can copy the right artifacts over this commit introduces a new build
step, libtest.
The new libtest build step has documentation, dist, and link steps as std/rustc
already do. The compiler now depends on libtest instead of libstd, and all
compiler crates can now assume that test and its dependencies are implicitly
part of the sysroot (hence explicit dependencies being removed). This makes the
build a tad less parallel as in theory many rustc crates can be compiled in
parallel with libtest, but this likely isn't where we really need parallelism
either (all the time is still spent in the compiler).
All in all this allows the `dist-std` step to depend on both libstd and libtest,
so `rust-std` packages produced by rustbuild should start having both the
standard library and libtest.
Closes #32523
2016-03-28 00:28:10 -05:00
|
|
|
cargo.arg("--manifest-path")
|
2017-02-15 10:53:18 -06:00
|
|
|
.arg(build.src.join("src/libtest/Cargo.toml"));
|
rustbuild: Fix dist for non-host targets
The `rust-std` package that we produce is expected to have not only the standard
library but also libtest for compiling unit tests. Unfortunately this does not
currently happen due to the way rustbuild is structured.
There are currently two main stages of compilation in rustbuild, one for the
standard library and one for the compiler. This is primarily done to allow us to
fill in the sysroot right after the standard library has finished compiling to
continue compiling the rest of the crates. Consequently the entire compiler does
not have to explicitly depend on the standard library, and this also should
allow us to pull in crates.io dependencies into the build in the future because
they'll just naturally build against the std we just produced.
These phases, however, do not represent a cross-compiled build. Target-only
builds also require libtest, and libtest is currently part of the
all-encompassing "compiler build". There's unfortunately no way to learn about
just libtest and its dependencies (in a great and robust fashion) so to ensure
that we can copy the right artifacts over this commit introduces a new build
step, libtest.
The new libtest build step has documentation, dist, and link steps as std/rustc
already do. The compiler now depends on libtest instead of libstd, and all
compiler crates can now assume that test and its dependencies are implicitly
part of the sysroot (hence explicit dependencies being removed). This makes the
build a tad less parallel as in theory many rustc crates can be compiled in
parallel with libtest, but this likely isn't where we really need parallelism
either (all the time is still spent in the compiler).
All in all this allows the `dist-std` step to depend on both libstd and libtest,
so `rust-std` packages produced by rustbuild should start having both the
standard library and libtest.
Closes #32523
2016-03-28 00:28:10 -05:00
|
|
|
build.run(&mut cargo);
|
2017-03-01 17:34:54 -06:00
|
|
|
cp_r(&my_out, &out);
|
rustbuild: Fix dist for non-host targets
The `rust-std` package that we produce is expected to have not only the standard
library but also libtest for compiling unit tests. Unfortunately this does not
currently happen due to the way rustbuild is structured.
There are currently two main stages of compilation in rustbuild, one for the
standard library and one for the compiler. This is primarily done to allow us to
fill in the sysroot right after the standard library has finished compiling to
continue compiling the rest of the crates. Consequently the entire compiler does
not have to explicitly depend on the standard library, and this also should
allow us to pull in crates.io dependencies into the build in the future because
they'll just naturally build against the std we just produced.
These phases, however, do not represent a cross-compiled build. Target-only
builds also require libtest, and libtest is currently part of the
all-encompassing "compiler build". There's unfortunately no way to learn about
just libtest and its dependencies (in a great and robust fashion) so to ensure
that we can copy the right artifacts over this commit introduces a new build
step, libtest.
The new libtest build step has documentation, dist, and link steps as std/rustc
already do. The compiler now depends on libtest instead of libstd, and all
compiler crates can now assume that test and its dependencies are implicitly
part of the sysroot (hence explicit dependencies being removed). This makes the
build a tad less parallel as in theory many rustc crates can be compiled in
parallel with libtest, but this likely isn't where we really need parallelism
either (all the time is still spent in the compiler).
All in all this allows the `dist-std` step to depend on both libstd and libtest,
so `rust-std` packages produced by rustbuild should start having both the
standard library and libtest.
Closes #32523
2016-03-28 00:28:10 -05:00
|
|
|
}
|
|
|
|
|
2016-05-02 17:16:15 -05:00
|
|
|
/// Generate all compiler documentation.
|
|
|
|
///
|
|
|
|
/// This will generate all documentation for the compiler libraries and their
|
|
|
|
/// dependencies. This is largely just a wrapper around `cargo doc`.
|
2016-10-21 15:18:09 -05:00
|
|
|
pub fn rustc(build: &Build, stage: u32, target: &str) {
|
2016-04-05 12:01:31 -05:00
|
|
|
println!("Documenting stage{} compiler ({})", stage, target);
|
2016-10-21 15:18:09 -05:00
|
|
|
let out = build.doc_out(target);
|
|
|
|
t!(fs::create_dir_all(&out));
|
2016-04-05 12:01:31 -05:00
|
|
|
let compiler = Compiler::new(stage, &build.config.build);
|
rustbuild: Compile rustc twice, not thrice
This commit switches the rustbuild build system to compiling the
compiler twice for a normal bootstrap rather than the historical three
times.
Rust is a bootstrapped language which means that a previous version of
the compiler is used to build the next version of the compiler. Over
time, however, we change many parts of compiler artifacts such as the
metadata format, symbol names, etc. These changes make artifacts from
one compiler incompatible from another compiler. Consequently if a
compiler wants to be able to use some artifacts then it itself must have
compiled the artifacts.
Historically the rustc build system has achieved this by compiling the
compiler three times:
* An older compiler (stage0) is downloaded to kick off the chain.
* This compiler now compiles a new compiler (stage1)
* The stage1 compiler then compiles another compiler (stage2)
* Finally, the stage2 compiler needs libraries to link against, so it
compiles all the libraries again.
This entire process amounts in compiling the compiler three times.
Additionally, this process always guarantees that the Rust source tree
can compile itself because the stage2 compiler (created by a freshly
created compiler) would successfully compile itself again. This
property, ensuring Rust can compile itself, is quite important!
In general, though, this third compilation is not required for general
purpose development on the compiler. The third compiler (stage2) can
reuse the libraries that were created during the second compile. In
other words, the second compilation can produce both a compiler and the
libraries that compiler will use. These artifacts *must* be compatible
due to the way plugins work today anyway, and they were created by the
same source code so they *should* be compatible as well.
So given all that, this commit switches the default build process to
only compile the compiler three times, avoiding this third compilation
by copying artifacts from the previous one. Along the way a new entry in
the Travis matrix was also added to ensure that our full bootstrap can
succeed. This entry does not run tests, though, as it should not be
necessary.
To restore the old behavior of a full bootstrap (three compiles) you can
either pass:
./configure --enable-full-bootstrap
or if you're using config.toml:
[build]
full-bootstrap = true
Overall this will hopefully be an easy 33% win in build times of the
compiler. If we do 33% less work we should be 33% faster! This in turn
should affect cycle times and such on Travis and AppVeyor positively as
well as making it easier to work on the compiler itself.
2016-12-25 17:20:33 -06:00
|
|
|
let compiler = if build.force_use_stage1(&compiler, target) {
|
|
|
|
Compiler::new(1, compiler.host)
|
|
|
|
} else {
|
|
|
|
compiler
|
|
|
|
};
|
2016-03-11 19:30:16 -06:00
|
|
|
let out_dir = build.stage_out(&compiler, Mode::Librustc)
|
2016-04-05 12:01:31 -05:00
|
|
|
.join(target).join("doc");
|
2016-03-08 01:11:05 -06:00
|
|
|
let rustdoc = build.rustdoc(&compiler);
|
2017-03-01 17:34:54 -06:00
|
|
|
|
|
|
|
// See docs in std above for why we symlink
|
|
|
|
let my_out = build.crate_doc_out(target);
|
|
|
|
build.clear_if_dirty(&my_out, &rustdoc);
|
|
|
|
t!(symlink_dir_force(&my_out, &out_dir));
|
|
|
|
|
2016-04-05 12:01:31 -05:00
|
|
|
let mut cargo = build.cargo(&compiler, Mode::Librustc, target, "doc");
|
2016-03-08 00:36:21 -06:00
|
|
|
cargo.arg("--manifest-path")
|
|
|
|
.arg(build.src.join("src/rustc/Cargo.toml"))
|
2016-03-08 01:21:05 -06:00
|
|
|
.arg("--features").arg(build.rustc_features());
|
2017-03-01 17:34:54 -06:00
|
|
|
|
2017-03-11 20:45:20 -06:00
|
|
|
if build.config.compiler_docs {
|
|
|
|
// src/rustc/Cargo.toml contains bin crates called rustc and rustdoc
|
|
|
|
// which would otherwise overwrite the docs for the real rustc and
|
|
|
|
// rustdoc lib crates.
|
|
|
|
cargo.arg("-p").arg("rustc_driver")
|
|
|
|
.arg("-p").arg("rustdoc");
|
|
|
|
} else {
|
|
|
|
// Like with libstd above if compiler docs aren't enabled then we're not
|
|
|
|
// documenting internal dependencies, so we have a whitelist.
|
2017-03-01 17:34:54 -06:00
|
|
|
cargo.arg("--no-deps");
|
|
|
|
for krate in &["proc_macro"] {
|
|
|
|
cargo.arg("-p").arg(krate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-08 00:36:21 -06:00
|
|
|
build.run(&mut cargo);
|
2017-03-01 17:34:54 -06:00
|
|
|
cp_r(&my_out, &out);
|
2016-03-08 00:36:21 -06:00
|
|
|
}
|
2016-03-08 15:42:32 -06:00
|
|
|
|
2016-05-02 17:16:15 -05:00
|
|
|
/// Generates the HTML rendered error-index by running the
|
|
|
|
/// `error_index_generator` tool.
|
2016-12-28 17:01:21 -06:00
|
|
|
pub fn error_index(build: &Build, target: &str) {
|
|
|
|
println!("Documenting error index ({})", target);
|
2016-10-21 15:18:09 -05:00
|
|
|
let out = build.doc_out(target);
|
|
|
|
t!(fs::create_dir_all(&out));
|
2016-12-28 17:01:21 -06:00
|
|
|
let compiler = Compiler::new(0, &build.config.build);
|
2016-03-11 18:21:05 -06:00
|
|
|
let mut index = build.tool_cmd(&compiler, "error_index_generator");
|
2016-03-08 15:42:32 -06:00
|
|
|
index.arg("html");
|
|
|
|
index.arg(out.join("error-index.html"));
|
|
|
|
|
|
|
|
// FIXME: shouldn't have to pass this env var
|
|
|
|
index.env("CFG_BUILD", &build.config.build);
|
|
|
|
|
|
|
|
build.run(&mut index);
|
|
|
|
}
|
2017-03-01 17:34:54 -06:00
|
|
|
|
|
|
|
fn symlink_dir_force(src: &Path, dst: &Path) -> io::Result<()> {
|
|
|
|
if let Ok(m) = fs::symlink_metadata(dst) {
|
|
|
|
if m.file_type().is_dir() {
|
|
|
|
try!(fs::remove_dir_all(dst));
|
|
|
|
} else {
|
|
|
|
// handle directory junctions on windows by falling back to
|
|
|
|
// `remove_dir`.
|
|
|
|
try!(fs::remove_file(dst).or_else(|_| {
|
|
|
|
fs::remove_dir(dst)
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
symlink_dir(src, dst)
|
|
|
|
}
|