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, SourceType};
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 out_dir = builder.cargo_out(compiler, Mode::Codegen, target);
141 builder.clear_if_dirty(&out_dir, &librustc_stamp(builder, compiler, target));
143 let mut cargo = builder.cargo(compiler, Mode::Codegen, target, "check");
144 cargo.arg("--manifest-path").arg(builder.src.join("src/librustc_codegen_llvm/Cargo.toml"));
145 rustc_cargo_env(builder, &mut cargo);
147 // We won't build LLVM if it's not available, as it shouldn't affect `check`.
149 let _folder = builder.fold_output(|| format!("stage{}-rustc_codegen_llvm", compiler.stage));
152 &codegen_backend_stamp(builder, compiler, target, backend),
157 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
159 pub target: Interned<String>,
164 const DEFAULT: bool = true;
166 fn should_run(run: ShouldRun) -> ShouldRun {
167 run.all_krates("test")
170 fn make_run(run: RunConfig) {
171 run.builder.ensure(Test {
176 fn run(self, builder: &Builder) {
177 let compiler = builder.compiler(0, builder.config.build);
178 let target = self.target;
180 let out_dir = builder.stage_out(compiler, Mode::Test);
181 builder.clear_if_dirty(&out_dir, &libstd_stamp(builder, compiler, target));
183 let mut cargo = builder.cargo(compiler, Mode::Test, target, "check");
184 test_cargo(builder, &compiler, target, &mut cargo);
186 let _folder = builder.fold_output(|| format!("stage{}-test", compiler.stage));
187 println!("Checking test artifacts ({} -> {})", &compiler.host, target);
190 &libtest_stamp(builder, compiler, target),
193 let libdir = builder.sysroot_libdir(compiler, target);
194 add_to_sysroot(builder, &libdir, &libtest_stamp(builder, compiler, target));
198 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
200 pub target: Interned<String>,
203 impl Step for Rustdoc {
205 const ONLY_HOSTS: bool = true;
206 const DEFAULT: bool = true;
208 fn should_run(run: ShouldRun) -> ShouldRun {
209 run.path("src/tools/rustdoc")
212 fn make_run(run: RunConfig) {
213 run.builder.ensure(Rustdoc {
218 fn run(self, builder: &Builder) {
219 let compiler = builder.compiler(0, builder.config.build);
220 let target = self.target;
222 let stage_out = builder.stage_out(compiler, Mode::ToolRustc);
223 builder.clear_if_dirty(&stage_out, &libstd_stamp(builder, compiler, target));
224 builder.clear_if_dirty(&stage_out, &libtest_stamp(builder, compiler, target));
225 builder.clear_if_dirty(&stage_out, &librustc_stamp(builder, compiler, target));
227 let mut cargo = prepare_tool_cargo(builder,
235 let _folder = builder.fold_output(|| format!("stage{}-rustdoc", compiler.stage));
236 println!("Checking rustdoc artifacts ({} -> {})", &compiler.host, target);
239 &rustdoc_stamp(builder, compiler, target),
242 let libdir = builder.sysroot_libdir(compiler, target);
243 add_to_sysroot(&builder, &libdir, &rustdoc_stamp(builder, compiler, target));
245 builder.ensure(tool::CleanTools {
253 /// Cargo's output path for the standard library in a given stage, compiled
254 /// by a particular compiler for the specified target.
255 pub fn libstd_stamp(builder: &Builder, compiler: Compiler, target: Interned<String>) -> PathBuf {
256 builder.cargo_out(compiler, Mode::Std, target).join(".libstd-check.stamp")
259 /// Cargo's output path for libtest in a given stage, compiled by a particular
260 /// compiler for the specified target.
261 pub fn libtest_stamp(builder: &Builder, compiler: Compiler, target: Interned<String>) -> PathBuf {
262 builder.cargo_out(compiler, Mode::Test, target).join(".libtest-check.stamp")
265 /// Cargo's output path for librustc in a given stage, compiled by a particular
266 /// compiler for the specified target.
267 pub fn librustc_stamp(builder: &Builder, compiler: Compiler, target: Interned<String>) -> PathBuf {
268 builder.cargo_out(compiler, Mode::Rustc, target).join(".librustc-check.stamp")
271 /// Cargo's output path for librustc_codegen_llvm in a given stage, compiled by a particular
272 /// compiler for the specified target and backend.
273 fn codegen_backend_stamp(builder: &Builder,
275 target: Interned<String>,
276 backend: Interned<String>) -> PathBuf {
277 builder.cargo_out(compiler, Mode::Codegen, target)
278 .join(format!(".librustc_codegen_llvm-{}-check.stamp", backend))
281 /// Cargo's output path for rustdoc in a given stage, compiled by a particular
282 /// compiler for the specified target.
283 pub fn rustdoc_stamp(builder: &Builder, compiler: Compiler, target: Interned<String>) -> PathBuf {
284 builder.cargo_out(compiler, Mode::ToolRustc, target)
285 .join(".rustdoc-check.stamp")