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 // We need `ToolStd` for the locally-built sysroot because
488 // compiletest uses unstable features of the `test` crate.
489 builder.ensure(compile::Std { compiler, target: host });
490 let cargo = tool::prepare_tool_cargo(
496 "src/tools/compiletest",
501 try_run(builder, &mut cargo.into());
505 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
508 host: TargetSelection,
511 impl Step for Clippy {
513 const ONLY_HOSTS: bool = true;
514 const DEFAULT: bool = false;
516 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
517 run.path("src/tools/clippy")
520 fn make_run(run: RunConfig<'_>) {
521 run.builder.ensure(Clippy { stage: run.builder.top_stage, host: run.target });
524 /// Runs `cargo test` for clippy.
525 fn run(self, builder: &Builder<'_>) {
526 let stage = self.stage;
527 let host = self.host;
528 let compiler = builder.compiler(stage, host);
531 .ensure(tool::Clippy { compiler, target: self.host, extra_features: Vec::new() })
532 .expect("in-tree tool");
533 let mut cargo = tool::prepare_tool_cargo(
544 // clippy tests need to know about the stage sysroot
545 cargo.env("SYSROOT", builder.sysroot(compiler));
546 cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
547 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
548 let host_libs = builder.stage_out(compiler, Mode::ToolRustc).join(builder.cargo_dir());
549 let target_libs = builder
550 .stage_out(compiler, Mode::ToolRustc)
551 .join(&self.host.triple)
552 .join(builder.cargo_dir());
553 cargo.env("HOST_LIBS", host_libs);
554 cargo.env("TARGET_LIBS", target_libs);
555 // clippy tests need to find the driver
556 cargo.env("CLIPPY_DRIVER_PATH", clippy);
558 cargo.arg("--").args(builder.config.cmd.test_args());
560 cargo.add_rustc_lib_path(builder, compiler);
562 builder.run(&mut cargo.into());
566 fn path_for_cargo(builder: &Builder<'_>, compiler: Compiler) -> OsString {
567 // Configure PATH to find the right rustc. NB. we have to use PATH
568 // and not RUSTC because the Cargo test suite has tests that will
569 // fail if rustc is not spelled `rustc`.
570 let path = builder.sysroot(compiler).join("bin");
571 let old_path = env::var_os("PATH").unwrap_or_default();
572 env::join_paths(iter::once(path).chain(env::split_paths(&old_path))).expect("")
575 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
576 pub struct RustdocTheme {
577 pub compiler: Compiler,
580 impl Step for RustdocTheme {
582 const DEFAULT: bool = true;
583 const ONLY_HOSTS: bool = true;
585 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
586 run.path("src/tools/rustdoc-themes")
589 fn make_run(run: RunConfig<'_>) {
590 let compiler = run.builder.compiler(run.builder.top_stage, run.target);
592 run.builder.ensure(RustdocTheme { compiler });
595 fn run(self, builder: &Builder<'_>) {
596 let rustdoc = builder.out.join("bootstrap/debug/rustdoc");
597 let mut cmd = builder.tool_cmd(Tool::RustdocTheme);
598 cmd.arg(rustdoc.to_str().unwrap())
599 .arg(builder.src.join("src/librustdoc/html/static/themes").to_str().unwrap())
600 .env("RUSTC_STAGE", self.compiler.stage.to_string())
601 .env("RUSTC_SYSROOT", builder.sysroot(self.compiler))
602 .env("RUSTDOC_LIBDIR", builder.sysroot_libdir(self.compiler, self.compiler.host))
603 .env("CFG_RELEASE_CHANNEL", &builder.config.channel)
604 .env("RUSTDOC_REAL", builder.rustdoc(self.compiler))
605 .env("RUSTC_BOOTSTRAP", "1");
606 if let Some(linker) = builder.linker(self.compiler.host) {
607 cmd.env("RUSTDOC_LINKER", linker);
609 if builder.is_fuse_ld_lld(self.compiler.host) {
610 cmd.env("RUSTDOC_FUSE_LD_LLD", "1");
612 try_run(builder, &mut cmd);
616 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
617 pub struct RustdocJSStd {
618 pub target: TargetSelection,
621 impl Step for RustdocJSStd {
623 const DEFAULT: bool = true;
624 const ONLY_HOSTS: bool = true;
626 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
627 run.path("src/test/rustdoc-js-std")
630 fn make_run(run: RunConfig<'_>) {
631 run.builder.ensure(RustdocJSStd { target: run.target });
634 fn run(self, builder: &Builder<'_>) {
635 if let Some(ref nodejs) = builder.config.nodejs {
636 let mut command = Command::new(nodejs);
638 .arg(builder.src.join("src/tools/rustdoc-js/tester.js"))
641 .arg("--resource-suffix")
642 .arg(&builder.version)
644 .arg(builder.doc_out(self.target))
645 .arg("--test-folder")
646 .arg(builder.src.join("src/test/rustdoc-js-std"));
647 builder.ensure(crate::doc::Std { target: self.target, stage: builder.top_stage });
648 builder.run(&mut command);
650 builder.info("No nodejs found, skipping \"src/test/rustdoc-js-std\" tests");
655 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
656 pub struct RustdocJSNotStd {
657 pub target: TargetSelection,
658 pub compiler: Compiler,
661 impl Step for RustdocJSNotStd {
663 const DEFAULT: bool = true;
664 const ONLY_HOSTS: bool = true;
666 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
667 run.path("src/test/rustdoc-js")
670 fn make_run(run: RunConfig<'_>) {
671 let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
672 run.builder.ensure(RustdocJSNotStd { target: run.target, compiler });
675 fn run(self, builder: &Builder<'_>) {
676 if builder.config.nodejs.is_some() {
677 builder.ensure(Compiletest {
678 compiler: self.compiler,
682 path: "src/test/rustdoc-js",
686 builder.info("No nodejs found, skipping \"src/test/rustdoc-js\" tests");
691 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
696 const DEFAULT: bool = true;
697 const ONLY_HOSTS: bool = true;
699 /// Runs the `tidy` tool.
701 /// This tool in `src/tools` checks up on various bits and pieces of style and
702 /// otherwise just implements a few lint-like checks that are specific to the
705 /// Once tidy passes, this step also runs `fmt --check` if tests are being run
706 /// for the `dev` or `nightly` channels.
707 fn run(self, builder: &Builder<'_>) {
708 let mut cmd = builder.tool_cmd(Tool::Tidy);
709 cmd.arg(&builder.src);
710 cmd.arg(&builder.initial_cargo);
711 cmd.arg(&builder.out);
712 if builder.is_verbose() {
713 cmd.arg("--verbose");
716 builder.info("tidy check");
717 try_run(builder, &mut cmd);
719 if builder.config.channel == "dev" || builder.config.channel == "nightly" {
720 builder.info("fmt check");
721 crate::format::format(&builder.build, !builder.config.cmd.bless());
725 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
726 run.path("src/tools/tidy")
729 fn make_run(run: RunConfig<'_>) {
730 run.builder.ensure(Tidy);
734 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
735 pub struct ExpandYamlAnchors;
737 impl Step for ExpandYamlAnchors {
739 const ONLY_HOSTS: bool = true;
741 /// Ensure the `generate-ci-config` tool was run locally.
743 /// The tool in `src/tools` reads the CI definition in `src/ci/builders.yml` and generates the
744 /// appropriate configuration for all our CI providers. This step ensures the tool was called
745 /// by the user before committing CI changes.
746 fn run(self, builder: &Builder<'_>) {
747 builder.info("Ensuring the YAML anchors in the GitHub Actions config were expanded");
750 &mut builder.tool_cmd(Tool::ExpandYamlAnchors).arg("check").arg(&builder.src),
754 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
755 run.path("src/tools/expand-yaml-anchors")
758 fn make_run(run: RunConfig<'_>) {
759 run.builder.ensure(ExpandYamlAnchors);
763 fn testdir(builder: &Builder<'_>, host: TargetSelection) -> PathBuf {
764 builder.out.join(host.triple).join("test")
767 macro_rules! default_test {
768 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
769 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: false });
773 macro_rules! default_test_with_compare_mode {
774 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr,
775 compare_mode: $compare_mode:expr }) => {
776 test_with_compare_mode!($name {
782 compare_mode: $compare_mode
787 macro_rules! host_test {
788 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
789 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: true });
794 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
795 host: $host:expr }) => {
796 test_definitions!($name {
807 macro_rules! test_with_compare_mode {
808 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
809 host: $host:expr, compare_mode: $compare_mode:expr }) => {
810 test_definitions!($name {
816 compare_mode: Some($compare_mode)
821 macro_rules! test_definitions {
826 default: $default:expr,
828 compare_mode: $compare_mode:expr
830 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
832 pub compiler: Compiler,
833 pub target: TargetSelection,
836 impl Step for $name {
838 const DEFAULT: bool = $default;
839 const ONLY_HOSTS: bool = $host;
841 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
842 run.suite_path($path)
845 fn make_run(run: RunConfig<'_>) {
846 let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
848 run.builder.ensure($name { compiler, target: run.target });
851 fn run(self, builder: &Builder<'_>) {
852 builder.ensure(Compiletest {
853 compiler: self.compiler,
858 compare_mode: $compare_mode,
865 default_test_with_compare_mode!(Ui {
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_with_compare_mode!(Debuginfo {
895 path: "src/test/debuginfo",
898 compare_mode: "split-dwarf"
901 host_test!(UiFullDeps { path: "src/test/ui-fulldeps", mode: "ui", suite: "ui-fulldeps" });
903 host_test!(Rustdoc { path: "src/test/rustdoc", mode: "rustdoc", suite: "rustdoc" });
904 host_test!(RustdocUi { path: "src/test/rustdoc-ui", mode: "ui", suite: "rustdoc-ui" });
906 host_test!(RustdocJson {
907 path: "src/test/rustdoc-json",
908 mode: "rustdoc-json",
909 suite: "rustdoc-json"
912 host_test!(Pretty { path: "src/test/pretty", mode: "pretty", suite: "pretty" });
914 default_test!(RunMake { path: "src/test/run-make", mode: "run-make", suite: "run-make" });
916 host_test!(RunMakeFullDeps {
917 path: "src/test/run-make-fulldeps",
919 suite: "run-make-fulldeps"
922 default_test!(Assembly { path: "src/test/assembly", mode: "assembly", suite: "assembly" });
924 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
927 target: TargetSelection,
931 compare_mode: Option<&'static str>,
934 impl Step for Compiletest {
937 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
941 /// Executes the `compiletest` tool to run a suite of tests.
943 /// Compiles all tests with `compiler` for `target` with the specified
944 /// compiletest `mode` and `suite` arguments. For example `mode` can be
945 /// "run-pass" or `suite` can be something like `debuginfo`.
946 fn run(self, builder: &Builder<'_>) {
947 if builder.top_stage == 0 && env::var("COMPILETEST_FORCE_STAGE0").is_err() {
949 error: `--stage 0` runs compiletest on the beta compiler, not your local changes, and will almost always cause tests to fail
950 help: to test the compiler, use `--stage 1` instead
951 help: to test the standard library, use `--stage 0 library/std` instead
952 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`."
954 std::process::exit(1);
957 let compiler = self.compiler;
958 let target = self.target;
959 let mode = self.mode;
960 let suite = self.suite;
962 // Path for test suite
963 let suite_path = self.path;
965 // Skip codegen tests if they aren't enabled in configuration.
966 if !builder.config.codegen_tests && suite == "codegen" {
970 if suite == "debuginfo" {
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"
1009 || mode == "rustdoc-json"
1011 cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler));
1014 if mode == "run-make" && suite.ends_with("fulldeps") {
1015 cmd.arg("--rust-demangler-path").arg(builder.tool_exe(Tool::RustDemangler));
1018 cmd.arg("--src-base").arg(builder.src.join("src/test").join(suite));
1019 cmd.arg("--build-base").arg(testdir(builder, compiler.host).join(suite));
1020 cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target));
1021 cmd.arg("--suite").arg(suite);
1022 cmd.arg("--mode").arg(mode);
1023 cmd.arg("--target").arg(target.rustc_target_arg());
1024 cmd.arg("--host").arg(&*compiler.host.triple);
1025 cmd.arg("--llvm-filecheck").arg(builder.llvm_filecheck(builder.config.build));
1027 if builder.config.cmd.bless() {
1032 builder.config.cmd.compare_mode().or_else(|| {
1033 if builder.config.test_compare_mode { self.compare_mode } else { None }
1036 if let Some(ref pass) = builder.config.cmd.pass() {
1041 if let Some(ref nodejs) = builder.config.nodejs {
1042 cmd.arg("--nodejs").arg(nodejs);
1045 let mut flags = if is_rustdoc { Vec::new() } else { vec!["-Crpath".to_string()] };
1047 if builder.config.rust_optimize_tests {
1048 flags.push("-O".to_string());
1051 flags.push(format!("-Cdebuginfo={}", builder.config.rust_debuginfo_level_tests));
1052 flags.push("-Zunstable-options".to_string());
1053 flags.push(builder.config.cmd.rustc_args().join(" "));
1055 if let Some(linker) = builder.linker(target) {
1056 cmd.arg("--linker").arg(linker);
1059 let mut hostflags = flags.clone();
1060 hostflags.push(format!("-Lnative={}", builder.test_helpers_out(compiler.host).display()));
1061 if builder.is_fuse_ld_lld(compiler.host) {
1062 hostflags.push("-Clink-args=-fuse-ld=lld".to_string());
1064 cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
1066 let mut targetflags = flags;
1067 targetflags.push(format!("-Lnative={}", builder.test_helpers_out(target).display()));
1068 if builder.is_fuse_ld_lld(target) {
1069 targetflags.push("-Clink-args=-fuse-ld=lld".to_string());
1071 cmd.arg("--target-rustcflags").arg(targetflags.join(" "));
1073 cmd.arg("--docck-python").arg(builder.python());
1075 if builder.config.build.ends_with("apple-darwin") {
1076 // Force /usr/bin/python3 on macOS for LLDB tests because we're loading the
1077 // LLDB plugin's compiled module which only works with the system python
1078 // (namely not Homebrew-installed python)
1079 cmd.arg("--lldb-python").arg("/usr/bin/python3");
1081 cmd.arg("--lldb-python").arg(builder.python());
1084 if let Some(ref gdb) = builder.config.gdb {
1085 cmd.arg("--gdb").arg(gdb);
1088 let run = |cmd: &mut Command| {
1089 cmd.output().map(|output| {
1090 String::from_utf8_lossy(&output.stdout)
1093 .unwrap_or_else(|| panic!("{:?} failed {:?}", cmd, output))
1097 let lldb_exe = "lldb";
1098 let lldb_version = Command::new(lldb_exe)
1101 .map(|output| String::from_utf8_lossy(&output.stdout).to_string())
1103 if let Some(ref vers) = lldb_version {
1104 cmd.arg("--lldb-version").arg(vers);
1105 let lldb_python_dir = run(Command::new(lldb_exe).arg("-P")).ok();
1106 if let Some(ref dir) = lldb_python_dir {
1107 cmd.arg("--lldb-python-dir").arg(dir);
1111 if util::forcing_clang_based_tests() {
1112 let clang_exe = builder.llvm_out(target).join("bin").join("clang");
1113 cmd.arg("--run-clang-based-tests-with").arg(clang_exe);
1116 // Get paths from cmd args
1117 let paths = match &builder.config.cmd {
1118 Subcommand::Test { ref paths, .. } => &paths[..],
1122 // Get test-args by striping suite path
1123 let mut test_args: Vec<&str> = paths
1125 .map(|p| match p.strip_prefix(".") {
1129 .filter(|p| p.starts_with(suite_path))
1131 let exists = p.is_dir() || p.is_file();
1133 if let Some(p) = p.to_str() {
1134 builder.info(&format!(
1135 "Warning: Skipping \"{}\": not a regular file or directory",
1143 // Since test suite paths are themselves directories, if we don't
1144 // specify a directory or file, we'll get an empty string here
1145 // (the result of the test suite directory without its suite prefix).
1146 // Therefore, we need to filter these out, as only the first --test-args
1147 // flag is respected, so providing an empty --test-args conflicts with
1148 // any following it.
1149 match p.strip_prefix(suite_path).ok().and_then(|p| p.to_str()) {
1150 Some(s) if !s.is_empty() => Some(s),
1156 test_args.append(&mut builder.config.cmd.test_args());
1158 cmd.args(&test_args);
1160 if builder.is_verbose() {
1161 cmd.arg("--verbose");
1164 if !builder.config.verbose_tests {
1168 let mut llvm_components_passed = false;
1169 let mut copts_passed = false;
1170 if builder.config.llvm_enabled() {
1171 let llvm_config = builder.ensure(native::Llvm { target: builder.config.build });
1172 if !builder.config.dry_run {
1173 let llvm_version = output(Command::new(&llvm_config).arg("--version"));
1174 let llvm_components = output(Command::new(&llvm_config).arg("--components"));
1175 // Remove trailing newline from llvm-config output.
1176 cmd.arg("--llvm-version")
1177 .arg(llvm_version.trim())
1178 .arg("--llvm-components")
1179 .arg(llvm_components.trim());
1180 llvm_components_passed = true;
1182 if !builder.is_rust_llvm(target) {
1183 cmd.arg("--system-llvm");
1186 // Tests that use compiler libraries may inherit the `-lLLVM` link
1187 // requirement, but the `-L` library path is not propagated across
1188 // separate compilations. We can add LLVM's library path to the
1189 // platform-specific environment variable as a workaround.
1190 if !builder.config.dry_run && suite.ends_with("fulldeps") {
1191 let llvm_libdir = output(Command::new(&llvm_config).arg("--libdir"));
1192 add_link_lib_path(vec![llvm_libdir.trim().into()], &mut cmd);
1195 // Only pass correct values for these flags for the `run-make` suite as it
1196 // requires that a C++ compiler was configured which isn't always the case.
1197 if !builder.config.dry_run && matches!(suite, "run-make" | "run-make-fulldeps") {
1198 // The llvm/bin directory contains many useful cross-platform
1199 // tools. Pass the path to run-make tests so they can use them.
1200 let llvm_bin_path = llvm_config
1202 .expect("Expected llvm-config to be contained in directory");
1203 assert!(llvm_bin_path.is_dir());
1204 cmd.arg("--llvm-bin-dir").arg(llvm_bin_path);
1206 // If LLD is available, add it to the PATH
1207 if builder.config.lld_enabled {
1208 let lld_install_root =
1209 builder.ensure(native::Lld { target: builder.config.build });
1211 let lld_bin_path = lld_install_root.join("bin");
1213 let old_path = env::var_os("PATH").unwrap_or_default();
1214 let new_path = env::join_paths(
1215 std::iter::once(lld_bin_path).chain(env::split_paths(&old_path)),
1217 .expect("Could not add LLD bin path to PATH");
1218 cmd.env("PATH", new_path);
1223 // Only pass correct values for these flags for the `run-make` suite as it
1224 // requires that a C++ compiler was configured which isn't always the case.
1225 if !builder.config.dry_run && matches!(suite, "run-make" | "run-make-fulldeps") {
1227 .arg(builder.cc(target))
1229 .arg(builder.cxx(target).unwrap())
1231 .arg(builder.cflags(target, GitRepo::Rustc).join(" "));
1232 copts_passed = true;
1233 if let Some(ar) = builder.ar(target) {
1234 cmd.arg("--ar").arg(ar);
1238 if !llvm_components_passed {
1239 cmd.arg("--llvm-components").arg("");
1242 cmd.arg("--cc").arg("").arg("--cxx").arg("").arg("--cflags").arg("");
1245 if builder.remote_tested(target) {
1246 cmd.arg("--remote-test-client").arg(builder.tool_exe(Tool::RemoteTestClient));
1249 // Running a C compiler on MSVC requires a few env vars to be set, to be
1250 // sure to set them here.
1252 // Note that if we encounter `PATH` we make sure to append to our own `PATH`
1253 // rather than stomp over it.
1254 if target.contains("msvc") {
1255 for &(ref k, ref v) in builder.cc[&target].env() {
1261 cmd.env("RUSTC_BOOTSTRAP", "1");
1262 builder.add_rust_test_threads(&mut cmd);
1264 if builder.config.sanitizers_enabled(target) {
1265 cmd.env("RUSTC_SANITIZER_SUPPORT", "1");
1268 if builder.config.profiler_enabled(target) {
1269 cmd.env("RUSTC_PROFILER_SUPPORT", "1");
1272 let tmp = builder.out.join("tmp");
1273 std::fs::create_dir_all(&tmp).unwrap();
1274 cmd.env("RUST_TEST_TMPDIR", tmp);
1276 cmd.arg("--adb-path").arg("adb");
1277 cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
1278 if target.contains("android") {
1279 // Assume that cc for this target comes from the android sysroot
1280 cmd.arg("--android-cross-path")
1281 .arg(builder.cc(target).parent().unwrap().parent().unwrap());
1283 cmd.arg("--android-cross-path").arg("");
1286 if builder.config.cmd.rustfix_coverage() {
1287 cmd.arg("--rustfix-coverage");
1290 cmd.env("BOOTSTRAP_CARGO", &builder.initial_cargo);
1292 builder.ci_env.force_coloring_in_ci(&mut cmd);
1294 builder.info(&format!(
1295 "Check compiletest suite={} mode={} ({} -> {})",
1296 suite, mode, &compiler.host, target
1298 let _time = util::timeit(&builder);
1299 try_run(builder, &mut cmd);
1301 if let Some(compare_mode) = compare_mode {
1302 cmd.arg("--compare-mode").arg(compare_mode);
1303 builder.info(&format!(
1304 "Check compiletest suite={} mode={} compare_mode={} ({} -> {})",
1305 suite, mode, compare_mode, &compiler.host, target
1307 let _time = util::timeit(&builder);
1308 try_run(builder, &mut cmd);
1313 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1321 impl Step for BookTest {
1323 const ONLY_HOSTS: bool = true;
1325 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1329 /// Runs the documentation tests for a book in `src/doc`.
1331 /// This uses the `rustdoc` that sits next to `compiler`.
1332 fn run(self, builder: &Builder<'_>) {
1333 // External docs are different from local because:
1334 // - Some books need pre-processing by mdbook before being tested.
1335 // - They need to save their state to toolstate.
1336 // - They are only tested on the "checktools" builders.
1338 // The local docs are tested by default, and we don't want to pay the
1339 // cost of building mdbook, so they use `rustdoc --test` directly.
1340 // Also, the unstable book is special because SUMMARY.md is generated,
1341 // so it is easier to just run `rustdoc` on its files.
1342 if self.is_ext_doc {
1343 self.run_ext_doc(builder);
1345 self.run_local_doc(builder);
1351 /// This runs the equivalent of `mdbook test` (via the rustbook wrapper)
1352 /// which in turn runs `rustdoc --test` on each file in the book.
1353 fn run_ext_doc(self, builder: &Builder<'_>) {
1354 let compiler = self.compiler;
1356 builder.ensure(compile::Std { compiler, target: compiler.host });
1358 // mdbook just executes a binary named "rustdoc", so we need to update
1359 // PATH so that it points to our rustdoc.
1360 let mut rustdoc_path = builder.rustdoc(compiler);
1362 let old_path = env::var_os("PATH").unwrap_or_default();
1363 let new_path = env::join_paths(iter::once(rustdoc_path).chain(env::split_paths(&old_path)))
1364 .expect("could not add rustdoc to PATH");
1366 let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
1367 let path = builder.src.join(&self.path);
1368 rustbook_cmd.env("PATH", new_path).arg("test").arg(path);
1369 builder.add_rust_test_threads(&mut rustbook_cmd);
1370 builder.info(&format!("Testing rustbook {}", self.path.display()));
1371 let _time = util::timeit(&builder);
1372 let toolstate = if try_run(builder, &mut rustbook_cmd) {
1377 builder.save_toolstate(self.name, toolstate);
1380 /// This runs `rustdoc --test` on all `.md` files in the path.
1381 fn run_local_doc(self, builder: &Builder<'_>) {
1382 let compiler = self.compiler;
1384 builder.ensure(compile::Std { compiler, target: compiler.host });
1386 // Do a breadth-first traversal of the `src/doc` directory and just run
1387 // tests for all files that end in `*.md`
1388 let mut stack = vec![builder.src.join(self.path)];
1389 let _time = util::timeit(&builder);
1390 let mut files = Vec::new();
1391 while let Some(p) = stack.pop() {
1393 stack.extend(t!(p.read_dir()).map(|p| t!(p).path()));
1397 if p.extension().and_then(|s| s.to_str()) != Some("md") {
1407 markdown_test(builder, compiler, &file);
1412 macro_rules! test_book {
1413 ($($name:ident, $path:expr, $book_name:expr, default=$default:expr;)+) => {
1415 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1420 impl Step for $name {
1422 const DEFAULT: bool = $default;
1423 const ONLY_HOSTS: bool = true;
1425 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1429 fn make_run(run: RunConfig<'_>) {
1430 run.builder.ensure($name {
1431 compiler: run.builder.compiler(run.builder.top_stage, run.target),
1435 fn run(self, builder: &Builder<'_>) {
1436 builder.ensure(BookTest {
1437 compiler: self.compiler,
1438 path: PathBuf::from($path),
1440 is_ext_doc: !$default,
1449 Nomicon, "src/doc/nomicon", "nomicon", default=false;
1450 Reference, "src/doc/reference", "reference", default=false;
1451 RustdocBook, "src/doc/rustdoc", "rustdoc", default=true;
1452 RustcBook, "src/doc/rustc", "rustc", default=true;
1453 RustByExample, "src/doc/rust-by-example", "rust-by-example", default=false;
1454 EmbeddedBook, "src/doc/embedded-book", "embedded-book", default=false;
1455 TheBook, "src/doc/book", "book", default=false;
1456 UnstableBook, "src/doc/unstable-book", "unstable-book", default=true;
1457 EditionGuide, "src/doc/edition-guide", "edition-guide", default=false;
1460 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1461 pub struct ErrorIndex {
1465 impl Step for ErrorIndex {
1467 const DEFAULT: bool = true;
1468 const ONLY_HOSTS: bool = true;
1470 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1471 run.path("src/tools/error_index_generator")
1474 fn make_run(run: RunConfig<'_>) {
1475 // error_index_generator depends on librustdoc. Use the compiler that
1476 // is normally used to build rustdoc for other tests (like compiletest
1477 // tests in src/test/rustdoc) so that it shares the same artifacts.
1478 let compiler = run.builder.compiler_for(run.builder.top_stage, run.target, run.target);
1479 run.builder.ensure(ErrorIndex { compiler });
1482 /// Runs the error index generator tool to execute the tests located in the error
1485 /// The `error_index_generator` tool lives in `src/tools` and is used to
1486 /// generate a markdown file from the error indexes of the code base which is
1487 /// then passed to `rustdoc --test`.
1488 fn run(self, builder: &Builder<'_>) {
1489 let compiler = self.compiler;
1491 let dir = testdir(builder, compiler.host);
1492 t!(fs::create_dir_all(&dir));
1493 let output = dir.join("error-index.md");
1495 let mut tool = tool::ErrorIndex::command(builder, compiler);
1496 tool.arg("markdown").arg(&output);
1498 // Use the rustdoc that was built by self.compiler. This copy of
1499 // rustdoc is shared with other tests (like compiletest tests in
1500 // src/test/rustdoc). This helps avoid building rustdoc multiple
1502 let rustdoc_compiler = builder.compiler(builder.top_stage, builder.config.build);
1503 builder.info(&format!("Testing error-index stage{}", rustdoc_compiler.stage));
1504 let _time = util::timeit(&builder);
1505 builder.run_quiet(&mut tool);
1506 builder.ensure(compile::Std { compiler: rustdoc_compiler, target: rustdoc_compiler.host });
1507 markdown_test(builder, rustdoc_compiler, &output);
1511 fn markdown_test(builder: &Builder<'_>, compiler: Compiler, markdown: &Path) -> bool {
1512 if let Ok(contents) = fs::read_to_string(markdown) {
1513 if !contents.contains("```") {
1518 builder.info(&format!("doc tests for: {}", markdown.display()));
1519 let mut cmd = builder.rustdoc_cmd(compiler);
1520 builder.add_rust_test_threads(&mut cmd);
1523 cmd.env("RUSTC_BOOTSTRAP", "1");
1525 let test_args = builder.config.cmd.test_args().join(" ");
1526 cmd.arg("--test-args").arg(test_args);
1528 if builder.config.verbose_tests {
1529 try_run(builder, &mut cmd)
1531 try_run_quiet(builder, &mut cmd)
1535 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1536 pub struct RustcGuide;
1538 impl Step for RustcGuide {
1540 const DEFAULT: bool = false;
1541 const ONLY_HOSTS: bool = true;
1543 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1544 run.path("src/doc/rustc-dev-guide")
1547 fn make_run(run: RunConfig<'_>) {
1548 run.builder.ensure(RustcGuide);
1551 fn run(self, builder: &Builder<'_>) {
1552 let src = builder.src.join("src/doc/rustc-dev-guide");
1553 let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
1554 let toolstate = if try_run(builder, rustbook_cmd.arg("linkcheck").arg(&src)) {
1559 builder.save_toolstate("rustc-dev-guide", toolstate);
1563 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1564 pub struct CrateLibrustc {
1566 target: TargetSelection,
1567 test_kind: TestKind,
1568 krate: Interned<String>,
1571 impl Step for CrateLibrustc {
1573 const DEFAULT: bool = true;
1574 const ONLY_HOSTS: bool = true;
1576 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1577 run.krate("rustc-main")
1580 fn make_run(run: RunConfig<'_>) {
1581 let builder = run.builder;
1582 let compiler = builder.compiler(builder.top_stage, run.build_triple());
1584 for krate in builder.in_tree_crates("rustc-main", Some(run.target)) {
1585 if krate.path.ends_with(&run.path) {
1586 let test_kind = builder.kind.into();
1588 builder.ensure(CrateLibrustc {
1598 fn run(self, builder: &Builder<'_>) {
1599 builder.ensure(Crate {
1600 compiler: self.compiler,
1601 target: self.target,
1603 test_kind: self.test_kind,
1609 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1610 pub struct CrateNotDefault {
1612 target: TargetSelection,
1613 test_kind: TestKind,
1614 krate: &'static str,
1617 impl Step for CrateNotDefault {
1620 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1621 run.path("src/librustc_asan")
1622 .path("src/librustc_lsan")
1623 .path("src/librustc_msan")
1624 .path("src/librustc_tsan")
1627 fn make_run(run: RunConfig<'_>) {
1628 let builder = run.builder;
1629 let compiler = builder.compiler(builder.top_stage, run.build_triple());
1631 let test_kind = builder.kind.into();
1633 builder.ensure(CrateNotDefault {
1637 krate: match run.path {
1638 _ if run.path.ends_with("src/librustc_asan") => "rustc_asan",
1639 _ if run.path.ends_with("src/librustc_lsan") => "rustc_lsan",
1640 _ if run.path.ends_with("src/librustc_msan") => "rustc_msan",
1641 _ if run.path.ends_with("src/librustc_tsan") => "rustc_tsan",
1642 _ => panic!("unexpected path {:?}", run.path),
1647 fn run(self, builder: &Builder<'_>) {
1648 builder.ensure(Crate {
1649 compiler: self.compiler,
1650 target: self.target,
1652 test_kind: self.test_kind,
1653 krate: INTERNER.intern_str(self.krate),
1658 #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
1660 pub compiler: Compiler,
1661 pub target: TargetSelection,
1663 pub test_kind: TestKind,
1664 pub krate: Interned<String>,
1667 impl Step for Crate {
1669 const DEFAULT: bool = true;
1671 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1675 fn make_run(run: RunConfig<'_>) {
1676 let builder = run.builder;
1677 let compiler = builder.compiler(builder.top_stage, run.build_triple());
1679 let make = |mode: Mode, krate: &CargoCrate| {
1680 let test_kind = builder.kind.into();
1682 builder.ensure(Crate {
1691 for krate in builder.in_tree_crates("test", Some(run.target)) {
1692 if krate.path.ends_with(&run.path) {
1693 make(Mode::Std, krate);
1698 /// Runs all unit tests plus documentation tests for a given crate defined
1699 /// by a `Cargo.toml` (single manifest)
1701 /// This is what runs tests for crates like the standard library, compiler, etc.
1702 /// It essentially is the driver for running `cargo test`.
1704 /// Currently this runs all tests for a DAG by passing a bunch of `-p foo`
1705 /// arguments, and those arguments are discovered from `cargo metadata`.
1706 fn run(self, builder: &Builder<'_>) {
1707 let compiler = self.compiler;
1708 let target = self.target;
1709 let mode = self.mode;
1710 let test_kind = self.test_kind;
1711 let krate = self.krate;
1713 builder.ensure(compile::Std { compiler, target });
1714 builder.ensure(RemoteCopyLibs { compiler, target });
1716 // If we're not doing a full bootstrap but we're testing a stage2
1717 // version of libstd, then what we're actually testing is the libstd
1718 // produced in stage1. Reflect that here by updating the compiler that
1719 // we're working with automatically.
1720 let compiler = builder.compiler_for(compiler.stage, compiler.host, target);
1723 builder.cargo(compiler, mode, SourceType::InTree, target, test_kind.subcommand());
1726 compile::std_cargo(builder, target, compiler.stage, &mut cargo);
1729 builder.ensure(compile::Rustc { compiler, target });
1730 compile::rustc_cargo(builder, &mut cargo, target);
1732 _ => panic!("can only test libraries"),
1735 // Build up the base `cargo test` command.
1737 // Pass in some standard flags then iterate over the graph we've discovered
1738 // in `cargo metadata` with the maps above and figure out what `-p`
1739 // arguments need to get passed.
1740 if test_kind.subcommand() == "test" && !builder.fail_fast {
1741 cargo.arg("--no-fail-fast");
1743 match builder.doc_tests {
1748 cargo.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
1753 cargo.arg("-p").arg(krate);
1755 // The tests are going to run with the *target* libraries, so we need to
1756 // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
1758 // Note that to run the compiler we need to run with the *host* libraries,
1759 // but our wrapper scripts arrange for that to be the case anyway.
1760 let mut dylib_path = dylib_path();
1761 dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
1762 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
1765 cargo.args(&builder.config.cmd.test_args());
1767 if !builder.config.verbose_tests {
1768 cargo.arg("--quiet");
1771 if target.contains("emscripten") {
1773 format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)),
1774 builder.config.nodejs.as_ref().expect("nodejs not configured"),
1776 } else if target.starts_with("wasm32") {
1777 let node = builder.config.nodejs.as_ref().expect("nodejs not configured");
1779 format!("{} {}/src/etc/wasm32-shim.js", node.display(), builder.src.display());
1780 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)), &runner);
1781 } else if builder.remote_tested(target) {
1783 format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)),
1784 format!("{} run 0", builder.tool_exe(Tool::RemoteTestClient).display()),
1788 builder.info(&format!(
1789 "{} {} stage{} ({} -> {})",
1790 test_kind, krate, compiler.stage, &compiler.host, target
1792 let _time = util::timeit(&builder);
1793 try_run(builder, &mut cargo.into());
1797 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1798 pub struct CrateRustdoc {
1799 host: TargetSelection,
1800 test_kind: TestKind,
1803 impl Step for CrateRustdoc {
1805 const DEFAULT: bool = true;
1806 const ONLY_HOSTS: bool = true;
1808 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1809 run.paths(&["src/librustdoc", "src/tools/rustdoc"])
1812 fn make_run(run: RunConfig<'_>) {
1813 let builder = run.builder;
1815 let test_kind = builder.kind.into();
1817 builder.ensure(CrateRustdoc { host: run.target, test_kind });
1820 fn run(self, builder: &Builder<'_>) {
1821 let test_kind = self.test_kind;
1822 let target = self.host;
1824 // Use the previous stage compiler to reuse the artifacts that are
1825 // created when running compiletest for src/test/rustdoc. If this used
1826 // `compiler`, then it would cause rustdoc to be built *again*, which
1827 // isn't really necessary.
1828 let compiler = builder.compiler_for(builder.top_stage, target, target);
1829 builder.ensure(compile::Rustc { compiler, target });
1831 let mut cargo = tool::prepare_tool_cargo(
1836 test_kind.subcommand(),
1837 "src/tools/rustdoc",
1841 if test_kind.subcommand() == "test" && !builder.fail_fast {
1842 cargo.arg("--no-fail-fast");
1845 cargo.arg("-p").arg("rustdoc:0.0.0");
1848 cargo.args(&builder.config.cmd.test_args());
1850 if self.host.contains("musl") {
1851 cargo.arg("'-Ctarget-feature=-crt-static'");
1854 // This is needed for running doctests on librustdoc. This is a bit of
1855 // an unfortunate interaction with how bootstrap works and how cargo
1856 // sets up the dylib path, and the fact that the doctest (in
1857 // html/markdown.rs) links to rustc-private libs. For stage1, the
1858 // compiler host dylibs (in stage1/lib) are not the same as the target
1859 // dylibs (in stage1/lib/rustlib/...). This is different from a normal
1860 // rust distribution where they are the same.
1862 // On the cargo side, normal tests use `target_process` which handles
1863 // setting up the dylib for a *target* (stage1/lib/rustlib/... in this
1864 // case). However, for doctests it uses `rustdoc_process` which only
1865 // sets up the dylib path for the *host* (stage1/lib), which is the
1868 // It should be considered to just stop running doctests on
1869 // librustdoc. There is only one test, and it doesn't look too
1870 // important. There might be other ways to avoid this, but it seems
1871 // pretty convoluted.
1873 // See also https://github.com/rust-lang/rust/issues/13983 where the
1874 // host vs target dylibs for rustdoc are consistently tricky to deal
1876 let mut dylib_path = dylib_path();
1877 dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
1878 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
1880 if !builder.config.verbose_tests {
1881 cargo.arg("--quiet");
1884 builder.info(&format!(
1885 "{} rustdoc stage{} ({} -> {})",
1886 test_kind, compiler.stage, &compiler.host, target
1888 let _time = util::timeit(&builder);
1890 try_run(builder, &mut cargo.into());
1894 /// Some test suites are run inside emulators or on remote devices, and most
1895 /// of our test binaries are linked dynamically which means we need to ship
1896 /// the standard library and such to the emulator ahead of time. This step
1897 /// represents this and is a dependency of all test suites.
1899 /// Most of the time this is a no-op. For some steps such as shipping data to
1900 /// QEMU we have to build our own tools so we've got conditional dependencies
1901 /// on those programs as well. Note that the remote test client is built for
1902 /// the build target (us) and the server is built for the target.
1903 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1904 pub struct RemoteCopyLibs {
1906 target: TargetSelection,
1909 impl Step for RemoteCopyLibs {
1912 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1916 fn run(self, builder: &Builder<'_>) {
1917 let compiler = self.compiler;
1918 let target = self.target;
1919 if !builder.remote_tested(target) {
1923 builder.ensure(compile::Std { compiler, target });
1925 builder.info(&format!("REMOTE copy libs to emulator ({})", target));
1926 t!(fs::create_dir_all(builder.out.join("tmp")));
1929 builder.ensure(tool::RemoteTestServer { compiler: compiler.with_stage(0), target });
1931 // Spawn the emulator and wait for it to come online
1932 let tool = builder.tool_exe(Tool::RemoteTestClient);
1933 let mut cmd = Command::new(&tool);
1934 cmd.arg("spawn-emulator").arg(target.triple).arg(&server).arg(builder.out.join("tmp"));
1935 if let Some(rootfs) = builder.qemu_rootfs(target) {
1938 builder.run(&mut cmd);
1940 // Push all our dylibs to the emulator
1941 for f in t!(builder.sysroot_libdir(compiler, target).read_dir()) {
1943 let name = f.file_name().into_string().unwrap();
1944 if util::is_dylib(&name) {
1945 builder.run(Command::new(&tool).arg("push").arg(f.path()));
1951 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1952 pub struct Distcheck;
1954 impl Step for Distcheck {
1957 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1958 run.path("distcheck")
1961 fn make_run(run: RunConfig<'_>) {
1962 run.builder.ensure(Distcheck);
1965 /// Runs "distcheck", a 'make check' from a tarball
1966 fn run(self, builder: &Builder<'_>) {
1967 builder.info("Distcheck");
1968 let dir = builder.out.join("tmp").join("distcheck");
1969 let _ = fs::remove_dir_all(&dir);
1970 t!(fs::create_dir_all(&dir));
1972 // Guarantee that these are built before we begin running.
1973 builder.ensure(dist::PlainSourceTarball);
1974 builder.ensure(dist::Src);
1976 let mut cmd = Command::new("tar");
1978 .arg(builder.ensure(dist::PlainSourceTarball).tarball())
1979 .arg("--strip-components=1")
1981 builder.run(&mut cmd);
1983 Command::new("./configure")
1984 .args(&builder.config.configure_args)
1985 .arg("--enable-vendor")
1989 Command::new(build_helper::make(&builder.config.build.triple))
1994 // Now make sure that rust-src has all of libstd's dependencies
1995 builder.info("Distcheck rust-src");
1996 let dir = builder.out.join("tmp").join("distcheck-src");
1997 let _ = fs::remove_dir_all(&dir);
1998 t!(fs::create_dir_all(&dir));
2000 let mut cmd = Command::new("tar");
2002 .arg(builder.ensure(dist::Src).tarball())
2003 .arg("--strip-components=1")
2005 builder.run(&mut cmd);
2007 let toml = dir.join("rust-src/lib/rustlib/src/rust/library/std/Cargo.toml");
2009 Command::new(&builder.initial_cargo)
2010 .arg("generate-lockfile")
2011 .arg("--manifest-path")
2018 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2019 pub struct Bootstrap;
2021 impl Step for Bootstrap {
2023 const DEFAULT: bool = true;
2024 const ONLY_HOSTS: bool = true;
2026 /// Tests the build system itself.
2027 fn run(self, builder: &Builder<'_>) {
2028 let mut cmd = Command::new(&builder.initial_cargo);
2030 .current_dir(builder.src.join("src/bootstrap"))
2031 .env("RUSTFLAGS", "-Cdebuginfo=2")
2032 .env("CARGO_TARGET_DIR", builder.out.join("bootstrap"))
2033 .env("BOOTSTRAP_OUTPUT_DIRECTORY", &builder.config.out)
2034 .env("BOOTSTRAP_INITIAL_CARGO", &builder.config.initial_cargo)
2035 .env("RUSTC_BOOTSTRAP", "1")
2036 .env("RUSTC", &builder.initial_rustc);
2037 if let Some(flags) = option_env!("RUSTFLAGS") {
2038 // Use the same rustc flags for testing as for "normal" compilation,
2039 // so that Cargo doesn’t recompile the entire dependency graph every time:
2040 // https://github.com/rust-lang/rust/issues/49215
2041 cmd.env("RUSTFLAGS", flags);
2043 if !builder.fail_fast {
2044 cmd.arg("--no-fail-fast");
2046 cmd.arg("--").args(&builder.config.cmd.test_args());
2047 // rustbuild tests are racy on directory creation so just run them one at a time.
2048 // Since there's not many this shouldn't be a problem.
2049 cmd.arg("--test-threads=1");
2050 try_run(builder, &mut cmd);
2053 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2054 run.path("src/bootstrap")
2057 fn make_run(run: RunConfig<'_>) {
2058 run.builder.ensure(Bootstrap);
2062 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2063 pub struct TierCheck {
2064 pub compiler: Compiler,
2067 impl Step for TierCheck {
2069 const DEFAULT: bool = true;
2070 const ONLY_HOSTS: bool = true;
2072 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2073 run.path("src/tools/tier-check")
2076 fn make_run(run: RunConfig<'_>) {
2078 run.builder.compiler_for(run.builder.top_stage, run.builder.build.build, run.target);
2079 run.builder.ensure(TierCheck { compiler });
2082 /// Tests the Platform Support page in the rustc book.
2083 fn run(self, builder: &Builder<'_>) {
2084 builder.ensure(compile::Std { compiler: self.compiler, target: self.compiler.host });
2085 let mut cargo = tool::prepare_tool_cargo(
2091 "src/tools/tier-check",
2095 cargo.arg(builder.src.join("src/doc/rustc/src/platform-support.md"));
2096 cargo.arg(&builder.rustc(self.compiler));
2097 if builder.is_verbose() {
2098 cargo.arg("--verbose");
2101 builder.info("platform support check");
2102 try_run(builder, &mut cargo.into());
2106 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2107 pub struct LintDocs {
2108 pub compiler: Compiler,
2109 pub target: TargetSelection,
2112 impl Step for LintDocs {
2114 const DEFAULT: bool = true;
2115 const ONLY_HOSTS: bool = true;
2117 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2118 run.path("src/tools/lint-docs")
2121 fn make_run(run: RunConfig<'_>) {
2122 run.builder.ensure(LintDocs {
2123 compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
2128 /// Tests that the lint examples in the rustc book generate the correct
2129 /// lints and have the expected format.
2130 fn run(self, builder: &Builder<'_>) {
2131 builder.ensure(crate::doc::RustcBook {
2132 compiler: self.compiler,
2133 target: self.target,