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::{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 mut cargo = builder.cargo(compiler, Mode::Std, target, "check");
44 std_cargo(builder, &compiler, target, &mut cargo);
46 let _folder = builder.fold_output(|| format!("stage{}-std", compiler.stage));
47 builder.info(&format!("Checking std artifacts ({} -> {})", &compiler.host, target));
51 &libstd_stamp(builder, compiler, target),
54 let libdir = builder.sysroot_libdir(compiler, target);
55 add_to_sysroot(&builder, &libdir, &libstd_stamp(builder, compiler, target));
59 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
61 pub target: Interned<String>,
66 const ONLY_HOSTS: bool = true;
67 const DEFAULT: bool = true;
69 fn should_run(run: ShouldRun) -> ShouldRun {
70 run.all_krates("rustc-main")
73 fn make_run(run: RunConfig) {
74 run.builder.ensure(Rustc {
79 /// Build the compiler.
81 /// This will build the compiler for a particular stage of the build using
82 /// the `compiler` targeting the `target` architecture. The artifacts
83 /// created will also be linked into the sysroot directory.
84 fn run(self, builder: &Builder) {
85 let compiler = builder.compiler(0, builder.config.build);
86 let target = self.target;
88 builder.ensure(Test { target });
90 let mut cargo = builder.cargo(compiler, Mode::Rustc, target, "check");
91 rustc_cargo(builder, &mut cargo);
93 let _folder = builder.fold_output(|| format!("stage{}-rustc", compiler.stage));
94 builder.info(&format!("Checking compiler artifacts ({} -> {})", &compiler.host, target));
98 &librustc_stamp(builder, compiler, target),
101 let libdir = builder.sysroot_libdir(compiler, target);
102 add_to_sysroot(&builder, &libdir, &librustc_stamp(builder, compiler, target));
106 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
107 pub struct CodegenBackend {
108 pub target: Interned<String>,
109 pub backend: Interned<String>,
112 impl Step for CodegenBackend {
114 const ONLY_HOSTS: bool = true;
115 const DEFAULT: bool = true;
117 fn should_run(run: ShouldRun) -> ShouldRun {
118 run.all_krates("rustc_codegen_llvm")
121 fn make_run(run: RunConfig) {
122 let backend = run.builder.config.rust_codegen_backends.get(0);
123 let backend = backend.cloned().unwrap_or_else(|| {
124 INTERNER.intern_str("llvm")
126 run.builder.ensure(CodegenBackend {
132 fn run(self, builder: &Builder) {
133 let compiler = builder.compiler(0, builder.config.build);
134 let target = self.target;
135 let backend = self.backend;
137 builder.ensure(Rustc { target });
139 let mut cargo = builder.cargo(compiler, Mode::Codegen, target, "check");
140 cargo.arg("--manifest-path").arg(builder.src.join("src/librustc_codegen_llvm/Cargo.toml"));
141 rustc_cargo_env(builder, &mut cargo);
143 // We won't build LLVM if it's not available, as it shouldn't affect `check`.
145 let _folder = builder.fold_output(|| format!("stage{}-rustc_codegen_llvm", compiler.stage));
149 &codegen_backend_stamp(builder, compiler, target, backend),
154 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
156 pub target: Interned<String>,
161 const DEFAULT: bool = true;
163 fn should_run(run: ShouldRun) -> ShouldRun {
164 run.all_krates("test")
167 fn make_run(run: RunConfig) {
168 run.builder.ensure(Test {
173 fn run(self, builder: &Builder) {
174 let compiler = builder.compiler(0, builder.config.build);
175 let target = self.target;
177 builder.ensure(Std { target });
179 let mut cargo = builder.cargo(compiler, Mode::Test, target, "check");
180 test_cargo(builder, &compiler, target, &mut cargo);
182 let _folder = builder.fold_output(|| format!("stage{}-test", compiler.stage));
183 builder.info(&format!("Checking test artifacts ({} -> {})", &compiler.host, target));
187 &libtest_stamp(builder, compiler, target),
190 let libdir = builder.sysroot_libdir(compiler, target);
191 add_to_sysroot(builder, &libdir, &libtest_stamp(builder, compiler, target));
195 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
197 pub target: Interned<String>,
200 impl Step for Rustdoc {
202 const ONLY_HOSTS: bool = true;
203 const DEFAULT: bool = true;
205 fn should_run(run: ShouldRun) -> ShouldRun {
206 run.path("src/tools/rustdoc")
209 fn make_run(run: RunConfig) {
210 run.builder.ensure(Rustdoc {
215 fn run(self, builder: &Builder) {
216 let compiler = builder.compiler(0, builder.config.build);
217 let target = self.target;
219 builder.ensure(Rustc { target });
221 let mut cargo = prepare_tool_cargo(builder,
229 let _folder = builder.fold_output(|| format!("stage{}-rustdoc", compiler.stage));
230 println!("Checking rustdoc artifacts ({} -> {})", &compiler.host, target);
234 &rustdoc_stamp(builder, compiler, target),
237 let libdir = builder.sysroot_libdir(compiler, target);
238 add_to_sysroot(&builder, &libdir, &rustdoc_stamp(builder, compiler, target));
239 builder.cargo(compiler, Mode::ToolRustc, target, "clean");
243 /// Cargo's output path for the standard library in a given stage, compiled
244 /// by a particular compiler for the specified target.
245 pub fn libstd_stamp(builder: &Builder, compiler: Compiler, target: Interned<String>) -> PathBuf {
246 builder.cargo_out(compiler, Mode::Std, target).join(".libstd-check.stamp")
249 /// Cargo's output path for libtest in a given stage, compiled by a particular
250 /// compiler for the specified target.
251 pub fn libtest_stamp(builder: &Builder, compiler: Compiler, target: Interned<String>) -> PathBuf {
252 builder.cargo_out(compiler, Mode::Test, target).join(".libtest-check.stamp")
255 /// Cargo's output path for librustc in a given stage, compiled by a particular
256 /// compiler for the specified target.
257 pub fn librustc_stamp(builder: &Builder, compiler: Compiler, target: Interned<String>) -> PathBuf {
258 builder.cargo_out(compiler, Mode::Rustc, target).join(".librustc-check.stamp")
261 /// Cargo's output path for librustc_codegen_llvm in a given stage, compiled by a particular
262 /// compiler for the specified target and backend.
263 fn codegen_backend_stamp(builder: &Builder,
265 target: Interned<String>,
266 backend: Interned<String>) -> PathBuf {
267 builder.cargo_out(compiler, Mode::Codegen, target)
268 .join(format!(".librustc_codegen_llvm-{}-check.stamp", backend))
271 /// Cargo's output path for rustdoc in a given stage, compiled by a particular
272 /// compiler for the specified target.
273 pub fn rustdoc_stamp(builder: &Builder, compiler: Compiler, target: Interned<String>) -> PathBuf {
274 builder.cargo_out(compiler, Mode::ToolRustc, target)
275 .join(".rustdoc-check.stamp")