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};
19 use crate::config::TargetSelection;
21 use crate::flags::Subcommand;
23 use crate::tool::{self, SourceType, Tool};
24 use crate::toolstate::ToolState;
25 use crate::util::{self, add_link_lib_path, dylib_path, dylib_path_var};
26 use crate::Crate as CargoCrate;
27 use crate::{envify, DocTests, GitRepo, Mode};
29 const ADB_TEST_DIR: &str = "/data/tmp/work";
31 /// The two modes of the test runner; tests or benchmarks.
32 #[derive(Debug, PartialEq, Eq, Hash, Copy, Clone, PartialOrd, Ord)]
36 /// Run `cargo bench`.
40 impl From<Kind> for TestKind {
41 fn from(kind: Kind) -> Self {
43 Kind::Test => TestKind::Test,
44 Kind::Bench => TestKind::Bench,
45 _ => panic!("unexpected kind in crate: {:?}", kind),
51 // Return the cargo subcommand for this test kind
52 fn subcommand(self) -> &'static str {
54 TestKind::Test => "test",
55 TestKind::Bench => "bench",
60 impl fmt::Display for TestKind {
61 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
62 f.write_str(match *self {
63 TestKind::Test => "Testing",
64 TestKind::Bench => "Benchmarking",
69 fn try_run(builder: &Builder<'_>, cmd: &mut Command) -> bool {
70 if !builder.fail_fast {
71 if !builder.try_run(cmd) {
72 let mut failures = builder.delayed_failures.borrow_mut();
73 failures.push(format!("{:?}", cmd));
82 fn try_run_quiet(builder: &Builder<'_>, cmd: &mut Command) -> bool {
83 if !builder.fail_fast {
84 if !builder.try_run_quiet(cmd) {
85 let mut failures = builder.delayed_failures.borrow_mut();
86 failures.push(format!("{:?}", cmd));
90 builder.run_quiet(cmd);
95 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
96 pub struct Linkcheck {
97 host: TargetSelection,
100 impl Step for Linkcheck {
102 const ONLY_HOSTS: bool = true;
103 const DEFAULT: bool = true;
105 /// Runs the `linkchecker` tool as compiled in `stage` by the `host` compiler.
107 /// This tool in `src/tools` will verify the validity of all our links in the
108 /// documentation to ensure we don't have a bunch of dead ones.
109 fn run(self, builder: &Builder<'_>) {
110 let host = self.host;
112 builder.info(&format!("Linkcheck ({})", host));
114 builder.default_doc(None);
116 let _time = util::timeit(&builder);
119 builder.tool_cmd(Tool::Linkchecker).arg(builder.out.join(host.triple).join("doc")),
123 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
124 let builder = run.builder;
125 run.path("src/tools/linkchecker").default_condition(builder.config.docs)
128 fn make_run(run: RunConfig<'_>) {
129 run.builder.ensure(Linkcheck { host: run.target });
133 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
134 pub struct Cargotest {
136 host: TargetSelection,
139 impl Step for Cargotest {
141 const ONLY_HOSTS: bool = true;
143 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
144 run.path("src/tools/cargotest")
147 fn make_run(run: RunConfig<'_>) {
148 run.builder.ensure(Cargotest { stage: run.builder.top_stage, host: run.target });
151 /// Runs the `cargotest` tool as compiled in `stage` by the `host` compiler.
153 /// This tool in `src/tools` will check out a few Rust projects and run `cargo
154 /// test` to ensure that we don't regress the test suites there.
155 fn run(self, builder: &Builder<'_>) {
156 let compiler = builder.compiler(self.stage, self.host);
157 builder.ensure(compile::Rustc { compiler, target: compiler.host });
158 let cargo = builder.ensure(tool::Cargo { compiler, target: compiler.host });
160 // Note that this is a short, cryptic, and not scoped directory name. This
161 // is currently to minimize the length of path on Windows where we otherwise
162 // quickly run into path name limit constraints.
163 let out_dir = builder.out.join("ct");
164 t!(fs::create_dir_all(&out_dir));
166 let _time = util::timeit(&builder);
167 let mut cmd = builder.tool_cmd(Tool::CargoTest);
172 .env("RUSTC", builder.rustc(compiler))
173 .env("RUSTDOC", builder.rustdoc(compiler)),
178 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
181 host: TargetSelection,
184 impl Step for Cargo {
186 const ONLY_HOSTS: bool = true;
188 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
189 run.path("src/tools/cargo")
192 fn make_run(run: RunConfig<'_>) {
193 run.builder.ensure(Cargo { stage: run.builder.top_stage, host: run.target });
196 /// Runs `cargo test` for `cargo` packaged with Rust.
197 fn run(self, builder: &Builder<'_>) {
198 let compiler = builder.compiler(self.stage, self.host);
200 builder.ensure(tool::Cargo { compiler, target: self.host });
201 let mut cargo = tool::prepare_tool_cargo(
208 SourceType::Submodule,
212 if !builder.fail_fast {
213 cargo.arg("--no-fail-fast");
216 // Don't run cross-compile tests, we may not have cross-compiled libstd libs
218 cargo.env("CFG_DISABLE_CROSS_TESTS", "1");
219 // Disable a test that has issues with mingw.
220 cargo.env("CARGO_TEST_DISABLE_GIT_CLI", "1");
221 // Forcibly disable tests using nightly features since any changes to
222 // those features won't be able to land.
223 cargo.env("CARGO_TEST_DISABLE_NIGHTLY", "1");
225 cargo.env("PATH", &path_for_cargo(builder, compiler));
227 try_run(builder, &mut cargo.into());
231 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
234 host: TargetSelection,
239 const ONLY_HOSTS: bool = true;
241 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
242 run.path("src/tools/rls")
245 fn make_run(run: RunConfig<'_>) {
246 run.builder.ensure(Rls { stage: run.builder.top_stage, host: run.target });
249 /// Runs `cargo test` for the rls.
250 fn run(self, builder: &Builder<'_>) {
251 let stage = self.stage;
252 let host = self.host;
253 let compiler = builder.compiler(stage, host);
256 builder.ensure(tool::Rls { compiler, target: self.host, extra_features: Vec::new() });
257 if build_result.is_none() {
258 eprintln!("failed to test rls: could not build");
262 let mut cargo = tool::prepare_tool_cargo(
269 SourceType::Submodule,
273 cargo.add_rustc_lib_path(builder, compiler);
274 cargo.arg("--").args(builder.config.cmd.test_args());
276 if try_run(builder, &mut cargo.into()) {
277 builder.save_toolstate("rls", ToolState::TestPass);
282 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
285 host: TargetSelection,
288 impl Step for Rustfmt {
290 const ONLY_HOSTS: bool = true;
292 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
293 run.path("src/tools/rustfmt")
296 fn make_run(run: RunConfig<'_>) {
297 run.builder.ensure(Rustfmt { stage: run.builder.top_stage, host: run.target });
300 /// Runs `cargo test` for rustfmt.
301 fn run(self, builder: &Builder<'_>) {
302 let stage = self.stage;
303 let host = self.host;
304 let compiler = builder.compiler(stage, host);
306 let build_result = builder.ensure(tool::Rustfmt {
309 extra_features: Vec::new(),
311 if build_result.is_none() {
312 eprintln!("failed to test rustfmt: could not build");
316 let mut cargo = tool::prepare_tool_cargo(
323 SourceType::Submodule,
327 let dir = testdir(builder, compiler.host);
328 t!(fs::create_dir_all(&dir));
329 cargo.env("RUSTFMT_TEST_DIR", dir);
331 cargo.add_rustc_lib_path(builder, compiler);
333 if try_run(builder, &mut cargo.into()) {
334 builder.save_toolstate("rustfmt", ToolState::TestPass);
339 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
342 host: TargetSelection,
347 const ONLY_HOSTS: bool = true;
349 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
350 run.path("src/tools/miri")
353 fn make_run(run: RunConfig<'_>) {
354 run.builder.ensure(Miri { stage: run.builder.top_stage, host: run.target });
357 /// Runs `cargo test` for miri.
358 fn run(self, builder: &Builder<'_>) {
359 let stage = self.stage;
360 let host = self.host;
361 let compiler = builder.compiler(stage, host);
364 builder.ensure(tool::Miri { compiler, target: self.host, extra_features: Vec::new() });
365 let cargo_miri = builder.ensure(tool::CargoMiri {
368 extra_features: Vec::new(),
370 if let (Some(miri), Some(_cargo_miri)) = (miri, cargo_miri) {
372 builder.cargo(compiler, Mode::ToolRustc, SourceType::Submodule, host, "install");
374 // Configure `cargo install` path. cargo adds a `bin/`.
375 cargo.env("CARGO_INSTALL_ROOT", &builder.out);
377 let mut cargo = Command::from(cargo);
378 if !try_run(builder, &mut cargo) {
382 // # Run `cargo miri setup`.
383 let mut cargo = tool::prepare_tool_cargo(
389 "src/tools/miri/cargo-miri",
390 SourceType::Submodule,
393 cargo.arg("--").arg("miri").arg("setup");
395 // Tell `cargo miri setup` where to find the sources.
396 cargo.env("XARGO_RUST_SRC", builder.src.join("library"));
397 // Tell it where to find Miri.
398 cargo.env("MIRI", &miri);
400 cargo.env("RUST_BACKTRACE", "1");
401 // Let cargo-miri know where xargo ended up.
402 cargo.env("XARGO_CHECK", builder.out.join("bin").join("xargo-check"));
404 let mut cargo = Command::from(cargo);
405 if !try_run(builder, &mut cargo) {
409 // # Determine where Miri put its sysroot.
410 // To this end, we run `cargo miri setup --print-sysroot` and capture the output.
411 // (We do this separately from the above so that when the setup actually
412 // happens we get some output.)
413 // We re-use the `cargo` from above.
414 cargo.arg("--print-sysroot");
416 // FIXME: Is there a way in which we can re-use the usual `run` helpers?
417 let miri_sysroot = if builder.config.dry_run {
420 builder.verbose(&format!("running: {:?}", cargo));
423 .expect("We already ran `cargo miri setup` before and that worked");
424 assert!(out.status.success(), "`cargo miri setup` returned with non-0 exit code");
425 // Output is "<sysroot>\n".
426 let stdout = String::from_utf8(out.stdout)
427 .expect("`cargo miri setup` stdout is not valid UTF-8");
428 let sysroot = stdout.trim_end();
429 builder.verbose(&format!("`cargo miri setup --print-sysroot` said: {:?}", sysroot));
433 // # Run `cargo test`.
434 let mut cargo = tool::prepare_tool_cargo(
441 SourceType::Submodule,
445 // miri tests need to know about the stage sysroot
446 cargo.env("MIRI_SYSROOT", miri_sysroot);
447 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
448 cargo.env("MIRI", miri);
450 cargo.arg("--").args(builder.config.cmd.test_args());
452 cargo.add_rustc_lib_path(builder, compiler);
454 if !try_run(builder, &mut cargo.into()) {
459 builder.save_toolstate("miri", ToolState::TestPass);
461 eprintln!("failed to test miri: could not build");
466 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
467 pub struct CompiletestTest {
468 host: TargetSelection,
471 impl Step for CompiletestTest {
474 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
475 run.path("src/tools/compiletest")
478 fn make_run(run: RunConfig<'_>) {
479 run.builder.ensure(CompiletestTest { host: run.target });
482 /// Runs `cargo test` for compiletest.
483 fn run(self, builder: &Builder<'_>) {
484 let host = self.host;
485 let compiler = builder.compiler(0, host);
487 let cargo = tool::prepare_tool_cargo(
493 "src/tools/compiletest",
498 try_run(builder, &mut cargo.into());
502 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
505 host: TargetSelection,
508 impl Step for Clippy {
510 const ONLY_HOSTS: bool = true;
511 const DEFAULT: bool = false;
513 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
514 run.path("src/tools/clippy")
517 fn make_run(run: RunConfig<'_>) {
518 run.builder.ensure(Clippy { stage: run.builder.top_stage, host: run.target });
521 /// Runs `cargo test` for clippy.
522 fn run(self, builder: &Builder<'_>) {
523 let stage = self.stage;
524 let host = self.host;
525 let compiler = builder.compiler(stage, host);
528 .ensure(tool::Clippy { compiler, target: self.host, extra_features: Vec::new() })
529 .expect("in-tree tool");
530 let mut cargo = tool::prepare_tool_cargo(
541 // clippy tests need to know about the stage sysroot
542 cargo.env("SYSROOT", builder.sysroot(compiler));
543 cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
544 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
545 let host_libs = builder.stage_out(compiler, Mode::ToolRustc).join(builder.cargo_dir());
546 let target_libs = builder
547 .stage_out(compiler, Mode::ToolRustc)
548 .join(&self.host.triple)
549 .join(builder.cargo_dir());
550 cargo.env("HOST_LIBS", host_libs);
551 cargo.env("TARGET_LIBS", target_libs);
552 // clippy tests need to find the driver
553 cargo.env("CLIPPY_DRIVER_PATH", clippy);
555 cargo.arg("--").args(builder.config.cmd.test_args());
557 cargo.add_rustc_lib_path(builder, compiler);
559 builder.run(&mut cargo.into());
563 fn path_for_cargo(builder: &Builder<'_>, compiler: Compiler) -> OsString {
564 // Configure PATH to find the right rustc. NB. we have to use PATH
565 // and not RUSTC because the Cargo test suite has tests that will
566 // fail if rustc is not spelled `rustc`.
567 let path = builder.sysroot(compiler).join("bin");
568 let old_path = env::var_os("PATH").unwrap_or_default();
569 env::join_paths(iter::once(path).chain(env::split_paths(&old_path))).expect("")
572 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
573 pub struct RustdocTheme {
574 pub compiler: Compiler,
577 impl Step for RustdocTheme {
579 const DEFAULT: bool = true;
580 const ONLY_HOSTS: bool = true;
582 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
583 run.path("src/tools/rustdoc-themes")
586 fn make_run(run: RunConfig<'_>) {
587 let compiler = run.builder.compiler(run.builder.top_stage, run.target);
589 run.builder.ensure(RustdocTheme { compiler });
592 fn run(self, builder: &Builder<'_>) {
593 let rustdoc = builder.out.join("bootstrap/debug/rustdoc");
594 let mut cmd = builder.tool_cmd(Tool::RustdocTheme);
595 cmd.arg(rustdoc.to_str().unwrap())
596 .arg(builder.src.join("src/librustdoc/html/static/themes").to_str().unwrap())
597 .env("RUSTC_STAGE", self.compiler.stage.to_string())
598 .env("RUSTC_SYSROOT", builder.sysroot(self.compiler))
599 .env("RUSTDOC_LIBDIR", builder.sysroot_libdir(self.compiler, self.compiler.host))
600 .env("CFG_RELEASE_CHANNEL", &builder.config.channel)
601 .env("RUSTDOC_REAL", builder.rustdoc(self.compiler))
602 .env("RUSTC_BOOTSTRAP", "1");
603 if let Some(linker) = builder.linker(self.compiler.host) {
604 cmd.env("RUSTDOC_LINKER", linker);
606 if builder.is_fuse_ld_lld(self.compiler.host) {
607 cmd.env("RUSTDOC_FUSE_LD_LLD", "1");
609 try_run(builder, &mut cmd);
613 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
614 pub struct RustdocJSStd {
615 pub target: TargetSelection,
618 impl Step for RustdocJSStd {
620 const DEFAULT: bool = true;
621 const ONLY_HOSTS: bool = true;
623 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
624 run.path("src/test/rustdoc-js-std")
627 fn make_run(run: RunConfig<'_>) {
628 run.builder.ensure(RustdocJSStd { target: run.target });
631 fn run(self, builder: &Builder<'_>) {
632 if let Some(ref nodejs) = builder.config.nodejs {
633 let mut command = Command::new(nodejs);
635 .arg(builder.src.join("src/tools/rustdoc-js/tester.js"))
638 .arg("--resource-suffix")
639 .arg(&builder.version)
641 .arg(builder.doc_out(self.target))
642 .arg("--test-folder")
643 .arg(builder.src.join("src/test/rustdoc-js-std"));
644 builder.ensure(crate::doc::Std { target: self.target, stage: builder.top_stage });
645 builder.run(&mut command);
647 builder.info("No nodejs found, skipping \"src/test/rustdoc-js-std\" tests");
652 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
653 pub struct RustdocJSNotStd {
654 pub target: TargetSelection,
655 pub compiler: Compiler,
658 impl Step for RustdocJSNotStd {
660 const DEFAULT: bool = true;
661 const ONLY_HOSTS: bool = true;
663 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
664 run.path("src/test/rustdoc-js")
667 fn make_run(run: RunConfig<'_>) {
668 let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
669 run.builder.ensure(RustdocJSNotStd { target: run.target, compiler });
672 fn run(self, builder: &Builder<'_>) {
673 if builder.config.nodejs.is_some() {
674 builder.ensure(Compiletest {
675 compiler: self.compiler,
679 path: "src/test/rustdoc-js",
683 builder.info("No nodejs found, skipping \"src/test/rustdoc-js\" tests");
688 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
689 pub struct RustdocUi {
690 pub target: TargetSelection,
691 pub compiler: Compiler,
694 impl Step for RustdocUi {
696 const DEFAULT: bool = true;
697 const ONLY_HOSTS: bool = true;
699 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
700 run.path("src/test/rustdoc-ui")
703 fn make_run(run: RunConfig<'_>) {
704 let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
705 run.builder.ensure(RustdocUi { target: run.target, compiler });
708 fn run(self, builder: &Builder<'_>) {
709 builder.ensure(Compiletest {
710 compiler: self.compiler,
714 path: "src/test/rustdoc-ui",
720 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
725 const DEFAULT: bool = true;
726 const ONLY_HOSTS: bool = true;
728 /// Runs the `tidy` tool.
730 /// This tool in `src/tools` checks up on various bits and pieces of style and
731 /// otherwise just implements a few lint-like checks that are specific to the
734 /// Once tidy passes, this step also runs `fmt --check` if tests are being run
735 /// for the `dev` or `nightly` channels.
736 fn run(self, builder: &Builder<'_>) {
737 let mut cmd = builder.tool_cmd(Tool::Tidy);
738 cmd.arg(&builder.src);
739 cmd.arg(&builder.initial_cargo);
740 cmd.arg(&builder.out);
741 if builder.is_verbose() {
742 cmd.arg("--verbose");
745 builder.info("tidy check");
746 try_run(builder, &mut cmd);
748 if builder.config.channel == "dev" || builder.config.channel == "nightly" {
749 builder.info("fmt check");
750 crate::format::format(&builder.build, !builder.config.cmd.bless());
754 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
755 run.path("src/tools/tidy")
758 fn make_run(run: RunConfig<'_>) {
759 run.builder.ensure(Tidy);
763 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
764 pub struct ExpandYamlAnchors;
766 impl Step for ExpandYamlAnchors {
768 const ONLY_HOSTS: bool = true;
770 /// Ensure the `generate-ci-config` tool was run locally.
772 /// The tool in `src/tools` reads the CI definition in `src/ci/builders.yml` and generates the
773 /// appropriate configuration for all our CI providers. This step ensures the tool was called
774 /// by the user before committing CI changes.
775 fn run(self, builder: &Builder<'_>) {
776 builder.info("Ensuring the YAML anchors in the GitHub Actions config were expanded");
779 &mut builder.tool_cmd(Tool::ExpandYamlAnchors).arg("check").arg(&builder.src),
783 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
784 run.path("src/tools/expand-yaml-anchors")
787 fn make_run(run: RunConfig<'_>) {
788 run.builder.ensure(ExpandYamlAnchors);
792 fn testdir(builder: &Builder<'_>, host: TargetSelection) -> PathBuf {
793 builder.out.join(host.triple).join("test")
796 macro_rules! default_test {
797 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
798 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: false });
802 macro_rules! default_test_with_compare_mode {
803 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr,
804 compare_mode: $compare_mode:expr }) => {
805 test_with_compare_mode!($name {
811 compare_mode: $compare_mode
816 macro_rules! host_test {
817 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
818 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: true });
823 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
824 host: $host:expr }) => {
825 test_definitions!($name {
836 macro_rules! test_with_compare_mode {
837 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
838 host: $host:expr, compare_mode: $compare_mode:expr }) => {
839 test_definitions!($name {
845 compare_mode: Some($compare_mode)
850 macro_rules! test_definitions {
855 default: $default:expr,
857 compare_mode: $compare_mode:expr
859 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
861 pub compiler: Compiler,
862 pub target: TargetSelection,
865 impl Step for $name {
867 const DEFAULT: bool = $default;
868 const ONLY_HOSTS: bool = $host;
870 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
871 run.suite_path($path)
874 fn make_run(run: RunConfig<'_>) {
875 let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
877 run.builder.ensure($name { compiler, target: run.target });
880 fn run(self, builder: &Builder<'_>) {
881 builder.ensure(Compiletest {
882 compiler: self.compiler,
887 compare_mode: $compare_mode,
894 default_test_with_compare_mode!(Ui {
901 default_test!(CompileFail {
902 path: "src/test/compile-fail",
903 mode: "compile-fail",
904 suite: "compile-fail"
907 default_test!(RunPassValgrind {
908 path: "src/test/run-pass-valgrind",
909 mode: "run-pass-valgrind",
910 suite: "run-pass-valgrind"
913 default_test!(MirOpt { path: "src/test/mir-opt", mode: "mir-opt", suite: "mir-opt" });
915 default_test!(Codegen { path: "src/test/codegen", mode: "codegen", suite: "codegen" });
917 default_test!(CodegenUnits {
918 path: "src/test/codegen-units",
919 mode: "codegen-units",
920 suite: "codegen-units"
923 default_test!(Incremental {
924 path: "src/test/incremental",
929 default_test!(Debuginfo { path: "src/test/debuginfo", mode: "debuginfo", suite: "debuginfo" });
931 host_test!(UiFullDeps { path: "src/test/ui-fulldeps", mode: "ui", suite: "ui-fulldeps" });
933 host_test!(Rustdoc { path: "src/test/rustdoc", mode: "rustdoc", suite: "rustdoc" });
935 host_test!(Pretty { path: "src/test/pretty", mode: "pretty", suite: "pretty" });
937 default_test!(RunMake { path: "src/test/run-make", mode: "run-make", suite: "run-make" });
939 host_test!(RunMakeFullDeps {
940 path: "src/test/run-make-fulldeps",
942 suite: "run-make-fulldeps"
945 default_test!(Assembly { path: "src/test/assembly", mode: "assembly", suite: "assembly" });
947 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
950 target: TargetSelection,
954 compare_mode: Option<&'static str>,
957 impl Step for Compiletest {
960 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
964 /// Executes the `compiletest` tool to run a suite of tests.
966 /// Compiles all tests with `compiler` for `target` with the specified
967 /// compiletest `mode` and `suite` arguments. For example `mode` can be
968 /// "run-pass" or `suite` can be something like `debuginfo`.
969 fn run(self, builder: &Builder<'_>) {
970 if builder.top_stage == 0 && env::var("COMPILETEST_FORCE_STAGE0").is_err() {
972 error: `--stage 0` runs compiletest on the beta compiler, not your local changes, and will almost always cause tests to fail
973 help: use `--stage 1` instead
974 note: if you're sure you want to do this, please open an issue as to why. In the meantime, you can override this with `COMPILETEST_FORCE_STAGE0=1`."
976 std::process::exit(1);
979 let compiler = self.compiler;
980 let target = self.target;
981 let mode = self.mode;
982 let suite = self.suite;
984 // Path for test suite
985 let suite_path = self.path;
987 // Skip codegen tests if they aren't enabled in configuration.
988 if !builder.config.codegen_tests && suite == "codegen" {
992 if suite == "debuginfo" {
994 .ensure(dist::DebuggerScripts { sysroot: builder.sysroot(compiler), host: target });
997 if suite.ends_with("fulldeps") {
998 builder.ensure(compile::Rustc { compiler, target });
1001 builder.ensure(compile::Std { compiler, target });
1002 // ensure that `libproc_macro` is available on the host.
1003 builder.ensure(compile::Std { compiler, target: compiler.host });
1005 // Also provide `rust_test_helpers` for the host.
1006 builder.ensure(native::TestHelpers { target: compiler.host });
1008 // As well as the target, except for plain wasm32, which can't build it
1009 if !target.contains("wasm32") || target.contains("emscripten") {
1010 builder.ensure(native::TestHelpers { target });
1013 builder.ensure(RemoteCopyLibs { compiler, target });
1015 let mut cmd = builder.tool_cmd(Tool::Compiletest);
1017 // compiletest currently has... a lot of arguments, so let's just pass all
1020 cmd.arg("--compile-lib-path").arg(builder.rustc_libdir(compiler));
1021 cmd.arg("--run-lib-path").arg(builder.sysroot_libdir(compiler, target));
1022 cmd.arg("--rustc-path").arg(builder.rustc(compiler));
1024 let is_rustdoc = suite.ends_with("rustdoc-ui") || suite.ends_with("rustdoc-js");
1026 // Avoid depending on rustdoc when we don't need it.
1027 if mode == "rustdoc"
1028 || (mode == "run-make" && suite.ends_with("fulldeps"))
1029 || (mode == "ui" && is_rustdoc)
1030 || mode == "js-doc-test"
1032 cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler));
1035 if mode == "run-make" && suite.ends_with("fulldeps") {
1036 cmd.arg("--rust-demangler-path").arg(builder.tool_exe(Tool::RustDemangler));
1039 cmd.arg("--src-base").arg(builder.src.join("src/test").join(suite));
1040 cmd.arg("--build-base").arg(testdir(builder, compiler.host).join(suite));
1041 cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target));
1042 cmd.arg("--mode").arg(mode);
1043 cmd.arg("--target").arg(target.rustc_target_arg());
1044 cmd.arg("--host").arg(&*compiler.host.triple);
1045 cmd.arg("--llvm-filecheck").arg(builder.llvm_filecheck(builder.config.build));
1047 if builder.config.cmd.bless() {
1052 builder.config.cmd.compare_mode().or_else(|| {
1053 if builder.config.test_compare_mode { self.compare_mode } else { None }
1056 if let Some(ref pass) = builder.config.cmd.pass() {
1061 if let Some(ref nodejs) = builder.config.nodejs {
1062 cmd.arg("--nodejs").arg(nodejs);
1065 let mut flags = if is_rustdoc { Vec::new() } else { vec!["-Crpath".to_string()] };
1067 if builder.config.rust_optimize_tests {
1068 flags.push("-O".to_string());
1071 flags.push(format!("-Cdebuginfo={}", builder.config.rust_debuginfo_level_tests));
1072 flags.push("-Zunstable-options".to_string());
1073 flags.push(builder.config.cmd.rustc_args().join(" "));
1075 if let Some(linker) = builder.linker(target) {
1076 cmd.arg("--linker").arg(linker);
1079 let mut hostflags = flags.clone();
1080 hostflags.push(format!("-Lnative={}", builder.test_helpers_out(compiler.host).display()));
1081 if builder.is_fuse_ld_lld(compiler.host) {
1082 hostflags.push("-Clink-args=-fuse-ld=lld".to_string());
1084 cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
1086 let mut targetflags = flags;
1087 targetflags.push(format!("-Lnative={}", builder.test_helpers_out(target).display()));
1088 if builder.is_fuse_ld_lld(target) {
1089 targetflags.push("-Clink-args=-fuse-ld=lld".to_string());
1091 cmd.arg("--target-rustcflags").arg(targetflags.join(" "));
1093 cmd.arg("--docck-python").arg(builder.python());
1095 if builder.config.build.ends_with("apple-darwin") {
1096 // Force /usr/bin/python3 on macOS for LLDB tests because we're loading the
1097 // LLDB plugin's compiled module which only works with the system python
1098 // (namely not Homebrew-installed python)
1099 cmd.arg("--lldb-python").arg("/usr/bin/python3");
1101 cmd.arg("--lldb-python").arg(builder.python());
1104 if let Some(ref gdb) = builder.config.gdb {
1105 cmd.arg("--gdb").arg(gdb);
1108 let run = |cmd: &mut Command| {
1109 cmd.output().map(|output| {
1110 String::from_utf8_lossy(&output.stdout)
1113 .unwrap_or_else(|| panic!("{:?} failed {:?}", cmd, output))
1117 let lldb_exe = "lldb";
1118 let lldb_version = Command::new(lldb_exe)
1121 .map(|output| String::from_utf8_lossy(&output.stdout).to_string())
1123 if let Some(ref vers) = lldb_version {
1124 cmd.arg("--lldb-version").arg(vers);
1125 let lldb_python_dir = run(Command::new(lldb_exe).arg("-P")).ok();
1126 if let Some(ref dir) = lldb_python_dir {
1127 cmd.arg("--lldb-python-dir").arg(dir);
1131 if util::forcing_clang_based_tests() {
1132 let clang_exe = builder.llvm_out(target).join("bin").join("clang");
1133 cmd.arg("--run-clang-based-tests-with").arg(clang_exe);
1136 // Get paths from cmd args
1137 let paths = match &builder.config.cmd {
1138 Subcommand::Test { ref paths, .. } => &paths[..],
1142 // Get test-args by striping suite path
1143 let mut test_args: Vec<&str> = paths
1145 .map(|p| match p.strip_prefix(".") {
1149 .filter(|p| p.starts_with(suite_path) && (p.is_dir() || p.is_file()))
1151 // Since test suite paths are themselves directories, if we don't
1152 // specify a directory or file, we'll get an empty string here
1153 // (the result of the test suite directory without its suite prefix).
1154 // Therefore, we need to filter these out, as only the first --test-args
1155 // flag is respected, so providing an empty --test-args conflicts with
1156 // any following it.
1157 match p.strip_prefix(suite_path).ok().and_then(|p| p.to_str()) {
1158 Some(s) if s != "" => Some(s),
1164 test_args.append(&mut builder.config.cmd.test_args());
1166 cmd.args(&test_args);
1168 if builder.is_verbose() {
1169 cmd.arg("--verbose");
1172 if !builder.config.verbose_tests {
1176 let mut llvm_components_passed = false;
1177 let mut copts_passed = false;
1178 if builder.config.llvm_enabled() {
1179 let llvm_config = builder.ensure(native::Llvm { target: builder.config.build });
1180 if !builder.config.dry_run {
1181 let llvm_version = output(Command::new(&llvm_config).arg("--version"));
1182 let llvm_components = output(Command::new(&llvm_config).arg("--components"));
1183 // Remove trailing newline from llvm-config output.
1184 cmd.arg("--llvm-version")
1185 .arg(llvm_version.trim())
1186 .arg("--llvm-components")
1187 .arg(llvm_components.trim());
1188 llvm_components_passed = true;
1190 if !builder.is_rust_llvm(target) {
1191 cmd.arg("--system-llvm");
1194 // Tests that use compiler libraries may inherit the `-lLLVM` link
1195 // requirement, but the `-L` library path is not propagated across
1196 // separate compilations. We can add LLVM's library path to the
1197 // platform-specific environment variable as a workaround.
1198 if !builder.config.dry_run && suite.ends_with("fulldeps") {
1199 let llvm_libdir = output(Command::new(&llvm_config).arg("--libdir"));
1200 add_link_lib_path(vec![llvm_libdir.trim().into()], &mut cmd);
1203 // Only pass correct values for these flags for the `run-make` suite as it
1204 // requires that a C++ compiler was configured which isn't always the case.
1205 if !builder.config.dry_run && suite == "run-make-fulldeps" {
1207 .arg(builder.cc(target))
1209 .arg(builder.cxx(target).unwrap())
1211 .arg(builder.cflags(target, GitRepo::Rustc).join(" "));
1212 copts_passed = true;
1213 if let Some(ar) = builder.ar(target) {
1214 cmd.arg("--ar").arg(ar);
1217 // The llvm/bin directory contains many useful cross-platform
1218 // tools. Pass the path to run-make tests so they can use them.
1219 let llvm_bin_path = llvm_config
1221 .expect("Expected llvm-config to be contained in directory");
1222 assert!(llvm_bin_path.is_dir());
1223 cmd.arg("--llvm-bin-dir").arg(llvm_bin_path);
1225 // If LLD is available, add it to the PATH
1226 if builder.config.lld_enabled {
1227 let lld_install_root =
1228 builder.ensure(native::Lld { target: builder.config.build });
1230 let lld_bin_path = lld_install_root.join("bin");
1232 let old_path = env::var_os("PATH").unwrap_or_default();
1233 let new_path = env::join_paths(
1234 std::iter::once(lld_bin_path).chain(env::split_paths(&old_path)),
1236 .expect("Could not add LLD bin path to PATH");
1237 cmd.env("PATH", new_path);
1242 if !llvm_components_passed {
1243 cmd.arg("--llvm-components").arg("");
1246 cmd.arg("--cc").arg("").arg("--cxx").arg("").arg("--cflags").arg("");
1249 if builder.remote_tested(target) {
1250 cmd.arg("--remote-test-client").arg(builder.tool_exe(Tool::RemoteTestClient));
1253 // Running a C compiler on MSVC requires a few env vars to be set, to be
1254 // sure to set them here.
1256 // Note that if we encounter `PATH` we make sure to append to our own `PATH`
1257 // rather than stomp over it.
1258 if target.contains("msvc") {
1259 for &(ref k, ref v) in builder.cc[&target].env() {
1265 cmd.env("RUSTC_BOOTSTRAP", "1");
1266 builder.add_rust_test_threads(&mut cmd);
1268 if builder.config.sanitizers {
1269 cmd.env("RUSTC_SANITIZER_SUPPORT", "1");
1272 if builder.config.profiler {
1273 cmd.env("RUSTC_PROFILER_SUPPORT", "1");
1276 let tmp = builder.out.join("tmp");
1277 std::fs::create_dir_all(&tmp).unwrap();
1278 cmd.env("RUST_TEST_TMPDIR", tmp);
1280 cmd.arg("--adb-path").arg("adb");
1281 cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
1282 if target.contains("android") {
1283 // Assume that cc for this target comes from the android sysroot
1284 cmd.arg("--android-cross-path")
1285 .arg(builder.cc(target).parent().unwrap().parent().unwrap());
1287 cmd.arg("--android-cross-path").arg("");
1290 if builder.config.cmd.rustfix_coverage() {
1291 cmd.arg("--rustfix-coverage");
1294 cmd.env("BOOTSTRAP_CARGO", &builder.initial_cargo);
1296 builder.ci_env.force_coloring_in_ci(&mut cmd);
1298 builder.info(&format!(
1299 "Check compiletest suite={} mode={} ({} -> {})",
1300 suite, mode, &compiler.host, target
1302 let _time = util::timeit(&builder);
1303 try_run(builder, &mut cmd);
1305 if let Some(compare_mode) = compare_mode {
1306 cmd.arg("--compare-mode").arg(compare_mode);
1307 builder.info(&format!(
1308 "Check compiletest suite={} mode={} compare_mode={} ({} -> {})",
1309 suite, mode, compare_mode, &compiler.host, target
1311 let _time = util::timeit(&builder);
1312 try_run(builder, &mut cmd);
1317 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1325 impl Step for BookTest {
1327 const ONLY_HOSTS: bool = true;
1329 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1333 /// Runs the documentation tests for a book in `src/doc`.
1335 /// This uses the `rustdoc` that sits next to `compiler`.
1336 fn run(self, builder: &Builder<'_>) {
1337 // External docs are different from local because:
1338 // - Some books need pre-processing by mdbook before being tested.
1339 // - They need to save their state to toolstate.
1340 // - They are only tested on the "checktools" builders.
1342 // The local docs are tested by default, and we don't want to pay the
1343 // cost of building mdbook, so they use `rustdoc --test` directly.
1344 // Also, the unstable book is special because SUMMARY.md is generated,
1345 // so it is easier to just run `rustdoc` on its files.
1346 if self.is_ext_doc {
1347 self.run_ext_doc(builder);
1349 self.run_local_doc(builder);
1355 /// This runs the equivalent of `mdbook test` (via the rustbook wrapper)
1356 /// which in turn runs `rustdoc --test` on each file in the book.
1357 fn run_ext_doc(self, builder: &Builder<'_>) {
1358 let compiler = self.compiler;
1360 builder.ensure(compile::Std { compiler, target: compiler.host });
1362 // mdbook just executes a binary named "rustdoc", so we need to update
1363 // PATH so that it points to our rustdoc.
1364 let mut rustdoc_path = builder.rustdoc(compiler);
1366 let old_path = env::var_os("PATH").unwrap_or_default();
1367 let new_path = env::join_paths(iter::once(rustdoc_path).chain(env::split_paths(&old_path)))
1368 .expect("could not add rustdoc to PATH");
1370 let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
1371 let path = builder.src.join(&self.path);
1372 rustbook_cmd.env("PATH", new_path).arg("test").arg(path);
1373 builder.add_rust_test_threads(&mut rustbook_cmd);
1374 builder.info(&format!("Testing rustbook {}", self.path.display()));
1375 let _time = util::timeit(&builder);
1376 let toolstate = if try_run(builder, &mut rustbook_cmd) {
1381 builder.save_toolstate(self.name, toolstate);
1384 /// This runs `rustdoc --test` on all `.md` files in the path.
1385 fn run_local_doc(self, builder: &Builder<'_>) {
1386 let compiler = self.compiler;
1388 builder.ensure(compile::Std { compiler, target: compiler.host });
1390 // Do a breadth-first traversal of the `src/doc` directory and just run
1391 // tests for all files that end in `*.md`
1392 let mut stack = vec![builder.src.join(self.path)];
1393 let _time = util::timeit(&builder);
1394 let mut files = Vec::new();
1395 while let Some(p) = stack.pop() {
1397 stack.extend(t!(p.read_dir()).map(|p| t!(p).path()));
1401 if p.extension().and_then(|s| s.to_str()) != Some("md") {
1411 markdown_test(builder, compiler, &file);
1416 macro_rules! test_book {
1417 ($($name:ident, $path:expr, $book_name:expr, default=$default:expr;)+) => {
1419 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1424 impl Step for $name {
1426 const DEFAULT: bool = $default;
1427 const ONLY_HOSTS: bool = true;
1429 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1433 fn make_run(run: RunConfig<'_>) {
1434 run.builder.ensure($name {
1435 compiler: run.builder.compiler(run.builder.top_stage, run.target),
1439 fn run(self, builder: &Builder<'_>) {
1440 builder.ensure(BookTest {
1441 compiler: self.compiler,
1442 path: PathBuf::from($path),
1444 is_ext_doc: !$default,
1453 Nomicon, "src/doc/nomicon", "nomicon", default=false;
1454 Reference, "src/doc/reference", "reference", default=false;
1455 RustdocBook, "src/doc/rustdoc", "rustdoc", default=true;
1456 RustcBook, "src/doc/rustc", "rustc", default=true;
1457 RustByExample, "src/doc/rust-by-example", "rust-by-example", default=false;
1458 EmbeddedBook, "src/doc/embedded-book", "embedded-book", default=false;
1459 TheBook, "src/doc/book", "book", default=false;
1460 UnstableBook, "src/doc/unstable-book", "unstable-book", default=true;
1461 EditionGuide, "src/doc/edition-guide", "edition-guide", default=false;
1464 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1465 pub struct ErrorIndex {
1469 impl Step for ErrorIndex {
1471 const DEFAULT: bool = true;
1472 const ONLY_HOSTS: bool = true;
1474 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1475 run.path("src/tools/error_index_generator")
1478 fn make_run(run: RunConfig<'_>) {
1479 // error_index_generator depends on librustdoc. Use the compiler that
1480 // is normally used to build rustdoc for other tests (like compiletest
1481 // tests in src/test/rustdoc) so that it shares the same artifacts.
1482 let compiler = run.builder.compiler_for(run.builder.top_stage, run.target, run.target);
1483 run.builder.ensure(ErrorIndex { compiler });
1486 /// Runs the error index generator tool to execute the tests located in the error
1489 /// The `error_index_generator` tool lives in `src/tools` and is used to
1490 /// generate a markdown file from the error indexes of the code base which is
1491 /// then passed to `rustdoc --test`.
1492 fn run(self, builder: &Builder<'_>) {
1493 let compiler = self.compiler;
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(builder, compiler);
1500 tool.arg("markdown").arg(&output);
1502 // Use the rustdoc that was built by self.compiler. This copy of
1503 // rustdoc is shared with other tests (like compiletest tests in
1504 // src/test/rustdoc). This helps avoid building rustdoc multiple
1506 let rustdoc_compiler = builder.compiler(builder.top_stage, builder.config.build);
1507 builder.info(&format!("Testing error-index stage{}", rustdoc_compiler.stage));
1508 let _time = util::timeit(&builder);
1509 builder.run_quiet(&mut tool);
1510 builder.ensure(compile::Std { compiler: rustdoc_compiler, target: rustdoc_compiler.host });
1511 markdown_test(builder, rustdoc_compiler, &output);
1515 fn markdown_test(builder: &Builder<'_>, compiler: Compiler, markdown: &Path) -> bool {
1516 if let Ok(contents) = fs::read_to_string(markdown) {
1517 if !contents.contains("```") {
1522 builder.info(&format!("doc tests for: {}", markdown.display()));
1523 let mut cmd = builder.rustdoc_cmd(compiler);
1524 builder.add_rust_test_threads(&mut cmd);
1527 cmd.env("RUSTC_BOOTSTRAP", "1");
1529 let test_args = builder.config.cmd.test_args().join(" ");
1530 cmd.arg("--test-args").arg(test_args);
1532 if builder.config.verbose_tests {
1533 try_run(builder, &mut cmd)
1535 try_run_quiet(builder, &mut cmd)
1539 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1540 pub struct RustcGuide;
1542 impl Step for RustcGuide {
1544 const DEFAULT: bool = false;
1545 const ONLY_HOSTS: bool = true;
1547 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1548 run.path("src/doc/rustc-dev-guide")
1551 fn make_run(run: RunConfig<'_>) {
1552 run.builder.ensure(RustcGuide);
1555 fn run(self, builder: &Builder<'_>) {
1556 let src = builder.src.join("src/doc/rustc-dev-guide");
1557 let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
1558 let toolstate = if try_run(builder, rustbook_cmd.arg("linkcheck").arg(&src)) {
1563 builder.save_toolstate("rustc-dev-guide", toolstate);
1567 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1568 pub struct CrateLibrustc {
1570 target: TargetSelection,
1571 test_kind: TestKind,
1572 krate: Interned<String>,
1575 impl Step for CrateLibrustc {
1577 const DEFAULT: bool = true;
1578 const ONLY_HOSTS: bool = true;
1580 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1581 run.krate("rustc-main")
1584 fn make_run(run: RunConfig<'_>) {
1585 let builder = run.builder;
1586 let compiler = builder.compiler(builder.top_stage, run.build_triple());
1588 for krate in builder.in_tree_crates("rustc-main") {
1589 if krate.path.ends_with(&run.path) {
1590 let test_kind = builder.kind.into();
1592 builder.ensure(CrateLibrustc {
1602 fn run(self, builder: &Builder<'_>) {
1603 builder.ensure(Crate {
1604 compiler: self.compiler,
1605 target: self.target,
1607 test_kind: self.test_kind,
1613 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1614 pub struct CrateNotDefault {
1616 target: TargetSelection,
1617 test_kind: TestKind,
1618 krate: &'static str,
1621 impl Step for CrateNotDefault {
1624 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1625 run.path("src/librustc_asan")
1626 .path("src/librustc_lsan")
1627 .path("src/librustc_msan")
1628 .path("src/librustc_tsan")
1631 fn make_run(run: RunConfig<'_>) {
1632 let builder = run.builder;
1633 let compiler = builder.compiler(builder.top_stage, run.build_triple());
1635 let test_kind = builder.kind.into();
1637 builder.ensure(CrateNotDefault {
1641 krate: match run.path {
1642 _ if run.path.ends_with("src/librustc_asan") => "rustc_asan",
1643 _ if run.path.ends_with("src/librustc_lsan") => "rustc_lsan",
1644 _ if run.path.ends_with("src/librustc_msan") => "rustc_msan",
1645 _ if run.path.ends_with("src/librustc_tsan") => "rustc_tsan",
1646 _ => panic!("unexpected path {:?}", run.path),
1651 fn run(self, builder: &Builder<'_>) {
1652 builder.ensure(Crate {
1653 compiler: self.compiler,
1654 target: self.target,
1656 test_kind: self.test_kind,
1657 krate: INTERNER.intern_str(self.krate),
1662 #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
1664 pub compiler: Compiler,
1665 pub target: TargetSelection,
1667 pub test_kind: TestKind,
1668 pub krate: Interned<String>,
1671 impl Step for Crate {
1673 const DEFAULT: bool = true;
1675 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1679 fn make_run(run: RunConfig<'_>) {
1680 let builder = run.builder;
1681 let compiler = builder.compiler(builder.top_stage, run.build_triple());
1683 let make = |mode: Mode, krate: &CargoCrate| {
1684 let test_kind = builder.kind.into();
1686 builder.ensure(Crate {
1695 for krate in builder.in_tree_crates("test") {
1696 if krate.path.ends_with(&run.path) {
1697 make(Mode::Std, krate);
1702 /// Runs all unit tests plus documentation tests for a given crate defined
1703 /// by a `Cargo.toml` (single manifest)
1705 /// This is what runs tests for crates like the standard library, compiler, etc.
1706 /// It essentially is the driver for running `cargo test`.
1708 /// Currently this runs all tests for a DAG by passing a bunch of `-p foo`
1709 /// arguments, and those arguments are discovered from `cargo metadata`.
1710 fn run(self, builder: &Builder<'_>) {
1711 let compiler = self.compiler;
1712 let target = self.target;
1713 let mode = self.mode;
1714 let test_kind = self.test_kind;
1715 let krate = self.krate;
1717 builder.ensure(compile::Std { compiler, target });
1718 builder.ensure(RemoteCopyLibs { compiler, target });
1720 // If we're not doing a full bootstrap but we're testing a stage2
1721 // version of libstd, then what we're actually testing is the libstd
1722 // produced in stage1. Reflect that here by updating the compiler that
1723 // we're working with automatically.
1724 let compiler = builder.compiler_for(compiler.stage, compiler.host, target);
1727 builder.cargo(compiler, mode, SourceType::InTree, target, test_kind.subcommand());
1730 compile::std_cargo(builder, target, compiler.stage, &mut cargo);
1733 builder.ensure(compile::Rustc { compiler, target });
1734 compile::rustc_cargo(builder, &mut cargo, target);
1736 _ => panic!("can only test libraries"),
1739 // Build up the base `cargo test` command.
1741 // Pass in some standard flags then iterate over the graph we've discovered
1742 // in `cargo metadata` with the maps above and figure out what `-p`
1743 // arguments need to get passed.
1744 if test_kind.subcommand() == "test" && !builder.fail_fast {
1745 cargo.arg("--no-fail-fast");
1747 match builder.doc_tests {
1752 cargo.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
1757 cargo.arg("-p").arg(krate);
1759 // The tests are going to run with the *target* libraries, so we need to
1760 // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
1762 // Note that to run the compiler we need to run with the *host* libraries,
1763 // but our wrapper scripts arrange for that to be the case anyway.
1764 let mut dylib_path = dylib_path();
1765 dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
1766 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
1769 cargo.args(&builder.config.cmd.test_args());
1771 if !builder.config.verbose_tests {
1772 cargo.arg("--quiet");
1775 if target.contains("emscripten") {
1777 format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)),
1778 builder.config.nodejs.as_ref().expect("nodejs not configured"),
1780 } else if target.starts_with("wasm32") {
1781 let node = builder.config.nodejs.as_ref().expect("nodejs not configured");
1783 format!("{} {}/src/etc/wasm32-shim.js", node.display(), builder.src.display());
1784 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)), &runner);
1785 } else if builder.remote_tested(target) {
1787 format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)),
1788 format!("{} run 0", builder.tool_exe(Tool::RemoteTestClient).display()),
1792 builder.info(&format!(
1793 "{} {} stage{} ({} -> {})",
1794 test_kind, krate, compiler.stage, &compiler.host, target
1796 let _time = util::timeit(&builder);
1797 try_run(builder, &mut cargo.into());
1801 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1802 pub struct CrateRustdoc {
1803 host: TargetSelection,
1804 test_kind: TestKind,
1807 impl Step for CrateRustdoc {
1809 const DEFAULT: bool = true;
1810 const ONLY_HOSTS: bool = true;
1812 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1813 run.paths(&["src/librustdoc", "src/tools/rustdoc"])
1816 fn make_run(run: RunConfig<'_>) {
1817 let builder = run.builder;
1819 let test_kind = builder.kind.into();
1821 builder.ensure(CrateRustdoc { host: run.target, test_kind });
1824 fn run(self, builder: &Builder<'_>) {
1825 let test_kind = self.test_kind;
1826 let target = self.host;
1828 // Use the previous stage compiler to reuse the artifacts that are
1829 // created when running compiletest for src/test/rustdoc. If this used
1830 // `compiler`, then it would cause rustdoc to be built *again*, which
1831 // isn't really necessary.
1832 let compiler = builder.compiler_for(builder.top_stage, target, target);
1833 builder.ensure(compile::Rustc { compiler, target });
1835 let mut cargo = tool::prepare_tool_cargo(
1840 test_kind.subcommand(),
1841 "src/tools/rustdoc",
1845 if test_kind.subcommand() == "test" && !builder.fail_fast {
1846 cargo.arg("--no-fail-fast");
1849 cargo.arg("-p").arg("rustdoc:0.0.0");
1852 cargo.args(&builder.config.cmd.test_args());
1854 if self.host.contains("musl") {
1855 cargo.arg("'-Ctarget-feature=-crt-static'");
1858 // This is needed for running doctests on librustdoc. This is a bit of
1859 // an unfortunate interaction with how bootstrap works and how cargo
1860 // sets up the dylib path, and the fact that the doctest (in
1861 // html/markdown.rs) links to rustc-private libs. For stage1, the
1862 // compiler host dylibs (in stage1/lib) are not the same as the target
1863 // dylibs (in stage1/lib/rustlib/...). This is different from a normal
1864 // rust distribution where they are the same.
1866 // On the cargo side, normal tests use `target_process` which handles
1867 // setting up the dylib for a *target* (stage1/lib/rustlib/... in this
1868 // case). However, for doctests it uses `rustdoc_process` which only
1869 // sets up the dylib path for the *host* (stage1/lib), which is the
1872 // It should be considered to just stop running doctests on
1873 // librustdoc. There is only one test, and it doesn't look too
1874 // important. There might be other ways to avoid this, but it seems
1875 // pretty convoluted.
1877 // See also https://github.com/rust-lang/rust/issues/13983 where the
1878 // host vs target dylibs for rustdoc are consistently tricky to deal
1880 let mut dylib_path = dylib_path();
1881 dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
1882 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
1884 if !builder.config.verbose_tests {
1885 cargo.arg("--quiet");
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.into());
1898 /// Some test suites are run inside emulators or on remote devices, and most
1899 /// of our test binaries are linked dynamically which means we need to ship
1900 /// the standard library and such to the emulator ahead of time. This step
1901 /// represents this and is a dependency of all test suites.
1903 /// Most of the time this is a no-op. For some steps such as shipping data to
1904 /// QEMU we have to build our own tools so we've got conditional dependencies
1905 /// on those programs as well. Note that the remote test client is built for
1906 /// the build target (us) and the server is built for the target.
1907 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1908 pub struct RemoteCopyLibs {
1910 target: TargetSelection,
1913 impl Step for RemoteCopyLibs {
1916 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1920 fn run(self, builder: &Builder<'_>) {
1921 let compiler = self.compiler;
1922 let target = self.target;
1923 if !builder.remote_tested(target) {
1927 builder.ensure(compile::Std { compiler, target });
1929 builder.info(&format!("REMOTE copy libs to emulator ({})", target));
1930 t!(fs::create_dir_all(builder.out.join("tmp")));
1933 builder.ensure(tool::RemoteTestServer { compiler: compiler.with_stage(0), target });
1935 // Spawn the emulator and wait for it to come online
1936 let tool = builder.tool_exe(Tool::RemoteTestClient);
1937 let mut cmd = Command::new(&tool);
1938 cmd.arg("spawn-emulator").arg(target.triple).arg(&server).arg(builder.out.join("tmp"));
1939 if let Some(rootfs) = builder.qemu_rootfs(target) {
1942 builder.run(&mut cmd);
1944 // Push all our dylibs to the emulator
1945 for f in t!(builder.sysroot_libdir(compiler, target).read_dir()) {
1947 let name = f.file_name().into_string().unwrap();
1948 if util::is_dylib(&name) {
1949 builder.run(Command::new(&tool).arg("push").arg(f.path()));
1955 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1956 pub struct Distcheck;
1958 impl Step for Distcheck {
1961 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1962 run.path("distcheck")
1965 fn make_run(run: RunConfig<'_>) {
1966 run.builder.ensure(Distcheck);
1969 /// Runs "distcheck", a 'make check' from a tarball
1970 fn run(self, builder: &Builder<'_>) {
1971 builder.info("Distcheck");
1972 let dir = builder.out.join("tmp").join("distcheck");
1973 let _ = fs::remove_dir_all(&dir);
1974 t!(fs::create_dir_all(&dir));
1976 // Guarantee that these are built before we begin running.
1977 builder.ensure(dist::PlainSourceTarball);
1978 builder.ensure(dist::Src);
1980 let mut cmd = Command::new("tar");
1982 .arg(builder.ensure(dist::PlainSourceTarball))
1983 .arg("--strip-components=1")
1985 builder.run(&mut cmd);
1987 Command::new("./configure")
1988 .args(&builder.config.configure_args)
1989 .arg("--enable-vendor")
1993 Command::new(build_helper::make(&builder.config.build.triple))
1998 // Now make sure that rust-src has all of libstd's dependencies
1999 builder.info("Distcheck rust-src");
2000 let dir = builder.out.join("tmp").join("distcheck-src");
2001 let _ = fs::remove_dir_all(&dir);
2002 t!(fs::create_dir_all(&dir));
2004 let mut cmd = Command::new("tar");
2006 .arg(builder.ensure(dist::Src))
2007 .arg("--strip-components=1")
2009 builder.run(&mut cmd);
2011 let toml = dir.join("rust-src/lib/rustlib/src/rust/library/std/Cargo.toml");
2013 Command::new(&builder.initial_cargo)
2014 .arg("generate-lockfile")
2015 .arg("--manifest-path")
2022 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2023 pub struct Bootstrap;
2025 impl Step for Bootstrap {
2027 const DEFAULT: bool = true;
2028 const ONLY_HOSTS: bool = true;
2030 /// Tests the build system itself.
2031 fn run(self, builder: &Builder<'_>) {
2032 let mut cmd = Command::new(&builder.initial_cargo);
2034 .current_dir(builder.src.join("src/bootstrap"))
2035 .env("RUSTFLAGS", "-Cdebuginfo=2")
2036 .env("CARGO_TARGET_DIR", builder.out.join("bootstrap"))
2037 .env("BOOTSTRAP_OUTPUT_DIRECTORY", &builder.config.out)
2038 .env("BOOTSTRAP_INITIAL_CARGO", &builder.config.initial_cargo)
2039 .env("RUSTC_BOOTSTRAP", "1")
2040 .env("RUSTC", &builder.initial_rustc);
2041 if let Some(flags) = option_env!("RUSTFLAGS") {
2042 // Use the same rustc flags for testing as for "normal" compilation,
2043 // so that Cargo doesn’t recompile the entire dependency graph every time:
2044 // https://github.com/rust-lang/rust/issues/49215
2045 cmd.env("RUSTFLAGS", flags);
2047 if !builder.fail_fast {
2048 cmd.arg("--no-fail-fast");
2050 cmd.arg("--").args(&builder.config.cmd.test_args());
2051 // rustbuild tests are racy on directory creation so just run them one at a time.
2052 // Since there's not many this shouldn't be a problem.
2053 cmd.arg("--test-threads=1");
2054 try_run(builder, &mut cmd);
2057 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2058 run.path("src/bootstrap")
2061 fn make_run(run: RunConfig<'_>) {
2062 run.builder.ensure(Bootstrap);
2066 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2067 pub struct TierCheck {
2068 pub compiler: Compiler,
2071 impl Step for TierCheck {
2073 const DEFAULT: bool = true;
2074 const ONLY_HOSTS: bool = true;
2076 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2077 run.path("src/tools/tier-check")
2080 fn make_run(run: RunConfig<'_>) {
2082 run.builder.compiler_for(run.builder.top_stage, run.builder.build.build, run.target);
2083 run.builder.ensure(TierCheck { compiler });
2086 /// Tests the Platform Support page in the rustc book.
2087 fn run(self, builder: &Builder<'_>) {
2088 builder.ensure(compile::Std { compiler: self.compiler, target: self.compiler.host });
2089 let mut cargo = tool::prepare_tool_cargo(
2095 "src/tools/tier-check",
2099 cargo.arg(builder.src.join("src/doc/rustc/src/platform-support.md"));
2100 cargo.arg(&builder.rustc(self.compiler));
2101 if builder.is_verbose() {
2102 cargo.arg("--verbose");
2105 builder.info("platform support check");
2106 try_run(builder, &mut cargo.into());