1 //! Implementation of the test-related targets of the build system.
3 //! This file implements the various regression test suites that we execute on
7 use std::ffi::OsString;
11 use std::path::{Path, PathBuf};
12 use std::process::Command;
14 use build_helper::{self, output, t};
16 use crate::builder::{Builder, Compiler, Kind, RunConfig, ShouldRun, Step};
17 use crate::cache::{Interned, INTERNER};
20 use crate::flags::Subcommand;
22 use crate::tool::{self, Tool, SourceType};
23 use crate::toolstate::ToolState;
24 use crate::util::{self, dylib_path, dylib_path_var};
25 use crate::Crate as CargoCrate;
26 use crate::{DocTests, Mode, GitRepo, envify};
28 const ADB_TEST_DIR: &str = "/data/tmp/work";
30 /// The two modes of the test runner; tests or benchmarks.
31 #[derive(Debug, PartialEq, Eq, Hash, Copy, Clone, PartialOrd, Ord)]
35 /// Run `cargo bench`.
39 impl From<Kind> for TestKind {
40 fn from(kind: Kind) -> Self {
42 Kind::Test => TestKind::Test,
43 Kind::Bench => TestKind::Bench,
44 _ => panic!("unexpected kind in crate: {:?}", kind),
50 // Return the cargo subcommand for this test kind
51 fn subcommand(self) -> &'static str {
53 TestKind::Test => "test",
54 TestKind::Bench => "bench",
59 impl fmt::Display for TestKind {
60 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
61 f.write_str(match *self {
62 TestKind::Test => "Testing",
63 TestKind::Bench => "Benchmarking",
68 fn try_run(builder: &Builder<'_>, cmd: &mut Command) -> bool {
69 if !builder.fail_fast {
70 if !builder.try_run(cmd) {
71 let mut failures = builder.delayed_failures.borrow_mut();
72 failures.push(format!("{:?}", cmd));
81 fn try_run_quiet(builder: &Builder<'_>, cmd: &mut Command) -> bool {
82 if !builder.fail_fast {
83 if !builder.try_run_quiet(cmd) {
84 let mut failures = builder.delayed_failures.borrow_mut();
85 failures.push(format!("{:?}", cmd));
89 builder.run_quiet(cmd);
94 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
95 pub struct Linkcheck {
96 host: Interned<String>,
99 impl Step for Linkcheck {
101 const ONLY_HOSTS: bool = true;
102 const DEFAULT: bool = true;
104 /// Runs the `linkchecker` tool as compiled in `stage` by the `host` compiler.
106 /// This tool in `src/tools` will verify the validity of all our links in the
107 /// documentation to ensure we don't have a bunch of dead ones.
108 fn run(self, builder: &Builder<'_>) {
109 let host = self.host;
111 builder.info(&format!("Linkcheck ({})", host));
113 builder.default_doc(None);
115 let _time = util::timeit(&builder);
119 .tool_cmd(Tool::Linkchecker)
120 .arg(builder.out.join(host).join("doc")),
124 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
125 let builder = run.builder;
126 run.path("src/tools/linkchecker")
127 .default_condition(builder.config.docs)
130 fn make_run(run: RunConfig<'_>) {
131 run.builder.ensure(Linkcheck { host: run.target });
135 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
136 pub struct Cargotest {
138 host: Interned<String>,
141 impl Step for Cargotest {
143 const ONLY_HOSTS: bool = true;
145 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
146 run.path("src/tools/cargotest")
149 fn make_run(run: RunConfig<'_>) {
150 run.builder.ensure(Cargotest {
151 stage: run.builder.top_stage,
156 /// Runs the `cargotest` tool as compiled in `stage` by the `host` compiler.
158 /// This tool in `src/tools` will check out a few Rust projects and run `cargo
159 /// test` to ensure that we don't regress the test suites there.
160 fn run(self, builder: &Builder<'_>) {
161 let compiler = builder.compiler(self.stage, self.host);
162 builder.ensure(compile::Rustc {
164 target: compiler.host,
167 // Note that this is a short, cryptic, and not scoped directory name. This
168 // is currently to minimize the length of path on Windows where we otherwise
169 // quickly run into path name limit constraints.
170 let out_dir = builder.out.join("ct");
171 t!(fs::create_dir_all(&out_dir));
173 let _time = util::timeit(&builder);
174 let mut cmd = builder.tool_cmd(Tool::CargoTest);
177 cmd.arg(&builder.initial_cargo)
179 .env("RUSTC", builder.rustc(compiler))
180 .env("RUSTDOC", builder.rustdoc(compiler)),
185 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
188 host: Interned<String>,
191 impl Step for Cargo {
193 const ONLY_HOSTS: bool = true;
195 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
196 run.path("src/tools/cargo")
199 fn make_run(run: RunConfig<'_>) {
200 run.builder.ensure(Cargo {
201 stage: run.builder.top_stage,
206 /// Runs `cargo test` for `cargo` packaged with Rust.
207 fn run(self, builder: &Builder<'_>) {
208 let compiler = builder.compiler(self.stage, self.host);
210 builder.ensure(tool::Cargo {
214 let mut cargo = tool::prepare_tool_cargo(builder,
220 SourceType::Submodule,
223 if !builder.fail_fast {
224 cargo.arg("--no-fail-fast");
227 // Don't run cross-compile tests, we may not have cross-compiled libstd libs
229 cargo.env("CFG_DISABLE_CROSS_TESTS", "1");
230 // Disable a test that has issues with mingw.
231 cargo.env("CARGO_TEST_DISABLE_GIT_CLI", "1");
232 // Forcibly disable tests using nightly features since any changes to
233 // those features won't be able to land.
234 cargo.env("CARGO_TEST_DISABLE_NIGHTLY", "1");
236 cargo.env("PATH", &path_for_cargo(builder, compiler));
238 try_run(builder, &mut cargo.into());
242 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
245 host: Interned<String>,
250 const ONLY_HOSTS: bool = true;
252 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
253 run.path("src/tools/rls")
256 fn make_run(run: RunConfig<'_>) {
257 run.builder.ensure(Rls {
258 stage: run.builder.top_stage,
263 /// Runs `cargo test` for the rls.
264 fn run(self, builder: &Builder<'_>) {
265 let stage = self.stage;
266 let host = self.host;
267 let compiler = builder.compiler(stage, host);
269 let build_result = builder.ensure(tool::Rls {
272 extra_features: Vec::new(),
274 if build_result.is_none() {
275 eprintln!("failed to test rls: could not build");
279 let mut cargo = tool::prepare_tool_cargo(builder,
285 SourceType::Submodule,
288 builder.add_rustc_lib_path(compiler, &mut cargo);
290 .args(builder.config.cmd.test_args());
292 if try_run(builder, &mut cargo.into()) {
293 builder.save_toolstate("rls", ToolState::TestPass);
298 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
301 host: Interned<String>,
304 impl Step for Rustfmt {
306 const ONLY_HOSTS: bool = true;
308 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
309 run.path("src/tools/rustfmt")
312 fn make_run(run: RunConfig<'_>) {
313 run.builder.ensure(Rustfmt {
314 stage: run.builder.top_stage,
319 /// Runs `cargo test` for rustfmt.
320 fn run(self, builder: &Builder<'_>) {
321 let stage = self.stage;
322 let host = self.host;
323 let compiler = builder.compiler(stage, host);
325 let build_result = builder.ensure(tool::Rustfmt {
328 extra_features: Vec::new(),
330 if build_result.is_none() {
331 eprintln!("failed to test rustfmt: could not build");
335 let mut cargo = tool::prepare_tool_cargo(builder,
341 SourceType::Submodule,
344 let dir = testdir(builder, compiler.host);
345 t!(fs::create_dir_all(&dir));
346 cargo.env("RUSTFMT_TEST_DIR", dir);
348 builder.add_rustc_lib_path(compiler, &mut cargo);
350 if try_run(builder, &mut cargo.into()) {
351 builder.save_toolstate("rustfmt", ToolState::TestPass);
356 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
359 host: Interned<String>,
364 const ONLY_HOSTS: bool = true;
366 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
367 run.path("src/tools/miri")
370 fn make_run(run: RunConfig<'_>) {
371 run.builder.ensure(Miri {
372 stage: run.builder.top_stage,
377 /// Runs `cargo test` for miri.
378 fn run(self, builder: &Builder<'_>) {
379 let stage = self.stage;
380 let host = self.host;
381 let compiler = builder.compiler(stage, host);
383 let miri = builder.ensure(tool::Miri {
386 extra_features: Vec::new(),
388 if let Some(miri) = miri {
389 let mut cargo = builder.cargo(compiler, Mode::ToolRustc, host, "install");
391 // Configure `cargo install` path. cargo adds a `bin/`.
392 cargo.env("CARGO_INSTALL_ROOT", &builder.out);
394 let mut cargo = Command::from(cargo);
395 if !try_run(builder, &mut cargo) {
399 // # Run `cargo miri setup`.
400 let mut cargo = tool::prepare_tool_cargo(
407 SourceType::Submodule,
417 // Tell `cargo miri` not to worry about the sysroot mismatch (we built with
418 // stage1 but run with stage2).
419 cargo.env("MIRI_SKIP_SYSROOT_CHECK", "1");
420 // Tell `cargo miri setup` where to find the sources.
421 cargo.env("XARGO_RUST_SRC", builder.src.join("src"));
423 cargo.env("RUST_BACKTRACE", "1");
424 // Let cargo-miri know where xargo ended up.
425 cargo.env("XARGO", builder.out.join("bin").join("xargo"));
427 let mut cargo = Command::from(cargo);
428 if !try_run(builder, &mut cargo) {
432 // # Determine where Miri put its sysroot.
433 // To this end, we run `cargo miri setup --env` and capture the output.
434 // (We do this separately from the above so that when the setup actually
435 // happens we get some output.)
436 // We re-use the `cargo` from above.
437 cargo.arg("--print-sysroot");
439 // FIXME: Is there a way in which we can re-use the usual `run` helpers?
440 let miri_sysroot = if builder.config.dry_run {
443 builder.verbose(&format!("running: {:?}", cargo));
444 let out = cargo.output()
445 .expect("We already ran `cargo miri setup` before and that worked");
446 assert!(out.status.success(), "`cargo miri setup` returned with non-0 exit code");
447 // Output is "<sysroot>\n".
448 let stdout = String::from_utf8(out.stdout)
449 .expect("`cargo miri setup` stdout is not valid UTF-8");
450 let sysroot = stdout.trim_end();
451 builder.verbose(&format!("`cargo miri setup --print-sysroot` said: {:?}", sysroot));
455 // # Run `cargo test`.
456 let mut cargo = tool::prepare_tool_cargo(
463 SourceType::Submodule,
467 // miri tests need to know about the stage sysroot
468 cargo.env("MIRI_SYSROOT", miri_sysroot);
469 cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
470 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
471 cargo.env("MIRI_PATH", miri);
473 builder.add_rustc_lib_path(compiler, &mut cargo);
475 if !try_run(builder, &mut cargo.into()) {
480 builder.save_toolstate("miri", ToolState::TestPass);
482 eprintln!("failed to test miri: could not build");
487 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
488 pub struct CompiletestTest {
489 host: Interned<String>,
492 impl Step for CompiletestTest {
495 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
496 run.path("src/tools/compiletest")
499 fn make_run(run: RunConfig<'_>) {
500 run.builder.ensure(CompiletestTest {
505 /// Runs `cargo test` for compiletest.
506 fn run(self, builder: &Builder<'_>) {
507 let host = self.host;
508 let compiler = builder.compiler(0, host);
510 let cargo = tool::prepare_tool_cargo(builder,
515 "src/tools/compiletest",
519 try_run(builder, &mut cargo.into());
523 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
526 host: Interned<String>,
529 impl Step for Clippy {
531 const ONLY_HOSTS: bool = true;
532 const DEFAULT: bool = false;
534 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
535 run.path("src/tools/clippy")
538 fn make_run(run: RunConfig<'_>) {
539 run.builder.ensure(Clippy {
540 stage: run.builder.top_stage,
545 /// Runs `cargo test` for clippy.
546 fn run(self, builder: &Builder<'_>) {
547 let stage = self.stage;
548 let host = self.host;
549 let compiler = builder.compiler(stage, host);
551 let clippy = builder.ensure(tool::Clippy {
554 extra_features: Vec::new(),
556 if let Some(clippy) = clippy {
557 let mut cargo = tool::prepare_tool_cargo(builder,
563 SourceType::Submodule,
566 // clippy tests need to know about the stage sysroot
567 cargo.env("SYSROOT", builder.sysroot(compiler));
568 cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
569 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
570 let host_libs = builder
571 .stage_out(compiler, Mode::ToolRustc)
572 .join(builder.cargo_dir());
573 let target_libs = builder
574 .stage_out(compiler, Mode::ToolRustc)
576 .join(builder.cargo_dir());
577 cargo.env("HOST_LIBS", host_libs);
578 cargo.env("TARGET_LIBS", target_libs);
579 // clippy tests need to find the driver
580 cargo.env("CLIPPY_DRIVER_PATH", clippy);
582 builder.add_rustc_lib_path(compiler, &mut cargo);
584 if try_run(builder, &mut cargo.into()) {
585 builder.save_toolstate("clippy-driver", ToolState::TestPass);
588 eprintln!("failed to test clippy: could not build");
593 fn path_for_cargo(builder: &Builder<'_>, compiler: Compiler) -> OsString {
594 // Configure PATH to find the right rustc. NB. we have to use PATH
595 // and not RUSTC because the Cargo test suite has tests that will
596 // fail if rustc is not spelled `rustc`.
597 let path = builder.sysroot(compiler).join("bin");
598 let old_path = env::var_os("PATH").unwrap_or_default();
599 env::join_paths(iter::once(path).chain(env::split_paths(&old_path))).expect("")
602 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
603 pub struct RustdocTheme {
604 pub compiler: Compiler,
607 impl Step for RustdocTheme {
609 const DEFAULT: bool = true;
610 const ONLY_HOSTS: bool = true;
612 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
613 run.path("src/tools/rustdoc-themes")
616 fn make_run(run: RunConfig<'_>) {
617 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
619 run.builder.ensure(RustdocTheme { compiler });
622 fn run(self, builder: &Builder<'_>) {
623 let rustdoc = builder.out.join("bootstrap/debug/rustdoc");
624 let mut cmd = builder.tool_cmd(Tool::RustdocTheme);
625 cmd.arg(rustdoc.to_str().unwrap())
629 .join("src/librustdoc/html/static/themes")
633 .env("RUSTC_STAGE", self.compiler.stage.to_string())
634 .env("RUSTC_SYSROOT", builder.sysroot(self.compiler))
637 builder.sysroot_libdir(self.compiler, self.compiler.host),
639 .env("CFG_RELEASE_CHANNEL", &builder.config.channel)
640 .env("RUSTDOC_REAL", builder.rustdoc(self.compiler))
641 .env("RUSTDOC_CRATE_VERSION", builder.rust_version())
642 .env("RUSTC_BOOTSTRAP", "1");
643 if let Some(linker) = builder.linker(self.compiler.host) {
644 cmd.env("RUSTC_TARGET_LINKER", linker);
646 try_run(builder, &mut cmd);
650 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
651 pub struct RustdocJSStd {
652 pub host: Interned<String>,
653 pub target: Interned<String>,
656 impl Step for RustdocJSStd {
658 const DEFAULT: bool = true;
659 const ONLY_HOSTS: bool = true;
661 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
662 run.path("src/test/rustdoc-js-std")
665 fn make_run(run: RunConfig<'_>) {
666 run.builder.ensure(RustdocJSStd {
672 fn run(self, builder: &Builder<'_>) {
673 if let Some(ref nodejs) = builder.config.nodejs {
674 let mut command = Command::new(nodejs);
675 command.args(&["src/tools/rustdoc-js-std/tester.js", &*self.host]);
676 builder.ensure(crate::doc::Std {
678 stage: builder.top_stage,
680 builder.run(&mut command);
683 "No nodejs found, skipping \"src/test/rustdoc-js-std\" tests"
689 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
690 pub struct RustdocJSNotStd {
691 pub host: Interned<String>,
692 pub target: Interned<String>,
693 pub compiler: Compiler,
696 impl Step for RustdocJSNotStd {
698 const DEFAULT: bool = true;
699 const ONLY_HOSTS: bool = true;
701 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
702 run.path("src/test/rustdoc-js")
705 fn make_run(run: RunConfig<'_>) {
706 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
707 run.builder.ensure(RustdocJSNotStd {
714 fn run(self, builder: &Builder<'_>) {
715 if builder.config.nodejs.is_some() {
716 builder.ensure(Compiletest {
717 compiler: self.compiler,
726 "No nodejs found, skipping \"src/test/rustdoc-js\" tests"
732 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
733 pub struct RustdocUi {
734 pub host: Interned<String>,
735 pub target: Interned<String>,
736 pub compiler: Compiler,
739 impl Step for RustdocUi {
741 const DEFAULT: bool = true;
742 const ONLY_HOSTS: bool = true;
744 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
745 run.path("src/test/rustdoc-ui")
748 fn make_run(run: RunConfig<'_>) {
749 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
750 run.builder.ensure(RustdocUi {
757 fn run(self, builder: &Builder<'_>) {
758 builder.ensure(Compiletest {
759 compiler: self.compiler,
763 path: Some("src/test/rustdoc-ui"),
769 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
774 const DEFAULT: bool = true;
775 const ONLY_HOSTS: bool = true;
777 /// Runs the `tidy` tool.
779 /// This tool in `src/tools` checks up on various bits and pieces of style and
780 /// otherwise just implements a few lint-like checks that are specific to the
782 fn run(self, builder: &Builder<'_>) {
783 let mut cmd = builder.tool_cmd(Tool::Tidy);
784 cmd.arg(builder.src.join("src"));
785 cmd.arg(&builder.initial_cargo);
786 if !builder.config.vendor {
787 cmd.arg("--no-vendor");
789 if builder.is_verbose() {
790 cmd.arg("--verbose");
793 builder.info("tidy check");
794 try_run(builder, &mut cmd);
797 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
798 run.path("src/tools/tidy")
801 fn make_run(run: RunConfig<'_>) {
802 run.builder.ensure(Tidy);
806 fn testdir(builder: &Builder<'_>, host: Interned<String>) -> PathBuf {
807 builder.out.join(host).join("test")
810 macro_rules! default_test {
811 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
812 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: false });
816 macro_rules! default_test_with_compare_mode {
817 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr,
818 compare_mode: $compare_mode:expr }) => {
819 test_with_compare_mode!($name { path: $path, mode: $mode, suite: $suite, default: true,
820 host: false, compare_mode: $compare_mode });
824 macro_rules! host_test {
825 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
826 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: true });
831 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
832 host: $host:expr }) => {
833 test_definitions!($name { path: $path, mode: $mode, suite: $suite, default: $default,
834 host: $host, compare_mode: None });
838 macro_rules! test_with_compare_mode {
839 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
840 host: $host:expr, compare_mode: $compare_mode:expr }) => {
841 test_definitions!($name { path: $path, mode: $mode, suite: $suite, default: $default,
842 host: $host, compare_mode: Some($compare_mode) });
846 macro_rules! test_definitions {
851 default: $default:expr,
853 compare_mode: $compare_mode:expr
855 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
857 pub compiler: Compiler,
858 pub target: Interned<String>,
861 impl Step for $name {
863 const DEFAULT: bool = $default;
864 const ONLY_HOSTS: bool = $host;
866 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
867 run.suite_path($path)
870 fn make_run(run: RunConfig<'_>) {
871 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
873 run.builder.ensure($name {
879 fn run(self, builder: &Builder<'_>) {
880 builder.ensure(Compiletest {
881 compiler: self.compiler,
886 compare_mode: $compare_mode,
893 default_test_with_compare_mode!(Ui {
900 default_test!(CompileFail {
901 path: "src/test/compile-fail",
902 mode: "compile-fail",
903 suite: "compile-fail"
906 default_test!(RunFail {
907 path: "src/test/run-fail",
912 default_test!(RunPassValgrind {
913 path: "src/test/run-pass-valgrind",
914 mode: "run-pass-valgrind",
915 suite: "run-pass-valgrind"
918 default_test!(MirOpt {
919 path: "src/test/mir-opt",
924 default_test!(Codegen {
925 path: "src/test/codegen",
930 default_test!(CodegenUnits {
931 path: "src/test/codegen-units",
932 mode: "codegen-units",
933 suite: "codegen-units"
936 default_test!(Incremental {
937 path: "src/test/incremental",
942 default_test!(Debuginfo {
943 path: "src/test/debuginfo",
948 host_test!(UiFullDeps {
949 path: "src/test/ui-fulldeps",
955 path: "src/test/rustdoc",
961 path: "src/test/pretty",
965 test!(RunFailPretty {
966 path: "src/test/run-fail/pretty",
972 test!(RunPassValgrindPretty {
973 path: "src/test/run-pass-valgrind/pretty",
975 suite: "run-pass-valgrind",
980 default_test!(RunMake {
981 path: "src/test/run-make",
986 host_test!(RunMakeFullDeps {
987 path: "src/test/run-make-fulldeps",
989 suite: "run-make-fulldeps"
992 default_test!(Assembly {
993 path: "src/test/assembly",
998 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1001 target: Interned<String>,
1003 suite: &'static str,
1004 path: Option<&'static str>,
1005 compare_mode: Option<&'static str>,
1008 impl Step for Compiletest {
1011 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1015 /// Executes the `compiletest` tool to run a suite of tests.
1017 /// Compiles all tests with `compiler` for `target` with the specified
1018 /// compiletest `mode` and `suite` arguments. For example `mode` can be
1019 /// "run-pass" or `suite` can be something like `debuginfo`.
1020 fn run(self, builder: &Builder<'_>) {
1021 let compiler = self.compiler;
1022 let target = self.target;
1023 let mode = self.mode;
1024 let suite = self.suite;
1026 // Path for test suite
1027 let suite_path = self.path.unwrap_or("");
1029 // Skip codegen tests if they aren't enabled in configuration.
1030 if !builder.config.codegen_tests && suite == "codegen" {
1034 if suite == "debuginfo" {
1035 let msvc = builder.config.build.contains("msvc");
1036 if mode == "debuginfo" {
1037 return builder.ensure(Compiletest {
1038 mode: if msvc { "debuginfo-cdb" } else { "debuginfo-gdb+lldb" },
1043 builder.ensure(dist::DebuggerScripts {
1044 sysroot: builder.sysroot(compiler),
1049 if suite.ends_with("fulldeps") {
1050 builder.ensure(compile::Rustc { compiler, target });
1053 builder.ensure(compile::Std { compiler, target });
1054 // ensure that `libproc_macro` is available on the host.
1055 builder.ensure(compile::Std { compiler, target: compiler.host });
1057 // Also provide `rust_test_helpers` for the host.
1058 builder.ensure(native::TestHelpers { target: compiler.host });
1060 // As well as the target, except for plain wasm32, which can't build it
1061 if !target.contains("wasm32") || target.contains("emscripten") {
1062 builder.ensure(native::TestHelpers { target });
1065 builder.ensure(RemoteCopyLibs { compiler, target });
1067 let mut cmd = builder.tool_cmd(Tool::Compiletest);
1069 // compiletest currently has... a lot of arguments, so let's just pass all
1072 cmd.arg("--compile-lib-path")
1073 .arg(builder.rustc_libdir(compiler));
1074 cmd.arg("--run-lib-path")
1075 .arg(builder.sysroot_libdir(compiler, target));
1076 cmd.arg("--rustc-path").arg(builder.rustc(compiler));
1078 let is_rustdoc = suite.ends_with("rustdoc-ui") || suite.ends_with("rustdoc-js");
1080 // Avoid depending on rustdoc when we don't need it.
1081 if mode == "rustdoc"
1082 || (mode == "run-make" && suite.ends_with("fulldeps"))
1083 || (mode == "ui" && is_rustdoc)
1084 || mode == "js-doc-test"
1086 cmd.arg("--rustdoc-path")
1087 .arg(builder.rustdoc(compiler));
1090 cmd.arg("--src-base")
1091 .arg(builder.src.join("src/test").join(suite));
1092 cmd.arg("--build-base")
1093 .arg(testdir(builder, compiler.host).join(suite));
1094 cmd.arg("--stage-id")
1095 .arg(format!("stage{}-{}", compiler.stage, target));
1096 cmd.arg("--mode").arg(mode);
1097 cmd.arg("--target").arg(target);
1098 cmd.arg("--host").arg(&*compiler.host);
1099 cmd.arg("--llvm-filecheck")
1100 .arg(builder.llvm_filecheck(builder.config.build));
1102 if builder.config.cmd.bless() {
1106 let compare_mode = builder.config.cmd.compare_mode().or_else(|| {
1107 if builder.config.test_compare_mode {
1114 if let Some(ref pass) = builder.config.cmd.pass() {
1119 if let Some(ref nodejs) = builder.config.nodejs {
1120 cmd.arg("--nodejs").arg(nodejs);
1123 let mut flags = if is_rustdoc {
1126 vec!["-Crpath".to_string()]
1129 if builder.config.rust_optimize_tests {
1130 flags.push("-O".to_string());
1133 flags.push(format!("-Cdebuginfo={}", builder.config.rust_debuginfo_level_tests));
1134 flags.push("-Zunstable-options".to_string());
1135 flags.push(builder.config.cmd.rustc_args().join(" "));
1137 if let Some(linker) = builder.linker(target) {
1138 cmd.arg("--linker").arg(linker);
1141 let mut hostflags = flags.clone();
1142 hostflags.push(format!(
1144 builder.test_helpers_out(compiler.host).display()
1146 cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
1148 let mut targetflags = flags;
1149 targetflags.push(format!(
1151 builder.test_helpers_out(target).display()
1153 cmd.arg("--target-rustcflags").arg(targetflags.join(" "));
1155 cmd.arg("--docck-python").arg(builder.python());
1157 if builder.config.build.ends_with("apple-darwin") {
1158 // Force /usr/bin/python on macOS for LLDB tests because we're loading the
1159 // LLDB plugin's compiled module which only works with the system python
1160 // (namely not Homebrew-installed python)
1161 cmd.arg("--lldb-python").arg("/usr/bin/python");
1163 cmd.arg("--lldb-python").arg(builder.python());
1166 if let Some(ref gdb) = builder.config.gdb {
1167 cmd.arg("--gdb").arg(gdb);
1170 let run = |cmd: &mut Command| {
1171 cmd.output().map(|output| {
1172 String::from_utf8_lossy(&output.stdout)
1173 .lines().next().unwrap_or_else(|| {
1174 panic!("{:?} failed {:?}", cmd, output)
1178 let lldb_exe = if builder.config.lldb_enabled {
1179 // Test against the lldb that was just built.
1180 builder.llvm_out(target).join("bin").join("lldb")
1182 PathBuf::from("lldb")
1184 let lldb_version = Command::new(&lldb_exe)
1187 .map(|output| { String::from_utf8_lossy(&output.stdout).to_string() })
1189 if let Some(ref vers) = lldb_version {
1190 cmd.arg("--lldb-version").arg(vers);
1191 let lldb_python_dir = run(Command::new(&lldb_exe).arg("-P")).ok();
1192 if let Some(ref dir) = lldb_python_dir {
1193 cmd.arg("--lldb-python-dir").arg(dir);
1197 if util::forcing_clang_based_tests() {
1198 let clang_exe = builder.llvm_out(target).join("bin").join("clang");
1199 cmd.arg("--run-clang-based-tests-with").arg(clang_exe);
1202 // Get paths from cmd args
1203 let paths = match &builder.config.cmd {
1204 Subcommand::Test { ref paths, .. } => &paths[..],
1208 // Get test-args by striping suite path
1209 let mut test_args: Vec<&str> = paths
1212 match p.strip_prefix(".") {
1217 .filter(|p| p.starts_with(suite_path) && (p.is_dir() || p.is_file()))
1219 // Since test suite paths are themselves directories, if we don't
1220 // specify a directory or file, we'll get an empty string here
1221 // (the result of the test suite directory without its suite prefix).
1222 // Therefore, we need to filter these out, as only the first --test-args
1223 // flag is respected, so providing an empty --test-args conflicts with
1224 // any following it.
1225 match p.strip_prefix(suite_path).ok().and_then(|p| p.to_str()) {
1226 Some(s) if s != "" => Some(s),
1232 test_args.append(&mut builder.config.cmd.test_args());
1234 cmd.args(&test_args);
1236 if builder.is_verbose() {
1237 cmd.arg("--verbose");
1240 if !builder.config.verbose_tests {
1244 if builder.config.llvm_enabled() {
1245 let llvm_config = builder.ensure(native::Llvm {
1246 target: builder.config.build,
1248 if !builder.config.dry_run {
1249 let llvm_version = output(Command::new(&llvm_config).arg("--version"));
1250 cmd.arg("--llvm-version").arg(llvm_version);
1252 if !builder.is_rust_llvm(target) {
1253 cmd.arg("--system-llvm");
1256 // Only pass correct values for these flags for the `run-make` suite as it
1257 // requires that a C++ compiler was configured which isn't always the case.
1258 if !builder.config.dry_run && suite == "run-make-fulldeps" {
1259 let llvm_components = output(Command::new(&llvm_config).arg("--components"));
1260 let llvm_cxxflags = output(Command::new(&llvm_config).arg("--cxxflags"));
1262 .arg(builder.cc(target))
1264 .arg(builder.cxx(target).unwrap())
1266 .arg(builder.cflags(target, GitRepo::Rustc).join(" "))
1267 .arg("--llvm-components")
1268 .arg(llvm_components.trim())
1269 .arg("--llvm-cxxflags")
1270 .arg(llvm_cxxflags.trim());
1271 if let Some(ar) = builder.ar(target) {
1272 cmd.arg("--ar").arg(ar);
1275 // The llvm/bin directory contains many useful cross-platform
1276 // tools. Pass the path to run-make tests so they can use them.
1277 let llvm_bin_path = llvm_config.parent()
1278 .expect("Expected llvm-config to be contained in directory");
1279 assert!(llvm_bin_path.is_dir());
1280 cmd.arg("--llvm-bin-dir").arg(llvm_bin_path);
1282 // If LLD is available, add it to the PATH
1283 if builder.config.lld_enabled {
1284 let lld_install_root = builder.ensure(native::Lld {
1285 target: builder.config.build,
1288 let lld_bin_path = lld_install_root.join("bin");
1290 let old_path = env::var_os("PATH").unwrap_or_default();
1291 let new_path = env::join_paths(std::iter::once(lld_bin_path)
1292 .chain(env::split_paths(&old_path)))
1293 .expect("Could not add LLD bin path to PATH");
1294 cmd.env("PATH", new_path);
1299 if suite != "run-make-fulldeps" {
1306 .arg("--llvm-components")
1308 .arg("--llvm-cxxflags")
1312 if builder.remote_tested(target) {
1313 cmd.arg("--remote-test-client")
1314 .arg(builder.tool_exe(Tool::RemoteTestClient));
1317 // Running a C compiler on MSVC requires a few env vars to be set, to be
1318 // sure to set them here.
1320 // Note that if we encounter `PATH` we make sure to append to our own `PATH`
1321 // rather than stomp over it.
1322 if target.contains("msvc") {
1323 for &(ref k, ref v) in builder.cc[&target].env() {
1329 cmd.env("RUSTC_BOOTSTRAP", "1");
1330 builder.add_rust_test_threads(&mut cmd);
1332 if builder.config.sanitizers {
1333 cmd.env("RUSTC_SANITIZER_SUPPORT", "1");
1336 if builder.config.profiler {
1337 cmd.env("RUSTC_PROFILER_SUPPORT", "1");
1340 let tmp = builder.out.join("tmp");
1341 std::fs::create_dir_all(&tmp).unwrap();
1342 cmd.env("RUST_TEST_TMPDIR", tmp);
1345 cmd.arg("--adb-path").arg("adb");
1346 cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
1347 if target.contains("android") {
1348 // Assume that cc for this target comes from the android sysroot
1349 cmd.arg("--android-cross-path")
1350 .arg(builder.cc(target).parent().unwrap().parent().unwrap());
1352 cmd.arg("--android-cross-path").arg("");
1355 if builder.config.cmd.rustfix_coverage() {
1356 cmd.arg("--rustfix-coverage");
1359 builder.ci_env.force_coloring_in_ci(&mut cmd);
1361 builder.info(&format!(
1362 "Check compiletest suite={} mode={} ({} -> {})",
1363 suite, mode, &compiler.host, target
1365 let _time = util::timeit(&builder);
1366 try_run(builder, &mut cmd);
1368 if let Some(compare_mode) = compare_mode {
1369 cmd.arg("--compare-mode").arg(compare_mode);
1370 builder.info(&format!(
1371 "Check compiletest suite={} mode={} compare_mode={} ({} -> {})",
1372 suite, mode, compare_mode, &compiler.host, target
1374 let _time = util::timeit(&builder);
1375 try_run(builder, &mut cmd);
1380 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1388 impl Step for DocTest {
1390 const ONLY_HOSTS: bool = true;
1392 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1396 /// Runs `rustdoc --test` for all documentation in `src/doc`.
1398 /// This will run all tests in our markdown documentation (e.g., the book)
1399 /// located in `src/doc`. The `rustdoc` that's run is the one that sits next to
1401 fn run(self, builder: &Builder<'_>) {
1402 let compiler = self.compiler;
1404 builder.ensure(compile::Std {
1406 target: compiler.host,
1409 // Do a breadth-first traversal of the `src/doc` directory and just run
1410 // tests for all files that end in `*.md`
1411 let mut stack = vec![builder.src.join(self.path)];
1412 let _time = util::timeit(&builder);
1414 let mut files = Vec::new();
1415 while let Some(p) = stack.pop() {
1417 stack.extend(t!(p.read_dir()).map(|p| t!(p).path()));
1421 if p.extension().and_then(|s| s.to_str()) != Some("md") {
1425 // The nostarch directory in the book is for no starch, and so isn't
1426 // guaranteed to builder. We don't care if it doesn't build, so skip it.
1427 if p.to_str().map_or(false, |p| p.contains("nostarch")) {
1436 let mut toolstate = ToolState::TestPass;
1438 if !markdown_test(builder, compiler, &file) {
1439 toolstate = ToolState::TestFail;
1442 if self.is_ext_doc {
1443 builder.save_toolstate(self.name, toolstate);
1448 macro_rules! test_book {
1449 ($($name:ident, $path:expr, $book_name:expr, default=$default:expr;)+) => {
1451 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1456 impl Step for $name {
1458 const DEFAULT: bool = $default;
1459 const ONLY_HOSTS: bool = true;
1461 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1465 fn make_run(run: RunConfig<'_>) {
1466 run.builder.ensure($name {
1467 compiler: run.builder.compiler(run.builder.top_stage, run.host),
1471 fn run(self, builder: &Builder<'_>) {
1472 builder.ensure(DocTest {
1473 compiler: self.compiler,
1476 is_ext_doc: !$default,
1485 Nomicon, "src/doc/nomicon", "nomicon", default=false;
1486 Reference, "src/doc/reference", "reference", default=false;
1487 RustdocBook, "src/doc/rustdoc", "rustdoc", default=true;
1488 RustcBook, "src/doc/rustc", "rustc", default=true;
1489 RustByExample, "src/doc/rust-by-example", "rust-by-example", default=false;
1490 EmbeddedBook, "src/doc/embedded-book", "embedded-book", default=false;
1491 TheBook, "src/doc/book", "book", default=false;
1492 UnstableBook, "src/doc/unstable-book", "unstable-book", default=true;
1493 EditionGuide, "src/doc/edition-guide", "edition-guide", default=false;
1496 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1497 pub struct ErrorIndex {
1501 impl Step for ErrorIndex {
1503 const DEFAULT: bool = true;
1504 const ONLY_HOSTS: bool = true;
1506 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1507 run.path("src/tools/error_index_generator")
1510 fn make_run(run: RunConfig<'_>) {
1511 run.builder.ensure(ErrorIndex {
1512 compiler: run.builder.compiler(run.builder.top_stage, run.host),
1516 /// Runs the error index generator tool to execute the tests located in the error
1519 /// The `error_index_generator` tool lives in `src/tools` and is used to
1520 /// generate a markdown file from the error indexes of the code base which is
1521 /// then passed to `rustdoc --test`.
1522 fn run(self, builder: &Builder<'_>) {
1523 let compiler = self.compiler;
1525 builder.ensure(compile::Std {
1527 target: compiler.host,
1530 let dir = testdir(builder, compiler.host);
1531 t!(fs::create_dir_all(&dir));
1532 let output = dir.join("error-index.md");
1534 let mut tool = tool::ErrorIndex::command(
1536 builder.compiler(compiler.stage, builder.config.build),
1538 tool.arg("markdown")
1540 .env("CFG_BUILD", &builder.config.build);
1542 builder.info(&format!("Testing error-index stage{}", compiler.stage));
1543 let _time = util::timeit(&builder);
1544 builder.run_quiet(&mut tool);
1545 markdown_test(builder, compiler, &output);
1549 fn markdown_test(builder: &Builder<'_>, compiler: Compiler, markdown: &Path) -> bool {
1550 match fs::read_to_string(markdown) {
1552 if !contents.contains("```") {
1559 builder.info(&format!("doc tests for: {}", markdown.display()));
1560 let mut cmd = builder.rustdoc_cmd(compiler);
1561 builder.add_rust_test_threads(&mut cmd);
1564 cmd.env("RUSTC_BOOTSTRAP", "1");
1566 let test_args = builder.config.cmd.test_args().join(" ");
1567 cmd.arg("--test-args").arg(test_args);
1569 if builder.config.verbose_tests {
1570 try_run(builder, &mut cmd)
1572 try_run_quiet(builder, &mut cmd)
1576 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1577 pub struct RustcGuide;
1579 impl Step for RustcGuide {
1581 const DEFAULT: bool = false;
1582 const ONLY_HOSTS: bool = true;
1584 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1585 run.path("src/doc/rustc-guide")
1588 fn make_run(run: RunConfig<'_>) {
1589 run.builder.ensure(RustcGuide);
1592 fn run(self, builder: &Builder<'_>) {
1593 let src = builder.src.join("src/doc/rustc-guide");
1594 let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
1595 let toolstate = if try_run(builder, rustbook_cmd.arg("linkcheck").arg(&src)) {
1600 builder.save_toolstate("rustc-guide", toolstate);
1604 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1605 pub struct CrateLibrustc {
1607 target: Interned<String>,
1608 test_kind: TestKind,
1609 krate: Interned<String>,
1612 impl Step for CrateLibrustc {
1614 const DEFAULT: bool = true;
1615 const ONLY_HOSTS: bool = true;
1617 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1618 run.krate("rustc-main")
1621 fn make_run(run: RunConfig<'_>) {
1622 let builder = run.builder;
1623 let compiler = builder.compiler(builder.top_stage, run.host);
1625 for krate in builder.in_tree_crates("rustc-main") {
1626 if run.path.ends_with(&krate.path) {
1627 let test_kind = builder.kind.into();
1629 builder.ensure(CrateLibrustc {
1639 fn run(self, builder: &Builder<'_>) {
1640 builder.ensure(Crate {
1641 compiler: self.compiler,
1642 target: self.target,
1644 test_kind: self.test_kind,
1650 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1651 pub struct CrateNotDefault {
1653 target: Interned<String>,
1654 test_kind: TestKind,
1655 krate: &'static str,
1658 impl Step for CrateNotDefault {
1661 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1662 run.path("src/librustc_asan")
1663 .path("src/librustc_lsan")
1664 .path("src/librustc_msan")
1665 .path("src/librustc_tsan")
1668 fn make_run(run: RunConfig<'_>) {
1669 let builder = run.builder;
1670 let compiler = builder.compiler(builder.top_stage, run.host);
1672 let test_kind = builder.kind.into();
1674 builder.ensure(CrateNotDefault {
1678 krate: match run.path {
1679 _ if run.path.ends_with("src/librustc_asan") => "rustc_asan",
1680 _ if run.path.ends_with("src/librustc_lsan") => "rustc_lsan",
1681 _ if run.path.ends_with("src/librustc_msan") => "rustc_msan",
1682 _ if run.path.ends_with("src/librustc_tsan") => "rustc_tsan",
1683 _ => panic!("unexpected path {:?}", run.path),
1688 fn run(self, builder: &Builder<'_>) {
1689 builder.ensure(Crate {
1690 compiler: self.compiler,
1691 target: self.target,
1693 test_kind: self.test_kind,
1694 krate: INTERNER.intern_str(self.krate),
1699 #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
1701 pub compiler: Compiler,
1702 pub target: Interned<String>,
1704 pub test_kind: TestKind,
1705 pub krate: Interned<String>,
1708 impl Step for Crate {
1710 const DEFAULT: bool = true;
1712 fn should_run(mut run: ShouldRun<'_>) -> ShouldRun<'_> {
1713 let builder = run.builder;
1714 for krate in run.builder.in_tree_crates("test") {
1715 if !(krate.name.starts_with("rustc_") && krate.name.ends_with("san")) {
1716 run = run.path(krate.local_path(&builder).to_str().unwrap());
1722 fn make_run(run: RunConfig<'_>) {
1723 let builder = run.builder;
1724 let compiler = builder.compiler(builder.top_stage, run.host);
1726 let make = |mode: Mode, krate: &CargoCrate| {
1727 let test_kind = builder.kind.into();
1729 builder.ensure(Crate {
1738 for krate in builder.in_tree_crates("test") {
1739 if run.path.ends_with(&krate.local_path(&builder)) {
1740 make(Mode::Std, krate);
1745 /// Runs all unit tests plus documentation tests for a given crate defined
1746 /// by a `Cargo.toml` (single manifest)
1748 /// This is what runs tests for crates like the standard library, compiler, etc.
1749 /// It essentially is the driver for running `cargo test`.
1751 /// Currently this runs all tests for a DAG by passing a bunch of `-p foo`
1752 /// arguments, and those arguments are discovered from `cargo metadata`.
1753 fn run(self, builder: &Builder<'_>) {
1754 let compiler = self.compiler;
1755 let target = self.target;
1756 let mode = self.mode;
1757 let test_kind = self.test_kind;
1758 let krate = self.krate;
1760 builder.ensure(compile::Std { compiler, target });
1761 builder.ensure(RemoteCopyLibs { compiler, target });
1763 // If we're not doing a full bootstrap but we're testing a stage2
1764 // version of libstd, then what we're actually testing is the libstd
1765 // produced in stage1. Reflect that here by updating the compiler that
1766 // we're working with automatically.
1767 let compiler = builder.compiler_for(compiler.stage, compiler.host, target);
1769 let mut cargo = builder.cargo(compiler, mode, target, test_kind.subcommand());
1772 compile::std_cargo(builder, &compiler, target, &mut cargo);
1775 builder.ensure(compile::Rustc { compiler, target });
1776 compile::rustc_cargo(builder, &mut cargo);
1778 _ => panic!("can only test libraries"),
1781 // Build up the base `cargo test` command.
1783 // Pass in some standard flags then iterate over the graph we've discovered
1784 // in `cargo metadata` with the maps above and figure out what `-p`
1785 // arguments need to get passed.
1786 if test_kind.subcommand() == "test" && !builder.fail_fast {
1787 cargo.arg("--no-fail-fast");
1789 match builder.doc_tests {
1794 cargo.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
1799 cargo.arg("-p").arg(krate);
1801 // The tests are going to run with the *target* libraries, so we need to
1802 // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
1804 // Note that to run the compiler we need to run with the *host* libraries,
1805 // but our wrapper scripts arrange for that to be the case anyway.
1806 let mut dylib_path = dylib_path();
1807 dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
1808 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
1811 cargo.args(&builder.config.cmd.test_args());
1813 if !builder.config.verbose_tests {
1814 cargo.arg("--quiet");
1817 if target.contains("emscripten") {
1819 format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
1824 .expect("nodejs not configured"),
1826 } else if target.starts_with("wasm32") {
1831 .expect("nodejs not configured");
1832 let runner = format!(
1833 "{} {}/src/etc/wasm32-shim.js",
1835 builder.src.display()
1837 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)), &runner);
1838 } else if builder.remote_tested(target) {
1840 format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
1841 format!("{} run", builder.tool_exe(Tool::RemoteTestClient).display()),
1845 builder.info(&format!(
1846 "{} {} stage{} ({} -> {})",
1847 test_kind, krate, compiler.stage, &compiler.host, target
1849 let _time = util::timeit(&builder);
1850 try_run(builder, &mut cargo.into());
1854 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1855 pub struct CrateRustdoc {
1856 host: Interned<String>,
1857 test_kind: TestKind,
1860 impl Step for CrateRustdoc {
1862 const DEFAULT: bool = true;
1863 const ONLY_HOSTS: bool = true;
1865 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1866 run.paths(&["src/librustdoc", "src/tools/rustdoc"])
1869 fn make_run(run: RunConfig<'_>) {
1870 let builder = run.builder;
1872 let test_kind = builder.kind.into();
1874 builder.ensure(CrateRustdoc {
1880 fn run(self, builder: &Builder<'_>) {
1881 let test_kind = self.test_kind;
1883 let compiler = builder.compiler(builder.top_stage, self.host);
1884 let target = compiler.host;
1885 builder.ensure(compile::Rustc { compiler, target });
1887 let mut cargo = tool::prepare_tool_cargo(builder,
1891 test_kind.subcommand(),
1892 "src/tools/rustdoc",
1895 if test_kind.subcommand() == "test" && !builder.fail_fast {
1896 cargo.arg("--no-fail-fast");
1899 cargo.arg("-p").arg("rustdoc:0.0.0");
1902 cargo.args(&builder.config.cmd.test_args());
1904 if self.host.contains("musl") {
1905 cargo.arg("'-Ctarget-feature=-crt-static'");
1908 if !builder.config.verbose_tests {
1909 cargo.arg("--quiet");
1912 builder.info(&format!(
1913 "{} rustdoc stage{} ({} -> {})",
1914 test_kind, compiler.stage, &compiler.host, target
1916 let _time = util::timeit(&builder);
1918 try_run(builder, &mut cargo.into());
1922 /// Some test suites are run inside emulators or on remote devices, and most
1923 /// of our test binaries are linked dynamically which means we need to ship
1924 /// the standard library and such to the emulator ahead of time. This step
1925 /// represents this and is a dependency of all test suites.
1927 /// Most of the time this is a no-op. For some steps such as shipping data to
1928 /// QEMU we have to build our own tools so we've got conditional dependencies
1929 /// on those programs as well. Note that the remote test client is built for
1930 /// the build target (us) and the server is built for the target.
1931 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1932 pub struct RemoteCopyLibs {
1934 target: Interned<String>,
1937 impl Step for RemoteCopyLibs {
1940 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1944 fn run(self, builder: &Builder<'_>) {
1945 let compiler = self.compiler;
1946 let target = self.target;
1947 if !builder.remote_tested(target) {
1951 builder.ensure(compile::Std { compiler, target });
1953 builder.info(&format!("REMOTE copy libs to emulator ({})", target));
1954 t!(fs::create_dir_all(builder.out.join("tmp")));
1956 let server = builder.ensure(tool::RemoteTestServer {
1957 compiler: compiler.with_stage(0),
1961 // Spawn the emulator and wait for it to come online
1962 let tool = builder.tool_exe(Tool::RemoteTestClient);
1963 let mut cmd = Command::new(&tool);
1964 cmd.arg("spawn-emulator")
1967 .arg(builder.out.join("tmp"));
1968 if let Some(rootfs) = builder.qemu_rootfs(target) {
1971 builder.run(&mut cmd);
1973 // Push all our dylibs to the emulator
1974 for f in t!(builder.sysroot_libdir(compiler, target).read_dir()) {
1976 let name = f.file_name().into_string().unwrap();
1977 if util::is_dylib(&name) {
1978 builder.run(Command::new(&tool).arg("push").arg(f.path()));
1984 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1985 pub struct Distcheck;
1987 impl Step for Distcheck {
1990 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1991 run.path("distcheck")
1994 fn make_run(run: RunConfig<'_>) {
1995 run.builder.ensure(Distcheck);
1998 /// Runs "distcheck", a 'make check' from a tarball
1999 fn run(self, builder: &Builder<'_>) {
2000 builder.info("Distcheck");
2001 let dir = builder.out.join("tmp").join("distcheck");
2002 let _ = fs::remove_dir_all(&dir);
2003 t!(fs::create_dir_all(&dir));
2005 // Guarantee that these are built before we begin running.
2006 builder.ensure(dist::PlainSourceTarball);
2007 builder.ensure(dist::Src);
2009 let mut cmd = Command::new("tar");
2011 .arg(builder.ensure(dist::PlainSourceTarball))
2012 .arg("--strip-components=1")
2014 builder.run(&mut cmd);
2016 Command::new("./configure")
2017 .args(&builder.config.configure_args)
2018 .arg("--enable-vendor")
2022 Command::new(build_helper::make(&builder.config.build))
2027 // Now make sure that rust-src has all of libstd's dependencies
2028 builder.info("Distcheck rust-src");
2029 let dir = builder.out.join("tmp").join("distcheck-src");
2030 let _ = fs::remove_dir_all(&dir);
2031 t!(fs::create_dir_all(&dir));
2033 let mut cmd = Command::new("tar");
2035 .arg(builder.ensure(dist::Src))
2036 .arg("--strip-components=1")
2038 builder.run(&mut cmd);
2040 let toml = dir.join("rust-src/lib/rustlib/src/rust/src/libstd/Cargo.toml");
2042 Command::new(&builder.initial_cargo)
2043 .arg("generate-lockfile")
2044 .arg("--manifest-path")
2051 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2052 pub struct Bootstrap;
2054 impl Step for Bootstrap {
2056 const DEFAULT: bool = true;
2057 const ONLY_HOSTS: bool = true;
2059 /// Tests the build system itself.
2060 fn run(self, builder: &Builder<'_>) {
2061 let mut cmd = Command::new(&builder.initial_cargo);
2063 .current_dir(builder.src.join("src/bootstrap"))
2064 .env("RUSTFLAGS", "-Cdebuginfo=2")
2065 .env("CARGO_TARGET_DIR", builder.out.join("bootstrap"))
2066 .env("RUSTC_BOOTSTRAP", "1")
2067 .env("RUSTC", &builder.initial_rustc);
2068 if let Some(flags) = option_env!("RUSTFLAGS") {
2069 // Use the same rustc flags for testing as for "normal" compilation,
2070 // so that Cargo doesn’t recompile the entire dependency graph every time:
2071 // https://github.com/rust-lang/rust/issues/49215
2072 cmd.env("RUSTFLAGS", flags);
2074 if !builder.fail_fast {
2075 cmd.arg("--no-fail-fast");
2077 cmd.arg("--").args(&builder.config.cmd.test_args());
2078 // rustbuild tests are racy on directory creation so just run them one at a time.
2079 // Since there's not many this shouldn't be a problem.
2080 cmd.arg("--test-threads=1");
2081 try_run(builder, &mut cmd);
2084 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2085 run.path("src/bootstrap")
2088 fn make_run(run: RunConfig<'_>) {
2089 run.builder.ensure(Bootstrap);