]> git.proxmox.com Git - rustc.git/blob - src/bootstrap/check.rs
New upstream version 1.26.0+dfsg1
[rustc.git] / src / bootstrap / check.rs
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.
4 //
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.
10
11 //! Implementation of compiling the compiler and standard library, in "check" mode.
12
13 use compile::{run_cargo, std_cargo, test_cargo, rustc_cargo, add_to_sysroot};
14 use builder::{RunConfig, Builder, ShouldRun, Step};
15 use {Build, Compiler, Mode};
16 use cache::Interned;
17 use std::path::PathBuf;
18
19 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
20 pub struct Std {
21 pub target: Interned<String>,
22 }
23
24 impl Step for Std {
25 type Output = ();
26 const DEFAULT: bool = true;
27
28 fn should_run(run: ShouldRun) -> ShouldRun {
29 run.all_krates("std")
30 }
31
32 fn make_run(run: RunConfig) {
33 run.builder.ensure(Std {
34 target: run.target,
35 });
36 }
37
38 fn run(self, builder: &Builder) {
39 let build = builder.build;
40 let target = self.target;
41 let compiler = builder.compiler(0, build.build);
42
43 let out_dir = build.stage_out(compiler, Mode::Libstd);
44 build.clear_if_dirty(&out_dir, &builder.rustc(compiler));
45 let mut cargo = builder.cargo(compiler, Mode::Libstd, target, "check");
46 std_cargo(builder, &compiler, target, &mut cargo);
47
48 let _folder = build.fold_output(|| format!("stage{}-std", compiler.stage));
49 println!("Checking std artifacts ({} -> {})", &compiler.host, target);
50 run_cargo(build,
51 &mut cargo,
52 &libstd_stamp(build, compiler, target),
53 true);
54
55 let libdir = builder.sysroot_libdir(compiler, target);
56 add_to_sysroot(&libdir, &libstd_stamp(build, compiler, target));
57 }
58 }
59
60 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
61 pub struct Rustc {
62 pub target: Interned<String>,
63 }
64
65 impl Step for Rustc {
66 type Output = ();
67 const ONLY_HOSTS: bool = true;
68 const DEFAULT: bool = true;
69
70 fn should_run(run: ShouldRun) -> ShouldRun {
71 run.all_krates("rustc-main")
72 }
73
74 fn make_run(run: RunConfig) {
75 run.builder.ensure(Rustc {
76 target: run.target,
77 });
78 }
79
80 /// Build the compiler.
81 ///
82 /// This will build the compiler for a particular stage of the build using
83 /// the `compiler` targeting the `target` architecture. The artifacts
84 /// created will also be linked into the sysroot directory.
85 fn run(self, builder: &Builder) {
86 let build = builder.build;
87 let compiler = builder.compiler(0, build.build);
88 let target = self.target;
89
90 let stage_out = builder.stage_out(compiler, Mode::Librustc);
91 build.clear_if_dirty(&stage_out, &libstd_stamp(build, compiler, target));
92 build.clear_if_dirty(&stage_out, &libtest_stamp(build, compiler, target));
93
94 let mut cargo = builder.cargo(compiler, Mode::Librustc, target, "check");
95 rustc_cargo(build, &mut cargo);
96
97 let _folder = build.fold_output(|| format!("stage{}-rustc", compiler.stage));
98 println!("Checking compiler artifacts ({} -> {})", &compiler.host, target);
99 run_cargo(build,
100 &mut cargo,
101 &librustc_stamp(build, compiler, target),
102 true);
103
104 let libdir = builder.sysroot_libdir(compiler, target);
105 add_to_sysroot(&libdir, &librustc_stamp(build, compiler, target));
106 }
107 }
108
109 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
110 pub struct Test {
111 pub target: Interned<String>,
112 }
113
114 impl Step for Test {
115 type Output = ();
116 const DEFAULT: bool = true;
117
118 fn should_run(run: ShouldRun) -> ShouldRun {
119 run.all_krates("test")
120 }
121
122 fn make_run(run: RunConfig) {
123 run.builder.ensure(Test {
124 target: run.target,
125 });
126 }
127
128 fn run(self, builder: &Builder) {
129 let build = builder.build;
130 let target = self.target;
131 let compiler = builder.compiler(0, build.build);
132
133 let out_dir = build.stage_out(compiler, Mode::Libtest);
134 build.clear_if_dirty(&out_dir, &libstd_stamp(build, compiler, target));
135 let mut cargo = builder.cargo(compiler, Mode::Libtest, target, "check");
136 test_cargo(build, &compiler, target, &mut cargo);
137
138 let _folder = build.fold_output(|| format!("stage{}-test", compiler.stage));
139 println!("Checking test artifacts ({} -> {})", &compiler.host, target);
140 run_cargo(build,
141 &mut cargo,
142 &libtest_stamp(build, compiler, target),
143 true);
144
145 let libdir = builder.sysroot_libdir(compiler, target);
146 add_to_sysroot(&libdir, &libtest_stamp(build, compiler, target));
147 }
148 }
149
150 /// Cargo's output path for the standard library in a given stage, compiled
151 /// by a particular compiler for the specified target.
152 pub fn libstd_stamp(build: &Build, compiler: Compiler, target: Interned<String>) -> PathBuf {
153 build.cargo_out(compiler, Mode::Libstd, target).join(".libstd-check.stamp")
154 }
155
156 /// Cargo's output path for libtest in a given stage, compiled by a particular
157 /// compiler for the specified target.
158 pub fn libtest_stamp(build: &Build, compiler: Compiler, target: Interned<String>) -> PathBuf {
159 build.cargo_out(compiler, Mode::Libtest, target).join(".libtest-check.stamp")
160 }
161
162 /// Cargo's output path for librustc in a given stage, compiled by a particular
163 /// compiler for the specified target.
164 pub fn librustc_stamp(build: &Build, compiler: Compiler, target: Interned<String>) -> PathBuf {
165 build.cargo_out(compiler, Mode::Librustc, target).join(".librustc-check.stamp")
166 }