2018-12-04 19:26:54 +01:00
|
|
|
//! Implementation of compiling the compiler and standard library, in "check"-based modes.
|
2018-01-15 10:44:00 -07:00
|
|
|
|
2019-12-22 17:42:04 -05:00
|
|
|
use crate::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
|
|
|
|
|
use crate::cache::Interned;
|
|
|
|
|
use crate::compile::{add_to_sysroot, run_cargo, rustc_cargo, std_cargo};
|
2018-12-07 13:21:05 +01:00
|
|
|
use crate::tool::{prepare_tool_cargo, SourceType};
|
|
|
|
|
use crate::{Compiler, Mode};
|
2018-01-15 10:44:00 -07:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
|
|
|
|
pub struct Std {
|
|
|
|
|
pub target: Interned<String>,
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 19:26:54 +01:00
|
|
|
fn args(kind: Kind) -> Vec<String> {
|
|
|
|
|
match kind {
|
|
|
|
|
Kind::Clippy => vec!["--".to_owned(), "--cap-lints".to_owned(), "warn".to_owned()],
|
2019-12-22 17:42:04 -05:00
|
|
|
_ => Vec::new(),
|
2018-12-04 19:26:54 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn cargo_subcommand(kind: Kind) -> &'static str {
|
|
|
|
|
match kind {
|
|
|
|
|
Kind::Check => "check",
|
|
|
|
|
Kind::Clippy => "clippy",
|
|
|
|
|
Kind::Fix => "fix",
|
2019-12-22 17:42:04 -05:00
|
|
|
_ => unreachable!(),
|
2018-12-04 19:26:54 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-15 10:44:00 -07:00
|
|
|
impl Step for Std {
|
|
|
|
|
type Output = ();
|
|
|
|
|
const DEFAULT: bool = true;
|
|
|
|
|
|
2019-02-25 19:30:32 +09:00
|
|
|
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
|
2019-08-28 00:32:21 +09:00
|
|
|
run.all_krates("test")
|
2018-01-15 10:44:00 -07:00
|
|
|
}
|
|
|
|
|
|
2019-02-25 19:30:32 +09:00
|
|
|
fn make_run(run: RunConfig<'_>) {
|
2019-12-22 17:42:04 -05:00
|
|
|
run.builder.ensure(Std { target: run.target });
|
2018-01-15 10:44:00 -07:00
|
|
|
}
|
|
|
|
|
|
2019-02-25 19:30:32 +09:00
|
|
|
fn run(self, builder: &Builder<'_>) {
|
2018-01-15 10:44:00 -07:00
|
|
|
let target = self.target;
|
2018-04-14 17:27:57 -06:00
|
|
|
let compiler = builder.compiler(0, builder.config.build);
|
2018-01-15 10:44:00 -07:00
|
|
|
|
2020-06-12 15:44:56 -07:00
|
|
|
let mut cargo = builder.cargo(
|
|
|
|
|
compiler,
|
|
|
|
|
Mode::Std,
|
|
|
|
|
SourceType::InTree,
|
|
|
|
|
target,
|
|
|
|
|
cargo_subcommand(builder.kind),
|
|
|
|
|
);
|
2020-04-19 21:17:38 +10:00
|
|
|
std_cargo(builder, target, compiler.stage, &mut cargo);
|
2018-03-16 08:35:03 -07:00
|
|
|
|
2018-08-02 11:59:27 -06:00
|
|
|
builder.info(&format!("Checking std artifacts ({} -> {})", &compiler.host, target));
|
2019-12-22 17:42:04 -05:00
|
|
|
run_cargo(
|
|
|
|
|
builder,
|
|
|
|
|
cargo,
|
|
|
|
|
args(builder.kind),
|
|
|
|
|
&libstd_stamp(builder, compiler, target),
|
|
|
|
|
vec![],
|
|
|
|
|
true,
|
|
|
|
|
);
|
2018-03-16 08:35:03 -07:00
|
|
|
|
2018-01-15 10:44:00 -07:00
|
|
|
let libdir = builder.sysroot_libdir(compiler, target);
|
2018-12-02 21:47:41 +01:00
|
|
|
let hostdir = builder.sysroot_libdir(compiler, compiler.host);
|
|
|
|
|
add_to_sysroot(&builder, &libdir, &hostdir, &libstd_stamp(builder, compiler, target));
|
2018-01-15 10:44:00 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
|
|
|
|
pub struct Rustc {
|
|
|
|
|
pub target: Interned<String>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Step for Rustc {
|
|
|
|
|
type Output = ();
|
|
|
|
|
const ONLY_HOSTS: bool = true;
|
|
|
|
|
const DEFAULT: bool = true;
|
|
|
|
|
|
2019-02-25 19:30:32 +09:00
|
|
|
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
|
Change Step to be invoked with a path when in default mode.
Previously, a Step would be able to tell on its own when it was invoked
"by-default" (that is, `./x.py test` was called instead of `./x.py test
some/path`). This commit replaces that functionality, invoking each Step
with each of the paths it has specified as "should be invoked by."
For example, if a step calls `path("src/tools/cargo")` and
`path("src/doc/cargo")` then it's make_run will be called twice, with
"src/tools/cargo" and "src/doc/cargo." This makes it so that default
handling logic is in builder, instead of spread across various Steps.
However, this meant that some Step specifications needed to be updated,
since for example `rustdoc` can be built by `./x.py build
src/librustdoc` or `./x.py build src/tools/rustdoc`. A `PathSet`
abstraction is added that handles this: now, each Step can not only list
`path(...)` but also `paths(&[a, b, ...])` which will make it so that we
don't invoke it with each of the individual paths, instead invoking it
with the first path in the list (though this shouldn't be depended on).
Future work likely consists of implementing a better/easier way for a
given Step to work with "any" crate in-tree, especially those that want
to run tests, build, or check crates in the std, test, or rustc crate
trees. Currently this is rather painful to do as most of the logic is
duplicated across should_run and make_run. It seems likely this can be
abstracted away into builder somehow.
2018-02-11 09:51:58 -07:00
|
|
|
run.all_krates("rustc-main")
|
2018-01-15 10:44:00 -07:00
|
|
|
}
|
|
|
|
|
|
2019-02-25 19:30:32 +09:00
|
|
|
fn make_run(run: RunConfig<'_>) {
|
2019-12-22 17:42:04 -05:00
|
|
|
run.builder.ensure(Rustc { target: run.target });
|
2018-01-15 10:44:00 -07:00
|
|
|
}
|
|
|
|
|
|
2019-02-08 14:53:55 +01:00
|
|
|
/// Builds the compiler.
|
2018-01-15 10:44:00 -07:00
|
|
|
///
|
|
|
|
|
/// This will build the compiler for a particular stage of the build using
|
|
|
|
|
/// the `compiler` targeting the `target` architecture. The artifacts
|
|
|
|
|
/// created will also be linked into the sysroot directory.
|
2019-02-25 19:30:32 +09:00
|
|
|
fn run(self, builder: &Builder<'_>) {
|
2018-04-14 17:27:57 -06:00
|
|
|
let compiler = builder.compiler(0, builder.config.build);
|
2018-01-15 10:44:00 -07:00
|
|
|
let target = self.target;
|
|
|
|
|
|
bootstrap: Merge the libtest build step with libstd
Since its inception rustbuild has always worked in three stages: one for
libstd, one for libtest, and one for rustc. These three stages were
architected around crates.io dependencies, where rustc wants to depend
on crates.io crates but said crates don't explicitly depend on libstd,
requiring a sysroot assembly step in the middle. This same logic was
applied for libtest where libtest wants to depend on crates.io crates
(`getopts`) but `getopts` didn't say that it depended on std, so it
needed `std` built ahead of time.
Lots of time has passed since the inception of rustbuild, however,
and we've since gotten to the point where even `std` itself is depending
on crates.io crates (albeit with some wonky configuration). This
commit applies the same logic to the two dependencies that the `test`
crate pulls in from crates.io, `getopts` and `unicode-width`. Over the
many years since rustbuild's inception `unicode-width` was the only
dependency picked up by the `test` crate, so the extra configuration
necessary to get crates building in this crate graph is unlikely to be
too much of a burden on developers.
After this patch it means that there are now only two build phasese of
rustbuild, one for libstd and one for rustc. The libtest/libproc_macro
build phase is all lumped into one now with `std`.
This was originally motivated by rust-lang/cargo#7216 where Cargo was
having to deal with synthesizing dependency edges but this commit makes
them explicit in this repository.
2019-08-16 08:29:08 -07:00
|
|
|
builder.ensure(Std { target });
|
2018-08-02 12:01:04 -06:00
|
|
|
|
2020-06-12 15:44:56 -07:00
|
|
|
let mut cargo = builder.cargo(
|
|
|
|
|
compiler,
|
|
|
|
|
Mode::Rustc,
|
|
|
|
|
SourceType::InTree,
|
|
|
|
|
target,
|
|
|
|
|
cargo_subcommand(builder.kind),
|
|
|
|
|
);
|
2019-10-22 08:51:35 -07:00
|
|
|
rustc_cargo(builder, &mut cargo, target);
|
2018-03-16 08:35:03 -07:00
|
|
|
|
2018-08-02 11:59:27 -06:00
|
|
|
builder.info(&format!("Checking compiler artifacts ({} -> {})", &compiler.host, target));
|
2019-12-22 17:42:04 -05:00
|
|
|
run_cargo(
|
|
|
|
|
builder,
|
|
|
|
|
cargo,
|
|
|
|
|
args(builder.kind),
|
|
|
|
|
&librustc_stamp(builder, compiler, target),
|
|
|
|
|
vec![],
|
|
|
|
|
true,
|
|
|
|
|
);
|
2018-03-16 08:35:03 -07:00
|
|
|
|
2018-01-15 10:44:00 -07:00
|
|
|
let libdir = builder.sysroot_libdir(compiler, target);
|
2018-12-02 21:47:41 +01:00
|
|
|
let hostdir = builder.sysroot_libdir(compiler, compiler.host);
|
|
|
|
|
add_to_sysroot(&builder, &libdir, &hostdir, &librustc_stamp(builder, compiler, target));
|
2018-01-15 10:44:00 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-01 15:57:48 +02:00
|
|
|
macro_rules! tool_check_step {
|
2020-06-12 15:44:56 -07:00
|
|
|
($name:ident, $path:expr, $source_type:expr) => {
|
2020-04-01 15:57:48 +02:00
|
|
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
|
|
|
|
pub struct $name {
|
|
|
|
|
pub target: Interned<String>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Step for $name {
|
|
|
|
|
type Output = ();
|
|
|
|
|
const ONLY_HOSTS: bool = true;
|
|
|
|
|
const DEFAULT: bool = true;
|
|
|
|
|
|
|
|
|
|
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
|
|
|
|
|
run.path($path)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn make_run(run: RunConfig<'_>) {
|
|
|
|
|
run.builder.ensure($name { target: run.target });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn run(self, builder: &Builder<'_>) {
|
|
|
|
|
let compiler = builder.compiler(0, builder.config.build);
|
|
|
|
|
let target = self.target;
|
|
|
|
|
|
|
|
|
|
builder.ensure(Rustc { target });
|
|
|
|
|
|
|
|
|
|
let cargo = prepare_tool_cargo(
|
|
|
|
|
builder,
|
|
|
|
|
compiler,
|
|
|
|
|
Mode::ToolRustc,
|
|
|
|
|
target,
|
|
|
|
|
cargo_subcommand(builder.kind),
|
|
|
|
|
$path,
|
2020-06-12 15:44:56 -07:00
|
|
|
$source_type,
|
2020-04-01 15:57:48 +02:00
|
|
|
&[],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
println!(
|
|
|
|
|
"Checking {} artifacts ({} -> {})",
|
|
|
|
|
stringify!($name).to_lowercase(),
|
|
|
|
|
&compiler.host,
|
|
|
|
|
target
|
|
|
|
|
);
|
|
|
|
|
run_cargo(
|
|
|
|
|
builder,
|
|
|
|
|
cargo,
|
|
|
|
|
args(builder.kind),
|
|
|
|
|
&stamp(builder, compiler, target),
|
|
|
|
|
vec![],
|
|
|
|
|
true,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let libdir = builder.sysroot_libdir(compiler, target);
|
|
|
|
|
let hostdir = builder.sysroot_libdir(compiler, compiler.host);
|
|
|
|
|
add_to_sysroot(&builder, &libdir, &hostdir, &stamp(builder, compiler, target));
|
|
|
|
|
|
|
|
|
|
/// Cargo's output path in a given stage, compiled by a particular
|
|
|
|
|
/// compiler for the specified target.
|
|
|
|
|
fn stamp(
|
|
|
|
|
builder: &Builder<'_>,
|
|
|
|
|
compiler: Compiler,
|
|
|
|
|
target: Interned<String>,
|
|
|
|
|
) -> PathBuf {
|
|
|
|
|
builder
|
|
|
|
|
.cargo_out(compiler, Mode::ToolRustc, target)
|
|
|
|
|
.join(format!(".{}-check.stamp", stringify!($name).to_lowercase()))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
2018-04-18 19:46:58 +01:00
|
|
|
}
|
|
|
|
|
|
2020-06-12 15:44:56 -07:00
|
|
|
tool_check_step!(Rustdoc, "src/tools/rustdoc", SourceType::InTree);
|
|
|
|
|
// Clippy is a hybrid. It is an external tool, but uses a git subtree instead
|
|
|
|
|
// of a submodule. Since the SourceType only drives the deny-warnings
|
|
|
|
|
// behavior, treat it as in-tree so that any new warnings in clippy will be
|
|
|
|
|
// rejected.
|
|
|
|
|
tool_check_step!(Clippy, "src/tools/clippy", SourceType::InTree);
|
2018-04-18 19:46:58 +01:00
|
|
|
|
2018-01-15 10:44:00 -07:00
|
|
|
/// Cargo's output path for the standard library in a given stage, compiled
|
|
|
|
|
/// by a particular compiler for the specified target.
|
2020-04-01 15:57:48 +02:00
|
|
|
fn libstd_stamp(builder: &Builder<'_>, compiler: Compiler, target: Interned<String>) -> PathBuf {
|
2018-05-19 23:04:41 +03:00
|
|
|
builder.cargo_out(compiler, Mode::Std, target).join(".libstd-check.stamp")
|
2018-01-15 10:44:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Cargo's output path for librustc in a given stage, compiled by a particular
|
|
|
|
|
/// compiler for the specified target.
|
2020-04-01 15:57:48 +02:00
|
|
|
fn librustc_stamp(builder: &Builder<'_>, compiler: Compiler, target: Interned<String>) -> PathBuf {
|
2018-05-19 23:04:41 +03:00
|
|
|
builder.cargo_out(compiler, Mode::Rustc, target).join(".librustc-check.stamp")
|
2018-01-15 10:44:00 -07:00
|
|
|
}
|