1 // Copyright 2018 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 //! Implementation of compiling the compiler and standard library, in "check" mode.
13 use compile::{run_cargo, std_cargo, test_cargo, rustc_cargo, rustc_cargo_env, add_to_sysroot};
14 use builder::{RunConfig, Builder, ShouldRun, Step};
15 use tool::{self, prepare_tool_cargo};
17 use cache::{INTERNER, Interned};
18 use std::path::PathBuf;
20 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
22 pub target: Interned<String>,
27 const DEFAULT: bool = true;
29 fn should_run(run: ShouldRun) -> ShouldRun {
33 fn make_run(run: RunConfig) {
34 run.builder.ensure(Std {
39 fn run(self, builder: &Builder) {
40 let target = self.target;
41 let compiler = builder.compiler(0, builder.config.build);
43 let out_dir = builder.stage_out(compiler, Mode::Std);
44 builder.clear_if_dirty(&out_dir, &builder.rustc(compiler));
46 let mut cargo = builder.cargo(compiler, Mode::Std, target, "check");
47 std_cargo(builder, &compiler, target, &mut cargo);
49 let _folder = builder.fold_output(|| format!("stage{}-std", compiler.stage));
50 println!("Checking std artifacts ({} -> {})", &compiler.host, target);
53 &libstd_stamp(builder, compiler, target),
56 let libdir = builder.sysroot_libdir(compiler, target);
57 add_to_sysroot(&builder, &libdir, &libstd_stamp(builder, compiler, target));
61 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
63 pub target: Interned<String>,
68 const ONLY_HOSTS: bool = true;
69 const DEFAULT: bool = true;
71 fn should_run(run: ShouldRun) -> ShouldRun {
72 run.all_krates("rustc-main")
75 fn make_run(run: RunConfig) {
76 run.builder.ensure(Rustc {
81 /// Build the compiler.
83 /// This will build the compiler for a particular stage of the build using
84 /// the `compiler` targeting the `target` architecture. The artifacts
85 /// created will also be linked into the sysroot directory.
86 fn run(self, builder: &Builder) {
87 let compiler = builder.compiler(0, builder.config.build);
88 let target = self.target;
90 let stage_out = builder.stage_out(compiler, Mode::Rustc);
91 builder.clear_if_dirty(&stage_out, &libstd_stamp(builder, compiler, target));
92 builder.clear_if_dirty(&stage_out, &libtest_stamp(builder, compiler, target));
94 let mut cargo = builder.cargo(compiler, Mode::Rustc, target, "check");
95 rustc_cargo(builder, &mut cargo);
97 let _folder = builder.fold_output(|| format!("stage{}-rustc", compiler.stage));
98 println!("Checking compiler artifacts ({} -> {})", &compiler.host, target);
101 &librustc_stamp(builder, compiler, target),
104 let libdir = builder.sysroot_libdir(compiler, target);
105 add_to_sysroot(&builder, &libdir, &librustc_stamp(builder, compiler, target));
109 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
110 pub struct CodegenBackend {
111 pub target: Interned<String>,
112 pub backend: Interned<String>,
115 impl Step for CodegenBackend {
117 const ONLY_HOSTS: bool = true;
118 const DEFAULT: bool = true;
120 fn should_run(run: ShouldRun) -> ShouldRun {
121 run.all_krates("rustc_codegen_llvm")
124 fn make_run(run: RunConfig) {
125 let backend = run.builder.config.rust_codegen_backends.get(0);
126 let backend = backend.cloned().unwrap_or_else(|| {
127 INTERNER.intern_str("llvm")
129 run.builder.ensure(CodegenBackend {
135 fn run(self, builder: &Builder) {
136 let compiler = builder.compiler(0, builder.config.build);
137 let target = self.target;
138 let backend = self.backend;
140 let mut cargo = builder.cargo(compiler, Mode::Codegen, target, "check");
141 let features = builder.rustc_features().to_string();
142 cargo.arg("--manifest-path").arg(builder.src.join("src/librustc_codegen_llvm/Cargo.toml"));
143 rustc_cargo_env(builder, &mut cargo);
145 // We won't build LLVM if it's not available, as it shouldn't affect `check`.
147 let _folder = builder.fold_output(|| format!("stage{}-rustc_codegen_llvm", compiler.stage));
149 cargo.arg("--features").arg(features),
150 &codegen_backend_stamp(builder, compiler, target, backend),
155 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
157 pub target: Interned<String>,
162 const DEFAULT: bool = true;
164 fn should_run(run: ShouldRun) -> ShouldRun {
165 run.all_krates("test")
168 fn make_run(run: RunConfig) {
169 run.builder.ensure(Test {
174 fn run(self, builder: &Builder) {
175 let compiler = builder.compiler(0, builder.config.build);
176 let target = self.target;
178 let out_dir = builder.stage_out(compiler, Mode::Test);
179 builder.clear_if_dirty(&out_dir, &libstd_stamp(builder, compiler, target));
181 let mut cargo = builder.cargo(compiler, Mode::Test, target, "check");
182 test_cargo(builder, &compiler, target, &mut cargo);
184 let _folder = builder.fold_output(|| format!("stage{}-test", compiler.stage));
185 println!("Checking test artifacts ({} -> {})", &compiler.host, target);
188 &libtest_stamp(builder, compiler, target),
191 let libdir = builder.sysroot_libdir(compiler, target);
192 add_to_sysroot(builder, &libdir, &libtest_stamp(builder, compiler, target));
196 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
198 pub target: Interned<String>,
201 impl Step for Rustdoc {
203 const ONLY_HOSTS: bool = true;
204 const DEFAULT: bool = true;
206 fn should_run(run: ShouldRun) -> ShouldRun {
207 run.path("src/tools/rustdoc")
210 fn make_run(run: RunConfig) {
211 run.builder.ensure(Rustdoc {
216 fn run(self, builder: &Builder) {
217 let compiler = builder.compiler(0, builder.config.build);
218 let target = self.target;
220 let mut cargo = prepare_tool_cargo(builder,
225 "src/tools/rustdoc");
227 let _folder = builder.fold_output(|| format!("stage{}-rustdoc", compiler.stage));
228 println!("Checking rustdoc artifacts ({} -> {})", &compiler.host, target);
231 &rustdoc_stamp(builder, compiler, target),
234 let libdir = builder.sysroot_libdir(compiler, target);
235 add_to_sysroot(&builder, &libdir, &rustdoc_stamp(builder, compiler, target));
237 builder.ensure(tool::CleanTools {
245 /// Cargo's output path for the standard library in a given stage, compiled
246 /// by a particular compiler for the specified target.
247 pub fn libstd_stamp(builder: &Builder, compiler: Compiler, target: Interned<String>) -> PathBuf {
248 builder.cargo_out(compiler, Mode::Std, target).join(".libstd-check.stamp")
251 /// Cargo's output path for libtest in a given stage, compiled by a particular
252 /// compiler for the specified target.
253 pub fn libtest_stamp(builder: &Builder, compiler: Compiler, target: Interned<String>) -> PathBuf {
254 builder.cargo_out(compiler, Mode::Test, target).join(".libtest-check.stamp")
257 /// Cargo's output path for librustc in a given stage, compiled by a particular
258 /// compiler for the specified target.
259 pub fn librustc_stamp(builder: &Builder, compiler: Compiler, target: Interned<String>) -> PathBuf {
260 builder.cargo_out(compiler, Mode::Rustc, target).join(".librustc-check.stamp")
263 /// Cargo's output path for librustc_codegen_llvm in a given stage, compiled by a particular
264 /// compiler for the specified target and backend.
265 fn codegen_backend_stamp(builder: &Builder,
267 target: Interned<String>,
268 backend: Interned<String>) -> PathBuf {
269 builder.cargo_out(compiler, Mode::Codegen, target)
270 .join(format!(".librustc_codegen_llvm-{}-check.stamp", backend))
273 /// Cargo's output path for rustdoc in a given stage, compiled by a particular
274 /// compiler for the specified target.
275 pub fn rustdoc_stamp(builder: &Builder, compiler: Compiler, target: Interned<String>) -> PathBuf {
276 builder.cargo_out(compiler, Mode::ToolRustc, target).join(".rustdoc-check.stamp")