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 if builder.is_verbose() {
741 cmd.arg("--verbose");
744 builder.info("tidy check");
745 try_run(builder, &mut cmd);
747 if builder.config.channel == "dev" || builder.config.channel == "nightly" {
748 builder.info("fmt check");
749 crate::format::format(&builder.build, !builder.config.cmd.bless());
753 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
754 run.path("src/tools/tidy")
757 fn make_run(run: RunConfig<'_>) {
758 run.builder.ensure(Tidy);
762 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
763 pub struct ExpandYamlAnchors;
765 impl Step for ExpandYamlAnchors {
767 const ONLY_HOSTS: bool = true;
769 /// Ensure the `generate-ci-config` tool was run locally.
771 /// The tool in `src/tools` reads the CI definition in `src/ci/builders.yml` and generates the
772 /// appropriate configuration for all our CI providers. This step ensures the tool was called
773 /// by the user before committing CI changes.
774 fn run(self, builder: &Builder<'_>) {
775 builder.info("Ensuring the YAML anchors in the GitHub Actions config were expanded");
778 &mut builder.tool_cmd(Tool::ExpandYamlAnchors).arg("check").arg(&builder.src),
782 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
783 run.path("src/tools/expand-yaml-anchors")
786 fn make_run(run: RunConfig<'_>) {
787 run.builder.ensure(ExpandYamlAnchors);
791 fn testdir(builder: &Builder<'_>, host: TargetSelection) -> PathBuf {
792 builder.out.join(host.triple).join("test")
795 macro_rules! default_test {
796 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
797 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: false });
801 macro_rules! default_test_with_compare_mode {
802 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr,
803 compare_mode: $compare_mode:expr }) => {
804 test_with_compare_mode!($name {
810 compare_mode: $compare_mode
815 macro_rules! host_test {
816 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
817 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: true });
822 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
823 host: $host:expr }) => {
824 test_definitions!($name {
835 macro_rules! test_with_compare_mode {
836 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
837 host: $host:expr, compare_mode: $compare_mode:expr }) => {
838 test_definitions!($name {
844 compare_mode: Some($compare_mode)
849 macro_rules! test_definitions {
854 default: $default:expr,
856 compare_mode: $compare_mode:expr
858 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
860 pub compiler: Compiler,
861 pub target: TargetSelection,
864 impl Step for $name {
866 const DEFAULT: bool = $default;
867 const ONLY_HOSTS: bool = $host;
869 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
870 run.suite_path($path)
873 fn make_run(run: RunConfig<'_>) {
874 let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
876 run.builder.ensure($name { compiler, target: run.target });
879 fn run(self, builder: &Builder<'_>) {
880 builder.ensure(Compiletest {
881 compiler: self.compiler,
886 compare_mode: $compare_mode,
893 default_test_with_compare_mode!(Ui {
900 default_test!(CompileFail {
901 path: "src/test/compile-fail",
902 mode: "compile-fail",
903 suite: "compile-fail"
906 default_test!(RunPassValgrind {
907 path: "src/test/run-pass-valgrind",
908 mode: "run-pass-valgrind",
909 suite: "run-pass-valgrind"
912 default_test!(MirOpt { path: "src/test/mir-opt", mode: "mir-opt", suite: "mir-opt" });
914 default_test!(Codegen { path: "src/test/codegen", mode: "codegen", suite: "codegen" });
916 default_test!(CodegenUnits {
917 path: "src/test/codegen-units",
918 mode: "codegen-units",
919 suite: "codegen-units"
922 default_test!(Incremental {
923 path: "src/test/incremental",
928 default_test!(Debuginfo { path: "src/test/debuginfo", mode: "debuginfo", suite: "debuginfo" });
930 host_test!(UiFullDeps { path: "src/test/ui-fulldeps", mode: "ui", suite: "ui-fulldeps" });
932 host_test!(Rustdoc { path: "src/test/rustdoc", mode: "rustdoc", suite: "rustdoc" });
934 host_test!(Pretty { path: "src/test/pretty", mode: "pretty", suite: "pretty" });
936 default_test!(RunMake { path: "src/test/run-make", mode: "run-make", suite: "run-make" });
938 host_test!(RunMakeFullDeps {
939 path: "src/test/run-make-fulldeps",
941 suite: "run-make-fulldeps"
944 default_test!(Assembly { path: "src/test/assembly", mode: "assembly", suite: "assembly" });
946 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
949 target: TargetSelection,
953 compare_mode: Option<&'static str>,
956 impl Step for Compiletest {
959 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
963 /// Executes the `compiletest` tool to run a suite of tests.
965 /// Compiles all tests with `compiler` for `target` with the specified
966 /// compiletest `mode` and `suite` arguments. For example `mode` can be
967 /// "run-pass" or `suite` can be something like `debuginfo`.
968 fn run(self, builder: &Builder<'_>) {
969 if builder.top_stage == 0 && env::var("COMPILETEST_FORCE_STAGE0").is_err() {
971 error: `--stage 0` runs compiletest on the beta compiler, not your local changes, and will almost always cause tests to fail
972 help: use `--stage 1` instead
973 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`."
975 std::process::exit(1);
978 let compiler = self.compiler;
979 let target = self.target;
980 let mode = self.mode;
981 let suite = self.suite;
983 // Path for test suite
984 let suite_path = self.path;
986 // Skip codegen tests if they aren't enabled in configuration.
987 if !builder.config.codegen_tests && suite == "codegen" {
991 if suite == "debuginfo" {
993 .ensure(dist::DebuggerScripts { sysroot: builder.sysroot(compiler), host: target });
996 if suite.ends_with("fulldeps") {
997 builder.ensure(compile::Rustc { compiler, target });
1000 builder.ensure(compile::Std { compiler, target });
1001 // ensure that `libproc_macro` is available on the host.
1002 builder.ensure(compile::Std { compiler, target: compiler.host });
1004 // Also provide `rust_test_helpers` for the host.
1005 builder.ensure(native::TestHelpers { target: compiler.host });
1007 // As well as the target, except for plain wasm32, which can't build it
1008 if !target.contains("wasm32") || target.contains("emscripten") {
1009 builder.ensure(native::TestHelpers { target });
1012 builder.ensure(RemoteCopyLibs { compiler, target });
1014 let mut cmd = builder.tool_cmd(Tool::Compiletest);
1016 // compiletest currently has... a lot of arguments, so let's just pass all
1019 cmd.arg("--compile-lib-path").arg(builder.rustc_libdir(compiler));
1020 cmd.arg("--run-lib-path").arg(builder.sysroot_libdir(compiler, target));
1021 cmd.arg("--rustc-path").arg(builder.rustc(compiler));
1023 let is_rustdoc = suite.ends_with("rustdoc-ui") || suite.ends_with("rustdoc-js");
1025 // Avoid depending on rustdoc when we don't need it.
1026 if mode == "rustdoc"
1027 || (mode == "run-make" && suite.ends_with("fulldeps"))
1028 || (mode == "ui" && is_rustdoc)
1029 || mode == "js-doc-test"
1031 cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler));
1034 if mode == "run-make" && suite.ends_with("fulldeps") {
1035 cmd.arg("--rust-demangler-path").arg(builder.tool_exe(Tool::RustDemangler));
1038 cmd.arg("--src-base").arg(builder.src.join("src/test").join(suite));
1039 cmd.arg("--build-base").arg(testdir(builder, compiler.host).join(suite));
1040 cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target));
1041 cmd.arg("--mode").arg(mode);
1042 cmd.arg("--target").arg(target.rustc_target_arg());
1043 cmd.arg("--host").arg(&*compiler.host.triple);
1044 cmd.arg("--llvm-filecheck").arg(builder.llvm_filecheck(builder.config.build));
1046 if builder.config.cmd.bless() {
1051 builder.config.cmd.compare_mode().or_else(|| {
1052 if builder.config.test_compare_mode { self.compare_mode } else { None }
1055 if let Some(ref pass) = builder.config.cmd.pass() {
1060 if let Some(ref nodejs) = builder.config.nodejs {
1061 cmd.arg("--nodejs").arg(nodejs);
1064 let mut flags = if is_rustdoc { Vec::new() } else { vec!["-Crpath".to_string()] };
1066 if builder.config.rust_optimize_tests {
1067 flags.push("-O".to_string());
1070 flags.push(format!("-Cdebuginfo={}", builder.config.rust_debuginfo_level_tests));
1071 flags.push("-Zunstable-options".to_string());
1072 flags.push(builder.config.cmd.rustc_args().join(" "));
1074 if let Some(linker) = builder.linker(target) {
1075 cmd.arg("--linker").arg(linker);
1078 let mut hostflags = flags.clone();
1079 hostflags.push(format!("-Lnative={}", builder.test_helpers_out(compiler.host).display()));
1080 if builder.is_fuse_ld_lld(compiler.host) {
1081 hostflags.push("-Clink-args=-fuse-ld=lld".to_string());
1083 cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
1085 let mut targetflags = flags;
1086 targetflags.push(format!("-Lnative={}", builder.test_helpers_out(target).display()));
1087 if builder.is_fuse_ld_lld(target) {
1088 targetflags.push("-Clink-args=-fuse-ld=lld".to_string());
1090 cmd.arg("--target-rustcflags").arg(targetflags.join(" "));
1092 cmd.arg("--docck-python").arg(builder.python());
1094 if builder.config.build.ends_with("apple-darwin") {
1095 // Force /usr/bin/python3 on macOS for LLDB tests because we're loading the
1096 // LLDB plugin's compiled module which only works with the system python
1097 // (namely not Homebrew-installed python)
1098 cmd.arg("--lldb-python").arg("/usr/bin/python3");
1100 cmd.arg("--lldb-python").arg(builder.python());
1103 if let Some(ref gdb) = builder.config.gdb {
1104 cmd.arg("--gdb").arg(gdb);
1107 let run = |cmd: &mut Command| {
1108 cmd.output().map(|output| {
1109 String::from_utf8_lossy(&output.stdout)
1112 .unwrap_or_else(|| panic!("{:?} failed {:?}", cmd, output))
1116 let lldb_exe = "lldb";
1117 let lldb_version = Command::new(lldb_exe)
1120 .map(|output| String::from_utf8_lossy(&output.stdout).to_string())
1122 if let Some(ref vers) = lldb_version {
1123 cmd.arg("--lldb-version").arg(vers);
1124 let lldb_python_dir = run(Command::new(lldb_exe).arg("-P")).ok();
1125 if let Some(ref dir) = lldb_python_dir {
1126 cmd.arg("--lldb-python-dir").arg(dir);
1130 if util::forcing_clang_based_tests() {
1131 let clang_exe = builder.llvm_out(target).join("bin").join("clang");
1132 cmd.arg("--run-clang-based-tests-with").arg(clang_exe);
1135 // Get paths from cmd args
1136 let paths = match &builder.config.cmd {
1137 Subcommand::Test { ref paths, .. } => &paths[..],
1141 // Get test-args by striping suite path
1142 let mut test_args: Vec<&str> = paths
1144 .map(|p| match p.strip_prefix(".") {
1148 .filter(|p| p.starts_with(suite_path) && (p.is_dir() || p.is_file()))
1150 // Since test suite paths are themselves directories, if we don't
1151 // specify a directory or file, we'll get an empty string here
1152 // (the result of the test suite directory without its suite prefix).
1153 // Therefore, we need to filter these out, as only the first --test-args
1154 // flag is respected, so providing an empty --test-args conflicts with
1155 // any following it.
1156 match p.strip_prefix(suite_path).ok().and_then(|p| p.to_str()) {
1157 Some(s) if s != "" => Some(s),
1163 test_args.append(&mut builder.config.cmd.test_args());
1165 cmd.args(&test_args);
1167 if builder.is_verbose() {
1168 cmd.arg("--verbose");
1171 if !builder.config.verbose_tests {
1175 let mut llvm_components_passed = false;
1176 let mut copts_passed = false;
1177 if builder.config.llvm_enabled() {
1178 let llvm_config = builder.ensure(native::Llvm { target: builder.config.build });
1179 if !builder.config.dry_run {
1180 let llvm_version = output(Command::new(&llvm_config).arg("--version"));
1181 let llvm_components = output(Command::new(&llvm_config).arg("--components"));
1182 // Remove trailing newline from llvm-config output.
1183 cmd.arg("--llvm-version")
1184 .arg(llvm_version.trim())
1185 .arg("--llvm-components")
1186 .arg(llvm_components.trim());
1187 llvm_components_passed = true;
1189 if !builder.is_rust_llvm(target) {
1190 cmd.arg("--system-llvm");
1193 // Tests that use compiler libraries may inherit the `-lLLVM` link
1194 // requirement, but the `-L` library path is not propagated across
1195 // separate compilations. We can add LLVM's library path to the
1196 // platform-specific environment variable as a workaround.
1197 if !builder.config.dry_run && suite.ends_with("fulldeps") {
1198 let llvm_libdir = output(Command::new(&llvm_config).arg("--libdir"));
1199 add_link_lib_path(vec![llvm_libdir.trim().into()], &mut cmd);
1202 // Only pass correct values for these flags for the `run-make` suite as it
1203 // requires that a C++ compiler was configured which isn't always the case.
1204 if !builder.config.dry_run && suite == "run-make-fulldeps" {
1206 .arg(builder.cc(target))
1208 .arg(builder.cxx(target).unwrap())
1210 .arg(builder.cflags(target, GitRepo::Rustc).join(" "));
1211 copts_passed = true;
1212 if let Some(ar) = builder.ar(target) {
1213 cmd.arg("--ar").arg(ar);
1216 // The llvm/bin directory contains many useful cross-platform
1217 // tools. Pass the path to run-make tests so they can use them.
1218 let llvm_bin_path = llvm_config
1220 .expect("Expected llvm-config to be contained in directory");
1221 assert!(llvm_bin_path.is_dir());
1222 cmd.arg("--llvm-bin-dir").arg(llvm_bin_path);
1224 // If LLD is available, add it to the PATH
1225 if builder.config.lld_enabled {
1226 let lld_install_root =
1227 builder.ensure(native::Lld { target: builder.config.build });
1229 let lld_bin_path = lld_install_root.join("bin");
1231 let old_path = env::var_os("PATH").unwrap_or_default();
1232 let new_path = env::join_paths(
1233 std::iter::once(lld_bin_path).chain(env::split_paths(&old_path)),
1235 .expect("Could not add LLD bin path to PATH");
1236 cmd.env("PATH", new_path);
1241 if !llvm_components_passed {
1242 cmd.arg("--llvm-components").arg("");
1245 cmd.arg("--cc").arg("").arg("--cxx").arg("").arg("--cflags").arg("");
1248 if builder.remote_tested(target) {
1249 cmd.arg("--remote-test-client").arg(builder.tool_exe(Tool::RemoteTestClient));
1252 // Running a C compiler on MSVC requires a few env vars to be set, to be
1253 // sure to set them here.
1255 // Note that if we encounter `PATH` we make sure to append to our own `PATH`
1256 // rather than stomp over it.
1257 if target.contains("msvc") {
1258 for &(ref k, ref v) in builder.cc[&target].env() {
1264 cmd.env("RUSTC_BOOTSTRAP", "1");
1265 builder.add_rust_test_threads(&mut cmd);
1267 if builder.config.sanitizers {
1268 cmd.env("RUSTC_SANITIZER_SUPPORT", "1");
1271 if builder.config.profiler {
1272 cmd.env("RUSTC_PROFILER_SUPPORT", "1");
1275 let tmp = builder.out.join("tmp");
1276 std::fs::create_dir_all(&tmp).unwrap();
1277 cmd.env("RUST_TEST_TMPDIR", tmp);
1279 cmd.arg("--adb-path").arg("adb");
1280 cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
1281 if target.contains("android") {
1282 // Assume that cc for this target comes from the android sysroot
1283 cmd.arg("--android-cross-path")
1284 .arg(builder.cc(target).parent().unwrap().parent().unwrap());
1286 cmd.arg("--android-cross-path").arg("");
1289 if builder.config.cmd.rustfix_coverage() {
1290 cmd.arg("--rustfix-coverage");
1293 cmd.env("BOOTSTRAP_CARGO", &builder.initial_cargo);
1295 builder.ci_env.force_coloring_in_ci(&mut cmd);
1297 builder.info(&format!(
1298 "Check compiletest suite={} mode={} ({} -> {})",
1299 suite, mode, &compiler.host, target
1301 let _time = util::timeit(&builder);
1302 try_run(builder, &mut cmd);
1304 if let Some(compare_mode) = compare_mode {
1305 cmd.arg("--compare-mode").arg(compare_mode);
1306 builder.info(&format!(
1307 "Check compiletest suite={} mode={} compare_mode={} ({} -> {})",
1308 suite, mode, compare_mode, &compiler.host, target
1310 let _time = util::timeit(&builder);
1311 try_run(builder, &mut cmd);
1316 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1324 impl Step for BookTest {
1326 const ONLY_HOSTS: bool = true;
1328 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1332 /// Runs the documentation tests for a book in `src/doc`.
1334 /// This uses the `rustdoc` that sits next to `compiler`.
1335 fn run(self, builder: &Builder<'_>) {
1336 // External docs are different from local because:
1337 // - Some books need pre-processing by mdbook before being tested.
1338 // - They need to save their state to toolstate.
1339 // - They are only tested on the "checktools" builders.
1341 // The local docs are tested by default, and we don't want to pay the
1342 // cost of building mdbook, so they use `rustdoc --test` directly.
1343 // Also, the unstable book is special because SUMMARY.md is generated,
1344 // so it is easier to just run `rustdoc` on its files.
1345 if self.is_ext_doc {
1346 self.run_ext_doc(builder);
1348 self.run_local_doc(builder);
1354 /// This runs the equivalent of `mdbook test` (via the rustbook wrapper)
1355 /// which in turn runs `rustdoc --test` on each file in the book.
1356 fn run_ext_doc(self, builder: &Builder<'_>) {
1357 let compiler = self.compiler;
1359 builder.ensure(compile::Std { compiler, target: compiler.host });
1361 // mdbook just executes a binary named "rustdoc", so we need to update
1362 // PATH so that it points to our rustdoc.
1363 let mut rustdoc_path = builder.rustdoc(compiler);
1365 let old_path = env::var_os("PATH").unwrap_or_default();
1366 let new_path = env::join_paths(iter::once(rustdoc_path).chain(env::split_paths(&old_path)))
1367 .expect("could not add rustdoc to PATH");
1369 let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
1370 let path = builder.src.join(&self.path);
1371 rustbook_cmd.env("PATH", new_path).arg("test").arg(path);
1372 builder.add_rust_test_threads(&mut rustbook_cmd);
1373 builder.info(&format!("Testing rustbook {}", self.path.display()));
1374 let _time = util::timeit(&builder);
1375 let toolstate = if try_run(builder, &mut rustbook_cmd) {
1380 builder.save_toolstate(self.name, toolstate);
1383 /// This runs `rustdoc --test` on all `.md` files in the path.
1384 fn run_local_doc(self, builder: &Builder<'_>) {
1385 let compiler = self.compiler;
1387 builder.ensure(compile::Std { compiler, target: compiler.host });
1389 // Do a breadth-first traversal of the `src/doc` directory and just run
1390 // tests for all files that end in `*.md`
1391 let mut stack = vec![builder.src.join(self.path)];
1392 let _time = util::timeit(&builder);
1393 let mut files = Vec::new();
1394 while let Some(p) = stack.pop() {
1396 stack.extend(t!(p.read_dir()).map(|p| t!(p).path()));
1400 if p.extension().and_then(|s| s.to_str()) != Some("md") {
1410 markdown_test(builder, compiler, &file);
1415 macro_rules! test_book {
1416 ($($name:ident, $path:expr, $book_name:expr, default=$default:expr;)+) => {
1418 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1423 impl Step for $name {
1425 const DEFAULT: bool = $default;
1426 const ONLY_HOSTS: bool = true;
1428 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1432 fn make_run(run: RunConfig<'_>) {
1433 run.builder.ensure($name {
1434 compiler: run.builder.compiler(run.builder.top_stage, run.target),
1438 fn run(self, builder: &Builder<'_>) {
1439 builder.ensure(BookTest {
1440 compiler: self.compiler,
1441 path: PathBuf::from($path),
1443 is_ext_doc: !$default,
1452 Nomicon, "src/doc/nomicon", "nomicon", default=false;
1453 Reference, "src/doc/reference", "reference", default=false;
1454 RustdocBook, "src/doc/rustdoc", "rustdoc", default=true;
1455 RustcBook, "src/doc/rustc", "rustc", default=true;
1456 RustByExample, "src/doc/rust-by-example", "rust-by-example", default=false;
1457 EmbeddedBook, "src/doc/embedded-book", "embedded-book", default=false;
1458 TheBook, "src/doc/book", "book", default=false;
1459 UnstableBook, "src/doc/unstable-book", "unstable-book", default=true;
1460 EditionGuide, "src/doc/edition-guide", "edition-guide", default=false;
1463 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1464 pub struct ErrorIndex {
1468 impl Step for ErrorIndex {
1470 const DEFAULT: bool = true;
1471 const ONLY_HOSTS: bool = true;
1473 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1474 run.path("src/tools/error_index_generator")
1477 fn make_run(run: RunConfig<'_>) {
1478 // error_index_generator depends on librustdoc. Use the compiler that
1479 // is normally used to build rustdoc for other tests (like compiletest
1480 // tests in src/test/rustdoc) so that it shares the same artifacts.
1481 let compiler = run.builder.compiler_for(run.builder.top_stage, run.target, run.target);
1482 run.builder.ensure(ErrorIndex { compiler });
1485 /// Runs the error index generator tool to execute the tests located in the error
1488 /// The `error_index_generator` tool lives in `src/tools` and is used to
1489 /// generate a markdown file from the error indexes of the code base which is
1490 /// then passed to `rustdoc --test`.
1491 fn run(self, builder: &Builder<'_>) {
1492 let compiler = self.compiler;
1494 let dir = testdir(builder, compiler.host);
1495 t!(fs::create_dir_all(&dir));
1496 let output = dir.join("error-index.md");
1498 let mut tool = tool::ErrorIndex::command(builder, compiler);
1499 tool.arg("markdown").arg(&output);
1501 // Use the rustdoc that was built by self.compiler. This copy of
1502 // rustdoc is shared with other tests (like compiletest tests in
1503 // src/test/rustdoc). This helps avoid building rustdoc multiple
1505 let rustdoc_compiler = builder.compiler(builder.top_stage, builder.config.build);
1506 builder.info(&format!("Testing error-index stage{}", rustdoc_compiler.stage));
1507 let _time = util::timeit(&builder);
1508 builder.run_quiet(&mut tool);
1509 builder.ensure(compile::Std { compiler: rustdoc_compiler, target: rustdoc_compiler.host });
1510 markdown_test(builder, rustdoc_compiler, &output);
1514 fn markdown_test(builder: &Builder<'_>, compiler: Compiler, markdown: &Path) -> bool {
1515 if let Ok(contents) = fs::read_to_string(markdown) {
1516 if !contents.contains("```") {
1521 builder.info(&format!("doc tests for: {}", markdown.display()));
1522 let mut cmd = builder.rustdoc_cmd(compiler);
1523 builder.add_rust_test_threads(&mut cmd);
1526 cmd.env("RUSTC_BOOTSTRAP", "1");
1528 let test_args = builder.config.cmd.test_args().join(" ");
1529 cmd.arg("--test-args").arg(test_args);
1531 if builder.config.verbose_tests {
1532 try_run(builder, &mut cmd)
1534 try_run_quiet(builder, &mut cmd)
1538 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1539 pub struct RustcGuide;
1541 impl Step for RustcGuide {
1543 const DEFAULT: bool = false;
1544 const ONLY_HOSTS: bool = true;
1546 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1547 run.path("src/doc/rustc-dev-guide")
1550 fn make_run(run: RunConfig<'_>) {
1551 run.builder.ensure(RustcGuide);
1554 fn run(self, builder: &Builder<'_>) {
1555 let src = builder.src.join("src/doc/rustc-dev-guide");
1556 let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
1557 let toolstate = if try_run(builder, rustbook_cmd.arg("linkcheck").arg(&src)) {
1562 builder.save_toolstate("rustc-dev-guide", toolstate);
1566 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1567 pub struct CrateLibrustc {
1569 target: TargetSelection,
1570 test_kind: TestKind,
1571 krate: Interned<String>,
1574 impl Step for CrateLibrustc {
1576 const DEFAULT: bool = true;
1577 const ONLY_HOSTS: bool = true;
1579 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1580 run.krate("rustc-main")
1583 fn make_run(run: RunConfig<'_>) {
1584 let builder = run.builder;
1585 let compiler = builder.compiler(builder.top_stage, run.build_triple());
1587 for krate in builder.in_tree_crates("rustc-main") {
1588 if krate.path.ends_with(&run.path) {
1589 let test_kind = builder.kind.into();
1591 builder.ensure(CrateLibrustc {
1601 fn run(self, builder: &Builder<'_>) {
1602 builder.ensure(Crate {
1603 compiler: self.compiler,
1604 target: self.target,
1606 test_kind: self.test_kind,
1612 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1613 pub struct CrateNotDefault {
1615 target: TargetSelection,
1616 test_kind: TestKind,
1617 krate: &'static str,
1620 impl Step for CrateNotDefault {
1623 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1624 run.path("src/librustc_asan")
1625 .path("src/librustc_lsan")
1626 .path("src/librustc_msan")
1627 .path("src/librustc_tsan")
1630 fn make_run(run: RunConfig<'_>) {
1631 let builder = run.builder;
1632 let compiler = builder.compiler(builder.top_stage, run.build_triple());
1634 let test_kind = builder.kind.into();
1636 builder.ensure(CrateNotDefault {
1640 krate: match run.path {
1641 _ if run.path.ends_with("src/librustc_asan") => "rustc_asan",
1642 _ if run.path.ends_with("src/librustc_lsan") => "rustc_lsan",
1643 _ if run.path.ends_with("src/librustc_msan") => "rustc_msan",
1644 _ if run.path.ends_with("src/librustc_tsan") => "rustc_tsan",
1645 _ => panic!("unexpected path {:?}", run.path),
1650 fn run(self, builder: &Builder<'_>) {
1651 builder.ensure(Crate {
1652 compiler: self.compiler,
1653 target: self.target,
1655 test_kind: self.test_kind,
1656 krate: INTERNER.intern_str(self.krate),
1661 #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
1663 pub compiler: Compiler,
1664 pub target: TargetSelection,
1666 pub test_kind: TestKind,
1667 pub krate: Interned<String>,
1670 impl Step for Crate {
1672 const DEFAULT: bool = true;
1674 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1678 fn make_run(run: RunConfig<'_>) {
1679 let builder = run.builder;
1680 let compiler = builder.compiler(builder.top_stage, run.build_triple());
1682 let make = |mode: Mode, krate: &CargoCrate| {
1683 let test_kind = builder.kind.into();
1685 builder.ensure(Crate {
1694 for krate in builder.in_tree_crates("test") {
1695 if krate.path.ends_with(&run.path) {
1696 make(Mode::Std, krate);
1701 /// Runs all unit tests plus documentation tests for a given crate defined
1702 /// by a `Cargo.toml` (single manifest)
1704 /// This is what runs tests for crates like the standard library, compiler, etc.
1705 /// It essentially is the driver for running `cargo test`.
1707 /// Currently this runs all tests for a DAG by passing a bunch of `-p foo`
1708 /// arguments, and those arguments are discovered from `cargo metadata`.
1709 fn run(self, builder: &Builder<'_>) {
1710 let compiler = self.compiler;
1711 let target = self.target;
1712 let mode = self.mode;
1713 let test_kind = self.test_kind;
1714 let krate = self.krate;
1716 builder.ensure(compile::Std { compiler, target });
1717 builder.ensure(RemoteCopyLibs { compiler, target });
1719 // If we're not doing a full bootstrap but we're testing a stage2
1720 // version of libstd, then what we're actually testing is the libstd
1721 // produced in stage1. Reflect that here by updating the compiler that
1722 // we're working with automatically.
1723 let compiler = builder.compiler_for(compiler.stage, compiler.host, target);
1726 builder.cargo(compiler, mode, SourceType::InTree, target, test_kind.subcommand());
1729 compile::std_cargo(builder, target, compiler.stage, &mut cargo);
1732 builder.ensure(compile::Rustc { compiler, target });
1733 compile::rustc_cargo(builder, &mut cargo, target);
1735 _ => panic!("can only test libraries"),
1738 // Build up the base `cargo test` command.
1740 // Pass in some standard flags then iterate over the graph we've discovered
1741 // in `cargo metadata` with the maps above and figure out what `-p`
1742 // arguments need to get passed.
1743 if test_kind.subcommand() == "test" && !builder.fail_fast {
1744 cargo.arg("--no-fail-fast");
1746 match builder.doc_tests {
1751 cargo.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
1756 cargo.arg("-p").arg(krate);
1758 // The tests are going to run with the *target* libraries, so we need to
1759 // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
1761 // Note that to run the compiler we need to run with the *host* libraries,
1762 // but our wrapper scripts arrange for that to be the case anyway.
1763 let mut dylib_path = dylib_path();
1764 dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
1765 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
1768 cargo.args(&builder.config.cmd.test_args());
1770 if !builder.config.verbose_tests {
1771 cargo.arg("--quiet");
1774 if target.contains("emscripten") {
1776 format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)),
1777 builder.config.nodejs.as_ref().expect("nodejs not configured"),
1779 } else if target.starts_with("wasm32") {
1780 let node = builder.config.nodejs.as_ref().expect("nodejs not configured");
1782 format!("{} {}/src/etc/wasm32-shim.js", node.display(), builder.src.display());
1783 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)), &runner);
1784 } else if builder.remote_tested(target) {
1786 format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)),
1787 format!("{} run 0", builder.tool_exe(Tool::RemoteTestClient).display()),
1791 builder.info(&format!(
1792 "{} {} stage{} ({} -> {})",
1793 test_kind, krate, compiler.stage, &compiler.host, target
1795 let _time = util::timeit(&builder);
1796 try_run(builder, &mut cargo.into());
1800 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1801 pub struct CrateRustdoc {
1802 host: TargetSelection,
1803 test_kind: TestKind,
1806 impl Step for CrateRustdoc {
1808 const DEFAULT: bool = true;
1809 const ONLY_HOSTS: bool = true;
1811 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1812 run.paths(&["src/librustdoc", "src/tools/rustdoc"])
1815 fn make_run(run: RunConfig<'_>) {
1816 let builder = run.builder;
1818 let test_kind = builder.kind.into();
1820 builder.ensure(CrateRustdoc { host: run.target, test_kind });
1823 fn run(self, builder: &Builder<'_>) {
1824 let test_kind = self.test_kind;
1825 let target = self.host;
1827 // Use the previous stage compiler to reuse the artifacts that are
1828 // created when running compiletest for src/test/rustdoc. If this used
1829 // `compiler`, then it would cause rustdoc to be built *again*, which
1830 // isn't really necessary.
1831 let compiler = builder.compiler_for(builder.top_stage, target, target);
1832 builder.ensure(compile::Rustc { compiler, target });
1834 let mut cargo = tool::prepare_tool_cargo(
1839 test_kind.subcommand(),
1840 "src/tools/rustdoc",
1844 if test_kind.subcommand() == "test" && !builder.fail_fast {
1845 cargo.arg("--no-fail-fast");
1848 cargo.arg("-p").arg("rustdoc:0.0.0");
1851 cargo.args(&builder.config.cmd.test_args());
1853 if self.host.contains("musl") {
1854 cargo.arg("'-Ctarget-feature=-crt-static'");
1857 // This is needed for running doctests on librustdoc. This is a bit of
1858 // an unfortunate interaction with how bootstrap works and how cargo
1859 // sets up the dylib path, and the fact that the doctest (in
1860 // html/markdown.rs) links to rustc-private libs. For stage1, the
1861 // compiler host dylibs (in stage1/lib) are not the same as the target
1862 // dylibs (in stage1/lib/rustlib/...). This is different from a normal
1863 // rust distribution where they are the same.
1865 // On the cargo side, normal tests use `target_process` which handles
1866 // setting up the dylib for a *target* (stage1/lib/rustlib/... in this
1867 // case). However, for doctests it uses `rustdoc_process` which only
1868 // sets up the dylib path for the *host* (stage1/lib), which is the
1871 // It should be considered to just stop running doctests on
1872 // librustdoc. There is only one test, and it doesn't look too
1873 // important. There might be other ways to avoid this, but it seems
1874 // pretty convoluted.
1876 // See also https://github.com/rust-lang/rust/issues/13983 where the
1877 // host vs target dylibs for rustdoc are consistently tricky to deal
1879 let mut dylib_path = dylib_path();
1880 dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
1881 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
1883 if !builder.config.verbose_tests {
1884 cargo.arg("--quiet");
1887 builder.info(&format!(
1888 "{} rustdoc stage{} ({} -> {})",
1889 test_kind, compiler.stage, &compiler.host, target
1891 let _time = util::timeit(&builder);
1893 try_run(builder, &mut cargo.into());
1897 /// Some test suites are run inside emulators or on remote devices, and most
1898 /// of our test binaries are linked dynamically which means we need to ship
1899 /// the standard library and such to the emulator ahead of time. This step
1900 /// represents this and is a dependency of all test suites.
1902 /// Most of the time this is a no-op. For some steps such as shipping data to
1903 /// QEMU we have to build our own tools so we've got conditional dependencies
1904 /// on those programs as well. Note that the remote test client is built for
1905 /// the build target (us) and the server is built for the target.
1906 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1907 pub struct RemoteCopyLibs {
1909 target: TargetSelection,
1912 impl Step for RemoteCopyLibs {
1915 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1919 fn run(self, builder: &Builder<'_>) {
1920 let compiler = self.compiler;
1921 let target = self.target;
1922 if !builder.remote_tested(target) {
1926 builder.ensure(compile::Std { compiler, target });
1928 builder.info(&format!("REMOTE copy libs to emulator ({})", target));
1929 t!(fs::create_dir_all(builder.out.join("tmp")));
1932 builder.ensure(tool::RemoteTestServer { compiler: compiler.with_stage(0), target });
1934 // Spawn the emulator and wait for it to come online
1935 let tool = builder.tool_exe(Tool::RemoteTestClient);
1936 let mut cmd = Command::new(&tool);
1937 cmd.arg("spawn-emulator").arg(target.triple).arg(&server).arg(builder.out.join("tmp"));
1938 if let Some(rootfs) = builder.qemu_rootfs(target) {
1941 builder.run(&mut cmd);
1943 // Push all our dylibs to the emulator
1944 for f in t!(builder.sysroot_libdir(compiler, target).read_dir()) {
1946 let name = f.file_name().into_string().unwrap();
1947 if util::is_dylib(&name) {
1948 builder.run(Command::new(&tool).arg("push").arg(f.path()));
1954 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1955 pub struct Distcheck;
1957 impl Step for Distcheck {
1960 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1961 run.path("distcheck")
1964 fn make_run(run: RunConfig<'_>) {
1965 run.builder.ensure(Distcheck);
1968 /// Runs "distcheck", a 'make check' from a tarball
1969 fn run(self, builder: &Builder<'_>) {
1970 builder.info("Distcheck");
1971 let dir = builder.out.join("tmp").join("distcheck");
1972 let _ = fs::remove_dir_all(&dir);
1973 t!(fs::create_dir_all(&dir));
1975 // Guarantee that these are built before we begin running.
1976 builder.ensure(dist::PlainSourceTarball);
1977 builder.ensure(dist::Src);
1979 let mut cmd = Command::new("tar");
1981 .arg(builder.ensure(dist::PlainSourceTarball))
1982 .arg("--strip-components=1")
1984 builder.run(&mut cmd);
1986 Command::new("./configure")
1987 .args(&builder.config.configure_args)
1988 .arg("--enable-vendor")
1992 Command::new(build_helper::make(&builder.config.build.triple))
1997 // Now make sure that rust-src has all of libstd's dependencies
1998 builder.info("Distcheck rust-src");
1999 let dir = builder.out.join("tmp").join("distcheck-src");
2000 let _ = fs::remove_dir_all(&dir);
2001 t!(fs::create_dir_all(&dir));
2003 let mut cmd = Command::new("tar");
2005 .arg(builder.ensure(dist::Src))
2006 .arg("--strip-components=1")
2008 builder.run(&mut cmd);
2010 let toml = dir.join("rust-src/lib/rustlib/src/rust/library/std/Cargo.toml");
2012 Command::new(&builder.initial_cargo)
2013 .arg("generate-lockfile")
2014 .arg("--manifest-path")
2021 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2022 pub struct Bootstrap;
2024 impl Step for Bootstrap {
2026 const DEFAULT: bool = true;
2027 const ONLY_HOSTS: bool = true;
2029 /// Tests the build system itself.
2030 fn run(self, builder: &Builder<'_>) {
2031 let mut cmd = Command::new(&builder.initial_cargo);
2033 .current_dir(builder.src.join("src/bootstrap"))
2034 .env("RUSTFLAGS", "-Cdebuginfo=2")
2035 .env("CARGO_TARGET_DIR", builder.out.join("bootstrap"))
2036 .env("BOOTSTRAP_OUTPUT_DIRECTORY", &builder.config.out)
2037 .env("BOOTSTRAP_INITIAL_CARGO", &builder.config.initial_cargo)
2038 .env("RUSTC_BOOTSTRAP", "1")
2039 .env("RUSTC", &builder.initial_rustc);
2040 if let Some(flags) = option_env!("RUSTFLAGS") {
2041 // Use the same rustc flags for testing as for "normal" compilation,
2042 // so that Cargo doesn’t recompile the entire dependency graph every time:
2043 // https://github.com/rust-lang/rust/issues/49215
2044 cmd.env("RUSTFLAGS", flags);
2046 if !builder.fail_fast {
2047 cmd.arg("--no-fail-fast");
2049 cmd.arg("--").args(&builder.config.cmd.test_args());
2050 // rustbuild tests are racy on directory creation so just run them one at a time.
2051 // Since there's not many this shouldn't be a problem.
2052 cmd.arg("--test-threads=1");
2053 try_run(builder, &mut cmd);
2056 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2057 run.path("src/bootstrap")
2060 fn make_run(run: RunConfig<'_>) {
2061 run.builder.ensure(Bootstrap);
2065 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2066 pub struct TierCheck {
2067 pub compiler: Compiler,
2070 impl Step for TierCheck {
2072 const DEFAULT: bool = true;
2073 const ONLY_HOSTS: bool = true;
2075 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2076 run.path("src/tools/tier-check")
2079 fn make_run(run: RunConfig<'_>) {
2081 run.builder.compiler_for(run.builder.top_stage, run.builder.build.build, run.target);
2082 run.builder.ensure(TierCheck { compiler });
2085 /// Tests the Platform Support page in the rustc book.
2086 fn run(self, builder: &Builder<'_>) {
2087 builder.ensure(compile::Std { compiler: self.compiler, target: self.compiler.host });
2088 let mut cargo = tool::prepare_tool_cargo(
2094 "src/tools/tier-check",
2098 cargo.arg(builder.src.join("src/doc/rustc/src/platform-support.md"));
2099 cargo.arg(&builder.rustc(self.compiler));
2100 if builder.is_verbose() {
2101 cargo.arg("--verbose");
2104 builder.info("platform support check");
2105 try_run(builder, &mut cargo.into());