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};
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");
238 cargo.env("PATH", &path_for_cargo(builder, compiler)),
243 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
246 host: Interned<String>,
251 const ONLY_HOSTS: bool = true;
253 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
254 run.path("src/tools/rls")
257 fn make_run(run: RunConfig<'_>) {
258 run.builder.ensure(Rls {
259 stage: run.builder.top_stage,
264 /// Runs `cargo test` for the rls.
265 fn run(self, builder: &Builder<'_>) {
266 let stage = self.stage;
267 let host = self.host;
268 let compiler = builder.compiler(stage, host);
270 let build_result = builder.ensure(tool::Rls {
273 extra_features: Vec::new(),
275 if build_result.is_none() {
276 eprintln!("failed to test rls: could not build");
280 let mut cargo = tool::prepare_tool_cargo(builder,
286 SourceType::Submodule,
289 builder.add_rustc_lib_path(compiler, &mut cargo);
291 .args(builder.config.cmd.test_args());
293 if try_run(builder, &mut cargo) {
294 builder.save_toolstate("rls", ToolState::TestPass);
299 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
302 host: Interned<String>,
305 impl Step for Rustfmt {
307 const ONLY_HOSTS: bool = true;
309 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
310 run.path("src/tools/rustfmt")
313 fn make_run(run: RunConfig<'_>) {
314 run.builder.ensure(Rustfmt {
315 stage: run.builder.top_stage,
320 /// Runs `cargo test` for rustfmt.
321 fn run(self, builder: &Builder<'_>) {
322 let stage = self.stage;
323 let host = self.host;
324 let compiler = builder.compiler(stage, host);
326 let build_result = builder.ensure(tool::Rustfmt {
329 extra_features: Vec::new(),
331 if build_result.is_none() {
332 eprintln!("failed to test rustfmt: could not build");
336 let mut cargo = tool::prepare_tool_cargo(builder,
342 SourceType::Submodule,
345 let dir = testdir(builder, compiler.host);
346 t!(fs::create_dir_all(&dir));
347 cargo.env("RUSTFMT_TEST_DIR", dir);
349 builder.add_rustc_lib_path(compiler, &mut cargo);
351 if try_run(builder, &mut cargo) {
352 builder.save_toolstate("rustfmt", ToolState::TestPass);
357 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
360 host: Interned<String>,
365 const ONLY_HOSTS: bool = true;
366 const DEFAULT: bool = true;
368 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
369 let test_miri = run.builder.config.test_miri;
370 run.path("src/tools/miri").default_condition(test_miri)
373 fn make_run(run: RunConfig<'_>) {
374 run.builder.ensure(Miri {
375 stage: run.builder.top_stage,
380 /// Runs `cargo test` for miri.
381 fn run(self, builder: &Builder<'_>) {
382 let stage = self.stage;
383 let host = self.host;
384 let compiler = builder.compiler(stage, host);
386 let miri = builder.ensure(tool::Miri {
389 extra_features: Vec::new(),
391 if let Some(miri) = miri {
392 let mut cargo = tool::prepare_tool_cargo(builder,
398 SourceType::Submodule,
401 // miri tests need to know about the stage sysroot
402 cargo.env("MIRI_SYSROOT", builder.sysroot(compiler));
403 cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
404 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
405 cargo.env("MIRI_PATH", miri);
407 builder.add_rustc_lib_path(compiler, &mut cargo);
409 if try_run(builder, &mut cargo) {
410 builder.save_toolstate("miri", ToolState::TestPass);
413 eprintln!("failed to test miri: could not build");
418 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
419 pub struct CompiletestTest {
420 host: Interned<String>,
423 impl Step for CompiletestTest {
426 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
427 run.path("src/tools/compiletest")
430 fn make_run(run: RunConfig<'_>) {
431 run.builder.ensure(CompiletestTest {
436 /// Runs `cargo test` for compiletest.
437 fn run(self, builder: &Builder<'_>) {
438 let host = self.host;
439 let compiler = builder.compiler(0, host);
441 let mut cargo = tool::prepare_tool_cargo(builder,
446 "src/tools/compiletest",
450 try_run(builder, &mut cargo);
454 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
457 host: Interned<String>,
460 impl Step for Clippy {
462 const ONLY_HOSTS: bool = true;
463 const DEFAULT: bool = false;
465 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
466 run.path("src/tools/clippy")
469 fn make_run(run: RunConfig<'_>) {
470 run.builder.ensure(Clippy {
471 stage: run.builder.top_stage,
476 /// Runs `cargo test` for clippy.
477 fn run(self, builder: &Builder<'_>) {
478 let stage = self.stage;
479 let host = self.host;
480 let compiler = builder.compiler(stage, host);
482 let clippy = builder.ensure(tool::Clippy {
485 extra_features: Vec::new(),
487 if let Some(clippy) = clippy {
488 let mut cargo = tool::prepare_tool_cargo(builder,
494 SourceType::Submodule,
497 // clippy tests need to know about the stage sysroot
498 cargo.env("SYSROOT", builder.sysroot(compiler));
499 cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
500 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
501 let host_libs = builder
502 .stage_out(compiler, Mode::ToolRustc)
503 .join(builder.cargo_dir());
504 cargo.env("HOST_LIBS", host_libs);
505 // clippy tests need to find the driver
506 cargo.env("CLIPPY_DRIVER_PATH", clippy);
508 builder.add_rustc_lib_path(compiler, &mut cargo);
510 if try_run(builder, &mut cargo) {
511 builder.save_toolstate("clippy-driver", ToolState::TestPass);
514 eprintln!("failed to test clippy: could not build");
519 fn path_for_cargo(builder: &Builder<'_>, compiler: Compiler) -> OsString {
520 // Configure PATH to find the right rustc. NB. we have to use PATH
521 // and not RUSTC because the Cargo test suite has tests that will
522 // fail if rustc is not spelled `rustc`.
523 let path = builder.sysroot(compiler).join("bin");
524 let old_path = env::var_os("PATH").unwrap_or_default();
525 env::join_paths(iter::once(path).chain(env::split_paths(&old_path))).expect("")
528 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
529 pub struct RustdocTheme {
530 pub compiler: Compiler,
533 impl Step for RustdocTheme {
535 const DEFAULT: bool = true;
536 const ONLY_HOSTS: bool = true;
538 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
539 run.path("src/tools/rustdoc-themes")
542 fn make_run(run: RunConfig<'_>) {
543 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
545 run.builder.ensure(RustdocTheme { compiler });
548 fn run(self, builder: &Builder<'_>) {
549 let rustdoc = builder.out.join("bootstrap/debug/rustdoc");
550 let mut cmd = builder.tool_cmd(Tool::RustdocTheme);
551 cmd.arg(rustdoc.to_str().unwrap())
555 .join("src/librustdoc/html/static/themes")
559 .env("RUSTC_STAGE", self.compiler.stage.to_string())
560 .env("RUSTC_SYSROOT", builder.sysroot(self.compiler))
563 builder.sysroot_libdir(self.compiler, self.compiler.host),
565 .env("CFG_RELEASE_CHANNEL", &builder.config.channel)
566 .env("RUSTDOC_REAL", builder.rustdoc(self.compiler))
567 .env("RUSTDOC_CRATE_VERSION", builder.rust_version())
568 .env("RUSTC_BOOTSTRAP", "1");
569 if let Some(linker) = builder.linker(self.compiler.host) {
570 cmd.env("RUSTC_TARGET_LINKER", linker);
572 try_run(builder, &mut cmd);
576 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
577 pub struct RustdocJSStd {
578 pub host: Interned<String>,
579 pub target: Interned<String>,
582 impl Step for RustdocJSStd {
584 const DEFAULT: bool = true;
585 const ONLY_HOSTS: bool = true;
587 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
588 run.path("src/test/rustdoc-js-std")
591 fn make_run(run: RunConfig<'_>) {
592 run.builder.ensure(RustdocJSStd {
598 fn run(self, builder: &Builder<'_>) {
599 if let Some(ref nodejs) = builder.config.nodejs {
600 let mut command = Command::new(nodejs);
601 command.args(&["src/tools/rustdoc-js-std/tester.js", &*self.host]);
602 builder.ensure(crate::doc::Std {
604 stage: builder.top_stage,
606 builder.run(&mut command);
609 "No nodejs found, skipping \"src/test/rustdoc-js-std\" tests"
615 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
616 pub struct RustdocJSNotStd {
617 pub host: Interned<String>,
618 pub target: Interned<String>,
619 pub compiler: Compiler,
622 impl Step for RustdocJSNotStd {
624 const DEFAULT: bool = true;
625 const ONLY_HOSTS: bool = true;
627 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
628 run.path("src/test/rustdoc-js")
631 fn make_run(run: RunConfig<'_>) {
632 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
633 run.builder.ensure(RustdocJSNotStd {
640 fn run(self, builder: &Builder<'_>) {
641 if builder.config.nodejs.is_some() {
642 builder.ensure(Compiletest {
643 compiler: self.compiler,
652 "No nodejs found, skipping \"src/test/rustdoc-js\" tests"
658 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
659 pub struct RustdocUi {
660 pub host: Interned<String>,
661 pub target: Interned<String>,
662 pub compiler: Compiler,
665 impl Step for RustdocUi {
667 const DEFAULT: bool = true;
668 const ONLY_HOSTS: bool = true;
670 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
671 run.path("src/test/rustdoc-ui")
674 fn make_run(run: RunConfig<'_>) {
675 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
676 run.builder.ensure(RustdocUi {
683 fn run(self, builder: &Builder<'_>) {
684 builder.ensure(Compiletest {
685 compiler: self.compiler,
689 path: Some("src/test/rustdoc-ui"),
695 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
700 const DEFAULT: bool = true;
701 const ONLY_HOSTS: bool = true;
703 /// Runs the `tidy` tool.
705 /// This tool in `src/tools` checks up on various bits and pieces of style and
706 /// otherwise just implements a few lint-like checks that are specific to the
708 fn run(self, builder: &Builder<'_>) {
709 let mut cmd = builder.tool_cmd(Tool::Tidy);
710 cmd.arg(builder.src.join("src"));
711 cmd.arg(&builder.initial_cargo);
712 if !builder.config.vendor {
713 cmd.arg("--no-vendor");
715 if builder.is_verbose() {
716 cmd.arg("--verbose");
719 builder.info("tidy check");
720 try_run(builder, &mut cmd);
723 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
724 run.path("src/tools/tidy")
727 fn make_run(run: RunConfig<'_>) {
728 run.builder.ensure(Tidy);
732 fn testdir(builder: &Builder<'_>, host: Interned<String>) -> PathBuf {
733 builder.out.join(host).join("test")
736 macro_rules! default_test {
737 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
738 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: false });
742 macro_rules! default_test_with_compare_mode {
743 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr,
744 compare_mode: $compare_mode:expr }) => {
745 test_with_compare_mode!($name { path: $path, mode: $mode, suite: $suite, default: true,
746 host: false, compare_mode: $compare_mode });
750 macro_rules! host_test {
751 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
752 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: true });
757 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
758 host: $host:expr }) => {
759 test_definitions!($name { path: $path, mode: $mode, suite: $suite, default: $default,
760 host: $host, compare_mode: None });
764 macro_rules! test_with_compare_mode {
765 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
766 host: $host:expr, compare_mode: $compare_mode:expr }) => {
767 test_definitions!($name { path: $path, mode: $mode, suite: $suite, default: $default,
768 host: $host, compare_mode: Some($compare_mode) });
772 macro_rules! test_definitions {
777 default: $default:expr,
779 compare_mode: $compare_mode:expr
781 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
783 pub compiler: Compiler,
784 pub target: Interned<String>,
787 impl Step for $name {
789 const DEFAULT: bool = $default;
790 const ONLY_HOSTS: bool = $host;
792 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
793 run.suite_path($path)
796 fn make_run(run: RunConfig<'_>) {
797 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
799 run.builder.ensure($name {
805 fn run(self, builder: &Builder<'_>) {
806 builder.ensure(Compiletest {
807 compiler: self.compiler,
812 compare_mode: $compare_mode,
819 default_test_with_compare_mode!(Ui {
826 default_test!(CompileFail {
827 path: "src/test/compile-fail",
828 mode: "compile-fail",
829 suite: "compile-fail"
832 default_test!(RunFail {
833 path: "src/test/run-fail",
838 default_test!(RunPassValgrind {
839 path: "src/test/run-pass-valgrind",
840 mode: "run-pass-valgrind",
841 suite: "run-pass-valgrind"
844 default_test!(MirOpt {
845 path: "src/test/mir-opt",
850 default_test!(Codegen {
851 path: "src/test/codegen",
856 default_test!(CodegenUnits {
857 path: "src/test/codegen-units",
858 mode: "codegen-units",
859 suite: "codegen-units"
862 default_test!(Incremental {
863 path: "src/test/incremental",
868 default_test!(Debuginfo {
869 path: "src/test/debuginfo",
874 host_test!(UiFullDeps {
875 path: "src/test/ui-fulldeps",
881 path: "src/test/rustdoc",
887 path: "src/test/pretty",
891 test!(RunFailPretty {
892 path: "src/test/run-fail/pretty",
898 test!(RunPassValgrindPretty {
899 path: "src/test/run-pass-valgrind/pretty",
901 suite: "run-pass-valgrind",
906 default_test!(RunMake {
907 path: "src/test/run-make",
912 host_test!(RunMakeFullDeps {
913 path: "src/test/run-make-fulldeps",
915 suite: "run-make-fulldeps"
918 default_test!(Assembly {
919 path: "src/test/assembly",
924 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
927 target: Interned<String>,
930 path: Option<&'static str>,
931 compare_mode: Option<&'static str>,
934 impl Step for Compiletest {
937 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
941 /// Executes the `compiletest` tool to run a suite of tests.
943 /// Compiles all tests with `compiler` for `target` with the specified
944 /// compiletest `mode` and `suite` arguments. For example `mode` can be
945 /// "run-pass" or `suite` can be something like `debuginfo`.
946 fn run(self, builder: &Builder<'_>) {
947 let compiler = self.compiler;
948 let target = self.target;
949 let mode = self.mode;
950 let suite = self.suite;
952 // Path for test suite
953 let suite_path = self.path.unwrap_or("");
955 // Skip codegen tests if they aren't enabled in configuration.
956 if !builder.config.codegen_tests && suite == "codegen" {
960 if suite == "debuginfo" {
961 let msvc = builder.config.build.contains("msvc");
962 if mode == "debuginfo" {
963 return builder.ensure(Compiletest {
964 mode: if msvc { "debuginfo-cdb" } else { "debuginfo-gdb+lldb" },
969 builder.ensure(dist::DebuggerScripts {
970 sysroot: builder.sysroot(compiler),
975 if suite.ends_with("fulldeps") {
976 builder.ensure(compile::Rustc { compiler, target });
979 if builder.no_std(target) == Some(true) {
980 // the `test` doesn't compile for no-std targets
981 builder.ensure(compile::Std { compiler, target });
983 builder.ensure(compile::Test { compiler, target });
986 if builder.no_std(target) == Some(true) {
987 // for no_std run-make (e.g., thumb*),
988 // we need a host compiler which is called by cargo.
989 builder.ensure(compile::Std { compiler, target: compiler.host });
992 // HACK(eddyb) ensure that `libproc_macro` is available on the host.
993 builder.ensure(compile::Test { compiler, target: compiler.host });
994 // Also provide `rust_test_helpers` for the host.
995 builder.ensure(native::TestHelpers { target: compiler.host });
997 // wasm32 can't build the test helpers
998 if !target.contains("wasm32") {
999 builder.ensure(native::TestHelpers { target });
1001 builder.ensure(RemoteCopyLibs { compiler, target });
1003 let mut cmd = builder.tool_cmd(Tool::Compiletest);
1005 // compiletest currently has... a lot of arguments, so let's just pass all
1008 cmd.arg("--compile-lib-path")
1009 .arg(builder.rustc_libdir(compiler));
1010 cmd.arg("--run-lib-path")
1011 .arg(builder.sysroot_libdir(compiler, target));
1012 cmd.arg("--rustc-path").arg(builder.rustc(compiler));
1014 let is_rustdoc = suite.ends_with("rustdoc-ui") || suite.ends_with("rustdoc-js");
1016 // Avoid depending on rustdoc when we don't need it.
1017 if mode == "rustdoc"
1018 || (mode == "run-make" && suite.ends_with("fulldeps"))
1019 || (mode == "ui" && is_rustdoc)
1020 || mode == "js-doc-test"
1022 cmd.arg("--rustdoc-path")
1023 .arg(builder.rustdoc(compiler));
1026 cmd.arg("--src-base")
1027 .arg(builder.src.join("src/test").join(suite));
1028 cmd.arg("--build-base")
1029 .arg(testdir(builder, compiler.host).join(suite));
1030 cmd.arg("--stage-id")
1031 .arg(format!("stage{}-{}", compiler.stage, target));
1032 cmd.arg("--mode").arg(mode);
1033 cmd.arg("--target").arg(target);
1034 cmd.arg("--host").arg(&*compiler.host);
1035 cmd.arg("--llvm-filecheck")
1036 .arg(builder.llvm_filecheck(builder.config.build));
1038 if builder.config.cmd.bless() {
1042 let compare_mode = builder.config.cmd.compare_mode().or_else(|| {
1043 if builder.config.test_compare_mode {
1050 if let Some(ref pass) = builder.config.cmd.pass() {
1055 if let Some(ref nodejs) = builder.config.nodejs {
1056 cmd.arg("--nodejs").arg(nodejs);
1059 let mut flags = if is_rustdoc {
1062 vec!["-Crpath".to_string()]
1065 if builder.config.rust_optimize_tests {
1066 flags.push("-O".to_string());
1069 flags.push(format!("-Cdebuginfo={}", builder.config.rust_debuginfo_level_tests));
1070 flags.push("-Zunstable-options".to_string());
1071 flags.push(builder.config.cmd.rustc_args().join(" "));
1073 if let Some(linker) = builder.linker(target) {
1074 cmd.arg("--linker").arg(linker);
1077 let mut hostflags = flags.clone();
1078 hostflags.push(format!(
1080 builder.test_helpers_out(compiler.host).display()
1082 cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
1084 let mut targetflags = flags;
1085 targetflags.push(format!(
1087 builder.test_helpers_out(target).display()
1089 cmd.arg("--target-rustcflags").arg(targetflags.join(" "));
1091 cmd.arg("--docck-python").arg(builder.python());
1093 if builder.config.build.ends_with("apple-darwin") {
1094 // Force /usr/bin/python on macOS for LLDB tests because we're loading the
1095 // LLDB plugin's compiled module which only works with the system python
1096 // (namely not Homebrew-installed python)
1097 cmd.arg("--lldb-python").arg("/usr/bin/python");
1099 cmd.arg("--lldb-python").arg(builder.python());
1102 if let Some(ref gdb) = builder.config.gdb {
1103 cmd.arg("--gdb").arg(gdb);
1106 let run = |cmd: &mut Command| {
1107 cmd.output().map(|output| {
1108 String::from_utf8_lossy(&output.stdout)
1109 .lines().next().unwrap_or_else(|| {
1110 panic!("{:?} failed {:?}", cmd, output)
1114 let lldb_exe = if builder.config.lldb_enabled && !target.contains("emscripten") {
1115 // Test against the lldb that was just built.
1116 builder.llvm_out(target).join("bin").join("lldb")
1118 PathBuf::from("lldb")
1120 let lldb_version = Command::new(&lldb_exe)
1123 .map(|output| { String::from_utf8_lossy(&output.stdout).to_string() })
1125 if let Some(ref vers) = lldb_version {
1126 cmd.arg("--lldb-version").arg(vers);
1127 let lldb_python_dir = run(Command::new(&lldb_exe).arg("-P")).ok();
1128 if let Some(ref dir) = lldb_python_dir {
1129 cmd.arg("--lldb-python-dir").arg(dir);
1133 if util::forcing_clang_based_tests() {
1134 let clang_exe = builder.llvm_out(target).join("bin").join("clang");
1135 cmd.arg("--run-clang-based-tests-with").arg(clang_exe);
1138 // Get paths from cmd args
1139 let paths = match &builder.config.cmd {
1140 Subcommand::Test { ref paths, .. } => &paths[..],
1144 // Get test-args by striping suite path
1145 let mut test_args: Vec<&str> = paths
1148 match p.strip_prefix(".") {
1153 .filter(|p| p.starts_with(suite_path) && (p.is_dir() || p.is_file()))
1155 // Since test suite paths are themselves directories, if we don't
1156 // specify a directory or file, we'll get an empty string here
1157 // (the result of the test suite directory without its suite prefix).
1158 // Therefore, we need to filter these out, as only the first --test-args
1159 // flag is respected, so providing an empty --test-args conflicts with
1160 // any following it.
1161 match p.strip_prefix(suite_path).ok().and_then(|p| p.to_str()) {
1162 Some(s) if s != "" => Some(s),
1168 test_args.append(&mut builder.config.cmd.test_args());
1170 cmd.args(&test_args);
1172 if builder.is_verbose() {
1173 cmd.arg("--verbose");
1176 if !builder.config.verbose_tests {
1180 if builder.config.llvm_enabled() {
1181 let llvm_config = builder.ensure(native::Llvm {
1182 target: builder.config.build,
1185 if !builder.config.dry_run {
1186 let llvm_version = output(Command::new(&llvm_config).arg("--version"));
1187 cmd.arg("--llvm-version").arg(llvm_version);
1189 if !builder.is_rust_llvm(target) {
1190 cmd.arg("--system-llvm");
1193 // Only pass correct values for these flags for the `run-make` suite as it
1194 // requires that a C++ compiler was configured which isn't always the case.
1195 if !builder.config.dry_run && suite == "run-make-fulldeps" {
1196 let llvm_components = output(Command::new(&llvm_config).arg("--components"));
1197 let llvm_cxxflags = output(Command::new(&llvm_config).arg("--cxxflags"));
1199 .arg(builder.cc(target))
1201 .arg(builder.cxx(target).unwrap())
1203 .arg(builder.cflags(target, GitRepo::Rustc).join(" "))
1204 .arg("--llvm-components")
1205 .arg(llvm_components.trim())
1206 .arg("--llvm-cxxflags")
1207 .arg(llvm_cxxflags.trim());
1208 if let Some(ar) = builder.ar(target) {
1209 cmd.arg("--ar").arg(ar);
1212 // The llvm/bin directory contains many useful cross-platform
1213 // tools. Pass the path to run-make tests so they can use them.
1214 let llvm_bin_path = llvm_config.parent()
1215 .expect("Expected llvm-config to be contained in directory");
1216 assert!(llvm_bin_path.is_dir());
1217 cmd.arg("--llvm-bin-dir").arg(llvm_bin_path);
1219 // If LLD is available, add it to the PATH
1220 if builder.config.lld_enabled {
1221 let lld_install_root = builder.ensure(native::Lld {
1222 target: builder.config.build,
1225 let lld_bin_path = lld_install_root.join("bin");
1227 let old_path = env::var_os("PATH").unwrap_or_default();
1228 let new_path = env::join_paths(std::iter::once(lld_bin_path)
1229 .chain(env::split_paths(&old_path)))
1230 .expect("Could not add LLD bin path to PATH");
1231 cmd.env("PATH", new_path);
1236 if suite != "run-make-fulldeps" {
1243 .arg("--llvm-components")
1245 .arg("--llvm-cxxflags")
1249 if builder.remote_tested(target) {
1250 cmd.arg("--remote-test-client")
1251 .arg(builder.tool_exe(Tool::RemoteTestClient));
1254 // Running a C compiler on MSVC requires a few env vars to be set, to be
1255 // sure to set them here.
1257 // Note that if we encounter `PATH` we make sure to append to our own `PATH`
1258 // rather than stomp over it.
1259 if target.contains("msvc") {
1260 for &(ref k, ref v) in builder.cc[&target].env() {
1266 cmd.env("RUSTC_BOOTSTRAP", "1");
1267 builder.add_rust_test_threads(&mut cmd);
1269 if builder.config.sanitizers {
1270 cmd.env("RUSTC_SANITIZER_SUPPORT", "1");
1273 if builder.config.profiler {
1274 cmd.env("RUSTC_PROFILER_SUPPORT", "1");
1277 cmd.env("RUST_TEST_TMPDIR", builder.out.join("tmp"));
1279 cmd.arg("--adb-path").arg("adb");
1280 cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
1281 if target.contains("android") {
1282 // Assume that cc for this target comes from the android sysroot
1283 cmd.arg("--android-cross-path")
1284 .arg(builder.cc(target).parent().unwrap().parent().unwrap());
1286 cmd.arg("--android-cross-path").arg("");
1289 if builder.config.cmd.rustfix_coverage() {
1290 cmd.arg("--rustfix-coverage");
1293 builder.ci_env.force_coloring_in_ci(&mut cmd);
1295 builder.info(&format!(
1296 "Check compiletest suite={} mode={} ({} -> {})",
1297 suite, mode, &compiler.host, target
1299 let _time = util::timeit(&builder);
1300 try_run(builder, &mut cmd);
1302 if let Some(compare_mode) = compare_mode {
1303 cmd.arg("--compare-mode").arg(compare_mode);
1304 builder.info(&format!(
1305 "Check compiletest suite={} mode={} compare_mode={} ({} -> {})",
1306 suite, mode, compare_mode, &compiler.host, target
1308 let _time = util::timeit(&builder);
1309 try_run(builder, &mut cmd);
1314 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1322 impl Step for DocTest {
1324 const ONLY_HOSTS: bool = true;
1326 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1330 /// Runs `rustdoc --test` for all documentation in `src/doc`.
1332 /// This will run all tests in our markdown documentation (e.g., the book)
1333 /// located in `src/doc`. The `rustdoc` that's run is the one that sits next to
1335 fn run(self, builder: &Builder<'_>) {
1336 let compiler = self.compiler;
1338 builder.ensure(compile::Test {
1340 target: compiler.host,
1343 // Do a breadth-first traversal of the `src/doc` directory and just run
1344 // tests for all files that end in `*.md`
1345 let mut stack = vec![builder.src.join(self.path)];
1346 let _time = util::timeit(&builder);
1348 let mut files = Vec::new();
1349 while let Some(p) = stack.pop() {
1351 stack.extend(t!(p.read_dir()).map(|p| t!(p).path()));
1355 if p.extension().and_then(|s| s.to_str()) != Some("md") {
1359 // The nostarch directory in the book is for no starch, and so isn't
1360 // guaranteed to builder. We don't care if it doesn't build, so skip it.
1361 if p.to_str().map_or(false, |p| p.contains("nostarch")) {
1370 let mut toolstate = ToolState::TestPass;
1372 if !markdown_test(builder, compiler, &file) {
1373 toolstate = ToolState::TestFail;
1376 if self.is_ext_doc {
1377 builder.save_toolstate(self.name, toolstate);
1382 macro_rules! test_book {
1383 ($($name:ident, $path:expr, $book_name:expr, default=$default:expr;)+) => {
1385 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1390 impl Step for $name {
1392 const DEFAULT: bool = $default;
1393 const ONLY_HOSTS: bool = true;
1395 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1399 fn make_run(run: RunConfig<'_>) {
1400 run.builder.ensure($name {
1401 compiler: run.builder.compiler(run.builder.top_stage, run.host),
1405 fn run(self, builder: &Builder<'_>) {
1406 builder.ensure(DocTest {
1407 compiler: self.compiler,
1410 is_ext_doc: !$default,
1419 Nomicon, "src/doc/nomicon", "nomicon", default=false;
1420 Reference, "src/doc/reference", "reference", default=false;
1421 RustdocBook, "src/doc/rustdoc", "rustdoc", default=true;
1422 RustcBook, "src/doc/rustc", "rustc", default=true;
1423 RustByExample, "src/doc/rust-by-example", "rust-by-example", default=false;
1424 EmbeddedBook, "src/doc/embedded-book", "embedded-book", default=false;
1425 TheBook, "src/doc/book", "book", default=false;
1426 UnstableBook, "src/doc/unstable-book", "unstable-book", default=true;
1427 EditionGuide, "src/doc/edition-guide", "edition-guide", default=false;
1430 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1431 pub struct ErrorIndex {
1435 impl Step for ErrorIndex {
1437 const DEFAULT: bool = true;
1438 const ONLY_HOSTS: bool = true;
1440 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1441 run.path("src/tools/error_index_generator")
1444 fn make_run(run: RunConfig<'_>) {
1445 run.builder.ensure(ErrorIndex {
1446 compiler: run.builder.compiler(run.builder.top_stage, run.host),
1450 /// Runs the error index generator tool to execute the tests located in the error
1453 /// The `error_index_generator` tool lives in `src/tools` and is used to
1454 /// generate a markdown file from the error indexes of the code base which is
1455 /// then passed to `rustdoc --test`.
1456 fn run(self, builder: &Builder<'_>) {
1457 let compiler = self.compiler;
1459 builder.ensure(compile::Std {
1461 target: compiler.host,
1464 let dir = testdir(builder, compiler.host);
1465 t!(fs::create_dir_all(&dir));
1466 let output = dir.join("error-index.md");
1468 let mut tool = tool::ErrorIndex::command(
1470 builder.compiler(compiler.stage, builder.config.build),
1472 tool.arg("markdown")
1474 .env("CFG_BUILD", &builder.config.build)
1475 .env("RUSTC_ERROR_METADATA_DST", builder.extended_error_dir());
1477 builder.info(&format!("Testing error-index stage{}", compiler.stage));
1478 let _time = util::timeit(&builder);
1479 builder.run_quiet(&mut tool);
1480 markdown_test(builder, compiler, &output);
1484 fn markdown_test(builder: &Builder<'_>, compiler: Compiler, markdown: &Path) -> bool {
1485 match fs::read_to_string(markdown) {
1487 if !contents.contains("```") {
1494 builder.info(&format!("doc tests for: {}", markdown.display()));
1495 let mut cmd = builder.rustdoc_cmd(compiler);
1496 builder.add_rust_test_threads(&mut cmd);
1499 cmd.env("RUSTC_BOOTSTRAP", "1");
1501 let test_args = builder.config.cmd.test_args().join(" ");
1502 cmd.arg("--test-args").arg(test_args);
1504 if builder.config.verbose_tests {
1505 try_run(builder, &mut cmd)
1507 try_run_quiet(builder, &mut cmd)
1511 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1512 pub struct RustcGuide;
1514 impl Step for RustcGuide {
1516 const DEFAULT: bool = false;
1517 const ONLY_HOSTS: bool = true;
1519 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1520 run.path("src/doc/rustc-guide")
1523 fn make_run(run: RunConfig<'_>) {
1524 run.builder.ensure(RustcGuide);
1527 fn run(self, builder: &Builder<'_>) {
1528 let src = builder.src.join("src/doc/rustc-guide");
1529 let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
1530 let toolstate = if try_run(builder, rustbook_cmd.arg("linkcheck").arg(&src)) {
1535 builder.save_toolstate("rustc-guide", toolstate);
1539 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1540 pub struct CrateLibrustc {
1542 target: Interned<String>,
1543 test_kind: TestKind,
1544 krate: Interned<String>,
1547 impl Step for CrateLibrustc {
1549 const DEFAULT: bool = true;
1550 const ONLY_HOSTS: bool = true;
1552 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1553 run.krate("rustc-main")
1556 fn make_run(run: RunConfig<'_>) {
1557 let builder = run.builder;
1558 let compiler = builder.compiler(builder.top_stage, run.host);
1560 for krate in builder.in_tree_crates("rustc-main") {
1561 if run.path.ends_with(&krate.path) {
1562 let test_kind = builder.kind.into();
1564 builder.ensure(CrateLibrustc {
1574 fn run(self, builder: &Builder<'_>) {
1575 builder.ensure(Crate {
1576 compiler: self.compiler,
1577 target: self.target,
1579 test_kind: self.test_kind,
1585 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1586 pub struct CrateNotDefault {
1588 target: Interned<String>,
1589 test_kind: TestKind,
1590 krate: &'static str,
1593 impl Step for CrateNotDefault {
1596 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1597 run.path("src/librustc_asan")
1598 .path("src/librustc_lsan")
1599 .path("src/librustc_msan")
1600 .path("src/librustc_tsan")
1603 fn make_run(run: RunConfig<'_>) {
1604 let builder = run.builder;
1605 let compiler = builder.compiler(builder.top_stage, run.host);
1607 let test_kind = builder.kind.into();
1609 builder.ensure(CrateNotDefault {
1613 krate: match run.path {
1614 _ if run.path.ends_with("src/librustc_asan") => "rustc_asan",
1615 _ if run.path.ends_with("src/librustc_lsan") => "rustc_lsan",
1616 _ if run.path.ends_with("src/librustc_msan") => "rustc_msan",
1617 _ if run.path.ends_with("src/librustc_tsan") => "rustc_tsan",
1618 _ => panic!("unexpected path {:?}", run.path),
1623 fn run(self, builder: &Builder<'_>) {
1624 builder.ensure(Crate {
1625 compiler: self.compiler,
1626 target: self.target,
1628 test_kind: self.test_kind,
1629 krate: INTERNER.intern_str(self.krate),
1634 #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
1636 pub compiler: Compiler,
1637 pub target: Interned<String>,
1639 pub test_kind: TestKind,
1640 pub krate: Interned<String>,
1643 impl Step for Crate {
1645 const DEFAULT: bool = true;
1647 fn should_run(mut run: ShouldRun<'_>) -> ShouldRun<'_> {
1648 let builder = run.builder;
1649 run = run.krate("test");
1650 for krate in run.builder.in_tree_crates("std") {
1651 if !(krate.name.starts_with("rustc_") && krate.name.ends_with("san")) {
1652 run = run.path(krate.local_path(&builder).to_str().unwrap());
1658 fn make_run(run: RunConfig<'_>) {
1659 let builder = run.builder;
1660 let compiler = builder.compiler(builder.top_stage, run.host);
1662 let make = |mode: Mode, krate: &CargoCrate| {
1663 let test_kind = builder.kind.into();
1665 builder.ensure(Crate {
1674 for krate in builder.in_tree_crates("std") {
1675 if run.path.ends_with(&krate.local_path(&builder)) {
1676 make(Mode::Std, krate);
1679 for krate in builder.in_tree_crates("test") {
1680 if run.path.ends_with(&krate.local_path(&builder)) {
1681 make(Mode::Test, krate);
1686 /// Runs all unit tests plus documentation tests for a given crate defined
1687 /// by a `Cargo.toml` (single manifest)
1689 /// This is what runs tests for crates like the standard library, compiler, etc.
1690 /// It essentially is the driver for running `cargo test`.
1692 /// Currently this runs all tests for a DAG by passing a bunch of `-p foo`
1693 /// arguments, and those arguments are discovered from `cargo metadata`.
1694 fn run(self, builder: &Builder<'_>) {
1695 let compiler = self.compiler;
1696 let target = self.target;
1697 let mode = self.mode;
1698 let test_kind = self.test_kind;
1699 let krate = self.krate;
1701 builder.ensure(compile::Test { compiler, target });
1702 builder.ensure(RemoteCopyLibs { compiler, target });
1704 // If we're not doing a full bootstrap but we're testing a stage2
1705 // version of libstd, then what we're actually testing is the libstd
1706 // produced in stage1. Reflect that here by updating the compiler that
1707 // we're working with automatically.
1708 let compiler = builder.compiler_for(compiler.stage, compiler.host, target);
1710 let mut cargo = builder.cargo(compiler, mode, target, test_kind.subcommand());
1713 compile::std_cargo(builder, &compiler, target, &mut cargo);
1716 compile::test_cargo(builder, &compiler, target, &mut cargo);
1719 builder.ensure(compile::Rustc { compiler, target });
1720 compile::rustc_cargo(builder, &mut cargo);
1722 _ => panic!("can only test libraries"),
1725 // Build up the base `cargo test` command.
1727 // Pass in some standard flags then iterate over the graph we've discovered
1728 // in `cargo metadata` with the maps above and figure out what `-p`
1729 // arguments need to get passed.
1730 if test_kind.subcommand() == "test" && !builder.fail_fast {
1731 cargo.arg("--no-fail-fast");
1733 match builder.doc_tests {
1738 cargo.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
1743 cargo.arg("-p").arg(krate);
1745 // The tests are going to run with the *target* libraries, so we need to
1746 // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
1748 // Note that to run the compiler we need to run with the *host* libraries,
1749 // but our wrapper scripts arrange for that to be the case anyway.
1750 let mut dylib_path = dylib_path();
1751 dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
1752 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
1755 cargo.args(&builder.config.cmd.test_args());
1757 if !builder.config.verbose_tests {
1758 cargo.arg("--quiet");
1761 if target.contains("emscripten") {
1763 format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
1768 .expect("nodejs not configured"),
1770 } else if target.starts_with("wasm32") {
1771 // Warn about running tests without the `wasm_syscall` feature enabled.
1772 // The javascript shim implements the syscall interface so that test
1773 // output can be correctly reported.
1774 if !builder.config.wasm_syscall {
1776 "Libstd was built without `wasm_syscall` feature enabled: \
1777 test output may not be visible."
1781 // On the wasm32-unknown-unknown target we're using LTO which is
1782 // incompatible with `-C prefer-dynamic`, so disable that here
1783 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
1789 .expect("nodejs not configured");
1790 let runner = format!(
1791 "{} {}/src/etc/wasm32-shim.js",
1793 builder.src.display()
1795 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)), &runner);
1796 } else if builder.remote_tested(target) {
1798 format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
1799 format!("{} run", builder.tool_exe(Tool::RemoteTestClient).display()),
1803 builder.info(&format!(
1804 "{} {} stage{} ({} -> {})",
1805 test_kind, krate, compiler.stage, &compiler.host, target
1807 let _time = util::timeit(&builder);
1808 try_run(builder, &mut cargo);
1812 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1813 pub struct CrateRustdoc {
1814 host: Interned<String>,
1815 test_kind: TestKind,
1818 impl Step for CrateRustdoc {
1820 const DEFAULT: bool = true;
1821 const ONLY_HOSTS: bool = true;
1823 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1824 run.paths(&["src/librustdoc", "src/tools/rustdoc"])
1827 fn make_run(run: RunConfig<'_>) {
1828 let builder = run.builder;
1830 let test_kind = builder.kind.into();
1832 builder.ensure(CrateRustdoc {
1838 fn run(self, builder: &Builder<'_>) {
1839 let test_kind = self.test_kind;
1841 let compiler = builder.compiler(builder.top_stage, self.host);
1842 let target = compiler.host;
1843 builder.ensure(compile::Rustc { compiler, target });
1845 let mut cargo = tool::prepare_tool_cargo(builder,
1849 test_kind.subcommand(),
1850 "src/tools/rustdoc",
1853 if test_kind.subcommand() == "test" && !builder.fail_fast {
1854 cargo.arg("--no-fail-fast");
1857 cargo.arg("-p").arg("rustdoc:0.0.0");
1860 cargo.args(&builder.config.cmd.test_args());
1862 if self.host.contains("musl") {
1863 cargo.arg("'-Ctarget-feature=-crt-static'");
1866 if !builder.config.verbose_tests {
1867 cargo.arg("--quiet");
1870 builder.info(&format!(
1871 "{} rustdoc stage{} ({} -> {})",
1872 test_kind, compiler.stage, &compiler.host, target
1874 let _time = util::timeit(&builder);
1876 try_run(builder, &mut cargo);
1880 fn envify(s: &str) -> String {
1886 .flat_map(|c| c.to_uppercase())
1890 /// Some test suites are run inside emulators or on remote devices, and most
1891 /// of our test binaries are linked dynamically which means we need to ship
1892 /// the standard library and such to the emulator ahead of time. This step
1893 /// represents this and is a dependency of all test suites.
1895 /// Most of the time this is a no-op. For some steps such as shipping data to
1896 /// QEMU we have to build our own tools so we've got conditional dependencies
1897 /// on those programs as well. Note that the remote test client is built for
1898 /// the build target (us) and the server is built for the target.
1899 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1900 pub struct RemoteCopyLibs {
1902 target: Interned<String>,
1905 impl Step for RemoteCopyLibs {
1908 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1912 fn run(self, builder: &Builder<'_>) {
1913 let compiler = self.compiler;
1914 let target = self.target;
1915 if !builder.remote_tested(target) {
1919 builder.ensure(compile::Test { compiler, target });
1921 builder.info(&format!("REMOTE copy libs to emulator ({})", target));
1922 t!(fs::create_dir_all(builder.out.join("tmp")));
1924 let server = builder.ensure(tool::RemoteTestServer {
1925 compiler: compiler.with_stage(0),
1929 // Spawn the emulator and wait for it to come online
1930 let tool = builder.tool_exe(Tool::RemoteTestClient);
1931 let mut cmd = Command::new(&tool);
1932 cmd.arg("spawn-emulator")
1935 .arg(builder.out.join("tmp"));
1936 if let Some(rootfs) = builder.qemu_rootfs(target) {
1939 builder.run(&mut cmd);
1941 // Push all our dylibs to the emulator
1942 for f in t!(builder.sysroot_libdir(compiler, target).read_dir()) {
1944 let name = f.file_name().into_string().unwrap();
1945 if util::is_dylib(&name) {
1946 builder.run(Command::new(&tool).arg("push").arg(f.path()));
1952 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1953 pub struct Distcheck;
1955 impl Step for Distcheck {
1958 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1959 run.path("distcheck")
1962 fn make_run(run: RunConfig<'_>) {
1963 run.builder.ensure(Distcheck);
1966 /// Runs "distcheck", a 'make check' from a tarball
1967 fn run(self, builder: &Builder<'_>) {
1968 builder.info("Distcheck");
1969 let dir = builder.out.join("tmp").join("distcheck");
1970 let _ = fs::remove_dir_all(&dir);
1971 t!(fs::create_dir_all(&dir));
1973 // Guarantee that these are built before we begin running.
1974 builder.ensure(dist::PlainSourceTarball);
1975 builder.ensure(dist::Src);
1977 let mut cmd = Command::new("tar");
1979 .arg(builder.ensure(dist::PlainSourceTarball))
1980 .arg("--strip-components=1")
1982 builder.run(&mut cmd);
1984 Command::new("./configure")
1985 .args(&builder.config.configure_args)
1986 .arg("--enable-vendor")
1990 Command::new(build_helper::make(&builder.config.build))
1995 // Now make sure that rust-src has all of libstd's dependencies
1996 builder.info("Distcheck rust-src");
1997 let dir = builder.out.join("tmp").join("distcheck-src");
1998 let _ = fs::remove_dir_all(&dir);
1999 t!(fs::create_dir_all(&dir));
2001 let mut cmd = Command::new("tar");
2003 .arg(builder.ensure(dist::Src))
2004 .arg("--strip-components=1")
2006 builder.run(&mut cmd);
2008 let toml = dir.join("rust-src/lib/rustlib/src/rust/src/libstd/Cargo.toml");
2010 Command::new(&builder.initial_cargo)
2011 .arg("generate-lockfile")
2012 .arg("--manifest-path")
2019 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2020 pub struct Bootstrap;
2022 impl Step for Bootstrap {
2024 const DEFAULT: bool = true;
2025 const ONLY_HOSTS: bool = true;
2027 /// Tests the build system itself.
2028 fn run(self, builder: &Builder<'_>) {
2029 let mut cmd = Command::new(&builder.initial_cargo);
2031 .current_dir(builder.src.join("src/bootstrap"))
2032 .env("RUSTFLAGS", "-Cdebuginfo=2")
2033 .env("CARGO_TARGET_DIR", builder.out.join("bootstrap"))
2034 .env("RUSTC_BOOTSTRAP", "1")
2035 .env("RUSTC", &builder.initial_rustc);
2036 if let Some(flags) = option_env!("RUSTFLAGS") {
2037 // Use the same rustc flags for testing as for "normal" compilation,
2038 // so that Cargo doesn’t recompile the entire dependency graph every time:
2039 // https://github.com/rust-lang/rust/issues/49215
2040 cmd.env("RUSTFLAGS", flags);
2042 if !builder.fail_fast {
2043 cmd.arg("--no-fail-fast");
2045 cmd.arg("--").args(&builder.config.cmd.test_args());
2046 // rustbuild tests are racy on directory creation so just run them one at a time.
2047 // Since there's not many this shouldn't be a problem.
2048 cmd.arg("--test-threads=1");
2049 try_run(builder, &mut cmd);
2052 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2053 run.path("src/bootstrap")
2056 fn make_run(run: RunConfig<'_>) {
2057 run.builder.ensure(Bootstrap);