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");
235 cargo.env("PATH", &path_for_cargo(builder, compiler)),
240 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
243 host: Interned<String>,
248 const ONLY_HOSTS: bool = true;
250 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
251 run.path("src/tools/rls")
254 fn make_run(run: RunConfig<'_>) {
255 run.builder.ensure(Rls {
256 stage: run.builder.top_stage,
261 /// Runs `cargo test` for the rls.
262 fn run(self, builder: &Builder<'_>) {
263 let stage = self.stage;
264 let host = self.host;
265 let compiler = builder.compiler(stage, host);
267 let build_result = builder.ensure(tool::Rls {
270 extra_features: Vec::new(),
272 if build_result.is_none() {
273 eprintln!("failed to test rls: could not build");
277 let mut cargo = tool::prepare_tool_cargo(builder,
283 SourceType::Submodule,
286 builder.add_rustc_lib_path(compiler, &mut cargo);
288 .args(builder.config.cmd.test_args());
290 if try_run(builder, &mut cargo) {
291 builder.save_toolstate("rls", ToolState::TestPass);
296 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
299 host: Interned<String>,
302 impl Step for Rustfmt {
304 const ONLY_HOSTS: bool = true;
306 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
307 run.path("src/tools/rustfmt")
310 fn make_run(run: RunConfig<'_>) {
311 run.builder.ensure(Rustfmt {
312 stage: run.builder.top_stage,
317 /// Runs `cargo test` for rustfmt.
318 fn run(self, builder: &Builder<'_>) {
319 let stage = self.stage;
320 let host = self.host;
321 let compiler = builder.compiler(stage, host);
323 let build_result = builder.ensure(tool::Rustfmt {
326 extra_features: Vec::new(),
328 if build_result.is_none() {
329 eprintln!("failed to test rustfmt: could not build");
333 let mut cargo = tool::prepare_tool_cargo(builder,
339 SourceType::Submodule,
342 let dir = testdir(builder, compiler.host);
343 t!(fs::create_dir_all(&dir));
344 cargo.env("RUSTFMT_TEST_DIR", dir);
346 builder.add_rustc_lib_path(compiler, &mut cargo);
348 if try_run(builder, &mut cargo) {
349 builder.save_toolstate("rustfmt", ToolState::TestPass);
354 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
357 host: Interned<String>,
362 const ONLY_HOSTS: bool = true;
363 const DEFAULT: bool = true;
365 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
366 let test_miri = run.builder.config.test_miri;
367 run.path("src/tools/miri").default_condition(test_miri)
370 fn make_run(run: RunConfig<'_>) {
371 run.builder.ensure(Miri {
372 stage: run.builder.top_stage,
377 /// Runs `cargo test` for miri.
378 fn run(self, builder: &Builder<'_>) {
379 let stage = self.stage;
380 let host = self.host;
381 let compiler = builder.compiler(stage, host);
383 let miri = builder.ensure(tool::Miri {
386 extra_features: Vec::new(),
388 if let Some(miri) = miri {
389 let mut cargo = tool::prepare_tool_cargo(builder,
395 SourceType::Submodule,
398 // miri tests need to know about the stage sysroot
399 cargo.env("MIRI_SYSROOT", builder.sysroot(compiler));
400 cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
401 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
402 cargo.env("MIRI_PATH", miri);
404 builder.add_rustc_lib_path(compiler, &mut cargo);
406 if try_run(builder, &mut cargo) {
407 builder.save_toolstate("miri", ToolState::TestPass);
410 eprintln!("failed to test miri: could not build");
415 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
416 pub struct CompiletestTest {
417 host: Interned<String>,
420 impl Step for CompiletestTest {
423 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
424 run.path("src/tools/compiletest")
427 fn make_run(run: RunConfig<'_>) {
428 run.builder.ensure(CompiletestTest {
433 /// Runs `cargo test` for compiletest.
434 fn run(self, builder: &Builder<'_>) {
435 let host = self.host;
436 let compiler = builder.compiler(0, host);
438 let mut cargo = tool::prepare_tool_cargo(builder,
443 "src/tools/compiletest",
447 try_run(builder, &mut cargo);
451 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
454 host: Interned<String>,
457 impl Step for Clippy {
459 const ONLY_HOSTS: bool = true;
460 const DEFAULT: bool = false;
462 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
463 run.path("src/tools/clippy")
466 fn make_run(run: RunConfig<'_>) {
467 run.builder.ensure(Clippy {
468 stage: run.builder.top_stage,
473 /// Runs `cargo test` for clippy.
474 fn run(self, builder: &Builder<'_>) {
475 let stage = self.stage;
476 let host = self.host;
477 let compiler = builder.compiler(stage, host);
479 let clippy = builder.ensure(tool::Clippy {
482 extra_features: Vec::new(),
484 if let Some(clippy) = clippy {
485 let mut cargo = tool::prepare_tool_cargo(builder,
491 SourceType::Submodule,
494 // clippy tests need to know about the stage sysroot
495 cargo.env("SYSROOT", builder.sysroot(compiler));
496 cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
497 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
498 let host_libs = builder
499 .stage_out(compiler, Mode::ToolRustc)
500 .join(builder.cargo_dir());
501 cargo.env("HOST_LIBS", host_libs);
502 // clippy tests need to find the driver
503 cargo.env("CLIPPY_DRIVER_PATH", clippy);
505 builder.add_rustc_lib_path(compiler, &mut cargo);
507 if try_run(builder, &mut cargo) {
508 builder.save_toolstate("clippy-driver", ToolState::TestPass);
511 eprintln!("failed to test clippy: could not build");
516 fn path_for_cargo(builder: &Builder<'_>, compiler: Compiler) -> OsString {
517 // Configure PATH to find the right rustc. NB. we have to use PATH
518 // and not RUSTC because the Cargo test suite has tests that will
519 // fail if rustc is not spelled `rustc`.
520 let path = builder.sysroot(compiler).join("bin");
521 let old_path = env::var_os("PATH").unwrap_or_default();
522 env::join_paths(iter::once(path).chain(env::split_paths(&old_path))).expect("")
525 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
526 pub struct RustdocTheme {
527 pub compiler: Compiler,
530 impl Step for RustdocTheme {
532 const DEFAULT: bool = true;
533 const ONLY_HOSTS: bool = true;
535 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
536 run.path("src/tools/rustdoc-themes")
539 fn make_run(run: RunConfig<'_>) {
540 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
542 run.builder.ensure(RustdocTheme { compiler });
545 fn run(self, builder: &Builder<'_>) {
546 let rustdoc = builder.out.join("bootstrap/debug/rustdoc");
547 let mut cmd = builder.tool_cmd(Tool::RustdocTheme);
548 cmd.arg(rustdoc.to_str().unwrap())
552 .join("src/librustdoc/html/static/themes")
556 .env("RUSTC_STAGE", self.compiler.stage.to_string())
557 .env("RUSTC_SYSROOT", builder.sysroot(self.compiler))
560 builder.sysroot_libdir(self.compiler, self.compiler.host),
562 .env("CFG_RELEASE_CHANNEL", &builder.config.channel)
563 .env("RUSTDOC_REAL", builder.rustdoc(self.compiler))
564 .env("RUSTDOC_CRATE_VERSION", builder.rust_version())
565 .env("RUSTC_BOOTSTRAP", "1");
566 if let Some(linker) = builder.linker(self.compiler.host) {
567 cmd.env("RUSTC_TARGET_LINKER", linker);
569 try_run(builder, &mut cmd);
573 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
574 pub struct RustdocJSStd {
575 pub host: Interned<String>,
576 pub target: Interned<String>,
579 impl Step for RustdocJSStd {
581 const DEFAULT: bool = true;
582 const ONLY_HOSTS: bool = true;
584 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
585 run.path("src/test/rustdoc-js-std")
588 fn make_run(run: RunConfig<'_>) {
589 run.builder.ensure(RustdocJSStd {
595 fn run(self, builder: &Builder<'_>) {
596 if let Some(ref nodejs) = builder.config.nodejs {
597 let mut command = Command::new(nodejs);
598 command.args(&["src/tools/rustdoc-js-std/tester.js", &*self.host]);
599 builder.ensure(crate::doc::Std {
601 stage: builder.top_stage,
603 builder.run(&mut command);
606 "No nodejs found, skipping \"src/test/rustdoc-js-std\" tests"
612 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
613 pub struct RustdocJSNotStd {
614 pub host: Interned<String>,
615 pub target: Interned<String>,
616 pub compiler: Compiler,
619 impl Step for RustdocJSNotStd {
621 const DEFAULT: bool = true;
622 const ONLY_HOSTS: bool = true;
624 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
625 run.path("src/test/rustdoc-js")
628 fn make_run(run: RunConfig<'_>) {
629 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
630 run.builder.ensure(RustdocJSNotStd {
637 fn run(self, builder: &Builder<'_>) {
638 if builder.config.nodejs.is_some() {
639 builder.ensure(Compiletest {
640 compiler: self.compiler,
649 "No nodejs found, skipping \"src/test/rustdoc-js\" tests"
655 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
656 pub struct RustdocUi {
657 pub host: Interned<String>,
658 pub target: Interned<String>,
659 pub compiler: Compiler,
662 impl Step for RustdocUi {
664 const DEFAULT: bool = true;
665 const ONLY_HOSTS: bool = true;
667 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
668 run.path("src/test/rustdoc-ui")
671 fn make_run(run: RunConfig<'_>) {
672 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
673 run.builder.ensure(RustdocUi {
680 fn run(self, builder: &Builder<'_>) {
681 builder.ensure(Compiletest {
682 compiler: self.compiler,
686 path: Some("src/test/rustdoc-ui"),
692 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
697 const DEFAULT: bool = true;
698 const ONLY_HOSTS: bool = true;
700 /// Runs the `tidy` tool.
702 /// This tool in `src/tools` checks up on various bits and pieces of style and
703 /// otherwise just implements a few lint-like checks that are specific to the
705 fn run(self, builder: &Builder<'_>) {
706 let mut cmd = builder.tool_cmd(Tool::Tidy);
707 cmd.arg(builder.src.join("src"));
708 cmd.arg(&builder.initial_cargo);
709 if !builder.config.vendor {
710 cmd.arg("--no-vendor");
712 if !builder.config.verbose_tests {
716 let _folder = builder.fold_output(|| "tidy");
717 builder.info("tidy check");
718 try_run(builder, &mut cmd);
721 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
722 run.path("src/tools/tidy")
725 fn make_run(run: RunConfig<'_>) {
726 run.builder.ensure(Tidy);
730 fn testdir(builder: &Builder<'_>, host: Interned<String>) -> PathBuf {
731 builder.out.join(host).join("test")
734 macro_rules! default_test {
735 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
736 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: false });
740 macro_rules! default_test_with_compare_mode {
741 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr,
742 compare_mode: $compare_mode:expr }) => {
743 test_with_compare_mode!($name { path: $path, mode: $mode, suite: $suite, default: true,
744 host: false, compare_mode: $compare_mode });
748 macro_rules! host_test {
749 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
750 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: true });
755 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
756 host: $host:expr }) => {
757 test_definitions!($name { path: $path, mode: $mode, suite: $suite, default: $default,
758 host: $host, compare_mode: None });
762 macro_rules! test_with_compare_mode {
763 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
764 host: $host:expr, compare_mode: $compare_mode:expr }) => {
765 test_definitions!($name { path: $path, mode: $mode, suite: $suite, default: $default,
766 host: $host, compare_mode: Some($compare_mode) });
770 macro_rules! test_definitions {
775 default: $default:expr,
777 compare_mode: $compare_mode:expr
779 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
781 pub compiler: Compiler,
782 pub target: Interned<String>,
785 impl Step for $name {
787 const DEFAULT: bool = $default;
788 const ONLY_HOSTS: bool = $host;
790 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
791 run.suite_path($path)
794 fn make_run(run: RunConfig<'_>) {
795 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
797 run.builder.ensure($name {
803 fn run(self, builder: &Builder<'_>) {
804 builder.ensure(Compiletest {
805 compiler: self.compiler,
810 compare_mode: $compare_mode,
817 default_test_with_compare_mode!(Ui {
824 default_test_with_compare_mode!(RunPass {
825 path: "src/test/run-pass",
831 default_test!(CompileFail {
832 path: "src/test/compile-fail",
833 mode: "compile-fail",
834 suite: "compile-fail"
837 default_test!(RunFail {
838 path: "src/test/run-fail",
843 default_test!(RunPassValgrind {
844 path: "src/test/run-pass-valgrind",
845 mode: "run-pass-valgrind",
846 suite: "run-pass-valgrind"
849 default_test!(MirOpt {
850 path: "src/test/mir-opt",
855 default_test!(Codegen {
856 path: "src/test/codegen",
861 default_test!(CodegenUnits {
862 path: "src/test/codegen-units",
863 mode: "codegen-units",
864 suite: "codegen-units"
867 default_test!(Incremental {
868 path: "src/test/incremental",
873 default_test!(Debuginfo {
874 path: "src/test/debuginfo",
879 host_test!(UiFullDeps {
880 path: "src/test/ui-fulldeps",
885 host_test!(RunPassFullDeps {
886 path: "src/test/run-pass-fulldeps",
888 suite: "run-pass-fulldeps"
892 path: "src/test/rustdoc",
898 path: "src/test/pretty",
902 test!(RunPassPretty {
903 path: "src/test/run-pass/pretty",
909 test!(RunFailPretty {
910 path: "src/test/run-fail/pretty",
916 test!(RunPassValgrindPretty {
917 path: "src/test/run-pass-valgrind/pretty",
919 suite: "run-pass-valgrind",
924 default_test!(RunMake {
925 path: "src/test/run-make",
930 host_test!(RunMakeFullDeps {
931 path: "src/test/run-make-fulldeps",
933 suite: "run-make-fulldeps"
936 default_test!(Assembly {
937 path: "src/test/assembly",
942 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
945 target: Interned<String>,
948 path: Option<&'static str>,
949 compare_mode: Option<&'static str>,
952 impl Step for Compiletest {
955 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
959 /// Executes the `compiletest` tool to run a suite of tests.
961 /// Compiles all tests with `compiler` for `target` with the specified
962 /// compiletest `mode` and `suite` arguments. For example `mode` can be
963 /// "run-pass" or `suite` can be something like `debuginfo`.
964 fn run(self, builder: &Builder<'_>) {
965 let compiler = self.compiler;
966 let target = self.target;
967 let mode = self.mode;
968 let suite = self.suite;
970 // Path for test suite
971 let suite_path = self.path.unwrap_or("");
973 // Skip codegen tests if they aren't enabled in configuration.
974 if !builder.config.codegen_tests && suite == "codegen" {
978 if suite == "debuginfo" {
979 let msvc = builder.config.build.contains("msvc");
980 if mode == "debuginfo" {
981 return builder.ensure(Compiletest {
982 mode: if msvc { "debuginfo-cdb" } else { "debuginfo-gdb+lldb" },
987 builder.ensure(dist::DebuggerScripts {
988 sysroot: builder.sysroot(compiler),
993 if suite.ends_with("fulldeps") {
994 builder.ensure(compile::Rustc { compiler, target });
997 if builder.no_std(target) == Some(true) {
998 // the `test` doesn't compile for no-std targets
999 builder.ensure(compile::Std { compiler, target });
1001 builder.ensure(compile::Test { compiler, target });
1004 if builder.no_std(target) == Some(true) {
1005 // for no_std run-make (e.g., thumb*),
1006 // we need a host compiler which is called by cargo.
1007 builder.ensure(compile::Std { compiler, target: compiler.host });
1010 // HACK(eddyb) ensure that `libproc_macro` is available on the host.
1011 builder.ensure(compile::Test { compiler, target: compiler.host });
1012 // Also provide `rust_test_helpers` for the host.
1013 builder.ensure(native::TestHelpers { target: compiler.host });
1015 // wasm32 can't build the test helpers
1016 if !target.contains("wasm32") {
1017 builder.ensure(native::TestHelpers { target });
1019 builder.ensure(RemoteCopyLibs { compiler, target });
1021 let mut cmd = builder.tool_cmd(Tool::Compiletest);
1023 // compiletest currently has... a lot of arguments, so let's just pass all
1026 cmd.arg("--compile-lib-path")
1027 .arg(builder.rustc_libdir(compiler));
1028 cmd.arg("--run-lib-path")
1029 .arg(builder.sysroot_libdir(compiler, target));
1030 cmd.arg("--rustc-path").arg(builder.rustc(compiler));
1032 let is_rustdoc = suite.ends_with("rustdoc-ui") || suite.ends_with("rustdoc-js");
1034 // Avoid depending on rustdoc when we don't need it.
1035 if mode == "rustdoc"
1036 || (mode == "run-make" && suite.ends_with("fulldeps"))
1037 || (mode == "ui" && is_rustdoc)
1038 || mode == "js-doc-test"
1040 cmd.arg("--rustdoc-path")
1041 .arg(builder.rustdoc(compiler));
1044 cmd.arg("--src-base")
1045 .arg(builder.src.join("src/test").join(suite));
1046 cmd.arg("--build-base")
1047 .arg(testdir(builder, compiler.host).join(suite));
1048 cmd.arg("--stage-id")
1049 .arg(format!("stage{}-{}", compiler.stage, target));
1050 cmd.arg("--mode").arg(mode);
1051 cmd.arg("--target").arg(target);
1052 cmd.arg("--host").arg(&*compiler.host);
1053 cmd.arg("--llvm-filecheck")
1054 .arg(builder.llvm_filecheck(builder.config.build));
1056 if builder.config.cmd.bless() {
1060 let compare_mode = builder.config.cmd.compare_mode().or_else(|| {
1061 if builder.config.test_compare_mode {
1068 if let Some(ref nodejs) = builder.config.nodejs {
1069 cmd.arg("--nodejs").arg(nodejs);
1072 let mut flags = if is_rustdoc {
1075 vec!["-Crpath".to_string()]
1078 if builder.config.rust_optimize_tests {
1079 flags.push("-O".to_string());
1082 flags.push(format!("-Cdebuginfo={}", builder.config.rust_debuginfo_level_tests));
1083 flags.push("-Zunstable-options".to_string());
1084 flags.push(builder.config.cmd.rustc_args().join(" "));
1086 if let Some(linker) = builder.linker(target) {
1087 cmd.arg("--linker").arg(linker);
1090 let mut hostflags = flags.clone();
1091 hostflags.push(format!(
1093 builder.test_helpers_out(compiler.host).display()
1095 cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
1097 let mut targetflags = flags;
1098 targetflags.push(format!(
1100 builder.test_helpers_out(target).display()
1102 cmd.arg("--target-rustcflags").arg(targetflags.join(" "));
1104 cmd.arg("--docck-python").arg(builder.python());
1106 if builder.config.build.ends_with("apple-darwin") {
1107 // Force /usr/bin/python on macOS for LLDB tests because we're loading the
1108 // LLDB plugin's compiled module which only works with the system python
1109 // (namely not Homebrew-installed python)
1110 cmd.arg("--lldb-python").arg("/usr/bin/python");
1112 cmd.arg("--lldb-python").arg(builder.python());
1115 if let Some(ref gdb) = builder.config.gdb {
1116 cmd.arg("--gdb").arg(gdb);
1119 let run = |cmd: &mut Command| {
1120 cmd.output().map(|output| {
1121 String::from_utf8_lossy(&output.stdout)
1122 .lines().next().unwrap_or_else(|| {
1123 panic!("{:?} failed {:?}", cmd, output)
1127 let lldb_exe = if builder.config.lldb_enabled && !target.contains("emscripten") {
1128 // Test against the lldb that was just built.
1129 builder.llvm_out(target).join("bin").join("lldb")
1131 PathBuf::from("lldb")
1133 let lldb_version = Command::new(&lldb_exe)
1136 .map(|output| { String::from_utf8_lossy(&output.stdout).to_string() })
1138 if let Some(ref vers) = lldb_version {
1139 cmd.arg("--lldb-version").arg(vers);
1140 let lldb_python_dir = run(Command::new(&lldb_exe).arg("-P")).ok();
1141 if let Some(ref dir) = lldb_python_dir {
1142 cmd.arg("--lldb-python-dir").arg(dir);
1146 if let Some(var) = env::var_os("RUSTBUILD_FORCE_CLANG_BASED_TESTS") {
1147 match &var.to_string_lossy().to_lowercase()[..] {
1148 "1" | "yes" | "on" => {
1149 assert!(builder.config.lldb_enabled,
1150 "RUSTBUILD_FORCE_CLANG_BASED_TESTS needs Clang/LLDB to \
1152 let clang_exe = builder.llvm_out(target).join("bin").join("clang");
1153 cmd.arg("--run-clang-based-tests-with").arg(clang_exe);
1155 "0" | "no" | "off" => {
1159 // Let's make sure typos don't get unnoticed
1160 panic!("Unrecognized option '{}' set in \
1161 RUSTBUILD_FORCE_CLANG_BASED_TESTS", other);
1166 // Get paths from cmd args
1167 let paths = match &builder.config.cmd {
1168 Subcommand::Test { ref paths, .. } => &paths[..],
1172 // Get test-args by striping suite path
1173 let mut test_args: Vec<&str> = paths
1176 match p.strip_prefix(".") {
1181 .filter(|p| p.starts_with(suite_path) && (p.is_dir() || p.is_file()))
1183 // Since test suite paths are themselves directories, if we don't
1184 // specify a directory or file, we'll get an empty string here
1185 // (the result of the test suite directory without its suite prefix).
1186 // Therefore, we need to filter these out, as only the first --test-args
1187 // flag is respected, so providing an empty --test-args conflicts with
1188 // any following it.
1189 match p.strip_prefix(suite_path).ok().and_then(|p| p.to_str()) {
1190 Some(s) if s != "" => Some(s),
1196 test_args.append(&mut builder.config.cmd.test_args());
1198 cmd.args(&test_args);
1200 if builder.is_verbose() {
1201 cmd.arg("--verbose");
1204 if !builder.config.verbose_tests {
1208 if builder.config.llvm_enabled() {
1209 let llvm_config = builder.ensure(native::Llvm {
1210 target: builder.config.build,
1213 if !builder.config.dry_run {
1214 let llvm_version = output(Command::new(&llvm_config).arg("--version"));
1215 cmd.arg("--llvm-version").arg(llvm_version);
1217 if !builder.is_rust_llvm(target) {
1218 cmd.arg("--system-llvm");
1221 // Only pass correct values for these flags for the `run-make` suite as it
1222 // requires that a C++ compiler was configured which isn't always the case.
1223 if !builder.config.dry_run && suite == "run-make-fulldeps" {
1224 let llvm_components = output(Command::new(&llvm_config).arg("--components"));
1225 let llvm_cxxflags = output(Command::new(&llvm_config).arg("--cxxflags"));
1227 .arg(builder.cc(target))
1229 .arg(builder.cxx(target).unwrap())
1231 .arg(builder.cflags(target, GitRepo::Rustc).join(" "))
1232 .arg("--llvm-components")
1233 .arg(llvm_components.trim())
1234 .arg("--llvm-cxxflags")
1235 .arg(llvm_cxxflags.trim());
1236 if let Some(ar) = builder.ar(target) {
1237 cmd.arg("--ar").arg(ar);
1240 // The llvm/bin directory contains many useful cross-platform
1241 // tools. Pass the path to run-make tests so they can use them.
1242 let llvm_bin_path = llvm_config.parent()
1243 .expect("Expected llvm-config to be contained in directory");
1244 assert!(llvm_bin_path.is_dir());
1245 cmd.arg("--llvm-bin-dir").arg(llvm_bin_path);
1247 // If LLD is available, add it to the PATH
1248 if builder.config.lld_enabled {
1249 let lld_install_root = builder.ensure(native::Lld {
1250 target: builder.config.build,
1253 let lld_bin_path = lld_install_root.join("bin");
1255 let old_path = env::var_os("PATH").unwrap_or_default();
1256 let new_path = env::join_paths(std::iter::once(lld_bin_path)
1257 .chain(env::split_paths(&old_path)))
1258 .expect("Could not add LLD bin path to PATH");
1259 cmd.env("PATH", new_path);
1264 if suite != "run-make-fulldeps" {
1271 .arg("--llvm-components")
1273 .arg("--llvm-cxxflags")
1277 if builder.remote_tested(target) {
1278 cmd.arg("--remote-test-client")
1279 .arg(builder.tool_exe(Tool::RemoteTestClient));
1282 // Running a C compiler on MSVC requires a few env vars to be set, to be
1283 // sure to set them here.
1285 // Note that if we encounter `PATH` we make sure to append to our own `PATH`
1286 // rather than stomp over it.
1287 if target.contains("msvc") {
1288 for &(ref k, ref v) in builder.cc[&target].env() {
1294 cmd.env("RUSTC_BOOTSTRAP", "1");
1295 builder.add_rust_test_threads(&mut cmd);
1297 if builder.config.sanitizers {
1298 cmd.env("RUSTC_SANITIZER_SUPPORT", "1");
1301 if builder.config.profiler {
1302 cmd.env("RUSTC_PROFILER_SUPPORT", "1");
1305 cmd.env("RUST_TEST_TMPDIR", builder.out.join("tmp"));
1307 cmd.arg("--adb-path").arg("adb");
1308 cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
1309 if target.contains("android") {
1310 // Assume that cc for this target comes from the android sysroot
1311 cmd.arg("--android-cross-path")
1312 .arg(builder.cc(target).parent().unwrap().parent().unwrap());
1314 cmd.arg("--android-cross-path").arg("");
1317 if builder.config.cmd.rustfix_coverage() {
1318 cmd.arg("--rustfix-coverage");
1321 builder.ci_env.force_coloring_in_ci(&mut cmd);
1323 let _folder = builder.fold_output(|| format!("test_{}", suite));
1324 builder.info(&format!(
1325 "Check compiletest suite={} mode={} ({} -> {})",
1326 suite, mode, &compiler.host, target
1328 let _time = util::timeit(&builder);
1329 try_run(builder, &mut cmd);
1331 if let Some(compare_mode) = compare_mode {
1332 cmd.arg("--compare-mode").arg(compare_mode);
1333 let _folder = builder.fold_output(|| format!("test_{}_{}", suite, compare_mode));
1334 builder.info(&format!(
1335 "Check compiletest suite={} mode={} compare_mode={} ({} -> {})",
1336 suite, mode, compare_mode, &compiler.host, target
1338 let _time = util::timeit(&builder);
1339 try_run(builder, &mut cmd);
1344 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1352 impl Step for DocTest {
1354 const ONLY_HOSTS: bool = true;
1356 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1360 /// Runs `rustdoc --test` for all documentation in `src/doc`.
1362 /// This will run all tests in our markdown documentation (e.g., the book)
1363 /// located in `src/doc`. The `rustdoc` that's run is the one that sits next to
1365 fn run(self, builder: &Builder<'_>) {
1366 let compiler = self.compiler;
1368 builder.ensure(compile::Test {
1370 target: compiler.host,
1373 // Do a breadth-first traversal of the `src/doc` directory and just run
1374 // tests for all files that end in `*.md`
1375 let mut stack = vec![builder.src.join(self.path)];
1376 let _time = util::timeit(&builder);
1377 let _folder = builder.fold_output(|| format!("test_{}", self.name));
1379 let mut files = Vec::new();
1380 while let Some(p) = stack.pop() {
1382 stack.extend(t!(p.read_dir()).map(|p| t!(p).path()));
1386 if p.extension().and_then(|s| s.to_str()) != Some("md") {
1390 // The nostarch directory in the book is for no starch, and so isn't
1391 // guaranteed to builder. We don't care if it doesn't build, so skip it.
1392 if p.to_str().map_or(false, |p| p.contains("nostarch")) {
1401 let mut toolstate = ToolState::TestPass;
1403 if !markdown_test(builder, compiler, &file) {
1404 toolstate = ToolState::TestFail;
1407 if self.is_ext_doc {
1408 builder.save_toolstate(self.name, toolstate);
1413 macro_rules! test_book {
1414 ($($name:ident, $path:expr, $book_name:expr, default=$default:expr;)+) => {
1416 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1421 impl Step for $name {
1423 const DEFAULT: bool = $default;
1424 const ONLY_HOSTS: bool = true;
1426 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1430 fn make_run(run: RunConfig<'_>) {
1431 run.builder.ensure($name {
1432 compiler: run.builder.compiler(run.builder.top_stage, run.host),
1436 fn run(self, builder: &Builder<'_>) {
1437 builder.ensure(DocTest {
1438 compiler: self.compiler,
1441 is_ext_doc: !$default,
1450 Nomicon, "src/doc/nomicon", "nomicon", default=false;
1451 Reference, "src/doc/reference", "reference", default=false;
1452 RustdocBook, "src/doc/rustdoc", "rustdoc", default=true;
1453 RustcBook, "src/doc/rustc", "rustc", default=true;
1454 RustByExample, "src/doc/rust-by-example", "rust-by-example", default=false;
1455 EmbeddedBook, "src/doc/embedded-book", "embedded-book", default=false;
1456 TheBook, "src/doc/book", "book", default=false;
1457 UnstableBook, "src/doc/unstable-book", "unstable-book", default=true;
1458 EditionGuide, "src/doc/edition-guide", "edition-guide", default=false;
1461 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1462 pub struct ErrorIndex {
1466 impl Step for ErrorIndex {
1468 const DEFAULT: bool = true;
1469 const ONLY_HOSTS: bool = true;
1471 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1472 run.path("src/tools/error_index_generator")
1475 fn make_run(run: RunConfig<'_>) {
1476 run.builder.ensure(ErrorIndex {
1477 compiler: run.builder.compiler(run.builder.top_stage, run.host),
1481 /// Runs the error index generator tool to execute the tests located in the error
1484 /// The `error_index_generator` tool lives in `src/tools` and is used to
1485 /// generate a markdown file from the error indexes of the code base which is
1486 /// then passed to `rustdoc --test`.
1487 fn run(self, builder: &Builder<'_>) {
1488 let compiler = self.compiler;
1490 builder.ensure(compile::Std {
1492 target: compiler.host,
1495 let dir = testdir(builder, compiler.host);
1496 t!(fs::create_dir_all(&dir));
1497 let output = dir.join("error-index.md");
1499 let mut tool = tool::ErrorIndex::command(
1501 builder.compiler(compiler.stage, builder.config.build),
1503 tool.arg("markdown")
1505 .env("CFG_BUILD", &builder.config.build)
1506 .env("RUSTC_ERROR_METADATA_DST", builder.extended_error_dir());
1508 let _folder = builder.fold_output(|| "test_error_index");
1509 builder.info(&format!("Testing error-index stage{}", compiler.stage));
1510 let _time = util::timeit(&builder);
1511 builder.run(&mut tool);
1512 markdown_test(builder, compiler, &output);
1516 fn markdown_test(builder: &Builder<'_>, compiler: Compiler, markdown: &Path) -> bool {
1517 match fs::read_to_string(markdown) {
1519 if !contents.contains("```") {
1526 builder.info(&format!("doc tests for: {}", markdown.display()));
1527 let mut cmd = builder.rustdoc_cmd(compiler);
1528 builder.add_rust_test_threads(&mut cmd);
1531 cmd.env("RUSTC_BOOTSTRAP", "1");
1533 let test_args = builder.config.cmd.test_args().join(" ");
1534 cmd.arg("--test-args").arg(test_args);
1536 if builder.config.verbose_tests {
1537 try_run(builder, &mut cmd)
1539 try_run_quiet(builder, &mut cmd)
1543 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1544 pub struct CrateLibrustc {
1546 target: Interned<String>,
1547 test_kind: TestKind,
1548 krate: Interned<String>,
1551 impl Step for CrateLibrustc {
1553 const DEFAULT: bool = true;
1554 const ONLY_HOSTS: bool = true;
1556 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1557 run.krate("rustc-main")
1560 fn make_run(run: RunConfig<'_>) {
1561 let builder = run.builder;
1562 let compiler = builder.compiler(builder.top_stage, run.host);
1564 for krate in builder.in_tree_crates("rustc-main") {
1565 if run.path.ends_with(&krate.path) {
1566 let test_kind = builder.kind.into();
1568 builder.ensure(CrateLibrustc {
1578 fn run(self, builder: &Builder<'_>) {
1579 builder.ensure(Crate {
1580 compiler: self.compiler,
1581 target: self.target,
1583 test_kind: self.test_kind,
1589 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1590 pub struct CrateNotDefault {
1592 target: Interned<String>,
1593 test_kind: TestKind,
1594 krate: &'static str,
1597 impl Step for CrateNotDefault {
1600 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1601 run.path("src/librustc_asan")
1602 .path("src/librustc_lsan")
1603 .path("src/librustc_msan")
1604 .path("src/librustc_tsan")
1607 fn make_run(run: RunConfig<'_>) {
1608 let builder = run.builder;
1609 let compiler = builder.compiler(builder.top_stage, run.host);
1611 let test_kind = builder.kind.into();
1613 builder.ensure(CrateNotDefault {
1617 krate: match run.path {
1618 _ if run.path.ends_with("src/librustc_asan") => "rustc_asan",
1619 _ if run.path.ends_with("src/librustc_lsan") => "rustc_lsan",
1620 _ if run.path.ends_with("src/librustc_msan") => "rustc_msan",
1621 _ if run.path.ends_with("src/librustc_tsan") => "rustc_tsan",
1622 _ => panic!("unexpected path {:?}", run.path),
1627 fn run(self, builder: &Builder<'_>) {
1628 builder.ensure(Crate {
1629 compiler: self.compiler,
1630 target: self.target,
1632 test_kind: self.test_kind,
1633 krate: INTERNER.intern_str(self.krate),
1638 #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
1640 pub compiler: Compiler,
1641 pub target: Interned<String>,
1643 pub test_kind: TestKind,
1644 pub krate: Interned<String>,
1647 impl Step for Crate {
1649 const DEFAULT: bool = true;
1651 fn should_run(mut run: ShouldRun<'_>) -> ShouldRun<'_> {
1652 let builder = run.builder;
1653 run = run.krate("test");
1654 for krate in run.builder.in_tree_crates("std") {
1655 if !(krate.name.starts_with("rustc_") && krate.name.ends_with("san")) {
1656 run = run.path(krate.local_path(&builder).to_str().unwrap());
1662 fn make_run(run: RunConfig<'_>) {
1663 let builder = run.builder;
1664 let compiler = builder.compiler(builder.top_stage, run.host);
1666 let make = |mode: Mode, krate: &CargoCrate| {
1667 let test_kind = builder.kind.into();
1669 builder.ensure(Crate {
1678 for krate in builder.in_tree_crates("std") {
1679 if run.path.ends_with(&krate.local_path(&builder)) {
1680 make(Mode::Std, krate);
1683 for krate in builder.in_tree_crates("test") {
1684 if run.path.ends_with(&krate.local_path(&builder)) {
1685 make(Mode::Test, krate);
1690 /// Runs all unit tests plus documentation tests for a given crate defined
1691 /// by a `Cargo.toml` (single manifest)
1693 /// This is what runs tests for crates like the standard library, compiler, etc.
1694 /// It essentially is the driver for running `cargo test`.
1696 /// Currently this runs all tests for a DAG by passing a bunch of `-p foo`
1697 /// arguments, and those arguments are discovered from `cargo metadata`.
1698 fn run(self, builder: &Builder<'_>) {
1699 let compiler = self.compiler;
1700 let target = self.target;
1701 let mode = self.mode;
1702 let test_kind = self.test_kind;
1703 let krate = self.krate;
1705 builder.ensure(compile::Test { compiler, target });
1706 builder.ensure(RemoteCopyLibs { compiler, target });
1708 // If we're not doing a full bootstrap but we're testing a stage2 version of
1709 // libstd, then what we're actually testing is the libstd produced in
1710 // stage1. Reflect that here by updating the compiler that we're working
1711 // with automatically.
1712 let compiler = if builder.force_use_stage1(compiler, target) {
1713 builder.compiler(1, compiler.host)
1718 let mut cargo = builder.cargo(compiler, mode, target, test_kind.subcommand());
1721 compile::std_cargo(builder, &compiler, target, &mut cargo);
1724 compile::test_cargo(builder, &compiler, target, &mut cargo);
1727 builder.ensure(compile::Rustc { compiler, target });
1728 compile::rustc_cargo(builder, &mut cargo);
1730 _ => panic!("can only test libraries"),
1733 // Build up the base `cargo test` command.
1735 // Pass in some standard flags then iterate over the graph we've discovered
1736 // in `cargo metadata` with the maps above and figure out what `-p`
1737 // arguments need to get passed.
1738 if test_kind.subcommand() == "test" && !builder.fail_fast {
1739 cargo.arg("--no-fail-fast");
1741 match builder.doc_tests {
1746 cargo.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
1751 cargo.arg("-p").arg(krate);
1753 // The tests are going to run with the *target* libraries, so we need to
1754 // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
1756 // Note that to run the compiler we need to run with the *host* libraries,
1757 // but our wrapper scripts arrange for that to be the case anyway.
1758 let mut dylib_path = dylib_path();
1759 dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
1760 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
1763 cargo.args(&builder.config.cmd.test_args());
1765 if !builder.config.verbose_tests {
1766 cargo.arg("--quiet");
1769 if target.contains("emscripten") {
1771 format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
1776 .expect("nodejs not configured"),
1778 } else if target.starts_with("wasm32") {
1779 // Warn about running tests without the `wasm_syscall` feature enabled.
1780 // The javascript shim implements the syscall interface so that test
1781 // output can be correctly reported.
1782 if !builder.config.wasm_syscall {
1784 "Libstd was built without `wasm_syscall` feature enabled: \
1785 test output may not be visible."
1789 // On the wasm32-unknown-unknown target we're using LTO which is
1790 // incompatible with `-C prefer-dynamic`, so disable that here
1791 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
1797 .expect("nodejs not configured");
1798 let runner = format!(
1799 "{} {}/src/etc/wasm32-shim.js",
1801 builder.src.display()
1803 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)), &runner);
1804 } else if builder.remote_tested(target) {
1806 format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
1807 format!("{} run", builder.tool_exe(Tool::RemoteTestClient).display()),
1811 let _folder = builder.fold_output(|| {
1814 test_kind.subcommand(),
1819 builder.info(&format!(
1820 "{} {} stage{} ({} -> {})",
1821 test_kind, krate, compiler.stage, &compiler.host, target
1823 let _time = util::timeit(&builder);
1824 try_run(builder, &mut cargo);
1828 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1829 pub struct CrateRustdoc {
1830 host: Interned<String>,
1831 test_kind: TestKind,
1834 impl Step for CrateRustdoc {
1836 const DEFAULT: bool = true;
1837 const ONLY_HOSTS: bool = true;
1839 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1840 run.paths(&["src/librustdoc", "src/tools/rustdoc"])
1843 fn make_run(run: RunConfig<'_>) {
1844 let builder = run.builder;
1846 let test_kind = builder.kind.into();
1848 builder.ensure(CrateRustdoc {
1854 fn run(self, builder: &Builder<'_>) {
1855 let test_kind = self.test_kind;
1857 let compiler = builder.compiler(builder.top_stage, self.host);
1858 let target = compiler.host;
1859 builder.ensure(compile::Rustc { compiler, target });
1861 let mut cargo = tool::prepare_tool_cargo(builder,
1865 test_kind.subcommand(),
1866 "src/tools/rustdoc",
1869 if test_kind.subcommand() == "test" && !builder.fail_fast {
1870 cargo.arg("--no-fail-fast");
1873 cargo.arg("-p").arg("rustdoc:0.0.0");
1876 cargo.args(&builder.config.cmd.test_args());
1878 if self.host.contains("musl") {
1879 cargo.arg("'-Ctarget-feature=-crt-static'");
1882 if !builder.config.verbose_tests {
1883 cargo.arg("--quiet");
1886 let _folder = builder
1887 .fold_output(|| format!("{}_stage{}-rustdoc", test_kind.subcommand(), compiler.stage));
1888 builder.info(&format!(
1889 "{} rustdoc stage{} ({} -> {})",
1890 test_kind, compiler.stage, &compiler.host, target
1892 let _time = util::timeit(&builder);
1894 try_run(builder, &mut cargo);
1898 fn envify(s: &str) -> String {
1904 .flat_map(|c| c.to_uppercase())
1908 /// Some test suites are run inside emulators or on remote devices, and most
1909 /// of our test binaries are linked dynamically which means we need to ship
1910 /// the standard library and such to the emulator ahead of time. This step
1911 /// represents this and is a dependency of all test suites.
1913 /// Most of the time this is a no-op. For some steps such as shipping data to
1914 /// QEMU we have to build our own tools so we've got conditional dependencies
1915 /// on those programs as well. Note that the remote test client is built for
1916 /// the build target (us) and the server is built for the target.
1917 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1918 pub struct RemoteCopyLibs {
1920 target: Interned<String>,
1923 impl Step for RemoteCopyLibs {
1926 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1930 fn run(self, builder: &Builder<'_>) {
1931 let compiler = self.compiler;
1932 let target = self.target;
1933 if !builder.remote_tested(target) {
1937 builder.ensure(compile::Test { compiler, target });
1939 builder.info(&format!("REMOTE copy libs to emulator ({})", target));
1940 t!(fs::create_dir_all(builder.out.join("tmp")));
1942 let server = builder.ensure(tool::RemoteTestServer {
1943 compiler: compiler.with_stage(0),
1947 // Spawn the emulator and wait for it to come online
1948 let tool = builder.tool_exe(Tool::RemoteTestClient);
1949 let mut cmd = Command::new(&tool);
1950 cmd.arg("spawn-emulator")
1953 .arg(builder.out.join("tmp"));
1954 if let Some(rootfs) = builder.qemu_rootfs(target) {
1957 builder.run(&mut cmd);
1959 // Push all our dylibs to the emulator
1960 for f in t!(builder.sysroot_libdir(compiler, target).read_dir()) {
1962 let name = f.file_name().into_string().unwrap();
1963 if util::is_dylib(&name) {
1964 builder.run(Command::new(&tool).arg("push").arg(f.path()));
1970 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1971 pub struct Distcheck;
1973 impl Step for Distcheck {
1976 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1977 run.path("distcheck")
1980 fn make_run(run: RunConfig<'_>) {
1981 run.builder.ensure(Distcheck);
1984 /// Runs "distcheck", a 'make check' from a tarball
1985 fn run(self, builder: &Builder<'_>) {
1986 builder.info("Distcheck");
1987 let dir = builder.out.join("tmp").join("distcheck");
1988 let _ = fs::remove_dir_all(&dir);
1989 t!(fs::create_dir_all(&dir));
1991 // Guarantee that these are built before we begin running.
1992 builder.ensure(dist::PlainSourceTarball);
1993 builder.ensure(dist::Src);
1995 let mut cmd = Command::new("tar");
1997 .arg(builder.ensure(dist::PlainSourceTarball))
1998 .arg("--strip-components=1")
2000 builder.run(&mut cmd);
2002 Command::new("./configure")
2003 .args(&builder.config.configure_args)
2004 .arg("--enable-vendor")
2008 Command::new(build_helper::make(&builder.config.build))
2013 // Now make sure that rust-src has all of libstd's dependencies
2014 builder.info("Distcheck rust-src");
2015 let dir = builder.out.join("tmp").join("distcheck-src");
2016 let _ = fs::remove_dir_all(&dir);
2017 t!(fs::create_dir_all(&dir));
2019 let mut cmd = Command::new("tar");
2021 .arg(builder.ensure(dist::Src))
2022 .arg("--strip-components=1")
2024 builder.run(&mut cmd);
2026 let toml = dir.join("rust-src/lib/rustlib/src/rust/src/libstd/Cargo.toml");
2028 Command::new(&builder.initial_cargo)
2029 .arg("generate-lockfile")
2030 .arg("--manifest-path")
2037 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2038 pub struct Bootstrap;
2040 impl Step for Bootstrap {
2042 const DEFAULT: bool = true;
2043 const ONLY_HOSTS: bool = true;
2045 /// Tests the build system itself.
2046 fn run(self, builder: &Builder<'_>) {
2047 let mut cmd = Command::new(&builder.initial_cargo);
2049 .current_dir(builder.src.join("src/bootstrap"))
2050 .env("RUSTFLAGS", "-Cdebuginfo=2")
2051 .env("CARGO_TARGET_DIR", builder.out.join("bootstrap"))
2052 .env("RUSTC_BOOTSTRAP", "1")
2053 .env("RUSTC", &builder.initial_rustc);
2054 if let Some(flags) = option_env!("RUSTFLAGS") {
2055 // Use the same rustc flags for testing as for "normal" compilation,
2056 // so that Cargo doesn’t recompile the entire dependency graph every time:
2057 // https://github.com/rust-lang/rust/issues/49215
2058 cmd.env("RUSTFLAGS", flags);
2060 if !builder.fail_fast {
2061 cmd.arg("--no-fail-fast");
2063 cmd.arg("--").args(&builder.config.cmd.test_args());
2064 // rustbuild tests are racy on directory creation so just run them one at a time.
2065 // Since there's not many this shouldn't be a problem.
2066 cmd.arg("--test-threads=1");
2067 try_run(builder, &mut cmd);
2070 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2071 run.path("src/bootstrap")
2074 fn make_run(run: RunConfig<'_>) {
2075 run.builder.ensure(Bootstrap);