1 //! Implementation of the test-related targets of the build system.
3 //! This file implements the various regression test suites that we execute on
7 use std::ffi::OsString;
11 use std::path::{Path, PathBuf};
12 use std::process::Command;
14 use build_helper::{self, output, t};
16 use crate::builder::{Builder, Compiler, Kind, RunConfig, ShouldRun, Step};
17 use crate::cache::{Interned, INTERNER};
20 use crate::flags::Subcommand;
22 use crate::tool::{self, SourceType, Tool};
23 use crate::toolstate::ToolState;
24 use crate::util::{self, dylib_path, dylib_path_var};
25 use crate::Crate as CargoCrate;
26 use crate::{envify, DocTests, GitRepo, Mode};
28 const ADB_TEST_DIR: &str = "/data/tmp/work";
30 /// The two modes of the test runner; tests or benchmarks.
31 #[derive(Debug, PartialEq, Eq, Hash, Copy, Clone, PartialOrd, Ord)]
35 /// Run `cargo bench`.
39 impl From<Kind> for TestKind {
40 fn from(kind: Kind) -> Self {
42 Kind::Test => TestKind::Test,
43 Kind::Bench => TestKind::Bench,
44 _ => panic!("unexpected kind in crate: {:?}", kind),
50 // Return the cargo subcommand for this test kind
51 fn subcommand(self) -> &'static str {
53 TestKind::Test => "test",
54 TestKind::Bench => "bench",
59 impl fmt::Display for TestKind {
60 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
61 f.write_str(match *self {
62 TestKind::Test => "Testing",
63 TestKind::Bench => "Benchmarking",
68 fn try_run(builder: &Builder<'_>, cmd: &mut Command) -> bool {
69 if !builder.fail_fast {
70 if !builder.try_run(cmd) {
71 let mut failures = builder.delayed_failures.borrow_mut();
72 failures.push(format!("{:?}", cmd));
81 fn try_run_quiet(builder: &Builder<'_>, cmd: &mut Command) -> bool {
82 if !builder.fail_fast {
83 if !builder.try_run_quiet(cmd) {
84 let mut failures = builder.delayed_failures.borrow_mut();
85 failures.push(format!("{:?}", cmd));
89 builder.run_quiet(cmd);
94 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
95 pub struct Linkcheck {
96 host: Interned<String>,
99 impl Step for Linkcheck {
101 const ONLY_HOSTS: bool = true;
102 const DEFAULT: bool = true;
104 /// Runs the `linkchecker` tool as compiled in `stage` by the `host` compiler.
106 /// This tool in `src/tools` will verify the validity of all our links in the
107 /// documentation to ensure we don't have a bunch of dead ones.
108 fn run(self, builder: &Builder<'_>) {
109 let host = self.host;
111 builder.info(&format!("Linkcheck ({})", host));
113 builder.default_doc(None);
115 let _time = util::timeit(&builder);
118 builder.tool_cmd(Tool::Linkchecker).arg(builder.out.join(host).join("doc")),
122 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
123 let builder = run.builder;
124 run.path("src/tools/linkchecker").default_condition(builder.config.docs)
127 fn make_run(run: RunConfig<'_>) {
128 run.builder.ensure(Linkcheck { host: run.target });
132 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
133 pub struct Cargotest {
135 host: Interned<String>,
138 impl Step for Cargotest {
140 const ONLY_HOSTS: bool = true;
142 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
143 run.path("src/tools/cargotest")
146 fn make_run(run: RunConfig<'_>) {
147 run.builder.ensure(Cargotest { stage: run.builder.top_stage, host: run.target });
150 /// Runs the `cargotest` tool as compiled in `stage` by the `host` compiler.
152 /// This tool in `src/tools` will check out a few Rust projects and run `cargo
153 /// test` to ensure that we don't regress the test suites there.
154 fn run(self, builder: &Builder<'_>) {
155 let compiler = builder.compiler(self.stage, self.host);
156 builder.ensure(compile::Rustc { compiler, target: compiler.host });
158 // Note that this is a short, cryptic, and not scoped directory name. This
159 // is currently to minimize the length of path on Windows where we otherwise
160 // quickly run into path name limit constraints.
161 let out_dir = builder.out.join("ct");
162 t!(fs::create_dir_all(&out_dir));
164 let _time = util::timeit(&builder);
165 let mut cmd = builder.tool_cmd(Tool::CargoTest);
168 cmd.arg(&builder.initial_cargo)
170 .env("RUSTC", builder.rustc(compiler))
171 .env("RUSTDOC", builder.rustdoc(compiler)),
176 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
179 host: Interned<String>,
182 impl Step for Cargo {
184 const ONLY_HOSTS: bool = true;
186 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
187 run.path("src/tools/cargo")
190 fn make_run(run: RunConfig<'_>) {
191 run.builder.ensure(Cargo { stage: run.builder.top_stage, host: run.target });
194 /// Runs `cargo test` for `cargo` packaged with Rust.
195 fn run(self, builder: &Builder<'_>) {
196 let compiler = builder.compiler(self.stage, self.host);
198 builder.ensure(tool::Cargo { compiler, target: self.host });
199 let mut cargo = tool::prepare_tool_cargo(
206 SourceType::Submodule,
210 if !builder.fail_fast {
211 cargo.arg("--no-fail-fast");
214 // Don't run cross-compile tests, we may not have cross-compiled libstd libs
216 cargo.env("CFG_DISABLE_CROSS_TESTS", "1");
217 // Disable a test that has issues with mingw.
218 cargo.env("CARGO_TEST_DISABLE_GIT_CLI", "1");
219 // Forcibly disable tests using nightly features since any changes to
220 // those features won't be able to land.
221 cargo.env("CARGO_TEST_DISABLE_NIGHTLY", "1");
223 cargo.env("PATH", &path_for_cargo(builder, compiler));
225 try_run(builder, &mut cargo.into());
229 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
232 host: Interned<String>,
237 const ONLY_HOSTS: bool = true;
239 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
240 run.path("src/tools/rls")
243 fn make_run(run: RunConfig<'_>) {
244 run.builder.ensure(Rls { stage: run.builder.top_stage, host: run.target });
247 /// Runs `cargo test` for the rls.
248 fn run(self, builder: &Builder<'_>) {
249 let stage = self.stage;
250 let host = self.host;
251 let compiler = builder.compiler(stage, host);
254 builder.ensure(tool::Rls { compiler, target: self.host, extra_features: Vec::new() });
255 if build_result.is_none() {
256 eprintln!("failed to test rls: could not build");
260 let mut cargo = tool::prepare_tool_cargo(
267 SourceType::Submodule,
271 builder.add_rustc_lib_path(compiler, &mut cargo);
272 cargo.arg("--").args(builder.config.cmd.test_args());
274 if try_run(builder, &mut cargo.into()) {
275 builder.save_toolstate("rls", ToolState::TestPass);
280 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
283 host: Interned<String>,
286 impl Step for Rustfmt {
288 const ONLY_HOSTS: bool = true;
290 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
291 run.path("src/tools/rustfmt")
294 fn make_run(run: RunConfig<'_>) {
295 run.builder.ensure(Rustfmt { stage: run.builder.top_stage, host: run.target });
298 /// Runs `cargo test` for rustfmt.
299 fn run(self, builder: &Builder<'_>) {
300 let stage = self.stage;
301 let host = self.host;
302 let compiler = builder.compiler(stage, host);
304 let build_result = builder.ensure(tool::Rustfmt {
307 extra_features: Vec::new(),
309 if build_result.is_none() {
310 eprintln!("failed to test rustfmt: could not build");
314 let mut cargo = tool::prepare_tool_cargo(
321 SourceType::Submodule,
325 let dir = testdir(builder, compiler.host);
326 t!(fs::create_dir_all(&dir));
327 cargo.env("RUSTFMT_TEST_DIR", dir);
329 builder.add_rustc_lib_path(compiler, &mut cargo);
331 if try_run(builder, &mut cargo.into()) {
332 builder.save_toolstate("rustfmt", ToolState::TestPass);
337 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
340 host: Interned<String>,
345 const ONLY_HOSTS: bool = true;
347 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
348 run.path("src/tools/miri")
351 fn make_run(run: RunConfig<'_>) {
352 run.builder.ensure(Miri { stage: run.builder.top_stage, host: run.target });
355 /// Runs `cargo test` for miri.
356 fn run(self, builder: &Builder<'_>) {
357 let stage = self.stage;
358 let host = self.host;
359 let compiler = builder.compiler(stage, host);
362 builder.ensure(tool::Miri { compiler, target: self.host, extra_features: Vec::new() });
363 if let Some(miri) = miri {
364 let mut cargo = builder.cargo(compiler, Mode::ToolRustc, host, "install");
366 // Configure `cargo install` path. cargo adds a `bin/`.
367 cargo.env("CARGO_INSTALL_ROOT", &builder.out);
369 let mut cargo = Command::from(cargo);
370 if !try_run(builder, &mut cargo) {
374 // # Run `cargo miri setup`.
375 let mut cargo = tool::prepare_tool_cargo(
382 SourceType::Submodule,
385 cargo.arg("--bin").arg("cargo-miri").arg("--").arg("miri").arg("setup");
387 // Tell `cargo miri` not to worry about the sysroot mismatch (we built with
388 // stage1 but run with stage2).
389 cargo.env("MIRI_SKIP_SYSROOT_CHECK", "1");
390 // Tell `cargo miri setup` where to find the sources.
391 cargo.env("XARGO_RUST_SRC", builder.src.join("src"));
393 cargo.env("RUST_BACKTRACE", "1");
394 // Let cargo-miri know where xargo ended up.
395 cargo.env("XARGO", builder.out.join("bin").join("xargo"));
397 let mut cargo = Command::from(cargo);
398 if !try_run(builder, &mut cargo) {
402 // # Determine where Miri put its sysroot.
403 // To this end, we run `cargo miri setup --env` and capture the output.
404 // (We do this separately from the above so that when the setup actually
405 // happens we get some output.)
406 // We re-use the `cargo` from above.
407 cargo.arg("--print-sysroot");
409 // FIXME: Is there a way in which we can re-use the usual `run` helpers?
410 let miri_sysroot = if builder.config.dry_run {
413 builder.verbose(&format!("running: {:?}", cargo));
416 .expect("We already ran `cargo miri setup` before and that worked");
417 assert!(out.status.success(), "`cargo miri setup` returned with non-0 exit code");
418 // Output is "<sysroot>\n".
419 let stdout = String::from_utf8(out.stdout)
420 .expect("`cargo miri setup` stdout is not valid UTF-8");
421 let sysroot = stdout.trim_end();
422 builder.verbose(&format!("`cargo miri setup --print-sysroot` said: {:?}", sysroot));
426 // # Run `cargo test`.
427 let mut cargo = tool::prepare_tool_cargo(
434 SourceType::Submodule,
438 // miri tests need to know about the stage sysroot
439 cargo.env("MIRI_SYSROOT", miri_sysroot);
440 cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
441 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
442 cargo.env("MIRI_PATH", miri);
444 builder.add_rustc_lib_path(compiler, &mut cargo);
446 if !try_run(builder, &mut cargo.into()) {
451 builder.save_toolstate("miri", ToolState::TestPass);
453 eprintln!("failed to test miri: could not build");
458 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
459 pub struct CompiletestTest {
460 host: Interned<String>,
463 impl Step for CompiletestTest {
466 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
467 run.path("src/tools/compiletest")
470 fn make_run(run: RunConfig<'_>) {
471 run.builder.ensure(CompiletestTest { host: run.target });
474 /// Runs `cargo test` for compiletest.
475 fn run(self, builder: &Builder<'_>) {
476 let host = self.host;
477 let compiler = builder.compiler(0, host);
479 let cargo = tool::prepare_tool_cargo(
485 "src/tools/compiletest",
490 try_run(builder, &mut cargo.into());
494 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
497 host: Interned<String>,
500 impl Step for Clippy {
502 const ONLY_HOSTS: bool = true;
503 const DEFAULT: bool = false;
505 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
506 run.path("src/tools/clippy")
509 fn make_run(run: RunConfig<'_>) {
510 run.builder.ensure(Clippy { stage: run.builder.top_stage, host: run.target });
513 /// Runs `cargo test` for clippy.
514 fn run(self, builder: &Builder<'_>) {
515 let stage = self.stage;
516 let host = self.host;
517 let compiler = builder.compiler(stage, host);
519 let clippy = builder.ensure(tool::Clippy {
522 extra_features: Vec::new(),
524 if let Some(clippy) = clippy {
525 let mut cargo = tool::prepare_tool_cargo(
532 SourceType::Submodule,
536 // clippy tests need to know about the stage sysroot
537 cargo.env("SYSROOT", builder.sysroot(compiler));
538 cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
539 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
540 let host_libs = builder.stage_out(compiler, Mode::ToolRustc).join(builder.cargo_dir());
541 let target_libs = builder
542 .stage_out(compiler, Mode::ToolRustc)
544 .join(builder.cargo_dir());
545 cargo.env("HOST_LIBS", host_libs);
546 cargo.env("TARGET_LIBS", target_libs);
547 // clippy tests need to find the driver
548 cargo.env("CLIPPY_DRIVER_PATH", clippy);
550 builder.add_rustc_lib_path(compiler, &mut cargo);
552 if try_run(builder, &mut cargo.into()) {
553 builder.save_toolstate("clippy-driver", ToolState::TestPass);
556 eprintln!("failed to test clippy: could not build");
561 fn path_for_cargo(builder: &Builder<'_>, compiler: Compiler) -> OsString {
562 // Configure PATH to find the right rustc. NB. we have to use PATH
563 // and not RUSTC because the Cargo test suite has tests that will
564 // fail if rustc is not spelled `rustc`.
565 let path = builder.sysroot(compiler).join("bin");
566 let old_path = env::var_os("PATH").unwrap_or_default();
567 env::join_paths(iter::once(path).chain(env::split_paths(&old_path))).expect("")
570 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
571 pub struct RustdocTheme {
572 pub compiler: Compiler,
575 impl Step for RustdocTheme {
577 const DEFAULT: bool = true;
578 const ONLY_HOSTS: bool = true;
580 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
581 run.path("src/tools/rustdoc-themes")
584 fn make_run(run: RunConfig<'_>) {
585 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
587 run.builder.ensure(RustdocTheme { compiler });
590 fn run(self, builder: &Builder<'_>) {
591 let rustdoc = builder.out.join("bootstrap/debug/rustdoc");
592 let mut cmd = builder.tool_cmd(Tool::RustdocTheme);
593 cmd.arg(rustdoc.to_str().unwrap())
594 .arg(builder.src.join("src/librustdoc/html/static/themes").to_str().unwrap())
595 .env("RUSTC_STAGE", self.compiler.stage.to_string())
596 .env("RUSTC_SYSROOT", builder.sysroot(self.compiler))
597 .env("RUSTDOC_LIBDIR", builder.sysroot_libdir(self.compiler, self.compiler.host))
598 .env("CFG_RELEASE_CHANNEL", &builder.config.channel)
599 .env("RUSTDOC_REAL", builder.rustdoc(self.compiler))
600 .env("RUSTDOC_CRATE_VERSION", builder.rust_version())
601 .env("RUSTC_BOOTSTRAP", "1");
602 if let Some(linker) = builder.linker(self.compiler.host) {
603 cmd.env("RUSTC_TARGET_LINKER", linker);
605 try_run(builder, &mut cmd);
609 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
610 pub struct RustdocJSStd {
611 pub host: Interned<String>,
612 pub target: Interned<String>,
615 impl Step for RustdocJSStd {
617 const DEFAULT: bool = true;
618 const ONLY_HOSTS: bool = true;
620 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
621 run.path("src/test/rustdoc-js-std")
624 fn make_run(run: RunConfig<'_>) {
625 run.builder.ensure(RustdocJSStd { host: run.host, target: run.target });
628 fn run(self, builder: &Builder<'_>) {
629 if let Some(ref nodejs) = builder.config.nodejs {
630 let mut command = Command::new(nodejs);
631 command.args(&["src/tools/rustdoc-js-std/tester.js", &*self.host]);
632 builder.ensure(crate::doc::Std { target: self.target, stage: builder.top_stage });
633 builder.run(&mut command);
635 builder.info("No nodejs found, skipping \"src/test/rustdoc-js-std\" tests");
640 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
641 pub struct RustdocJSNotStd {
642 pub host: Interned<String>,
643 pub target: Interned<String>,
644 pub compiler: Compiler,
647 impl Step for RustdocJSNotStd {
649 const DEFAULT: bool = true;
650 const ONLY_HOSTS: bool = true;
652 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
653 run.path("src/test/rustdoc-js")
656 fn make_run(run: RunConfig<'_>) {
657 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
658 run.builder.ensure(RustdocJSNotStd { host: run.host, target: run.target, compiler });
661 fn run(self, builder: &Builder<'_>) {
662 if builder.config.nodejs.is_some() {
663 builder.ensure(Compiletest {
664 compiler: self.compiler,
672 builder.info("No nodejs found, skipping \"src/test/rustdoc-js\" tests");
677 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
678 pub struct RustdocUi {
679 pub host: Interned<String>,
680 pub target: Interned<String>,
681 pub compiler: Compiler,
684 impl Step for RustdocUi {
686 const DEFAULT: bool = true;
687 const ONLY_HOSTS: bool = true;
689 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
690 run.path("src/test/rustdoc-ui")
693 fn make_run(run: RunConfig<'_>) {
694 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
695 run.builder.ensure(RustdocUi { host: run.host, target: run.target, compiler });
698 fn run(self, builder: &Builder<'_>) {
699 builder.ensure(Compiletest {
700 compiler: self.compiler,
704 path: Some("src/test/rustdoc-ui"),
710 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
715 const DEFAULT: bool = true;
716 const ONLY_HOSTS: bool = true;
718 /// Runs the `tidy` tool.
720 /// This tool in `src/tools` checks up on various bits and pieces of style and
721 /// otherwise just implements a few lint-like checks that are specific to the
724 /// Once tidy passes, this step also runs `fmt --check` if tests are being run
725 /// for the `dev` or `nightly` channels.
726 fn run(self, builder: &Builder<'_>) {
727 let mut cmd = builder.tool_cmd(Tool::Tidy);
728 cmd.arg(builder.src.join("src"));
729 cmd.arg(&builder.initial_cargo);
730 if !builder.config.vendor {
731 cmd.arg("--no-vendor");
733 if builder.is_verbose() {
734 cmd.arg("--verbose");
737 builder.info("tidy check");
738 try_run(builder, &mut cmd);
740 if builder.config.channel == "dev" || builder.config.channel == "nightly" {
741 builder.info("fmt check");
742 crate::format::format(&builder.build, true);
746 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
747 run.path("src/tools/tidy")
750 fn make_run(run: RunConfig<'_>) {
751 run.builder.ensure(Tidy);
755 fn testdir(builder: &Builder<'_>, host: Interned<String>) -> PathBuf {
756 builder.out.join(host).join("test")
759 macro_rules! default_test {
760 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
761 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: false });
765 macro_rules! default_test_with_compare_mode {
766 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr,
767 compare_mode: $compare_mode:expr }) => {
768 test_with_compare_mode!($name {
774 compare_mode: $compare_mode
779 macro_rules! host_test {
780 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
781 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: true });
786 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
787 host: $host:expr }) => {
788 test_definitions!($name {
799 macro_rules! test_with_compare_mode {
800 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
801 host: $host:expr, compare_mode: $compare_mode:expr }) => {
802 test_definitions!($name {
808 compare_mode: Some($compare_mode)
813 macro_rules! test_definitions {
818 default: $default:expr,
820 compare_mode: $compare_mode:expr
822 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
824 pub compiler: Compiler,
825 pub target: Interned<String>,
828 impl Step for $name {
830 const DEFAULT: bool = $default;
831 const ONLY_HOSTS: bool = $host;
833 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
834 run.suite_path($path)
837 fn make_run(run: RunConfig<'_>) {
838 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
840 run.builder.ensure($name { compiler, target: run.target });
843 fn run(self, builder: &Builder<'_>) {
844 builder.ensure(Compiletest {
845 compiler: self.compiler,
850 compare_mode: $compare_mode,
857 default_test_with_compare_mode!(Ui {
864 default_test!(CompileFail {
865 path: "src/test/compile-fail",
866 mode: "compile-fail",
867 suite: "compile-fail"
870 default_test!(RunFail { path: "src/test/run-fail", mode: "run-fail", suite: "run-fail" });
872 default_test!(RunPassValgrind {
873 path: "src/test/run-pass-valgrind",
874 mode: "run-pass-valgrind",
875 suite: "run-pass-valgrind"
878 default_test!(MirOpt { path: "src/test/mir-opt", mode: "mir-opt", suite: "mir-opt" });
880 default_test!(Codegen { path: "src/test/codegen", mode: "codegen", suite: "codegen" });
882 default_test!(CodegenUnits {
883 path: "src/test/codegen-units",
884 mode: "codegen-units",
885 suite: "codegen-units"
888 default_test!(Incremental {
889 path: "src/test/incremental",
894 default_test!(Debuginfo { path: "src/test/debuginfo", mode: "debuginfo", suite: "debuginfo" });
896 host_test!(UiFullDeps { path: "src/test/ui-fulldeps", mode: "ui", suite: "ui-fulldeps" });
898 host_test!(Rustdoc { path: "src/test/rustdoc", mode: "rustdoc", suite: "rustdoc" });
900 host_test!(Pretty { path: "src/test/pretty", mode: "pretty", suite: "pretty" });
901 test!(RunFailPretty {
902 path: "src/test/run-fail/pretty",
908 test!(RunPassValgrindPretty {
909 path: "src/test/run-pass-valgrind/pretty",
911 suite: "run-pass-valgrind",
916 default_test!(RunMake { path: "src/test/run-make", mode: "run-make", suite: "run-make" });
918 host_test!(RunMakeFullDeps {
919 path: "src/test/run-make-fulldeps",
921 suite: "run-make-fulldeps"
924 default_test!(Assembly { path: "src/test/assembly", mode: "assembly", suite: "assembly" });
926 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
929 target: Interned<String>,
932 path: Option<&'static str>,
933 compare_mode: Option<&'static str>,
936 impl Step for Compiletest {
939 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
943 /// Executes the `compiletest` tool to run a suite of tests.
945 /// Compiles all tests with `compiler` for `target` with the specified
946 /// compiletest `mode` and `suite` arguments. For example `mode` can be
947 /// "run-pass" or `suite` can be something like `debuginfo`.
948 fn run(self, builder: &Builder<'_>) {
949 let compiler = self.compiler;
950 let target = self.target;
951 let mode = self.mode;
952 let suite = self.suite;
954 // Path for test suite
955 let suite_path = self.path.unwrap_or("");
957 // Skip codegen tests if they aren't enabled in configuration.
958 if !builder.config.codegen_tests && suite == "codegen" {
962 if suite == "debuginfo" {
963 let msvc = builder.config.build.contains("msvc");
964 if mode == "debuginfo" {
965 return builder.ensure(Compiletest {
966 mode: if msvc { "debuginfo-cdb" } else { "debuginfo-gdb+lldb" },
972 .ensure(dist::DebuggerScripts { sysroot: builder.sysroot(compiler), host: target });
975 if suite.ends_with("fulldeps") {
976 builder.ensure(compile::Rustc { compiler, target });
979 builder.ensure(compile::Std { compiler, target });
980 // ensure that `libproc_macro` is available on the host.
981 builder.ensure(compile::Std { compiler, target: compiler.host });
983 // Also provide `rust_test_helpers` for the host.
984 builder.ensure(native::TestHelpers { target: compiler.host });
986 // As well as the target, except for plain wasm32, which can't build it
987 if !target.contains("wasm32") || target.contains("emscripten") {
988 builder.ensure(native::TestHelpers { target });
991 builder.ensure(RemoteCopyLibs { compiler, target });
993 let mut cmd = builder.tool_cmd(Tool::Compiletest);
995 // compiletest currently has... a lot of arguments, so let's just pass all
998 cmd.arg("--compile-lib-path").arg(builder.rustc_libdir(compiler));
999 cmd.arg("--run-lib-path").arg(builder.sysroot_libdir(compiler, target));
1000 cmd.arg("--rustc-path").arg(builder.rustc(compiler));
1002 let is_rustdoc = suite.ends_with("rustdoc-ui") || suite.ends_with("rustdoc-js");
1004 // Avoid depending on rustdoc when we don't need it.
1005 if mode == "rustdoc"
1006 || (mode == "run-make" && suite.ends_with("fulldeps"))
1007 || (mode == "ui" && is_rustdoc)
1008 || mode == "js-doc-test"
1010 cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler));
1013 cmd.arg("--src-base").arg(builder.src.join("src/test").join(suite));
1014 cmd.arg("--build-base").arg(testdir(builder, compiler.host).join(suite));
1015 cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target));
1016 cmd.arg("--mode").arg(mode);
1017 cmd.arg("--target").arg(target);
1018 cmd.arg("--host").arg(&*compiler.host);
1019 cmd.arg("--llvm-filecheck").arg(builder.llvm_filecheck(builder.config.build));
1021 if builder.config.cmd.bless() {
1026 builder.config.cmd.compare_mode().or_else(|| {
1027 if builder.config.test_compare_mode { self.compare_mode } else { None }
1030 if let Some(ref pass) = builder.config.cmd.pass() {
1035 if let Some(ref nodejs) = builder.config.nodejs {
1036 cmd.arg("--nodejs").arg(nodejs);
1039 let mut flags = if is_rustdoc { Vec::new() } else { vec!["-Crpath".to_string()] };
1041 if builder.config.rust_optimize_tests {
1042 flags.push("-O".to_string());
1045 flags.push(format!("-Cdebuginfo={}", builder.config.rust_debuginfo_level_tests));
1046 flags.push("-Zunstable-options".to_string());
1047 flags.push(builder.config.cmd.rustc_args().join(" "));
1049 if let Some(linker) = builder.linker(target) {
1050 cmd.arg("--linker").arg(linker);
1053 let mut hostflags = flags.clone();
1054 hostflags.push(format!("-Lnative={}", builder.test_helpers_out(compiler.host).display()));
1055 cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
1057 let mut targetflags = flags;
1058 targetflags.push(format!("-Lnative={}", builder.test_helpers_out(target).display()));
1059 cmd.arg("--target-rustcflags").arg(targetflags.join(" "));
1061 cmd.arg("--docck-python").arg(builder.python());
1063 if builder.config.build.ends_with("apple-darwin") {
1064 // Force /usr/bin/python on macOS for LLDB tests because we're loading the
1065 // LLDB plugin's compiled module which only works with the system python
1066 // (namely not Homebrew-installed python)
1067 cmd.arg("--lldb-python").arg("/usr/bin/python");
1069 cmd.arg("--lldb-python").arg(builder.python());
1072 if let Some(ref gdb) = builder.config.gdb {
1073 cmd.arg("--gdb").arg(gdb);
1076 let run = |cmd: &mut Command| {
1077 cmd.output().map(|output| {
1078 String::from_utf8_lossy(&output.stdout)
1081 .unwrap_or_else(|| panic!("{:?} failed {:?}", cmd, output))
1085 let lldb_exe = if builder.config.lldb_enabled {
1086 // Test against the lldb that was just built.
1087 builder.llvm_out(target).join("bin").join("lldb")
1089 PathBuf::from("lldb")
1091 let lldb_version = Command::new(&lldb_exe)
1094 .map(|output| String::from_utf8_lossy(&output.stdout).to_string())
1096 if let Some(ref vers) = lldb_version {
1097 cmd.arg("--lldb-version").arg(vers);
1098 let lldb_python_dir = run(Command::new(&lldb_exe).arg("-P")).ok();
1099 if let Some(ref dir) = lldb_python_dir {
1100 cmd.arg("--lldb-python-dir").arg(dir);
1104 if util::forcing_clang_based_tests() {
1105 let clang_exe = builder.llvm_out(target).join("bin").join("clang");
1106 cmd.arg("--run-clang-based-tests-with").arg(clang_exe);
1109 // Get paths from cmd args
1110 let paths = match &builder.config.cmd {
1111 Subcommand::Test { ref paths, .. } => &paths[..],
1115 // Get test-args by striping suite path
1116 let mut test_args: Vec<&str> = paths
1118 .map(|p| match p.strip_prefix(".") {
1122 .filter(|p| p.starts_with(suite_path) && (p.is_dir() || p.is_file()))
1124 // Since test suite paths are themselves directories, if we don't
1125 // specify a directory or file, we'll get an empty string here
1126 // (the result of the test suite directory without its suite prefix).
1127 // Therefore, we need to filter these out, as only the first --test-args
1128 // flag is respected, so providing an empty --test-args conflicts with
1129 // any following it.
1130 match p.strip_prefix(suite_path).ok().and_then(|p| p.to_str()) {
1131 Some(s) if s != "" => Some(s),
1137 test_args.append(&mut builder.config.cmd.test_args());
1139 cmd.args(&test_args);
1141 if builder.is_verbose() {
1142 cmd.arg("--verbose");
1145 if !builder.config.verbose_tests {
1149 if builder.config.llvm_enabled() {
1150 let llvm_config = builder.ensure(native::Llvm { target: builder.config.build });
1151 if !builder.config.dry_run {
1152 let llvm_version = output(Command::new(&llvm_config).arg("--version"));
1153 cmd.arg("--llvm-version").arg(llvm_version);
1155 if !builder.is_rust_llvm(target) {
1156 cmd.arg("--system-llvm");
1159 // Only pass correct values for these flags for the `run-make` suite as it
1160 // requires that a C++ compiler was configured which isn't always the case.
1161 if !builder.config.dry_run && suite == "run-make-fulldeps" {
1162 let llvm_components = output(Command::new(&llvm_config).arg("--components"));
1163 let llvm_cxxflags = output(Command::new(&llvm_config).arg("--cxxflags"));
1165 .arg(builder.cc(target))
1167 .arg(builder.cxx(target).unwrap())
1169 .arg(builder.cflags(target, GitRepo::Rustc).join(" "))
1170 .arg("--llvm-components")
1171 .arg(llvm_components.trim())
1172 .arg("--llvm-cxxflags")
1173 .arg(llvm_cxxflags.trim());
1174 if let Some(ar) = builder.ar(target) {
1175 cmd.arg("--ar").arg(ar);
1178 // The llvm/bin directory contains many useful cross-platform
1179 // tools. Pass the path to run-make tests so they can use them.
1180 let llvm_bin_path = llvm_config
1182 .expect("Expected llvm-config to be contained in directory");
1183 assert!(llvm_bin_path.is_dir());
1184 cmd.arg("--llvm-bin-dir").arg(llvm_bin_path);
1186 // If LLD is available, add it to the PATH
1187 if builder.config.lld_enabled {
1188 let lld_install_root =
1189 builder.ensure(native::Lld { target: builder.config.build });
1191 let lld_bin_path = lld_install_root.join("bin");
1193 let old_path = env::var_os("PATH").unwrap_or_default();
1194 let new_path = env::join_paths(
1195 std::iter::once(lld_bin_path).chain(env::split_paths(&old_path)),
1197 .expect("Could not add LLD bin path to PATH");
1198 cmd.env("PATH", new_path);
1203 if suite != "run-make-fulldeps" {
1210 .arg("--llvm-components")
1212 .arg("--llvm-cxxflags")
1216 if builder.remote_tested(target) {
1217 cmd.arg("--remote-test-client").arg(builder.tool_exe(Tool::RemoteTestClient));
1220 // Running a C compiler on MSVC requires a few env vars to be set, to be
1221 // sure to set them here.
1223 // Note that if we encounter `PATH` we make sure to append to our own `PATH`
1224 // rather than stomp over it.
1225 if target.contains("msvc") {
1226 for &(ref k, ref v) in builder.cc[&target].env() {
1232 cmd.env("RUSTC_BOOTSTRAP", "1");
1233 builder.add_rust_test_threads(&mut cmd);
1235 if builder.config.sanitizers {
1236 cmd.env("RUSTC_SANITIZER_SUPPORT", "1");
1239 if builder.config.profiler {
1240 cmd.env("RUSTC_PROFILER_SUPPORT", "1");
1243 let tmp = builder.out.join("tmp");
1244 std::fs::create_dir_all(&tmp).unwrap();
1245 cmd.env("RUST_TEST_TMPDIR", tmp);
1247 cmd.arg("--adb-path").arg("adb");
1248 cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
1249 if target.contains("android") {
1250 // Assume that cc for this target comes from the android sysroot
1251 cmd.arg("--android-cross-path")
1252 .arg(builder.cc(target).parent().unwrap().parent().unwrap());
1254 cmd.arg("--android-cross-path").arg("");
1257 if builder.config.cmd.rustfix_coverage() {
1258 cmd.arg("--rustfix-coverage");
1261 builder.ci_env.force_coloring_in_ci(&mut cmd);
1263 builder.info(&format!(
1264 "Check compiletest suite={} mode={} ({} -> {})",
1265 suite, mode, &compiler.host, target
1267 let _time = util::timeit(&builder);
1268 try_run(builder, &mut cmd);
1270 if let Some(compare_mode) = compare_mode {
1271 cmd.arg("--compare-mode").arg(compare_mode);
1272 builder.info(&format!(
1273 "Check compiletest suite={} mode={} compare_mode={} ({} -> {})",
1274 suite, mode, compare_mode, &compiler.host, target
1276 let _time = util::timeit(&builder);
1277 try_run(builder, &mut cmd);
1282 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1290 impl Step for DocTest {
1292 const ONLY_HOSTS: bool = true;
1294 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1298 /// Runs `rustdoc --test` for all documentation in `src/doc`.
1300 /// This will run all tests in our markdown documentation (e.g., the book)
1301 /// located in `src/doc`. The `rustdoc` that's run is the one that sits next to
1303 fn run(self, builder: &Builder<'_>) {
1304 let compiler = self.compiler;
1306 builder.ensure(compile::Std { compiler, target: compiler.host });
1308 // Do a breadth-first traversal of the `src/doc` directory and just run
1309 // tests for all files that end in `*.md`
1310 let mut stack = vec![builder.src.join(self.path)];
1311 let _time = util::timeit(&builder);
1313 let mut files = Vec::new();
1314 while let Some(p) = stack.pop() {
1316 stack.extend(t!(p.read_dir()).map(|p| t!(p).path()));
1320 if p.extension().and_then(|s| s.to_str()) != Some("md") {
1324 // The nostarch directory in the book is for no starch, and so isn't
1325 // guaranteed to builder. We don't care if it doesn't build, so skip it.
1326 if p.to_str().map_or(false, |p| p.contains("nostarch")) {
1335 let mut toolstate = ToolState::TestPass;
1337 if !markdown_test(builder, compiler, &file) {
1338 toolstate = ToolState::TestFail;
1341 if self.is_ext_doc {
1342 builder.save_toolstate(self.name, toolstate);
1347 macro_rules! test_book {
1348 ($($name:ident, $path:expr, $book_name:expr, default=$default:expr;)+) => {
1350 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1355 impl Step for $name {
1357 const DEFAULT: bool = $default;
1358 const ONLY_HOSTS: bool = true;
1360 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1364 fn make_run(run: RunConfig<'_>) {
1365 run.builder.ensure($name {
1366 compiler: run.builder.compiler(run.builder.top_stage, run.host),
1370 fn run(self, builder: &Builder<'_>) {
1371 builder.ensure(DocTest {
1372 compiler: self.compiler,
1375 is_ext_doc: !$default,
1384 Nomicon, "src/doc/nomicon", "nomicon", default=false;
1385 Reference, "src/doc/reference", "reference", default=false;
1386 RustdocBook, "src/doc/rustdoc", "rustdoc", default=true;
1387 RustcBook, "src/doc/rustc", "rustc", default=true;
1388 RustByExample, "src/doc/rust-by-example", "rust-by-example", default=false;
1389 EmbeddedBook, "src/doc/embedded-book", "embedded-book", default=false;
1390 TheBook, "src/doc/book", "book", default=false;
1391 UnstableBook, "src/doc/unstable-book", "unstable-book", default=true;
1392 EditionGuide, "src/doc/edition-guide", "edition-guide", default=false;
1395 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1396 pub struct ErrorIndex {
1400 impl Step for ErrorIndex {
1402 const DEFAULT: bool = true;
1403 const ONLY_HOSTS: bool = true;
1405 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1406 run.path("src/tools/error_index_generator")
1409 fn make_run(run: RunConfig<'_>) {
1411 .ensure(ErrorIndex { compiler: run.builder.compiler(run.builder.top_stage, run.host) });
1414 /// Runs the error index generator tool to execute the tests located in the error
1417 /// The `error_index_generator` tool lives in `src/tools` and is used to
1418 /// generate a markdown file from the error indexes of the code base which is
1419 /// then passed to `rustdoc --test`.
1420 fn run(self, builder: &Builder<'_>) {
1421 let compiler = self.compiler;
1423 builder.ensure(compile::Std { compiler, target: compiler.host });
1425 let dir = testdir(builder, compiler.host);
1426 t!(fs::create_dir_all(&dir));
1427 let output = dir.join("error-index.md");
1429 let mut tool = tool::ErrorIndex::command(
1431 builder.compiler(compiler.stage, builder.config.build),
1433 tool.arg("markdown").arg(&output).env("CFG_BUILD", &builder.config.build);
1435 builder.info(&format!("Testing error-index stage{}", compiler.stage));
1436 let _time = util::timeit(&builder);
1437 builder.run_quiet(&mut tool);
1438 markdown_test(builder, compiler, &output);
1442 fn markdown_test(builder: &Builder<'_>, compiler: Compiler, markdown: &Path) -> bool {
1443 match fs::read_to_string(markdown) {
1445 if !contents.contains("```") {
1452 builder.info(&format!("doc tests for: {}", markdown.display()));
1453 let mut cmd = builder.rustdoc_cmd(compiler);
1454 builder.add_rust_test_threads(&mut cmd);
1457 cmd.env("RUSTC_BOOTSTRAP", "1");
1459 let test_args = builder.config.cmd.test_args().join(" ");
1460 cmd.arg("--test-args").arg(test_args);
1462 if builder.config.verbose_tests {
1463 try_run(builder, &mut cmd)
1465 try_run_quiet(builder, &mut cmd)
1469 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1470 pub struct RustcGuide;
1472 impl Step for RustcGuide {
1474 const DEFAULT: bool = false;
1475 const ONLY_HOSTS: bool = true;
1477 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1478 run.path("src/doc/rustc-guide")
1481 fn make_run(run: RunConfig<'_>) {
1482 run.builder.ensure(RustcGuide);
1485 fn run(self, builder: &Builder<'_>) {
1486 let src = builder.src.join("src/doc/rustc-guide");
1487 let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
1488 let toolstate = if try_run(builder, rustbook_cmd.arg("linkcheck").arg(&src)) {
1493 builder.save_toolstate("rustc-guide", toolstate);
1497 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1498 pub struct CrateLibrustc {
1500 target: Interned<String>,
1501 test_kind: TestKind,
1502 krate: Interned<String>,
1505 impl Step for CrateLibrustc {
1507 const DEFAULT: bool = true;
1508 const ONLY_HOSTS: bool = true;
1510 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1511 run.krate("rustc-main")
1514 fn make_run(run: RunConfig<'_>) {
1515 let builder = run.builder;
1516 let compiler = builder.compiler(builder.top_stage, run.host);
1518 for krate in builder.in_tree_crates("rustc-main") {
1519 if run.path.ends_with(&krate.path) {
1520 let test_kind = builder.kind.into();
1522 builder.ensure(CrateLibrustc {
1532 fn run(self, builder: &Builder<'_>) {
1533 builder.ensure(Crate {
1534 compiler: self.compiler,
1535 target: self.target,
1537 test_kind: self.test_kind,
1543 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1544 pub struct CrateNotDefault {
1546 target: Interned<String>,
1547 test_kind: TestKind,
1548 krate: &'static str,
1551 impl Step for CrateNotDefault {
1554 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1555 run.path("src/librustc_asan")
1556 .path("src/librustc_lsan")
1557 .path("src/librustc_msan")
1558 .path("src/librustc_tsan")
1561 fn make_run(run: RunConfig<'_>) {
1562 let builder = run.builder;
1563 let compiler = builder.compiler(builder.top_stage, run.host);
1565 let test_kind = builder.kind.into();
1567 builder.ensure(CrateNotDefault {
1571 krate: match run.path {
1572 _ if run.path.ends_with("src/librustc_asan") => "rustc_asan",
1573 _ if run.path.ends_with("src/librustc_lsan") => "rustc_lsan",
1574 _ if run.path.ends_with("src/librustc_msan") => "rustc_msan",
1575 _ if run.path.ends_with("src/librustc_tsan") => "rustc_tsan",
1576 _ => panic!("unexpected path {:?}", run.path),
1581 fn run(self, builder: &Builder<'_>) {
1582 builder.ensure(Crate {
1583 compiler: self.compiler,
1584 target: self.target,
1586 test_kind: self.test_kind,
1587 krate: INTERNER.intern_str(self.krate),
1592 #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
1594 pub compiler: Compiler,
1595 pub target: Interned<String>,
1597 pub test_kind: TestKind,
1598 pub krate: Interned<String>,
1601 impl Step for Crate {
1603 const DEFAULT: bool = true;
1605 fn should_run(mut run: ShouldRun<'_>) -> ShouldRun<'_> {
1606 let builder = run.builder;
1607 for krate in run.builder.in_tree_crates("test") {
1608 if !(krate.name.starts_with("rustc_") && krate.name.ends_with("san")) {
1609 run = run.path(krate.local_path(&builder).to_str().unwrap());
1615 fn make_run(run: RunConfig<'_>) {
1616 let builder = run.builder;
1617 let compiler = builder.compiler(builder.top_stage, run.host);
1619 let make = |mode: Mode, krate: &CargoCrate| {
1620 let test_kind = builder.kind.into();
1622 builder.ensure(Crate {
1631 for krate in builder.in_tree_crates("test") {
1632 if run.path.ends_with(&krate.local_path(&builder)) {
1633 make(Mode::Std, krate);
1638 /// Runs all unit tests plus documentation tests for a given crate defined
1639 /// by a `Cargo.toml` (single manifest)
1641 /// This is what runs tests for crates like the standard library, compiler, etc.
1642 /// It essentially is the driver for running `cargo test`.
1644 /// Currently this runs all tests for a DAG by passing a bunch of `-p foo`
1645 /// arguments, and those arguments are discovered from `cargo metadata`.
1646 fn run(self, builder: &Builder<'_>) {
1647 let compiler = self.compiler;
1648 let target = self.target;
1649 let mode = self.mode;
1650 let test_kind = self.test_kind;
1651 let krate = self.krate;
1653 builder.ensure(compile::Std { compiler, target });
1654 builder.ensure(RemoteCopyLibs { compiler, target });
1656 // If we're not doing a full bootstrap but we're testing a stage2
1657 // version of libstd, then what we're actually testing is the libstd
1658 // produced in stage1. Reflect that here by updating the compiler that
1659 // we're working with automatically.
1660 let compiler = builder.compiler_for(compiler.stage, compiler.host, target);
1662 let mut cargo = builder.cargo(compiler, mode, target, test_kind.subcommand());
1665 compile::std_cargo(builder, &compiler, target, &mut cargo);
1668 builder.ensure(compile::Rustc { compiler, target });
1669 compile::rustc_cargo(builder, &mut cargo, target);
1671 _ => panic!("can only test libraries"),
1674 // Build up the base `cargo test` command.
1676 // Pass in some standard flags then iterate over the graph we've discovered
1677 // in `cargo metadata` with the maps above and figure out what `-p`
1678 // arguments need to get passed.
1679 if test_kind.subcommand() == "test" && !builder.fail_fast {
1680 cargo.arg("--no-fail-fast");
1682 match builder.doc_tests {
1687 cargo.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
1692 cargo.arg("-p").arg(krate);
1694 // The tests are going to run with the *target* libraries, so we need to
1695 // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
1697 // Note that to run the compiler we need to run with the *host* libraries,
1698 // but our wrapper scripts arrange for that to be the case anyway.
1699 let mut dylib_path = dylib_path();
1700 dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
1701 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
1704 cargo.args(&builder.config.cmd.test_args());
1706 if !builder.config.verbose_tests {
1707 cargo.arg("--quiet");
1710 if target.contains("emscripten") {
1712 format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
1713 builder.config.nodejs.as_ref().expect("nodejs not configured"),
1715 } else if target.starts_with("wasm32") {
1716 let node = builder.config.nodejs.as_ref().expect("nodejs not configured");
1718 format!("{} {}/src/etc/wasm32-shim.js", node.display(), builder.src.display());
1719 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)), &runner);
1720 } else if builder.remote_tested(target) {
1722 format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
1723 format!("{} run", builder.tool_exe(Tool::RemoteTestClient).display()),
1727 builder.info(&format!(
1728 "{} {} stage{} ({} -> {})",
1729 test_kind, krate, compiler.stage, &compiler.host, target
1731 let _time = util::timeit(&builder);
1732 try_run(builder, &mut cargo.into());
1736 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1737 pub struct CrateRustdoc {
1738 host: Interned<String>,
1739 test_kind: TestKind,
1742 impl Step for CrateRustdoc {
1744 const DEFAULT: bool = true;
1745 const ONLY_HOSTS: bool = true;
1747 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1748 run.paths(&["src/librustdoc", "src/tools/rustdoc"])
1751 fn make_run(run: RunConfig<'_>) {
1752 let builder = run.builder;
1754 let test_kind = builder.kind.into();
1756 builder.ensure(CrateRustdoc { host: run.host, test_kind });
1759 fn run(self, builder: &Builder<'_>) {
1760 let test_kind = self.test_kind;
1762 let compiler = builder.compiler(builder.top_stage, self.host);
1763 let target = compiler.host;
1764 builder.ensure(compile::Rustc { compiler, target });
1766 let mut cargo = tool::prepare_tool_cargo(
1771 test_kind.subcommand(),
1772 "src/tools/rustdoc",
1776 if test_kind.subcommand() == "test" && !builder.fail_fast {
1777 cargo.arg("--no-fail-fast");
1780 cargo.arg("-p").arg("rustdoc:0.0.0");
1783 cargo.args(&builder.config.cmd.test_args());
1785 if self.host.contains("musl") {
1786 cargo.arg("'-Ctarget-feature=-crt-static'");
1789 if !builder.config.verbose_tests {
1790 cargo.arg("--quiet");
1793 builder.info(&format!(
1794 "{} rustdoc stage{} ({} -> {})",
1795 test_kind, compiler.stage, &compiler.host, target
1797 let _time = util::timeit(&builder);
1799 try_run(builder, &mut cargo.into());
1803 /// Some test suites are run inside emulators or on remote devices, and most
1804 /// of our test binaries are linked dynamically which means we need to ship
1805 /// the standard library and such to the emulator ahead of time. This step
1806 /// represents this and is a dependency of all test suites.
1808 /// Most of the time this is a no-op. For some steps such as shipping data to
1809 /// QEMU we have to build our own tools so we've got conditional dependencies
1810 /// on those programs as well. Note that the remote test client is built for
1811 /// the build target (us) and the server is built for the target.
1812 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1813 pub struct RemoteCopyLibs {
1815 target: Interned<String>,
1818 impl Step for RemoteCopyLibs {
1821 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1825 fn run(self, builder: &Builder<'_>) {
1826 let compiler = self.compiler;
1827 let target = self.target;
1828 if !builder.remote_tested(target) {
1832 builder.ensure(compile::Std { compiler, target });
1834 builder.info(&format!("REMOTE copy libs to emulator ({})", target));
1835 t!(fs::create_dir_all(builder.out.join("tmp")));
1838 builder.ensure(tool::RemoteTestServer { compiler: compiler.with_stage(0), target });
1840 // Spawn the emulator and wait for it to come online
1841 let tool = builder.tool_exe(Tool::RemoteTestClient);
1842 let mut cmd = Command::new(&tool);
1843 cmd.arg("spawn-emulator").arg(target).arg(&server).arg(builder.out.join("tmp"));
1844 if let Some(rootfs) = builder.qemu_rootfs(target) {
1847 builder.run(&mut cmd);
1849 // Push all our dylibs to the emulator
1850 for f in t!(builder.sysroot_libdir(compiler, target).read_dir()) {
1852 let name = f.file_name().into_string().unwrap();
1853 if util::is_dylib(&name) {
1854 builder.run(Command::new(&tool).arg("push").arg(f.path()));
1860 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1861 pub struct Distcheck;
1863 impl Step for Distcheck {
1866 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1867 run.path("distcheck")
1870 fn make_run(run: RunConfig<'_>) {
1871 run.builder.ensure(Distcheck);
1874 /// Runs "distcheck", a 'make check' from a tarball
1875 fn run(self, builder: &Builder<'_>) {
1876 builder.info("Distcheck");
1877 let dir = builder.out.join("tmp").join("distcheck");
1878 let _ = fs::remove_dir_all(&dir);
1879 t!(fs::create_dir_all(&dir));
1881 // Guarantee that these are built before we begin running.
1882 builder.ensure(dist::PlainSourceTarball);
1883 builder.ensure(dist::Src);
1885 let mut cmd = Command::new("tar");
1887 .arg(builder.ensure(dist::PlainSourceTarball))
1888 .arg("--strip-components=1")
1890 builder.run(&mut cmd);
1892 Command::new("./configure")
1893 .args(&builder.config.configure_args)
1894 .arg("--enable-vendor")
1898 Command::new(build_helper::make(&builder.config.build)).arg("check").current_dir(&dir),
1901 // Now make sure that rust-src has all of libstd's dependencies
1902 builder.info("Distcheck rust-src");
1903 let dir = builder.out.join("tmp").join("distcheck-src");
1904 let _ = fs::remove_dir_all(&dir);
1905 t!(fs::create_dir_all(&dir));
1907 let mut cmd = Command::new("tar");
1909 .arg(builder.ensure(dist::Src))
1910 .arg("--strip-components=1")
1912 builder.run(&mut cmd);
1914 let toml = dir.join("rust-src/lib/rustlib/src/rust/src/libstd/Cargo.toml");
1916 Command::new(&builder.initial_cargo)
1917 .arg("generate-lockfile")
1918 .arg("--manifest-path")
1925 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1926 pub struct Bootstrap;
1928 impl Step for Bootstrap {
1930 const DEFAULT: bool = true;
1931 const ONLY_HOSTS: bool = true;
1933 /// Tests the build system itself.
1934 fn run(self, builder: &Builder<'_>) {
1935 let mut cmd = Command::new(&builder.initial_cargo);
1937 .current_dir(builder.src.join("src/bootstrap"))
1938 .env("RUSTFLAGS", "-Cdebuginfo=2")
1939 .env("CARGO_TARGET_DIR", builder.out.join("bootstrap"))
1940 .env("RUSTC_BOOTSTRAP", "1")
1941 .env("RUSTC", &builder.initial_rustc);
1942 if let Some(flags) = option_env!("RUSTFLAGS") {
1943 // Use the same rustc flags for testing as for "normal" compilation,
1944 // so that Cargo doesn’t recompile the entire dependency graph every time:
1945 // https://github.com/rust-lang/rust/issues/49215
1946 cmd.env("RUSTFLAGS", flags);
1948 if !builder.fail_fast {
1949 cmd.arg("--no-fail-fast");
1951 cmd.arg("--").args(&builder.config.cmd.test_args());
1952 // rustbuild tests are racy on directory creation so just run them one at a time.
1953 // Since there's not many this shouldn't be a problem.
1954 cmd.arg("--test-threads=1");
1955 try_run(builder, &mut cmd);
1958 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1959 run.path("src/bootstrap")
1962 fn make_run(run: RunConfig<'_>) {
1963 run.builder.ensure(Bootstrap);