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, SourceType, Tool};
23 use crate::toolstate::ToolState;
24 use crate::util::{self, dylib_path, dylib_path_var};
25 use crate::Crate as CargoCrate;
26 use crate::{envify, DocTests, GitRepo, Mode};
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);
118 builder.tool_cmd(Tool::Linkchecker).arg(builder.out.join(host).join("doc")),
122 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
123 let builder = run.builder;
124 run.path("src/tools/linkchecker").default_condition(builder.config.docs)
127 fn make_run(run: RunConfig<'_>) {
128 run.builder.ensure(Linkcheck { host: run.target });
132 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
133 pub struct Cargotest {
135 host: Interned<String>,
138 impl Step for Cargotest {
140 const ONLY_HOSTS: bool = true;
142 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
143 run.path("src/tools/cargotest")
146 fn make_run(run: RunConfig<'_>) {
147 run.builder.ensure(Cargotest { stage: run.builder.top_stage, host: run.target });
150 /// Runs the `cargotest` tool as compiled in `stage` by the `host` compiler.
152 /// This tool in `src/tools` will check out a few Rust projects and run `cargo
153 /// test` to ensure that we don't regress the test suites there.
154 fn run(self, builder: &Builder<'_>) {
155 let compiler = builder.compiler(self.stage, self.host);
156 builder.ensure(compile::Rustc { compiler, target: compiler.host });
158 // Note that this is a short, cryptic, and not scoped directory name. This
159 // is currently to minimize the length of path on Windows where we otherwise
160 // quickly run into path name limit constraints.
161 let out_dir = builder.out.join("ct");
162 t!(fs::create_dir_all(&out_dir));
164 let _time = util::timeit(&builder);
165 let mut cmd = builder.tool_cmd(Tool::CargoTest);
168 cmd.arg(&builder.initial_cargo)
170 .env("RUSTC", builder.rustc(compiler))
171 .env("RUSTDOC", builder.rustdoc(compiler)),
176 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
179 host: Interned<String>,
182 impl Step for Cargo {
184 const ONLY_HOSTS: bool = true;
186 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
187 run.path("src/tools/cargo")
190 fn make_run(run: RunConfig<'_>) {
191 run.builder.ensure(Cargo { stage: run.builder.top_stage, host: run.target });
194 /// Runs `cargo test` for `cargo` packaged with Rust.
195 fn run(self, builder: &Builder<'_>) {
196 let compiler = builder.compiler(self.stage, self.host);
198 builder.ensure(tool::Cargo { compiler, target: self.host });
199 let mut cargo = tool::prepare_tool_cargo(
206 SourceType::Submodule,
210 if !builder.fail_fast {
211 cargo.arg("--no-fail-fast");
214 // Don't run cross-compile tests, we may not have cross-compiled libstd libs
216 cargo.env("CFG_DISABLE_CROSS_TESTS", "1");
217 // Disable a test that has issues with mingw.
218 cargo.env("CARGO_TEST_DISABLE_GIT_CLI", "1");
219 // Forcibly disable tests using nightly features since any changes to
220 // those features won't be able to land.
221 cargo.env("CARGO_TEST_DISABLE_NIGHTLY", "1");
223 cargo.env("PATH", &path_for_cargo(builder, compiler));
225 try_run(builder, &mut cargo.into());
229 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
232 host: Interned<String>,
237 const ONLY_HOSTS: bool = true;
239 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
240 run.path("src/tools/rls")
243 fn make_run(run: RunConfig<'_>) {
244 run.builder.ensure(Rls { stage: run.builder.top_stage, host: run.target });
247 /// Runs `cargo test` for the rls.
248 fn run(self, builder: &Builder<'_>) {
249 let stage = self.stage;
250 let host = self.host;
251 let compiler = builder.compiler(stage, host);
254 builder.ensure(tool::Rls { compiler, target: self.host, extra_features: Vec::new() });
255 if build_result.is_none() {
256 eprintln!("failed to test rls: could not build");
260 let mut cargo = tool::prepare_tool_cargo(
267 SourceType::Submodule,
271 builder.add_rustc_lib_path(compiler, &mut cargo);
272 cargo.arg("--").args(builder.config.cmd.test_args());
274 if try_run(builder, &mut cargo.into()) {
275 builder.save_toolstate("rls", ToolState::TestPass);
280 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
283 host: Interned<String>,
286 impl Step for Rustfmt {
288 const ONLY_HOSTS: bool = true;
290 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
291 run.path("src/tools/rustfmt")
294 fn make_run(run: RunConfig<'_>) {
295 run.builder.ensure(Rustfmt { stage: run.builder.top_stage, host: run.target });
298 /// Runs `cargo test` for rustfmt.
299 fn run(self, builder: &Builder<'_>) {
300 let stage = self.stage;
301 let host = self.host;
302 let compiler = builder.compiler(stage, host);
304 let build_result = builder.ensure(tool::Rustfmt {
307 extra_features: Vec::new(),
309 if build_result.is_none() {
310 eprintln!("failed to test rustfmt: could not build");
314 let mut cargo = tool::prepare_tool_cargo(
321 SourceType::Submodule,
325 let dir = testdir(builder, compiler.host);
326 t!(fs::create_dir_all(&dir));
327 cargo.env("RUSTFMT_TEST_DIR", dir);
329 builder.add_rustc_lib_path(compiler, &mut cargo);
331 if try_run(builder, &mut cargo.into()) {
332 builder.save_toolstate("rustfmt", ToolState::TestPass);
337 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
340 host: Interned<String>,
345 const ONLY_HOSTS: bool = true;
347 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
348 run.path("src/tools/miri")
351 fn make_run(run: RunConfig<'_>) {
352 run.builder.ensure(Miri { stage: run.builder.top_stage, host: run.target });
355 /// Runs `cargo test` for miri.
356 fn run(self, builder: &Builder<'_>) {
357 let stage = self.stage;
358 let host = self.host;
359 let compiler = builder.compiler(stage, host);
362 builder.ensure(tool::Miri { compiler, target: self.host, extra_features: Vec::new() });
363 if let Some(miri) = miri {
364 let mut cargo = builder.cargo(compiler, Mode::ToolRustc, host, "install");
366 // Configure `cargo install` path. cargo adds a `bin/`.
367 cargo.env("CARGO_INSTALL_ROOT", &builder.out);
369 let mut cargo = Command::from(cargo);
370 if !try_run(builder, &mut cargo) {
374 // # Run `cargo miri setup`.
375 let mut cargo = tool::prepare_tool_cargo(
382 SourceType::Submodule,
385 cargo.arg("--bin").arg("cargo-miri").arg("--").arg("miri").arg("setup");
387 // Tell `cargo miri setup` where to find the sources.
388 cargo.env("XARGO_RUST_SRC", builder.src.join("src"));
390 cargo.env("RUST_BACKTRACE", "1");
391 // Let cargo-miri know where xargo ended up.
392 cargo.env("XARGO", builder.out.join("bin").join("xargo"));
394 let mut cargo = Command::from(cargo);
395 if !try_run(builder, &mut cargo) {
399 // # Determine where Miri put its sysroot.
400 // To this end, we run `cargo miri setup --env` and capture the output.
401 // (We do this separately from the above so that when the setup actually
402 // happens we get some output.)
403 // We re-use the `cargo` from above.
404 cargo.arg("--print-sysroot");
406 // FIXME: Is there a way in which we can re-use the usual `run` helpers?
407 let miri_sysroot = if builder.config.dry_run {
410 builder.verbose(&format!("running: {:?}", cargo));
413 .expect("We already ran `cargo miri setup` before and that worked");
414 assert!(out.status.success(), "`cargo miri setup` returned with non-0 exit code");
415 // Output is "<sysroot>\n".
416 let stdout = String::from_utf8(out.stdout)
417 .expect("`cargo miri setup` stdout is not valid UTF-8");
418 let sysroot = stdout.trim_end();
419 builder.verbose(&format!("`cargo miri setup --print-sysroot` said: {:?}", sysroot));
423 // # Run `cargo test`.
424 let mut cargo = tool::prepare_tool_cargo(
431 SourceType::Submodule,
435 // miri tests need to know about the stage sysroot
436 cargo.env("MIRI_SYSROOT", miri_sysroot);
437 cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
438 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
439 cargo.env("MIRI_PATH", miri);
441 builder.add_rustc_lib_path(compiler, &mut cargo);
443 if !try_run(builder, &mut cargo.into()) {
448 builder.save_toolstate("miri", ToolState::TestPass);
450 eprintln!("failed to test miri: could not build");
455 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
456 pub struct CompiletestTest {
457 host: Interned<String>,
460 impl Step for CompiletestTest {
463 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
464 run.path("src/tools/compiletest")
467 fn make_run(run: RunConfig<'_>) {
468 run.builder.ensure(CompiletestTest { host: run.target });
471 /// Runs `cargo test` for compiletest.
472 fn run(self, builder: &Builder<'_>) {
473 let host = self.host;
474 let compiler = builder.compiler(0, host);
476 let cargo = tool::prepare_tool_cargo(
482 "src/tools/compiletest",
487 try_run(builder, &mut cargo.into());
491 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
494 host: Interned<String>,
497 impl Step for Clippy {
499 const ONLY_HOSTS: bool = true;
500 const DEFAULT: bool = false;
502 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
503 run.path("src/tools/clippy")
506 fn make_run(run: RunConfig<'_>) {
507 run.builder.ensure(Clippy { stage: run.builder.top_stage, host: run.target });
510 /// Runs `cargo test` for clippy.
511 fn run(self, builder: &Builder<'_>) {
512 let stage = self.stage;
513 let host = self.host;
514 let compiler = builder.compiler(stage, host);
516 let clippy = builder.ensure(tool::Clippy {
519 extra_features: Vec::new(),
521 if let Some(clippy) = clippy {
522 let mut cargo = tool::prepare_tool_cargo(
529 SourceType::Submodule,
533 // clippy tests need to know about the stage sysroot
534 cargo.env("SYSROOT", builder.sysroot(compiler));
535 cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
536 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
537 let host_libs = builder.stage_out(compiler, Mode::ToolRustc).join(builder.cargo_dir());
538 let target_libs = builder
539 .stage_out(compiler, Mode::ToolRustc)
541 .join(builder.cargo_dir());
542 cargo.env("HOST_LIBS", host_libs);
543 cargo.env("TARGET_LIBS", target_libs);
544 // clippy tests need to find the driver
545 cargo.env("CLIPPY_DRIVER_PATH", clippy);
547 builder.add_rustc_lib_path(compiler, &mut cargo);
549 if try_run(builder, &mut cargo.into()) {
550 builder.save_toolstate("clippy-driver", ToolState::TestPass);
553 eprintln!("failed to test clippy: could not build");
558 fn path_for_cargo(builder: &Builder<'_>, compiler: Compiler) -> OsString {
559 // Configure PATH to find the right rustc. NB. we have to use PATH
560 // and not RUSTC because the Cargo test suite has tests that will
561 // fail if rustc is not spelled `rustc`.
562 let path = builder.sysroot(compiler).join("bin");
563 let old_path = env::var_os("PATH").unwrap_or_default();
564 env::join_paths(iter::once(path).chain(env::split_paths(&old_path))).expect("")
567 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
568 pub struct RustdocTheme {
569 pub compiler: Compiler,
572 impl Step for RustdocTheme {
574 const DEFAULT: bool = true;
575 const ONLY_HOSTS: bool = true;
577 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
578 run.path("src/tools/rustdoc-themes")
581 fn make_run(run: RunConfig<'_>) {
582 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
584 run.builder.ensure(RustdocTheme { compiler });
587 fn run(self, builder: &Builder<'_>) {
588 let rustdoc = builder.out.join("bootstrap/debug/rustdoc");
589 let mut cmd = builder.tool_cmd(Tool::RustdocTheme);
590 cmd.arg(rustdoc.to_str().unwrap())
591 .arg(builder.src.join("src/librustdoc/html/static/themes").to_str().unwrap())
592 .env("RUSTC_STAGE", self.compiler.stage.to_string())
593 .env("RUSTC_SYSROOT", builder.sysroot(self.compiler))
594 .env("RUSTDOC_LIBDIR", builder.sysroot_libdir(self.compiler, self.compiler.host))
595 .env("CFG_RELEASE_CHANNEL", &builder.config.channel)
596 .env("RUSTDOC_REAL", builder.rustdoc(self.compiler))
597 .env("RUSTDOC_CRATE_VERSION", builder.rust_version())
598 .env("RUSTC_BOOTSTRAP", "1");
599 if let Some(linker) = builder.linker(self.compiler.host) {
600 cmd.env("RUSTC_TARGET_LINKER", linker);
602 try_run(builder, &mut cmd);
606 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
607 pub struct RustdocJSStd {
608 pub host: Interned<String>,
609 pub target: Interned<String>,
612 impl Step for RustdocJSStd {
614 const DEFAULT: bool = true;
615 const ONLY_HOSTS: bool = true;
617 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
618 run.path("src/test/rustdoc-js-std")
621 fn make_run(run: RunConfig<'_>) {
622 run.builder.ensure(RustdocJSStd { host: run.host, target: run.target });
625 fn run(self, builder: &Builder<'_>) {
626 if let Some(ref nodejs) = builder.config.nodejs {
627 let mut command = Command::new(nodejs);
628 command.args(&["src/tools/rustdoc-js-std/tester.js", &*self.host]);
629 builder.ensure(crate::doc::Std { target: self.target, stage: builder.top_stage });
630 builder.run(&mut command);
632 builder.info("No nodejs found, skipping \"src/test/rustdoc-js-std\" tests");
637 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
638 pub struct RustdocJSNotStd {
639 pub host: Interned<String>,
640 pub target: Interned<String>,
641 pub compiler: Compiler,
644 impl Step for RustdocJSNotStd {
646 const DEFAULT: bool = true;
647 const ONLY_HOSTS: bool = true;
649 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
650 run.path("src/test/rustdoc-js")
653 fn make_run(run: RunConfig<'_>) {
654 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
655 run.builder.ensure(RustdocJSNotStd { host: run.host, target: run.target, compiler });
658 fn run(self, builder: &Builder<'_>) {
659 if builder.config.nodejs.is_some() {
660 builder.ensure(Compiletest {
661 compiler: self.compiler,
669 builder.info("No nodejs found, skipping \"src/test/rustdoc-js\" tests");
674 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
675 pub struct RustdocUi {
676 pub host: Interned<String>,
677 pub target: Interned<String>,
678 pub compiler: Compiler,
681 impl Step for RustdocUi {
683 const DEFAULT: bool = true;
684 const ONLY_HOSTS: bool = true;
686 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
687 run.path("src/test/rustdoc-ui")
690 fn make_run(run: RunConfig<'_>) {
691 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
692 run.builder.ensure(RustdocUi { host: run.host, target: run.target, compiler });
695 fn run(self, builder: &Builder<'_>) {
696 builder.ensure(Compiletest {
697 compiler: self.compiler,
701 path: Some("src/test/rustdoc-ui"),
707 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
712 const DEFAULT: bool = true;
713 const ONLY_HOSTS: bool = true;
715 /// Runs the `tidy` tool.
717 /// This tool in `src/tools` checks up on various bits and pieces of style and
718 /// otherwise just implements a few lint-like checks that are specific to the
721 /// Once tidy passes, this step also runs `fmt --check` if tests are being run
722 /// for the `dev` or `nightly` channels.
723 fn run(self, builder: &Builder<'_>) {
724 let mut cmd = builder.tool_cmd(Tool::Tidy);
725 cmd.arg(builder.src.join("src"));
726 cmd.arg(&builder.initial_cargo);
727 if !builder.config.vendor {
728 cmd.arg("--no-vendor");
730 if builder.is_verbose() {
731 cmd.arg("--verbose");
734 builder.info("tidy check");
735 try_run(builder, &mut cmd);
737 if builder.config.channel == "dev" || builder.config.channel == "nightly" {
738 builder.info("fmt check");
739 crate::format::format(&builder.build, !builder.config.cmd.bless());
743 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
744 run.path("src/tools/tidy")
747 fn make_run(run: RunConfig<'_>) {
748 run.builder.ensure(Tidy);
752 fn testdir(builder: &Builder<'_>, host: Interned<String>) -> PathBuf {
753 builder.out.join(host).join("test")
756 macro_rules! default_test {
757 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
758 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: false });
762 macro_rules! default_test_with_compare_mode {
763 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr,
764 compare_mode: $compare_mode:expr }) => {
765 test_with_compare_mode!($name {
771 compare_mode: $compare_mode
776 macro_rules! host_test {
777 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
778 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: true });
783 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
784 host: $host:expr }) => {
785 test_definitions!($name {
796 macro_rules! test_with_compare_mode {
797 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
798 host: $host:expr, compare_mode: $compare_mode:expr }) => {
799 test_definitions!($name {
805 compare_mode: Some($compare_mode)
810 macro_rules! test_definitions {
815 default: $default:expr,
817 compare_mode: $compare_mode:expr
819 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
821 pub compiler: Compiler,
822 pub target: Interned<String>,
825 impl Step for $name {
827 const DEFAULT: bool = $default;
828 const ONLY_HOSTS: bool = $host;
830 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
831 run.suite_path($path)
834 fn make_run(run: RunConfig<'_>) {
835 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
837 run.builder.ensure($name { compiler, target: run.target });
840 fn run(self, builder: &Builder<'_>) {
841 builder.ensure(Compiletest {
842 compiler: self.compiler,
847 compare_mode: $compare_mode,
854 default_test_with_compare_mode!(Ui {
861 default_test!(CompileFail {
862 path: "src/test/compile-fail",
863 mode: "compile-fail",
864 suite: "compile-fail"
867 default_test!(RunFail { path: "src/test/run-fail", mode: "run-fail", suite: "run-fail" });
869 default_test!(RunPassValgrind {
870 path: "src/test/run-pass-valgrind",
871 mode: "run-pass-valgrind",
872 suite: "run-pass-valgrind"
875 default_test!(MirOpt { path: "src/test/mir-opt", mode: "mir-opt", suite: "mir-opt" });
877 default_test!(Codegen { path: "src/test/codegen", mode: "codegen", suite: "codegen" });
879 default_test!(CodegenUnits {
880 path: "src/test/codegen-units",
881 mode: "codegen-units",
882 suite: "codegen-units"
885 default_test!(Incremental {
886 path: "src/test/incremental",
891 default_test!(Debuginfo { path: "src/test/debuginfo", mode: "debuginfo", suite: "debuginfo" });
893 host_test!(UiFullDeps { path: "src/test/ui-fulldeps", mode: "ui", suite: "ui-fulldeps" });
895 host_test!(Rustdoc { path: "src/test/rustdoc", mode: "rustdoc", suite: "rustdoc" });
897 host_test!(Pretty { path: "src/test/pretty", mode: "pretty", suite: "pretty" });
898 test!(RunFailPretty {
899 path: "src/test/run-fail/pretty",
905 test!(RunPassValgrindPretty {
906 path: "src/test/run-pass-valgrind/pretty",
908 suite: "run-pass-valgrind",
913 default_test!(RunMake { path: "src/test/run-make", mode: "run-make", suite: "run-make" });
915 host_test!(RunMakeFullDeps {
916 path: "src/test/run-make-fulldeps",
918 suite: "run-make-fulldeps"
921 default_test!(Assembly { path: "src/test/assembly", mode: "assembly", suite: "assembly" });
923 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
926 target: Interned<String>,
929 path: Option<&'static str>,
930 compare_mode: Option<&'static str>,
933 impl Step for Compiletest {
936 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
940 /// Executes the `compiletest` tool to run a suite of tests.
942 /// Compiles all tests with `compiler` for `target` with the specified
943 /// compiletest `mode` and `suite` arguments. For example `mode` can be
944 /// "run-pass" or `suite` can be something like `debuginfo`.
945 fn run(self, builder: &Builder<'_>) {
946 let compiler = self.compiler;
947 let target = self.target;
948 let mode = self.mode;
949 let suite = self.suite;
951 // Path for test suite
952 let suite_path = self.path.unwrap_or("");
954 // Skip codegen tests if they aren't enabled in configuration.
955 if !builder.config.codegen_tests && suite == "codegen" {
959 if suite == "debuginfo" {
960 let msvc = builder.config.build.contains("msvc");
961 if mode == "debuginfo" {
962 return builder.ensure(Compiletest {
963 mode: if msvc { "debuginfo-cdb" } else { "debuginfo-gdb+lldb" },
969 .ensure(dist::DebuggerScripts { sysroot: builder.sysroot(compiler), host: target });
972 if suite.ends_with("fulldeps") {
973 builder.ensure(compile::Rustc { compiler, target });
976 builder.ensure(compile::Std { compiler, target });
977 // ensure that `libproc_macro` is available on the host.
978 builder.ensure(compile::Std { compiler, target: compiler.host });
980 // Also provide `rust_test_helpers` for the host.
981 builder.ensure(native::TestHelpers { target: compiler.host });
983 // As well as the target, except for plain wasm32, which can't build it
984 if !target.contains("wasm32") || target.contains("emscripten") {
985 builder.ensure(native::TestHelpers { target });
988 builder.ensure(RemoteCopyLibs { compiler, target });
990 let mut cmd = builder.tool_cmd(Tool::Compiletest);
992 // compiletest currently has... a lot of arguments, so let's just pass all
995 cmd.arg("--compile-lib-path").arg(builder.rustc_libdir(compiler));
996 cmd.arg("--run-lib-path").arg(builder.sysroot_libdir(compiler, target));
997 cmd.arg("--rustc-path").arg(builder.rustc(compiler));
999 let is_rustdoc = suite.ends_with("rustdoc-ui") || suite.ends_with("rustdoc-js");
1001 // Avoid depending on rustdoc when we don't need it.
1002 if mode == "rustdoc"
1003 || (mode == "run-make" && suite.ends_with("fulldeps"))
1004 || (mode == "ui" && is_rustdoc)
1005 || mode == "js-doc-test"
1007 cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler));
1010 cmd.arg("--src-base").arg(builder.src.join("src/test").join(suite));
1011 cmd.arg("--build-base").arg(testdir(builder, compiler.host).join(suite));
1012 cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target));
1013 cmd.arg("--mode").arg(mode);
1014 cmd.arg("--target").arg(target);
1015 cmd.arg("--host").arg(&*compiler.host);
1016 cmd.arg("--llvm-filecheck").arg(builder.llvm_filecheck(builder.config.build));
1018 if builder.config.cmd.bless() {
1023 builder.config.cmd.compare_mode().or_else(|| {
1024 if builder.config.test_compare_mode { self.compare_mode } else { None }
1027 if let Some(ref pass) = builder.config.cmd.pass() {
1032 if let Some(ref nodejs) = builder.config.nodejs {
1033 cmd.arg("--nodejs").arg(nodejs);
1036 let mut flags = if is_rustdoc { Vec::new() } else { vec!["-Crpath".to_string()] };
1038 if builder.config.rust_optimize_tests {
1039 flags.push("-O".to_string());
1042 flags.push(format!("-Cdebuginfo={}", builder.config.rust_debuginfo_level_tests));
1043 flags.push("-Zunstable-options".to_string());
1044 flags.push(builder.config.cmd.rustc_args().join(" "));
1046 if let Some(linker) = builder.linker(target) {
1047 cmd.arg("--linker").arg(linker);
1050 let mut hostflags = flags.clone();
1051 hostflags.push(format!("-Lnative={}", builder.test_helpers_out(compiler.host).display()));
1052 cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
1054 let mut targetflags = flags;
1055 targetflags.push(format!("-Lnative={}", builder.test_helpers_out(target).display()));
1056 cmd.arg("--target-rustcflags").arg(targetflags.join(" "));
1058 cmd.arg("--docck-python").arg(builder.python());
1060 if builder.config.build.ends_with("apple-darwin") {
1061 // Force /usr/bin/python on macOS for LLDB tests because we're loading the
1062 // LLDB plugin's compiled module which only works with the system python
1063 // (namely not Homebrew-installed python)
1064 cmd.arg("--lldb-python").arg("/usr/bin/python");
1066 cmd.arg("--lldb-python").arg(builder.python());
1069 if let Some(ref gdb) = builder.config.gdb {
1070 cmd.arg("--gdb").arg(gdb);
1073 let run = |cmd: &mut Command| {
1074 cmd.output().map(|output| {
1075 String::from_utf8_lossy(&output.stdout)
1078 .unwrap_or_else(|| panic!("{:?} failed {:?}", cmd, output))
1082 let lldb_exe = if builder.config.lldb_enabled {
1083 // Test against the lldb that was just built.
1084 builder.llvm_out(target).join("bin").join("lldb")
1086 PathBuf::from("lldb")
1088 let lldb_version = Command::new(&lldb_exe)
1091 .map(|output| String::from_utf8_lossy(&output.stdout).to_string())
1093 if let Some(ref vers) = lldb_version {
1094 cmd.arg("--lldb-version").arg(vers);
1095 let lldb_python_dir = run(Command::new(&lldb_exe).arg("-P")).ok();
1096 if let Some(ref dir) = lldb_python_dir {
1097 cmd.arg("--lldb-python-dir").arg(dir);
1101 if util::forcing_clang_based_tests() {
1102 let clang_exe = builder.llvm_out(target).join("bin").join("clang");
1103 cmd.arg("--run-clang-based-tests-with").arg(clang_exe);
1106 // Get paths from cmd args
1107 let paths = match &builder.config.cmd {
1108 Subcommand::Test { ref paths, .. } => &paths[..],
1112 // Get test-args by striping suite path
1113 let mut test_args: Vec<&str> = paths
1115 .map(|p| match p.strip_prefix(".") {
1119 .filter(|p| p.starts_with(suite_path) && (p.is_dir() || p.is_file()))
1121 // Since test suite paths are themselves directories, if we don't
1122 // specify a directory or file, we'll get an empty string here
1123 // (the result of the test suite directory without its suite prefix).
1124 // Therefore, we need to filter these out, as only the first --test-args
1125 // flag is respected, so providing an empty --test-args conflicts with
1126 // any following it.
1127 match p.strip_prefix(suite_path).ok().and_then(|p| p.to_str()) {
1128 Some(s) if s != "" => Some(s),
1134 test_args.append(&mut builder.config.cmd.test_args());
1136 cmd.args(&test_args);
1138 if builder.is_verbose() {
1139 cmd.arg("--verbose");
1142 if !builder.config.verbose_tests {
1146 if builder.config.llvm_enabled() {
1147 let llvm_config = builder.ensure(native::Llvm { target: builder.config.build });
1148 if !builder.config.dry_run {
1149 let llvm_version = output(Command::new(&llvm_config).arg("--version"));
1150 cmd.arg("--llvm-version").arg(llvm_version);
1152 if !builder.is_rust_llvm(target) {
1153 cmd.arg("--system-llvm");
1156 // Only pass correct values for these flags for the `run-make` suite as it
1157 // requires that a C++ compiler was configured which isn't always the case.
1158 if !builder.config.dry_run && suite == "run-make-fulldeps" {
1159 let llvm_components = output(Command::new(&llvm_config).arg("--components"));
1160 let llvm_cxxflags = output(Command::new(&llvm_config).arg("--cxxflags"));
1162 .arg(builder.cc(target))
1164 .arg(builder.cxx(target).unwrap())
1166 .arg(builder.cflags(target, GitRepo::Rustc).join(" "))
1167 .arg("--llvm-components")
1168 .arg(llvm_components.trim())
1169 .arg("--llvm-cxxflags")
1170 .arg(llvm_cxxflags.trim());
1171 if let Some(ar) = builder.ar(target) {
1172 cmd.arg("--ar").arg(ar);
1175 // The llvm/bin directory contains many useful cross-platform
1176 // tools. Pass the path to run-make tests so they can use them.
1177 let llvm_bin_path = llvm_config
1179 .expect("Expected llvm-config to be contained in directory");
1180 assert!(llvm_bin_path.is_dir());
1181 cmd.arg("--llvm-bin-dir").arg(llvm_bin_path);
1183 // If LLD is available, add it to the PATH
1184 if builder.config.lld_enabled {
1185 let lld_install_root =
1186 builder.ensure(native::Lld { target: builder.config.build });
1188 let lld_bin_path = lld_install_root.join("bin");
1190 let old_path = env::var_os("PATH").unwrap_or_default();
1191 let new_path = env::join_paths(
1192 std::iter::once(lld_bin_path).chain(env::split_paths(&old_path)),
1194 .expect("Could not add LLD bin path to PATH");
1195 cmd.env("PATH", new_path);
1200 if suite != "run-make-fulldeps" {
1207 .arg("--llvm-components")
1209 .arg("--llvm-cxxflags")
1213 if builder.remote_tested(target) {
1214 cmd.arg("--remote-test-client").arg(builder.tool_exe(Tool::RemoteTestClient));
1217 // Running a C compiler on MSVC requires a few env vars to be set, to be
1218 // sure to set them here.
1220 // Note that if we encounter `PATH` we make sure to append to our own `PATH`
1221 // rather than stomp over it.
1222 if target.contains("msvc") {
1223 for &(ref k, ref v) in builder.cc[&target].env() {
1229 cmd.env("RUSTC_BOOTSTRAP", "1");
1230 builder.add_rust_test_threads(&mut cmd);
1232 if builder.config.sanitizers {
1233 cmd.env("RUSTC_SANITIZER_SUPPORT", "1");
1236 if builder.config.profiler {
1237 cmd.env("RUSTC_PROFILER_SUPPORT", "1");
1240 let tmp = builder.out.join("tmp");
1241 std::fs::create_dir_all(&tmp).unwrap();
1242 cmd.env("RUST_TEST_TMPDIR", tmp);
1244 cmd.arg("--adb-path").arg("adb");
1245 cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
1246 if target.contains("android") {
1247 // Assume that cc for this target comes from the android sysroot
1248 cmd.arg("--android-cross-path")
1249 .arg(builder.cc(target).parent().unwrap().parent().unwrap());
1251 cmd.arg("--android-cross-path").arg("");
1254 if builder.config.cmd.rustfix_coverage() {
1255 cmd.arg("--rustfix-coverage");
1258 builder.ci_env.force_coloring_in_ci(&mut cmd);
1260 builder.info(&format!(
1261 "Check compiletest suite={} mode={} ({} -> {})",
1262 suite, mode, &compiler.host, target
1264 let _time = util::timeit(&builder);
1265 try_run(builder, &mut cmd);
1267 if let Some(compare_mode) = compare_mode {
1268 cmd.arg("--compare-mode").arg(compare_mode);
1269 builder.info(&format!(
1270 "Check compiletest suite={} mode={} compare_mode={} ({} -> {})",
1271 suite, mode, compare_mode, &compiler.host, target
1273 let _time = util::timeit(&builder);
1274 try_run(builder, &mut cmd);
1279 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1287 impl Step for DocTest {
1289 const ONLY_HOSTS: bool = true;
1291 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1295 /// Runs `rustdoc --test` for all documentation in `src/doc`.
1297 /// This will run all tests in our markdown documentation (e.g., the book)
1298 /// located in `src/doc`. The `rustdoc` that's run is the one that sits next to
1300 fn run(self, builder: &Builder<'_>) {
1301 let compiler = self.compiler;
1303 builder.ensure(compile::Std { compiler, target: compiler.host });
1305 // Do a breadth-first traversal of the `src/doc` directory and just run
1306 // tests for all files that end in `*.md`
1307 let mut stack = vec![builder.src.join(self.path)];
1308 let _time = util::timeit(&builder);
1310 let mut files = Vec::new();
1311 while let Some(p) = stack.pop() {
1313 stack.extend(t!(p.read_dir()).map(|p| t!(p).path()));
1317 if p.extension().and_then(|s| s.to_str()) != Some("md") {
1321 // The nostarch directory in the book is for no starch, and so isn't
1322 // guaranteed to builder. We don't care if it doesn't build, so skip it.
1323 if p.to_str().map_or(false, |p| p.contains("nostarch")) {
1332 let mut toolstate = ToolState::TestPass;
1334 if !markdown_test(builder, compiler, &file) {
1335 toolstate = ToolState::TestFail;
1338 if self.is_ext_doc {
1339 builder.save_toolstate(self.name, toolstate);
1344 macro_rules! test_book {
1345 ($($name:ident, $path:expr, $book_name:expr, default=$default:expr;)+) => {
1347 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1352 impl Step for $name {
1354 const DEFAULT: bool = $default;
1355 const ONLY_HOSTS: bool = true;
1357 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1361 fn make_run(run: RunConfig<'_>) {
1362 run.builder.ensure($name {
1363 compiler: run.builder.compiler(run.builder.top_stage, run.host),
1367 fn run(self, builder: &Builder<'_>) {
1368 builder.ensure(DocTest {
1369 compiler: self.compiler,
1372 is_ext_doc: !$default,
1381 Nomicon, "src/doc/nomicon", "nomicon", default=false;
1382 Reference, "src/doc/reference", "reference", default=false;
1383 RustdocBook, "src/doc/rustdoc", "rustdoc", default=true;
1384 RustcBook, "src/doc/rustc", "rustc", default=true;
1385 RustByExample, "src/doc/rust-by-example", "rust-by-example", default=false;
1386 EmbeddedBook, "src/doc/embedded-book", "embedded-book", default=false;
1387 TheBook, "src/doc/book", "book", default=false;
1388 UnstableBook, "src/doc/unstable-book", "unstable-book", default=true;
1389 EditionGuide, "src/doc/edition-guide", "edition-guide", default=false;
1392 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1393 pub struct ErrorIndex {
1397 impl Step for ErrorIndex {
1399 const DEFAULT: bool = true;
1400 const ONLY_HOSTS: bool = true;
1402 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1403 run.path("src/tools/error_index_generator")
1406 fn make_run(run: RunConfig<'_>) {
1408 .ensure(ErrorIndex { compiler: run.builder.compiler(run.builder.top_stage, run.host) });
1411 /// Runs the error index generator tool to execute the tests located in the error
1414 /// The `error_index_generator` tool lives in `src/tools` and is used to
1415 /// generate a markdown file from the error indexes of the code base which is
1416 /// then passed to `rustdoc --test`.
1417 fn run(self, builder: &Builder<'_>) {
1418 let compiler = self.compiler;
1420 builder.ensure(compile::Std { compiler, target: compiler.host });
1422 let dir = testdir(builder, compiler.host);
1423 t!(fs::create_dir_all(&dir));
1424 let output = dir.join("error-index.md");
1426 let mut tool = tool::ErrorIndex::command(
1428 builder.compiler(compiler.stage, builder.config.build),
1430 tool.arg("markdown").arg(&output).env("CFG_BUILD", &builder.config.build);
1432 builder.info(&format!("Testing error-index stage{}", compiler.stage));
1433 let _time = util::timeit(&builder);
1434 builder.run_quiet(&mut tool);
1435 markdown_test(builder, compiler, &output);
1439 fn markdown_test(builder: &Builder<'_>, compiler: Compiler, markdown: &Path) -> bool {
1440 match fs::read_to_string(markdown) {
1442 if !contents.contains("```") {
1449 builder.info(&format!("doc tests for: {}", markdown.display()));
1450 let mut cmd = builder.rustdoc_cmd(compiler);
1451 builder.add_rust_test_threads(&mut cmd);
1454 cmd.env("RUSTC_BOOTSTRAP", "1");
1456 let test_args = builder.config.cmd.test_args().join(" ");
1457 cmd.arg("--test-args").arg(test_args);
1459 if builder.config.verbose_tests {
1460 try_run(builder, &mut cmd)
1462 try_run_quiet(builder, &mut cmd)
1466 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1467 pub struct RustcGuide;
1469 impl Step for RustcGuide {
1471 const DEFAULT: bool = false;
1472 const ONLY_HOSTS: bool = true;
1474 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1475 run.path("src/doc/rustc-guide")
1478 fn make_run(run: RunConfig<'_>) {
1479 run.builder.ensure(RustcGuide);
1482 fn run(self, builder: &Builder<'_>) {
1483 let src = builder.src.join("src/doc/rustc-guide");
1484 let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
1485 let toolstate = if try_run(builder, rustbook_cmd.arg("linkcheck").arg(&src)) {
1490 builder.save_toolstate("rustc-guide", toolstate);
1494 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1495 pub struct CrateLibrustc {
1497 target: Interned<String>,
1498 test_kind: TestKind,
1499 krate: Interned<String>,
1502 impl Step for CrateLibrustc {
1504 const DEFAULT: bool = true;
1505 const ONLY_HOSTS: bool = true;
1507 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1508 run.krate("rustc-main")
1511 fn make_run(run: RunConfig<'_>) {
1512 let builder = run.builder;
1513 let compiler = builder.compiler(builder.top_stage, run.host);
1515 for krate in builder.in_tree_crates("rustc-main") {
1516 if run.path.ends_with(&krate.path) {
1517 let test_kind = builder.kind.into();
1519 builder.ensure(CrateLibrustc {
1529 fn run(self, builder: &Builder<'_>) {
1530 builder.ensure(Crate {
1531 compiler: self.compiler,
1532 target: self.target,
1534 test_kind: self.test_kind,
1540 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1541 pub struct CrateNotDefault {
1543 target: Interned<String>,
1544 test_kind: TestKind,
1545 krate: &'static str,
1548 impl Step for CrateNotDefault {
1551 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1552 run.path("src/librustc_asan")
1553 .path("src/librustc_lsan")
1554 .path("src/librustc_msan")
1555 .path("src/librustc_tsan")
1558 fn make_run(run: RunConfig<'_>) {
1559 let builder = run.builder;
1560 let compiler = builder.compiler(builder.top_stage, run.host);
1562 let test_kind = builder.kind.into();
1564 builder.ensure(CrateNotDefault {
1568 krate: match run.path {
1569 _ if run.path.ends_with("src/librustc_asan") => "rustc_asan",
1570 _ if run.path.ends_with("src/librustc_lsan") => "rustc_lsan",
1571 _ if run.path.ends_with("src/librustc_msan") => "rustc_msan",
1572 _ if run.path.ends_with("src/librustc_tsan") => "rustc_tsan",
1573 _ => panic!("unexpected path {:?}", run.path),
1578 fn run(self, builder: &Builder<'_>) {
1579 builder.ensure(Crate {
1580 compiler: self.compiler,
1581 target: self.target,
1583 test_kind: self.test_kind,
1584 krate: INTERNER.intern_str(self.krate),
1589 #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
1591 pub compiler: Compiler,
1592 pub target: Interned<String>,
1594 pub test_kind: TestKind,
1595 pub krate: Interned<String>,
1598 impl Step for Crate {
1600 const DEFAULT: bool = true;
1602 fn should_run(mut run: ShouldRun<'_>) -> ShouldRun<'_> {
1603 let builder = run.builder;
1604 for krate in run.builder.in_tree_crates("test") {
1605 if !(krate.name.starts_with("rustc_") && krate.name.ends_with("san")) {
1606 run = run.path(krate.local_path(&builder).to_str().unwrap());
1612 fn make_run(run: RunConfig<'_>) {
1613 let builder = run.builder;
1614 let compiler = builder.compiler(builder.top_stage, run.host);
1616 let make = |mode: Mode, krate: &CargoCrate| {
1617 let test_kind = builder.kind.into();
1619 builder.ensure(Crate {
1628 for krate in builder.in_tree_crates("test") {
1629 if run.path.ends_with(&krate.local_path(&builder)) {
1630 make(Mode::Std, krate);
1635 /// Runs all unit tests plus documentation tests for a given crate defined
1636 /// by a `Cargo.toml` (single manifest)
1638 /// This is what runs tests for crates like the standard library, compiler, etc.
1639 /// It essentially is the driver for running `cargo test`.
1641 /// Currently this runs all tests for a DAG by passing a bunch of `-p foo`
1642 /// arguments, and those arguments are discovered from `cargo metadata`.
1643 fn run(self, builder: &Builder<'_>) {
1644 let compiler = self.compiler;
1645 let target = self.target;
1646 let mode = self.mode;
1647 let test_kind = self.test_kind;
1648 let krate = self.krate;
1650 builder.ensure(compile::Std { compiler, target });
1651 builder.ensure(RemoteCopyLibs { compiler, target });
1653 // If we're not doing a full bootstrap but we're testing a stage2
1654 // version of libstd, then what we're actually testing is the libstd
1655 // produced in stage1. Reflect that here by updating the compiler that
1656 // we're working with automatically.
1657 let compiler = builder.compiler_for(compiler.stage, compiler.host, target);
1659 let mut cargo = builder.cargo(compiler, mode, target, test_kind.subcommand());
1662 compile::std_cargo(builder, target, &mut cargo);
1665 builder.ensure(compile::Rustc { compiler, target });
1666 compile::rustc_cargo(builder, &mut cargo, target);
1668 _ => panic!("can only test libraries"),
1671 // Build up the base `cargo test` command.
1673 // Pass in some standard flags then iterate over the graph we've discovered
1674 // in `cargo metadata` with the maps above and figure out what `-p`
1675 // arguments need to get passed.
1676 if test_kind.subcommand() == "test" && !builder.fail_fast {
1677 cargo.arg("--no-fail-fast");
1679 match builder.doc_tests {
1684 cargo.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
1689 cargo.arg("-p").arg(krate);
1691 // The tests are going to run with the *target* libraries, so we need to
1692 // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
1694 // Note that to run the compiler we need to run with the *host* libraries,
1695 // but our wrapper scripts arrange for that to be the case anyway.
1696 let mut dylib_path = dylib_path();
1697 dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
1698 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
1701 cargo.args(&builder.config.cmd.test_args());
1703 if !builder.config.verbose_tests {
1704 cargo.arg("--quiet");
1707 if target.contains("emscripten") {
1709 format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
1710 builder.config.nodejs.as_ref().expect("nodejs not configured"),
1712 } else if target.starts_with("wasm32") {
1713 let node = builder.config.nodejs.as_ref().expect("nodejs not configured");
1715 format!("{} {}/src/etc/wasm32-shim.js", node.display(), builder.src.display());
1716 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)), &runner);
1717 } else if builder.remote_tested(target) {
1719 format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
1720 format!("{} run", builder.tool_exe(Tool::RemoteTestClient).display()),
1724 builder.info(&format!(
1725 "{} {} stage{} ({} -> {})",
1726 test_kind, krate, compiler.stage, &compiler.host, target
1728 let _time = util::timeit(&builder);
1729 try_run(builder, &mut cargo.into());
1733 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1734 pub struct CrateRustdoc {
1735 host: Interned<String>,
1736 test_kind: TestKind,
1739 impl Step for CrateRustdoc {
1741 const DEFAULT: bool = true;
1742 const ONLY_HOSTS: bool = true;
1744 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1745 run.paths(&["src/librustdoc", "src/tools/rustdoc"])
1748 fn make_run(run: RunConfig<'_>) {
1749 let builder = run.builder;
1751 let test_kind = builder.kind.into();
1753 builder.ensure(CrateRustdoc { host: run.host, test_kind });
1756 fn run(self, builder: &Builder<'_>) {
1757 let test_kind = self.test_kind;
1759 let compiler = builder.compiler(builder.top_stage, self.host);
1760 let target = compiler.host;
1761 builder.ensure(compile::Rustc { compiler, target });
1763 let mut cargo = tool::prepare_tool_cargo(
1768 test_kind.subcommand(),
1769 "src/tools/rustdoc",
1773 if test_kind.subcommand() == "test" && !builder.fail_fast {
1774 cargo.arg("--no-fail-fast");
1777 cargo.arg("-p").arg("rustdoc:0.0.0");
1780 cargo.args(&builder.config.cmd.test_args());
1782 if self.host.contains("musl") {
1783 cargo.arg("'-Ctarget-feature=-crt-static'");
1786 if !builder.config.verbose_tests {
1787 cargo.arg("--quiet");
1790 builder.info(&format!(
1791 "{} rustdoc stage{} ({} -> {})",
1792 test_kind, compiler.stage, &compiler.host, target
1794 let _time = util::timeit(&builder);
1796 try_run(builder, &mut cargo.into());
1800 /// Some test suites are run inside emulators or on remote devices, and most
1801 /// of our test binaries are linked dynamically which means we need to ship
1802 /// the standard library and such to the emulator ahead of time. This step
1803 /// represents this and is a dependency of all test suites.
1805 /// Most of the time this is a no-op. For some steps such as shipping data to
1806 /// QEMU we have to build our own tools so we've got conditional dependencies
1807 /// on those programs as well. Note that the remote test client is built for
1808 /// the build target (us) and the server is built for the target.
1809 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1810 pub struct RemoteCopyLibs {
1812 target: Interned<String>,
1815 impl Step for RemoteCopyLibs {
1818 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1822 fn run(self, builder: &Builder<'_>) {
1823 let compiler = self.compiler;
1824 let target = self.target;
1825 if !builder.remote_tested(target) {
1829 builder.ensure(compile::Std { compiler, target });
1831 builder.info(&format!("REMOTE copy libs to emulator ({})", target));
1832 t!(fs::create_dir_all(builder.out.join("tmp")));
1835 builder.ensure(tool::RemoteTestServer { compiler: compiler.with_stage(0), target });
1837 // Spawn the emulator and wait for it to come online
1838 let tool = builder.tool_exe(Tool::RemoteTestClient);
1839 let mut cmd = Command::new(&tool);
1840 cmd.arg("spawn-emulator").arg(target).arg(&server).arg(builder.out.join("tmp"));
1841 if let Some(rootfs) = builder.qemu_rootfs(target) {
1844 builder.run(&mut cmd);
1846 // Push all our dylibs to the emulator
1847 for f in t!(builder.sysroot_libdir(compiler, target).read_dir()) {
1849 let name = f.file_name().into_string().unwrap();
1850 if util::is_dylib(&name) {
1851 builder.run(Command::new(&tool).arg("push").arg(f.path()));
1857 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1858 pub struct Distcheck;
1860 impl Step for Distcheck {
1863 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1864 run.path("distcheck")
1867 fn make_run(run: RunConfig<'_>) {
1868 run.builder.ensure(Distcheck);
1871 /// Runs "distcheck", a 'make check' from a tarball
1872 fn run(self, builder: &Builder<'_>) {
1873 builder.info("Distcheck");
1874 let dir = builder.out.join("tmp").join("distcheck");
1875 let _ = fs::remove_dir_all(&dir);
1876 t!(fs::create_dir_all(&dir));
1878 // Guarantee that these are built before we begin running.
1879 builder.ensure(dist::PlainSourceTarball);
1880 builder.ensure(dist::Src);
1882 let mut cmd = Command::new("tar");
1884 .arg(builder.ensure(dist::PlainSourceTarball))
1885 .arg("--strip-components=1")
1887 builder.run(&mut cmd);
1889 Command::new("./configure")
1890 .args(&builder.config.configure_args)
1891 .arg("--enable-vendor")
1895 Command::new(build_helper::make(&builder.config.build)).arg("check").current_dir(&dir),
1898 // Now make sure that rust-src has all of libstd's dependencies
1899 builder.info("Distcheck rust-src");
1900 let dir = builder.out.join("tmp").join("distcheck-src");
1901 let _ = fs::remove_dir_all(&dir);
1902 t!(fs::create_dir_all(&dir));
1904 let mut cmd = Command::new("tar");
1906 .arg(builder.ensure(dist::Src))
1907 .arg("--strip-components=1")
1909 builder.run(&mut cmd);
1911 let toml = dir.join("rust-src/lib/rustlib/src/rust/src/libstd/Cargo.toml");
1913 Command::new(&builder.initial_cargo)
1914 .arg("generate-lockfile")
1915 .arg("--manifest-path")
1922 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1923 pub struct Bootstrap;
1925 impl Step for Bootstrap {
1927 const DEFAULT: bool = true;
1928 const ONLY_HOSTS: bool = true;
1930 /// Tests the build system itself.
1931 fn run(self, builder: &Builder<'_>) {
1932 let mut cmd = Command::new(&builder.initial_cargo);
1934 .current_dir(builder.src.join("src/bootstrap"))
1935 .env("RUSTFLAGS", "-Cdebuginfo=2")
1936 .env("CARGO_TARGET_DIR", builder.out.join("bootstrap"))
1937 .env("RUSTC_BOOTSTRAP", "1")
1938 .env("RUSTC", &builder.initial_rustc);
1939 if let Some(flags) = option_env!("RUSTFLAGS") {
1940 // Use the same rustc flags for testing as for "normal" compilation,
1941 // so that Cargo doesn’t recompile the entire dependency graph every time:
1942 // https://github.com/rust-lang/rust/issues/49215
1943 cmd.env("RUSTFLAGS", flags);
1945 if !builder.fail_fast {
1946 cmd.arg("--no-fail-fast");
1948 cmd.arg("--").args(&builder.config.cmd.test_args());
1949 // rustbuild tests are racy on directory creation so just run them one at a time.
1950 // Since there's not many this shouldn't be a problem.
1951 cmd.arg("--test-threads=1");
1952 try_run(builder, &mut cmd);
1955 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1956 run.path("src/bootstrap")
1959 fn make_run(run: RunConfig<'_>) {
1960 run.builder.ensure(Bootstrap);