1 //! Implementation of compiling the compiler and standard library, in "check"-based modes.
3 use crate::builder
::{Builder, Kind, RunConfig, ShouldRun, Step}
;
4 use crate::cache
::Interned
;
5 use crate::compile
::{add_to_sysroot, run_cargo, rustc_cargo, std_cargo}
;
6 use crate::tool
::{prepare_tool_cargo, SourceType}
;
7 use crate::{Compiler, Mode}
;
8 use std
::path
::PathBuf
;
10 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
12 pub target
: Interned
<String
>,
15 fn args(kind
: Kind
) -> Vec
<String
> {
17 Kind
::Clippy
=> vec
!["--".to_owned(), "--cap-lints".to_owned(), "warn".to_owned()],
22 fn cargo_subcommand(kind
: Kind
) -> &'
static str {
24 Kind
::Check
=> "check",
25 Kind
::Clippy
=> "clippy",
33 const DEFAULT
: bool
= true;
35 fn should_run(run
: ShouldRun
<'_
>) -> ShouldRun
<'_
> {
36 run
.all_krates("test")
39 fn make_run(run
: RunConfig
<'_
>) {
40 run
.builder
.ensure(Std { target: run.target }
);
43 fn run(self, builder
: &Builder
<'_
>) {
44 let target
= self.target
;
45 let compiler
= builder
.compiler(0, builder
.config
.build
);
47 let mut cargo
= builder
.cargo(compiler
, Mode
::Std
, target
, cargo_subcommand(builder
.kind
));
48 std_cargo(builder
, target
, compiler
.stage
, &mut cargo
);
50 builder
.info(&format
!("Checking std artifacts ({} -> {})", &compiler
.host
, target
));
55 &libstd_stamp(builder
, compiler
, target
),
60 let libdir
= builder
.sysroot_libdir(compiler
, target
);
61 let hostdir
= builder
.sysroot_libdir(compiler
, compiler
.host
);
62 add_to_sysroot(&builder
, &libdir
, &hostdir
, &libstd_stamp(builder
, compiler
, target
));
66 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
68 pub target
: Interned
<String
>,
73 const ONLY_HOSTS
: bool
= true;
74 const DEFAULT
: bool
= true;
76 fn should_run(run
: ShouldRun
<'_
>) -> ShouldRun
<'_
> {
77 run
.all_krates("rustc-main")
80 fn make_run(run
: RunConfig
<'_
>) {
81 run
.builder
.ensure(Rustc { target: run.target }
);
84 /// Builds the compiler.
86 /// This will build the compiler for a particular stage of the build using
87 /// the `compiler` targeting the `target` architecture. The artifacts
88 /// created will also be linked into the sysroot directory.
89 fn run(self, builder
: &Builder
<'_
>) {
90 let compiler
= builder
.compiler(0, builder
.config
.build
);
91 let target
= self.target
;
93 builder
.ensure(Std { target }
);
96 builder
.cargo(compiler
, Mode
::Rustc
, target
, cargo_subcommand(builder
.kind
));
97 rustc_cargo(builder
, &mut cargo
, target
);
99 builder
.info(&format
!("Checking compiler artifacts ({} -> {})", &compiler
.host
, target
));
104 &librustc_stamp(builder
, compiler
, target
),
109 let libdir
= builder
.sysroot_libdir(compiler
, target
);
110 let hostdir
= builder
.sysroot_libdir(compiler
, compiler
.host
);
111 add_to_sysroot(&builder
, &libdir
, &hostdir
, &librustc_stamp(builder
, compiler
, target
));
115 macro_rules
! tool_check_step
{
116 ($name
:ident
, $path
:expr
) => {
117 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
119 pub target
: Interned
<String
>,
122 impl Step
for $name
{
124 const ONLY_HOSTS
: bool
= true;
125 const DEFAULT
: bool
= true;
127 fn should_run(run
: ShouldRun
<'_
>) -> ShouldRun
<'_
> {
131 fn make_run(run
: RunConfig
<'_
>) {
132 run
.builder
.ensure($name { target: run.target }
);
135 fn run(self, builder
: &Builder
<'_
>) {
136 let compiler
= builder
.compiler(0, builder
.config
.build
);
137 let target
= self.target
;
139 builder
.ensure(Rustc { target }
);
141 let cargo
= prepare_tool_cargo(
146 cargo_subcommand(builder
.kind
),
153 "Checking {} artifacts ({} -> {})",
154 stringify
!($name
).to_lowercase(),
162 &stamp(builder
, compiler
, target
),
167 let libdir
= builder
.sysroot_libdir(compiler
, target
);
168 let hostdir
= builder
.sysroot_libdir(compiler
, compiler
.host
);
169 add_to_sysroot(&builder
, &libdir
, &hostdir
, &stamp(builder
, compiler
, target
));
171 /// Cargo's output path in a given stage, compiled by a particular
172 /// compiler for the specified target.
174 builder
: &Builder
<'_
>,
176 target
: Interned
<String
>,
179 .cargo_out(compiler
, Mode
::ToolRustc
, target
)
180 .join(format
!(".{}-check.stamp", stringify
!($name
).to_lowercase()))
187 tool_check_step
!(Rustdoc
, "src/tools/rustdoc");
188 tool_check_step
!(Clippy
, "src/tools/clippy");
190 /// Cargo's output path for the standard library in a given stage, compiled
191 /// by a particular compiler for the specified target.
192 fn libstd_stamp(builder
: &Builder
<'_
>, compiler
: Compiler
, target
: Interned
<String
>) -> PathBuf
{
193 builder
.cargo_out(compiler
, Mode
::Std
, target
).join(".libstd-check.stamp")
196 /// Cargo's output path for librustc in a given stage, compiled by a particular
197 /// compiler for the specified target.
198 fn librustc_stamp(builder
: &Builder
<'_
>, compiler
: Compiler
, target
: Interned
<String
>) -> PathBuf
{
199 builder
.cargo_out(compiler
, Mode
::Rustc
, target
).join(".librustc-check.stamp")