]> git.lizzy.rs Git - rust.git/blob - src/bootstrap/check.rs
rustc: Load the `rustc_trans` crate at runtime
[rust.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.path("src/libstd").krate("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 _folder = build.fold_output(|| format!("stage{}-std", compiler.stage));
44         println!("Checking std artifacts ({} -> {})", &compiler.host, target);
45
46         let out_dir = build.stage_out(compiler, Mode::Libstd);
47         build.clear_if_dirty(&out_dir, &builder.rustc(compiler));
48         let mut cargo = builder.cargo(compiler, Mode::Libstd, target, "check");
49         std_cargo(build, &compiler, target, &mut cargo);
50         run_cargo(build,
51                   &mut cargo,
52                   &libstd_stamp(build, compiler, target),
53                   true);
54         let libdir = builder.sysroot_libdir(compiler, target);
55         add_to_sysroot(&libdir, &libstd_stamp(build, compiler, target));
56     }
57 }
58
59 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
60 pub struct Rustc {
61     pub target: Interned<String>,
62 }
63
64 impl Step for Rustc {
65     type Output = ();
66     const ONLY_HOSTS: bool = true;
67     const DEFAULT: bool = true;
68
69     fn should_run(run: ShouldRun) -> ShouldRun {
70         run.path("src/librustc").krate("rustc-main")
71     }
72
73     fn make_run(run: RunConfig) {
74         run.builder.ensure(Rustc {
75             target: run.target,
76         });
77     }
78
79     /// Build the compiler.
80     ///
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 build = builder.build;
86         let compiler = builder.compiler(0, build.build);
87         let target = self.target;
88
89         let _folder = build.fold_output(|| format!("stage{}-rustc", compiler.stage));
90         println!("Checking compiler artifacts ({} -> {})", &compiler.host, target);
91
92         let stage_out = builder.stage_out(compiler, Mode::Librustc);
93         build.clear_if_dirty(&stage_out, &libstd_stamp(build, compiler, target));
94         build.clear_if_dirty(&stage_out, &libtest_stamp(build, compiler, target));
95
96         let mut cargo = builder.cargo(compiler, Mode::Librustc, target, "check");
97         rustc_cargo(build, &mut cargo);
98         run_cargo(build,
99                   &mut cargo,
100                   &librustc_stamp(build, compiler, target),
101                   true);
102         let libdir = builder.sysroot_libdir(compiler, target);
103         add_to_sysroot(&libdir, &librustc_stamp(build, compiler, target));
104     }
105 }
106
107 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
108 pub struct Test {
109     pub target: Interned<String>,
110 }
111
112 impl Step for Test {
113     type Output = ();
114     const DEFAULT: bool = true;
115
116     fn should_run(run: ShouldRun) -> ShouldRun {
117         run.path("src/libtest").krate("test")
118     }
119
120     fn make_run(run: RunConfig) {
121         run.builder.ensure(Test {
122             target: run.target,
123         });
124     }
125
126     fn run(self, builder: &Builder) {
127         let build = builder.build;
128         let target = self.target;
129         let compiler = builder.compiler(0, build.build);
130
131         let _folder = build.fold_output(|| format!("stage{}-test", compiler.stage));
132         println!("Checking test artifacts ({} -> {})", &compiler.host, target);
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         run_cargo(build,
138                   &mut cargo,
139                   &libtest_stamp(build, compiler, target),
140                   true);
141         let libdir = builder.sysroot_libdir(compiler, target);
142         add_to_sysroot(&libdir, &libtest_stamp(build, compiler, target));
143     }
144 }
145
146 /// Cargo's output path for the standard library in a given stage, compiled
147 /// by a particular compiler for the specified target.
148 pub fn libstd_stamp(build: &Build, compiler: Compiler, target: Interned<String>) -> PathBuf {
149     build.cargo_out(compiler, Mode::Libstd, target).join(".libstd-check.stamp")
150 }
151
152 /// Cargo's output path for libtest in a given stage, compiled by a particular
153 /// compiler for the specified target.
154 pub fn libtest_stamp(build: &Build, compiler: Compiler, target: Interned<String>) -> PathBuf {
155     build.cargo_out(compiler, Mode::Libtest, target).join(".libtest-check.stamp")
156 }
157
158 /// Cargo's output path for librustc in a given stage, compiled by a particular
159 /// compiler for the specified target.
160 pub fn librustc_stamp(build: &Build, compiler: Compiler, target: Interned<String>) -> PathBuf {
161     build.cargo_out(compiler, Mode::Librustc, target).join(".librustc-check.stamp")
162 }
163