2018-01-15 11:44:00 -06:00
|
|
|
// Copyright 2018 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.
|
|
|
|
|
|
|
|
//! Implementation of compiling the compiler and standard library, in "check" mode.
|
|
|
|
|
2018-04-11 17:36:42 -05:00
|
|
|
use compile::{run_cargo, std_cargo, test_cargo, rustc_cargo, rustc_cargo_env, add_to_sysroot};
|
2018-01-15 11:44:00 -06:00
|
|
|
use builder::{RunConfig, Builder, ShouldRun, Step};
|
2018-04-18 18:45:18 -05:00
|
|
|
use tool::{self, prepare_tool_cargo};
|
2018-04-14 18:27:57 -05:00
|
|
|
use {Compiler, Mode};
|
2018-04-11 17:36:42 -05:00
|
|
|
use cache::{INTERNER, Interned};
|
2018-01-15 11:44:00 -06:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
|
|
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
|
|
|
pub struct Std {
|
|
|
|
pub target: Interned<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Step for Std {
|
|
|
|
type Output = ();
|
|
|
|
const DEFAULT: bool = true;
|
|
|
|
|
|
|
|
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 10:51:58 -06:00
|
|
|
run.all_krates("std")
|
2018-01-15 11:44:00 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn make_run(run: RunConfig) {
|
|
|
|
run.builder.ensure(Std {
|
|
|
|
target: run.target,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fn run(self, builder: &Builder) {
|
|
|
|
let target = self.target;
|
2018-04-14 18:27:57 -05:00
|
|
|
let compiler = builder.compiler(0, builder.config.build);
|
2018-01-15 11:44:00 -06:00
|
|
|
|
2018-04-14 18:27:57 -05:00
|
|
|
let out_dir = builder.stage_out(compiler, Mode::Libstd);
|
|
|
|
builder.clear_if_dirty(&out_dir, &builder.rustc(compiler));
|
2018-04-18 13:46:58 -05:00
|
|
|
|
2018-01-15 11:44:00 -06:00
|
|
|
let mut cargo = builder.cargo(compiler, Mode::Libstd, target, "check");
|
2018-03-05 11:47:54 -06:00
|
|
|
std_cargo(builder, &compiler, target, &mut cargo);
|
2018-03-16 10:35:03 -05:00
|
|
|
|
2018-04-14 18:27:57 -05:00
|
|
|
let _folder = builder.fold_output(|| format!("stage{}-std", compiler.stage));
|
2018-03-16 10:35:03 -05:00
|
|
|
println!("Checking std artifacts ({} -> {})", &compiler.host, target);
|
2018-04-14 18:27:57 -05:00
|
|
|
run_cargo(builder,
|
2018-01-15 11:44:00 -06:00
|
|
|
&mut cargo,
|
2018-04-14 18:27:57 -05:00
|
|
|
&libstd_stamp(builder, compiler, target),
|
2018-01-15 11:44:00 -06:00
|
|
|
true);
|
2018-03-16 10:35:03 -05:00
|
|
|
|
2018-01-15 11:44:00 -06:00
|
|
|
let libdir = builder.sysroot_libdir(compiler, target);
|
2018-04-14 18:27:57 -05:00
|
|
|
add_to_sysroot(&builder, &libdir, &libstd_stamp(builder, compiler, target));
|
2018-01-15 11:44:00 -06: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;
|
|
|
|
|
|
|
|
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 10:51:58 -06:00
|
|
|
run.all_krates("rustc-main")
|
2018-01-15 11:44:00 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn make_run(run: RunConfig) {
|
|
|
|
run.builder.ensure(Rustc {
|
|
|
|
target: run.target,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Build the compiler.
|
|
|
|
///
|
|
|
|
/// 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.
|
|
|
|
fn run(self, builder: &Builder) {
|
2018-04-14 18:27:57 -05:00
|
|
|
let compiler = builder.compiler(0, builder.config.build);
|
2018-01-15 11:44:00 -06:00
|
|
|
let target = self.target;
|
|
|
|
|
|
|
|
let stage_out = builder.stage_out(compiler, Mode::Librustc);
|
2018-04-14 18:27:57 -05:00
|
|
|
builder.clear_if_dirty(&stage_out, &libstd_stamp(builder, compiler, target));
|
|
|
|
builder.clear_if_dirty(&stage_out, &libtest_stamp(builder, compiler, target));
|
2018-01-15 11:44:00 -06:00
|
|
|
|
|
|
|
let mut cargo = builder.cargo(compiler, Mode::Librustc, target, "check");
|
2018-04-14 18:27:57 -05:00
|
|
|
rustc_cargo(builder, &mut cargo);
|
2018-03-16 10:35:03 -05:00
|
|
|
|
2018-04-14 18:27:57 -05:00
|
|
|
let _folder = builder.fold_output(|| format!("stage{}-rustc", compiler.stage));
|
2018-03-16 10:35:03 -05:00
|
|
|
println!("Checking compiler artifacts ({} -> {})", &compiler.host, target);
|
2018-04-14 18:27:57 -05:00
|
|
|
run_cargo(builder,
|
2018-01-15 11:44:00 -06:00
|
|
|
&mut cargo,
|
2018-04-14 18:27:57 -05:00
|
|
|
&librustc_stamp(builder, compiler, target),
|
2018-01-15 11:44:00 -06:00
|
|
|
true);
|
2018-03-16 10:35:03 -05:00
|
|
|
|
2018-01-15 11:44:00 -06:00
|
|
|
let libdir = builder.sysroot_libdir(compiler, target);
|
2018-04-14 18:27:57 -05:00
|
|
|
add_to_sysroot(&builder, &libdir, &librustc_stamp(builder, compiler, target));
|
2018-01-15 11:44:00 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-11 17:36:42 -05:00
|
|
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
|
|
|
pub struct CodegenBackend {
|
|
|
|
pub target: Interned<String>,
|
|
|
|
pub backend: Interned<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Step for CodegenBackend {
|
|
|
|
type Output = ();
|
|
|
|
const ONLY_HOSTS: bool = true;
|
|
|
|
const DEFAULT: bool = true;
|
|
|
|
|
|
|
|
fn should_run(run: ShouldRun) -> ShouldRun {
|
2018-05-08 08:10:16 -05:00
|
|
|
run.all_krates("rustc_codegen_llvm")
|
2018-04-11 17:36:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn make_run(run: RunConfig) {
|
|
|
|
let backend = run.builder.config.rust_codegen_backends.get(0);
|
|
|
|
let backend = backend.cloned().unwrap_or_else(|| {
|
|
|
|
INTERNER.intern_str("llvm")
|
|
|
|
});
|
|
|
|
run.builder.ensure(CodegenBackend {
|
|
|
|
target: run.target,
|
|
|
|
backend,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fn run(self, builder: &Builder) {
|
2018-04-18 04:56:04 -05:00
|
|
|
let compiler = builder.compiler(0, builder.config.build);
|
2018-04-11 17:36:42 -05:00
|
|
|
let target = self.target;
|
2018-04-12 09:51:55 -05:00
|
|
|
let backend = self.backend;
|
2018-04-11 17:36:42 -05:00
|
|
|
|
|
|
|
let mut cargo = builder.cargo(compiler, Mode::Librustc, target, "check");
|
2018-04-18 04:56:04 -05:00
|
|
|
let features = builder.rustc_features().to_string();
|
2018-05-08 08:10:16 -05:00
|
|
|
cargo.arg("--manifest-path").arg(builder.src.join("src/librustc_codegen_llvm/Cargo.toml"));
|
2018-04-18 04:56:04 -05:00
|
|
|
rustc_cargo_env(builder, &mut cargo);
|
2018-04-11 17:36:42 -05:00
|
|
|
|
2018-04-17 18:50:41 -05:00
|
|
|
// We won't build LLVM if it's not available, as it shouldn't affect `check`.
|
2018-04-11 17:36:42 -05:00
|
|
|
|
2018-05-08 08:10:16 -05:00
|
|
|
let _folder = builder.fold_output(|| format!("stage{}-rustc_codegen_llvm", compiler.stage));
|
2018-04-18 04:56:04 -05:00
|
|
|
run_cargo(builder,
|
2018-04-11 17:36:42 -05:00
|
|
|
cargo.arg("--features").arg(features),
|
2018-04-18 04:56:04 -05:00
|
|
|
&codegen_backend_stamp(builder, compiler, target, backend),
|
2018-04-11 17:36:42 -05:00
|
|
|
true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-15 11:44:00 -06:00
|
|
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
|
|
|
pub struct Test {
|
|
|
|
pub target: Interned<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Step for Test {
|
|
|
|
type Output = ();
|
|
|
|
const DEFAULT: bool = true;
|
|
|
|
|
|
|
|
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 10:51:58 -06:00
|
|
|
run.all_krates("test")
|
2018-01-15 11:44:00 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn make_run(run: RunConfig) {
|
|
|
|
run.builder.ensure(Test {
|
|
|
|
target: run.target,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fn run(self, builder: &Builder) {
|
2018-04-14 18:27:57 -05:00
|
|
|
let compiler = builder.compiler(0, builder.config.build);
|
2018-04-18 13:46:58 -05:00
|
|
|
let target = self.target;
|
2018-01-15 11:44:00 -06:00
|
|
|
|
2018-04-14 18:27:57 -05:00
|
|
|
let out_dir = builder.stage_out(compiler, Mode::Libtest);
|
|
|
|
builder.clear_if_dirty(&out_dir, &libstd_stamp(builder, compiler, target));
|
2018-04-18 13:46:58 -05:00
|
|
|
|
2018-01-15 11:44:00 -06:00
|
|
|
let mut cargo = builder.cargo(compiler, Mode::Libtest, target, "check");
|
2018-04-14 18:27:57 -05:00
|
|
|
test_cargo(builder, &compiler, target, &mut cargo);
|
2018-03-16 10:35:03 -05:00
|
|
|
|
2018-04-14 18:27:57 -05:00
|
|
|
let _folder = builder.fold_output(|| format!("stage{}-test", compiler.stage));
|
2018-03-16 10:35:03 -05:00
|
|
|
println!("Checking test artifacts ({} -> {})", &compiler.host, target);
|
2018-04-14 18:27:57 -05:00
|
|
|
run_cargo(builder,
|
2018-01-15 11:44:00 -06:00
|
|
|
&mut cargo,
|
2018-04-14 18:27:57 -05:00
|
|
|
&libtest_stamp(builder, compiler, target),
|
2018-01-15 11:44:00 -06:00
|
|
|
true);
|
2018-03-16 10:35:03 -05:00
|
|
|
|
2018-01-15 11:44:00 -06:00
|
|
|
let libdir = builder.sysroot_libdir(compiler, target);
|
2018-04-14 18:27:57 -05:00
|
|
|
add_to_sysroot(builder, &libdir, &libtest_stamp(builder, compiler, target));
|
2018-01-15 11:44:00 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-18 13:46:58 -05:00
|
|
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
|
|
|
pub struct Rustdoc {
|
|
|
|
pub target: Interned<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Step for Rustdoc {
|
|
|
|
type Output = ();
|
|
|
|
const ONLY_HOSTS: bool = true;
|
|
|
|
const DEFAULT: bool = true;
|
|
|
|
|
|
|
|
fn should_run(run: ShouldRun) -> ShouldRun {
|
|
|
|
run.path("src/tools/rustdoc")
|
|
|
|
}
|
|
|
|
|
|
|
|
fn make_run(run: RunConfig) {
|
|
|
|
run.builder.ensure(Rustdoc {
|
|
|
|
target: run.target,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fn run(self, builder: &Builder) {
|
|
|
|
let compiler = builder.compiler(0, builder.config.build);
|
|
|
|
let target = self.target;
|
|
|
|
|
|
|
|
let mut cargo = prepare_tool_cargo(builder,
|
|
|
|
compiler,
|
|
|
|
target,
|
|
|
|
"check",
|
|
|
|
"src/tools/rustdoc");
|
|
|
|
|
|
|
|
let _folder = builder.fold_output(|| format!("stage{}-rustdoc", compiler.stage));
|
|
|
|
println!("Checking rustdoc artifacts ({} -> {})", &compiler.host, target);
|
|
|
|
run_cargo(builder,
|
|
|
|
&mut cargo,
|
|
|
|
&rustdoc_stamp(builder, compiler, target),
|
|
|
|
true);
|
|
|
|
|
|
|
|
let libdir = builder.sysroot_libdir(compiler, target);
|
|
|
|
add_to_sysroot(&builder, &libdir, &rustdoc_stamp(builder, compiler, target));
|
2018-04-18 18:45:18 -05:00
|
|
|
|
|
|
|
builder.ensure(tool::CleanTools {
|
|
|
|
compiler,
|
|
|
|
target,
|
|
|
|
mode: Mode::Tool,
|
|
|
|
});
|
2018-04-18 13:46:58 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-15 11:44:00 -06:00
|
|
|
/// Cargo's output path for the standard library in a given stage, compiled
|
|
|
|
/// by a particular compiler for the specified target.
|
2018-04-14 18:27:57 -05:00
|
|
|
pub fn libstd_stamp(builder: &Builder, compiler: Compiler, target: Interned<String>) -> PathBuf {
|
|
|
|
builder.cargo_out(compiler, Mode::Libstd, target).join(".libstd-check.stamp")
|
2018-01-15 11:44:00 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Cargo's output path for libtest in a given stage, compiled by a particular
|
|
|
|
/// compiler for the specified target.
|
2018-04-14 18:27:57 -05:00
|
|
|
pub fn libtest_stamp(builder: &Builder, compiler: Compiler, target: Interned<String>) -> PathBuf {
|
|
|
|
builder.cargo_out(compiler, Mode::Libtest, target).join(".libtest-check.stamp")
|
2018-01-15 11:44:00 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Cargo's output path for librustc in a given stage, compiled by a particular
|
|
|
|
/// compiler for the specified target.
|
2018-04-14 18:27:57 -05:00
|
|
|
pub fn librustc_stamp(builder: &Builder, compiler: Compiler, target: Interned<String>) -> PathBuf {
|
|
|
|
builder.cargo_out(compiler, Mode::Librustc, target).join(".librustc-check.stamp")
|
2018-01-15 11:44:00 -06:00
|
|
|
}
|
2018-04-11 18:34:49 -05:00
|
|
|
|
2018-05-08 08:10:16 -05:00
|
|
|
/// Cargo's output path for librustc_codegen_llvm in a given stage, compiled by a particular
|
2018-04-11 18:34:49 -05:00
|
|
|
/// compiler for the specified target and backend.
|
2018-04-18 04:56:04 -05:00
|
|
|
fn codegen_backend_stamp(builder: &Builder,
|
2018-04-11 18:34:49 -05:00
|
|
|
compiler: Compiler,
|
|
|
|
target: Interned<String>,
|
|
|
|
backend: Interned<String>) -> PathBuf {
|
2018-04-18 04:56:04 -05:00
|
|
|
builder.cargo_out(compiler, Mode::Librustc, target)
|
2018-05-08 08:10:16 -05:00
|
|
|
.join(format!(".librustc_codegen_llvm-{}-check.stamp", backend))
|
2018-04-11 18:34:49 -05:00
|
|
|
}
|
2018-04-18 13:46:58 -05:00
|
|
|
|
|
|
|
/// Cargo's output path for rustdoc in a given stage, compiled by a particular
|
|
|
|
/// compiler for the specified target.
|
|
|
|
pub fn rustdoc_stamp(builder: &Builder, compiler: Compiler, target: Interned<String>) -> PathBuf {
|
|
|
|
builder.cargo_out(compiler, Mode::Tool, target).join(".rustdoc-check.stamp")
|
|
|
|
}
|