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, Stdio};
14 use crate::builder::{Builder, Compiler, Kind, RunConfig, ShouldRun, Step};
15 use crate::cache::Interned;
17 use crate::config::TargetSelection;
19 use crate::doc::DocumentationFormat;
20 use crate::flags::Subcommand;
22 use crate::tool::{self, SourceType, Tool};
23 use crate::toolstate::ToolState;
24 use crate::util::{self, add_link_lib_path, dylib_path, dylib_path_var, output, t};
25 use crate::{envify, CLang, DocTests, GitRepo, Mode};
27 const ADB_TEST_DIR: &str = "/data/local/tmp/work";
29 /// The two modes of the test runner; tests or benchmarks.
30 #[derive(Debug, PartialEq, Eq, Hash, Copy, Clone, PartialOrd, Ord)]
34 /// Run `cargo bench`.
38 impl From<Kind> for TestKind {
39 fn from(kind: Kind) -> Self {
41 Kind::Test => TestKind::Test,
42 Kind::Bench => TestKind::Bench,
43 _ => panic!("unexpected kind in crate: {:?}", kind),
49 // Return the cargo subcommand for this test kind
50 fn subcommand(self) -> &'static str {
52 TestKind::Test => "test",
53 TestKind::Bench => "bench",
58 impl fmt::Display for TestKind {
59 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
60 f.write_str(match *self {
61 TestKind::Test => "Testing",
62 TestKind::Bench => "Benchmarking",
67 fn try_run(builder: &Builder<'_>, cmd: &mut Command) -> bool {
68 if !builder.fail_fast {
69 if !builder.try_run(cmd) {
70 let mut failures = builder.delayed_failures.borrow_mut();
71 failures.push(format!("{:?}", cmd));
80 fn try_run_quiet(builder: &Builder<'_>, cmd: &mut Command) -> bool {
81 if !builder.fail_fast {
82 if !builder.try_run_quiet(cmd) {
83 let mut failures = builder.delayed_failures.borrow_mut();
84 failures.push(format!("{:?}", cmd));
88 builder.run_quiet(cmd);
93 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
94 pub struct Linkcheck {
95 host: TargetSelection,
98 impl Step for Linkcheck {
100 const ONLY_HOSTS: bool = true;
101 const DEFAULT: bool = true;
103 /// Runs the `linkchecker` tool as compiled in `stage` by the `host` compiler.
105 /// This tool in `src/tools` will verify the validity of all our links in the
106 /// documentation to ensure we don't have a bunch of dead ones.
107 fn run(self, builder: &Builder<'_>) {
108 let host = self.host;
109 let hosts = &builder.hosts;
110 let targets = &builder.targets;
112 // if we have different hosts and targets, some things may be built for
113 // the host (e.g. rustc) and others for the target (e.g. std). The
114 // documentation built for each will contain broken links to
115 // docs built for the other platform (e.g. rustc linking to cargo)
116 if (hosts != targets) && !hosts.is_empty() && !targets.is_empty() {
118 "Linkcheck currently does not support builds with different hosts and targets.
119 You can skip linkcheck with --exclude src/tools/linkchecker"
123 builder.info(&format!("Linkcheck ({})", host));
125 // Test the linkchecker itself.
126 let bootstrap_host = builder.config.build;
127 let compiler = builder.compiler(0, bootstrap_host);
128 let cargo = tool::prepare_tool_cargo(
134 "src/tools/linkchecker",
138 try_run(builder, &mut cargo.into());
140 // Build all the default documentation.
141 builder.default_doc(&[]);
143 // Run the linkchecker.
144 let _time = util::timeit(&builder);
147 builder.tool_cmd(Tool::Linkchecker).arg(builder.out.join(host.triple).join("doc")),
151 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
152 let builder = run.builder;
153 let run = run.path("src/tools/linkchecker");
154 run.default_condition(builder.config.docs)
157 fn make_run(run: RunConfig<'_>) {
158 run.builder.ensure(Linkcheck { host: run.target });
162 fn check_if_tidy_is_installed() -> bool {
165 .stdout(Stdio::null())
167 .map_or(false, |status| status.success())
170 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
171 pub struct HtmlCheck {
172 target: TargetSelection,
175 impl Step for HtmlCheck {
177 const DEFAULT: bool = true;
178 const ONLY_HOSTS: bool = true;
180 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
181 let run = run.path("src/tools/html-checker");
182 run.lazy_default_condition(Box::new(check_if_tidy_is_installed))
185 fn make_run(run: RunConfig<'_>) {
186 run.builder.ensure(HtmlCheck { target: run.target });
189 fn run(self, builder: &Builder<'_>) {
190 if !check_if_tidy_is_installed() {
191 eprintln!("not running HTML-check tool because `tidy` is missing");
193 "Note that `tidy` is not the in-tree `src/tools/tidy` but needs to be installed"
195 panic!("Cannot run html-check tests");
197 // Ensure that a few different kinds of documentation are available.
198 builder.default_doc(&[]);
199 builder.ensure(crate::doc::Rustc { target: self.target, stage: builder.top_stage });
201 try_run(builder, builder.tool_cmd(Tool::HtmlChecker).arg(builder.doc_out(self.target)));
205 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
206 pub struct Cargotest {
208 host: TargetSelection,
211 impl Step for Cargotest {
213 const ONLY_HOSTS: bool = true;
215 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
216 run.path("src/tools/cargotest")
219 fn make_run(run: RunConfig<'_>) {
220 run.builder.ensure(Cargotest { stage: run.builder.top_stage, host: run.target });
223 /// Runs the `cargotest` tool as compiled in `stage` by the `host` compiler.
225 /// This tool in `src/tools` will check out a few Rust projects and run `cargo
226 /// test` to ensure that we don't regress the test suites there.
227 fn run(self, builder: &Builder<'_>) {
228 let compiler = builder.compiler(self.stage, self.host);
229 builder.ensure(compile::Rustc::new(compiler, compiler.host));
230 let cargo = builder.ensure(tool::Cargo { compiler, target: compiler.host });
232 // Note that this is a short, cryptic, and not scoped directory name. This
233 // is currently to minimize the length of path on Windows where we otherwise
234 // quickly run into path name limit constraints.
235 let out_dir = builder.out.join("ct");
236 t!(fs::create_dir_all(&out_dir));
238 let _time = util::timeit(&builder);
239 let mut cmd = builder.tool_cmd(Tool::CargoTest);
244 .args(builder.config.cmd.test_args())
245 .env("RUSTC", builder.rustc(compiler))
246 .env("RUSTDOC", builder.rustdoc(compiler)),
251 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
254 host: TargetSelection,
257 impl Step for Cargo {
259 const ONLY_HOSTS: bool = true;
261 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
262 run.path("src/tools/cargo")
265 fn make_run(run: RunConfig<'_>) {
266 run.builder.ensure(Cargo { stage: run.builder.top_stage, host: run.target });
269 /// Runs `cargo test` for `cargo` packaged with Rust.
270 fn run(self, builder: &Builder<'_>) {
271 let compiler = builder.compiler(self.stage, self.host);
273 builder.ensure(tool::Cargo { compiler, target: self.host });
274 let mut cargo = tool::prepare_tool_cargo(
281 SourceType::Submodule,
285 if !builder.fail_fast {
286 cargo.arg("--no-fail-fast");
288 cargo.arg("--").args(builder.config.cmd.test_args());
290 // Don't run cross-compile tests, we may not have cross-compiled libstd libs
292 cargo.env("CFG_DISABLE_CROSS_TESTS", "1");
293 // Forcibly disable tests using nightly features since any changes to
294 // those features won't be able to land.
295 cargo.env("CARGO_TEST_DISABLE_NIGHTLY", "1");
297 cargo.env("PATH", &path_for_cargo(builder, compiler));
299 try_run(builder, &mut cargo.into());
303 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
304 pub struct RustAnalyzer {
306 host: TargetSelection,
309 impl Step for RustAnalyzer {
311 const ONLY_HOSTS: bool = true;
312 const DEFAULT: bool = true;
314 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
315 run.path("src/tools/rust-analyzer")
318 fn make_run(run: RunConfig<'_>) {
319 run.builder.ensure(Self { stage: run.builder.top_stage, host: run.target });
322 /// Runs `cargo test` for rust-analyzer
323 fn run(self, builder: &Builder<'_>) {
324 let stage = self.stage;
325 let host = self.host;
326 let compiler = builder.compiler(stage, host);
328 builder.ensure(tool::RustAnalyzer { compiler, target: self.host }).expect("in-tree tool");
330 let workspace_path = "src/tools/rust-analyzer";
331 // until the whole RA test suite runs on `i686`, we only run
332 // `proc-macro-srv` tests
333 let crate_path = "src/tools/rust-analyzer/crates/proc-macro-srv";
334 let mut cargo = tool::prepare_tool_cargo(
342 &["sysroot-abi".to_owned()],
345 let dir = builder.src.join(workspace_path);
346 // needed by rust-analyzer to find its own text fixtures, cf.
347 // https://github.com/rust-analyzer/expect-test/issues/33
348 cargo.env("CARGO_WORKSPACE_DIR", &dir);
350 // RA's test suite tries to write to the source directory, that can't
352 cargo.env("SKIP_SLOW_TESTS", "1");
354 cargo.add_rustc_lib_path(builder, compiler);
355 cargo.arg("--").args(builder.config.cmd.test_args());
357 builder.run(&mut cargo.into());
361 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
364 host: TargetSelection,
367 impl Step for Rustfmt {
369 const ONLY_HOSTS: bool = true;
371 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
372 run.path("src/tools/rustfmt")
375 fn make_run(run: RunConfig<'_>) {
376 run.builder.ensure(Rustfmt { stage: run.builder.top_stage, host: run.target });
379 /// Runs `cargo test` for rustfmt.
380 fn run(self, builder: &Builder<'_>) {
381 let stage = self.stage;
382 let host = self.host;
383 let compiler = builder.compiler(stage, host);
386 .ensure(tool::Rustfmt { compiler, target: self.host, extra_features: Vec::new() })
387 .expect("in-tree tool");
389 let mut cargo = tool::prepare_tool_cargo(
400 let dir = testdir(builder, compiler.host);
401 t!(fs::create_dir_all(&dir));
402 cargo.env("RUSTFMT_TEST_DIR", dir);
404 cargo.add_rustc_lib_path(builder, compiler);
406 builder.run(&mut cargo.into());
410 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
411 pub struct RustDemangler {
413 host: TargetSelection,
416 impl Step for RustDemangler {
418 const ONLY_HOSTS: bool = true;
420 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
421 run.path("src/tools/rust-demangler")
424 fn make_run(run: RunConfig<'_>) {
425 run.builder.ensure(RustDemangler { stage: run.builder.top_stage, host: run.target });
428 /// Runs `cargo test` for rust-demangler.
429 fn run(self, builder: &Builder<'_>) {
430 let stage = self.stage;
431 let host = self.host;
432 let compiler = builder.compiler(stage, host);
434 let rust_demangler = builder
435 .ensure(tool::RustDemangler { compiler, target: self.host, extra_features: Vec::new() })
436 .expect("in-tree tool");
437 let mut cargo = tool::prepare_tool_cargo(
443 "src/tools/rust-demangler",
448 let dir = testdir(builder, compiler.host);
449 t!(fs::create_dir_all(&dir));
451 cargo.env("RUST_DEMANGLER_DRIVER_PATH", rust_demangler);
453 cargo.arg("--").args(builder.config.cmd.test_args());
455 cargo.add_rustc_lib_path(builder, compiler);
457 builder.run(&mut cargo.into());
461 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
464 host: TargetSelection,
465 target: TargetSelection,
469 /// Run `cargo miri setup` for the given target, return where the Miri sysroot was put.
470 pub fn build_miri_sysroot(
471 builder: &Builder<'_>,
474 target: TargetSelection,
476 let miri_sysroot = builder.out.join(compiler.host.triple).join("miri-sysrot");
477 let mut cargo = tool::prepare_tool_cargo(
483 "src/tools/miri/cargo-miri",
487 cargo.add_rustc_lib_path(builder, compiler);
488 cargo.arg("--").arg("miri").arg("setup");
489 cargo.arg("--target").arg(target.rustc_target_arg());
491 // Tell `cargo miri setup` where to find the sources.
492 cargo.env("MIRI_LIB_SRC", builder.src.join("library"));
493 // Tell it where to find Miri.
494 cargo.env("MIRI", &miri);
495 // Tell it where to put the sysroot.
496 cargo.env("MIRI_SYSROOT", &miri_sysroot);
498 cargo.env("RUST_BACKTRACE", "1");
500 let mut cargo = Command::from(cargo);
501 builder.run(&mut cargo);
503 // # Determine where Miri put its sysroot.
504 // To this end, we run `cargo miri setup --print-sysroot` and capture the output.
505 // (We do this separately from the above so that when the setup actually
506 // happens we get some output.)
507 // We re-use the `cargo` from above.
508 cargo.arg("--print-sysroot");
510 // FIXME: Is there a way in which we can re-use the usual `run` helpers?
511 if builder.config.dry_run() {
514 builder.verbose(&format!("running: {:?}", cargo));
516 cargo.output().expect("We already ran `cargo miri setup` before and that worked");
517 assert!(out.status.success(), "`cargo miri setup` returned with non-0 exit code");
518 // Output is "<sysroot>\n".
519 let stdout = String::from_utf8(out.stdout)
520 .expect("`cargo miri setup` stdout is not valid UTF-8");
521 let sysroot = stdout.trim_end();
522 builder.verbose(&format!("`cargo miri setup --print-sysroot` said: {:?}", sysroot));
530 const ONLY_HOSTS: bool = false;
532 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
533 run.path("src/tools/miri")
536 fn make_run(run: RunConfig<'_>) {
537 run.builder.ensure(Miri {
538 stage: run.builder.top_stage,
539 host: run.build_triple(),
544 /// Runs `cargo test` for miri.
545 fn run(self, builder: &Builder<'_>) {
546 let stage = self.stage;
547 let host = self.host;
548 let target = self.target;
549 let compiler = builder.compiler(stage, host);
550 // We need the stdlib for the *next* stage, as it was built with this compiler that also built Miri.
551 // Except if we are at stage 2, the bootstrap loop is complete and we can stick with our current stage.
552 let compiler_std = builder.compiler(if stage < 2 { stage + 1 } else { stage }, host);
555 .ensure(tool::Miri { compiler, target: self.host, extra_features: Vec::new() })
556 .expect("in-tree tool");
557 let _cargo_miri = builder
558 .ensure(tool::CargoMiri { compiler, target: self.host, extra_features: Vec::new() })
559 .expect("in-tree tool");
560 // The stdlib we need might be at a different stage. And just asking for the
561 // sysroot does not seem to populate it, so we do that first.
562 builder.ensure(compile::Std::new(compiler_std, host));
563 let sysroot = builder.sysroot(compiler_std);
564 // We also need a Miri sysroot.
565 let miri_sysroot = Miri::build_miri_sysroot(builder, compiler, &miri, target);
567 // # Run `cargo test`.
568 let mut cargo = tool::prepare_tool_cargo(
578 cargo.add_rustc_lib_path(builder, compiler);
580 // miri tests need to know about the stage sysroot
581 cargo.env("MIRI_SYSROOT", &miri_sysroot);
582 cargo.env("MIRI_HOST_SYSROOT", sysroot);
583 cargo.env("MIRI", &miri);
585 if builder.config.cmd.bless() {
586 cargo.env("MIRI_BLESS", "Gesundheit");
590 cargo.env("MIRI_TEST_TARGET", target.rustc_target_arg());
591 // Forward test filters.
592 cargo.arg("--").args(builder.config.cmd.test_args());
594 let mut cargo = Command::from(cargo);
595 builder.run(&mut cargo);
597 // # Run `cargo miri test`.
598 // This is just a smoke test (Miri's own CI invokes this in a bunch of different ways and ensures
599 // that we get the desired output), but that is sufficient to make sure that the libtest harness
600 // itself executes properly under Miri.
601 let mut cargo = tool::prepare_tool_cargo(
607 "src/tools/miri/cargo-miri",
608 SourceType::Submodule,
611 cargo.add_rustc_lib_path(builder, compiler);
612 cargo.arg("--").arg("miri").arg("test");
614 .arg("--manifest-path")
615 .arg(builder.src.join("src/tools/miri/test-cargo-miri/Cargo.toml"));
616 cargo.arg("--target").arg(target.rustc_target_arg());
617 cargo.arg("--tests"); // don't run doctests, they are too confused by the staging
618 cargo.arg("--").args(builder.config.cmd.test_args());
620 // Tell `cargo miri` where to find things.
621 cargo.env("MIRI_SYSROOT", &miri_sysroot);
622 cargo.env("MIRI_HOST_SYSROOT", sysroot);
623 cargo.env("MIRI", &miri);
625 cargo.env("RUST_BACKTRACE", "1");
627 let mut cargo = Command::from(cargo);
628 builder.run(&mut cargo);
632 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
633 pub struct CompiletestTest {
634 host: TargetSelection,
637 impl Step for CompiletestTest {
640 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
641 run.path("src/tools/compiletest")
644 fn make_run(run: RunConfig<'_>) {
645 run.builder.ensure(CompiletestTest { host: run.target });
648 /// Runs `cargo test` for compiletest.
649 fn run(self, builder: &Builder<'_>) {
650 let host = self.host;
651 let compiler = builder.compiler(0, host);
653 // We need `ToolStd` for the locally-built sysroot because
654 // compiletest uses unstable features of the `test` crate.
655 builder.ensure(compile::Std::new(compiler, host));
656 let cargo = tool::prepare_tool_cargo(
662 "src/tools/compiletest",
667 try_run(builder, &mut cargo.into());
671 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
674 host: TargetSelection,
677 impl Step for Clippy {
679 const ONLY_HOSTS: bool = true;
680 const DEFAULT: bool = false;
682 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
683 run.path("src/tools/clippy")
686 fn make_run(run: RunConfig<'_>) {
687 run.builder.ensure(Clippy { stage: run.builder.top_stage, host: run.target });
690 /// Runs `cargo test` for clippy.
691 fn run(self, builder: &Builder<'_>) {
692 let stage = self.stage;
693 let host = self.host;
694 let compiler = builder.compiler(stage, host);
697 .ensure(tool::Clippy { compiler, target: self.host, extra_features: Vec::new() })
698 .expect("in-tree tool");
699 let mut cargo = tool::prepare_tool_cargo(
710 cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
711 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
712 let host_libs = builder.stage_out(compiler, Mode::ToolRustc).join(builder.cargo_dir());
713 cargo.env("HOST_LIBS", host_libs);
715 cargo.arg("--").args(builder.config.cmd.test_args());
717 cargo.add_rustc_lib_path(builder, compiler);
719 if builder.try_run(&mut cargo.into()) {
720 // The tests succeeded; nothing to do.
724 if !builder.config.cmd.bless() {
725 crate::detail_exit(1);
728 let mut cargo = builder.cargo(compiler, Mode::ToolRustc, SourceType::InTree, host, "run");
729 cargo.arg("-p").arg("clippy_dev");
730 // clippy_dev gets confused if it can't find `clippy/Cargo.toml`
731 cargo.current_dir(&builder.src.join("src").join("tools").join("clippy"));
732 if builder.config.rust_optimize {
733 cargo.env("PROFILE", "release");
735 cargo.env("PROFILE", "debug");
739 builder.run(&mut cargo.into());
743 fn path_for_cargo(builder: &Builder<'_>, compiler: Compiler) -> OsString {
744 // Configure PATH to find the right rustc. NB. we have to use PATH
745 // and not RUSTC because the Cargo test suite has tests that will
746 // fail if rustc is not spelled `rustc`.
747 let path = builder.sysroot(compiler).join("bin");
748 let old_path = env::var_os("PATH").unwrap_or_default();
749 env::join_paths(iter::once(path).chain(env::split_paths(&old_path))).expect("")
752 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
753 pub struct RustdocTheme {
754 pub compiler: Compiler,
757 impl Step for RustdocTheme {
759 const DEFAULT: bool = true;
760 const ONLY_HOSTS: bool = true;
762 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
763 run.path("src/tools/rustdoc-themes")
766 fn make_run(run: RunConfig<'_>) {
767 let compiler = run.builder.compiler(run.builder.top_stage, run.target);
769 run.builder.ensure(RustdocTheme { compiler });
772 fn run(self, builder: &Builder<'_>) {
773 let rustdoc = builder.bootstrap_out.join("rustdoc");
774 let mut cmd = builder.tool_cmd(Tool::RustdocTheme);
775 cmd.arg(rustdoc.to_str().unwrap())
776 .arg(builder.src.join("src/librustdoc/html/static/css/themes").to_str().unwrap())
777 .env("RUSTC_STAGE", self.compiler.stage.to_string())
778 .env("RUSTC_SYSROOT", builder.sysroot(self.compiler))
779 .env("RUSTDOC_LIBDIR", builder.sysroot_libdir(self.compiler, self.compiler.host))
780 .env("CFG_RELEASE_CHANNEL", &builder.config.channel)
781 .env("RUSTDOC_REAL", builder.rustdoc(self.compiler))
782 .env("RUSTC_BOOTSTRAP", "1");
783 if let Some(linker) = builder.linker(self.compiler.host) {
784 cmd.env("RUSTDOC_LINKER", linker);
786 if builder.is_fuse_ld_lld(self.compiler.host) {
788 "RUSTDOC_LLD_NO_THREADS",
789 util::lld_flag_no_threads(self.compiler.host.contains("windows")),
792 try_run(builder, &mut cmd);
796 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
797 pub struct RustdocJSStd {
798 pub target: TargetSelection,
801 impl Step for RustdocJSStd {
803 const DEFAULT: bool = true;
804 const ONLY_HOSTS: bool = true;
806 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
807 run.suite_path("src/test/rustdoc-js-std")
810 fn make_run(run: RunConfig<'_>) {
811 run.builder.ensure(RustdocJSStd { target: run.target });
814 fn run(self, builder: &Builder<'_>) {
815 if let Some(ref nodejs) = builder.config.nodejs {
816 let mut command = Command::new(nodejs);
818 .arg(builder.src.join("src/tools/rustdoc-js/tester.js"))
821 .arg("--resource-suffix")
822 .arg(&builder.version)
824 .arg(builder.doc_out(self.target))
825 .arg("--test-folder")
826 .arg(builder.src.join("src/test/rustdoc-js-std"));
827 for path in &builder.paths {
829 util::is_valid_test_suite_arg(path, "src/test/rustdoc-js-std", builder)
831 if !p.ends_with(".js") {
832 eprintln!("A non-js file was given: `{}`", path.display());
833 panic!("Cannot run rustdoc-js-std tests");
835 command.arg("--test-file").arg(path);
838 builder.ensure(crate::doc::Std {
840 stage: builder.top_stage,
841 format: DocumentationFormat::HTML,
843 builder.run(&mut command);
845 builder.info("No nodejs found, skipping \"src/test/rustdoc-js-std\" tests");
850 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
851 pub struct RustdocJSNotStd {
852 pub target: TargetSelection,
853 pub compiler: Compiler,
856 impl Step for RustdocJSNotStd {
858 const DEFAULT: bool = true;
859 const ONLY_HOSTS: bool = true;
861 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
862 run.suite_path("src/test/rustdoc-js")
865 fn make_run(run: RunConfig<'_>) {
866 let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
867 run.builder.ensure(RustdocJSNotStd { target: run.target, compiler });
870 fn run(self, builder: &Builder<'_>) {
871 if builder.config.nodejs.is_some() {
872 builder.ensure(Compiletest {
873 compiler: self.compiler,
877 path: "src/test/rustdoc-js",
881 builder.info("No nodejs found, skipping \"src/test/rustdoc-js\" tests");
886 fn get_browser_ui_test_version_inner(npm: &Path, global: bool) -> Option<String> {
887 let mut command = Command::new(&npm);
888 command.arg("list").arg("--parseable").arg("--long").arg("--depth=0");
890 command.arg("--global");
894 .map(|output| String::from_utf8_lossy(&output.stdout).into_owned())
895 .unwrap_or(String::new());
898 .find_map(|l| l.split(':').nth(1)?.strip_prefix("browser-ui-test@"))
899 .map(|v| v.to_owned())
902 fn get_browser_ui_test_version(npm: &Path) -> Option<String> {
903 get_browser_ui_test_version_inner(npm, false)
904 .or_else(|| get_browser_ui_test_version_inner(npm, true))
907 fn compare_browser_ui_test_version(installed_version: &str, src: &Path) {
908 match fs::read_to_string(
909 src.join("src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version"),
912 if v.trim() != installed_version {
914 "⚠️ Installed version of browser-ui-test (`{}`) is different than the \
915 one used in the CI (`{}`)",
919 "You can install this version using `npm update browser-ui-test` or by using \
920 `npm install browser-ui-test@{}`",
925 Err(e) => eprintln!("Couldn't find the CI browser-ui-test version: {:?}", e),
929 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
930 pub struct RustdocGUI {
931 pub target: TargetSelection,
932 pub compiler: Compiler,
935 impl Step for RustdocGUI {
937 const DEFAULT: bool = true;
938 const ONLY_HOSTS: bool = true;
940 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
941 let builder = run.builder;
942 let run = run.suite_path("src/test/rustdoc-gui");
943 run.lazy_default_condition(Box::new(move || {
944 builder.config.nodejs.is_some()
949 .map(|p| get_browser_ui_test_version(p).is_some())
954 fn make_run(run: RunConfig<'_>) {
955 let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
956 run.builder.ensure(RustdocGUI { target: run.target, compiler });
959 fn run(self, builder: &Builder<'_>) {
960 let nodejs = builder.config.nodejs.as_ref().expect("nodejs isn't available");
961 let npm = builder.config.npm.as_ref().expect("npm isn't available");
963 builder.ensure(compile::Std::new(self.compiler, self.target));
965 // The goal here is to check if the necessary packages are installed, and if not, we
967 match get_browser_ui_test_version(&npm) {
969 // We also check the version currently used in CI and emit a warning if it's not the
971 compare_browser_ui_test_version(&version, &builder.build.src);
975 "error: rustdoc-gui test suite cannot be run because npm `browser-ui-test` \
976 dependency is missing",
979 "If you want to install the `{0}` dependency, run `npm install {0}`",
982 panic!("Cannot run rustdoc-gui tests");
986 let out_dir = builder.test_out(self.target).join("rustdoc-gui");
988 // We remove existing folder to be sure there won't be artifacts remaining.
989 builder.clear_if_dirty(&out_dir, &builder.rustdoc(self.compiler));
991 let src_path = builder.build.src.join("src/test/rustdoc-gui/src");
992 // We generate docs for the libraries present in the rustdoc-gui's src folder.
993 for entry in src_path.read_dir().expect("read_dir call failed") {
994 if let Ok(entry) = entry {
995 let path = entry.path();
1001 let mut cargo = Command::new(&builder.initial_cargo);
1004 .arg("--target-dir")
1006 .env("RUSTC_BOOTSTRAP", "1")
1007 .env("RUSTDOC", builder.rustdoc(self.compiler))
1008 .env("RUSTC", builder.rustc(self.compiler))
1010 // FIXME: implement a `// compile-flags` command or similar
1011 // instead of hard-coding this test
1012 if entry.file_name() == "link_to_definition" {
1013 cargo.env("RUSTDOCFLAGS", "-Zunstable-options --generate-link-to-definition");
1014 } else if entry.file_name() == "scrape_examples" {
1015 cargo.arg("-Zrustdoc-scrape-examples=examples");
1017 builder.run(&mut cargo);
1021 // We now run GUI tests.
1022 let mut command = Command::new(&nodejs);
1024 .arg(builder.build.src.join("src/tools/rustdoc-gui/tester.js"))
1026 .arg(&builder.jobs().to_string())
1027 .arg("--doc-folder")
1028 .arg(out_dir.join("doc"))
1029 .arg("--tests-folder")
1030 .arg(builder.build.src.join("src/test/rustdoc-gui"));
1031 for path in &builder.paths {
1032 if let Some(p) = util::is_valid_test_suite_arg(path, "src/test/rustdoc-gui", builder) {
1033 if !p.ends_with(".goml") {
1034 eprintln!("A non-goml file was given: `{}`", path.display());
1035 panic!("Cannot run rustdoc-gui tests");
1037 if let Some(name) = path.file_name().and_then(|f| f.to_str()) {
1038 command.arg("--file").arg(name);
1042 for test_arg in builder.config.cmd.test_args() {
1043 command.arg(test_arg);
1045 builder.run(&mut command);
1049 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1052 impl Step for Tidy {
1054 const DEFAULT: bool = true;
1055 const ONLY_HOSTS: bool = true;
1057 /// Runs the `tidy` tool.
1059 /// This tool in `src/tools` checks up on various bits and pieces of style and
1060 /// otherwise just implements a few lint-like checks that are specific to the
1061 /// compiler itself.
1063 /// Once tidy passes, this step also runs `fmt --check` if tests are being run
1064 /// for the `dev` or `nightly` channels.
1065 fn run(self, builder: &Builder<'_>) {
1066 let mut cmd = builder.tool_cmd(Tool::Tidy);
1067 cmd.arg(&builder.src);
1068 cmd.arg(&builder.initial_cargo);
1069 cmd.arg(&builder.out);
1070 cmd.arg(builder.jobs().to_string());
1071 if builder.is_verbose() {
1072 cmd.arg("--verbose");
1074 if builder.config.cmd.bless() {
1078 builder.info("tidy check");
1079 try_run(builder, &mut cmd);
1081 if builder.config.channel == "dev" || builder.config.channel == "nightly" {
1082 builder.info("fmt check");
1083 if builder.initial_rustfmt().is_none() {
1084 let inferred_rustfmt_dir = builder.config.initial_rustc.parent().unwrap();
1087 error: no `rustfmt` binary found in {PATH}
1088 info: `rust.channel` is currently set to \"{CHAN}\"
1089 help: if you are testing a beta branch, set `rust.channel` to \"beta\" in the `config.toml` file
1090 help: to skip test's attempt to check tidiness, pass `--exclude src/tools/tidy` to `x.py test`",
1091 PATH = inferred_rustfmt_dir.display(),
1092 CHAN = builder.config.channel,
1094 crate::detail_exit(1);
1096 crate::format::format(&builder, !builder.config.cmd.bless(), &[]);
1100 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1101 run.path("src/tools/tidy")
1104 fn make_run(run: RunConfig<'_>) {
1105 run.builder.ensure(Tidy);
1109 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1110 pub struct ExpandYamlAnchors;
1112 impl Step for ExpandYamlAnchors {
1114 const ONLY_HOSTS: bool = true;
1116 /// Ensure the `generate-ci-config` tool was run locally.
1118 /// The tool in `src/tools` reads the CI definition in `src/ci/builders.yml` and generates the
1119 /// appropriate configuration for all our CI providers. This step ensures the tool was called
1120 /// by the user before committing CI changes.
1121 fn run(self, builder: &Builder<'_>) {
1122 builder.info("Ensuring the YAML anchors in the GitHub Actions config were expanded");
1125 &mut builder.tool_cmd(Tool::ExpandYamlAnchors).arg("check").arg(&builder.src),
1129 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1130 run.path("src/tools/expand-yaml-anchors")
1133 fn make_run(run: RunConfig<'_>) {
1134 run.builder.ensure(ExpandYamlAnchors);
1138 fn testdir(builder: &Builder<'_>, host: TargetSelection) -> PathBuf {
1139 builder.out.join(host.triple).join("test")
1142 macro_rules! default_test {
1143 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
1144 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: false });
1148 macro_rules! default_test_with_compare_mode {
1149 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr,
1150 compare_mode: $compare_mode:expr }) => {
1151 test_with_compare_mode!($name {
1157 compare_mode: $compare_mode
1162 macro_rules! host_test {
1163 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
1164 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: true });
1169 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
1170 host: $host:expr }) => {
1171 test_definitions!($name {
1182 macro_rules! test_with_compare_mode {
1183 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
1184 host: $host:expr, compare_mode: $compare_mode:expr }) => {
1185 test_definitions!($name {
1191 compare_mode: Some($compare_mode)
1196 macro_rules! test_definitions {
1201 default: $default:expr,
1203 compare_mode: $compare_mode:expr
1205 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1207 pub compiler: Compiler,
1208 pub target: TargetSelection,
1211 impl Step for $name {
1213 const DEFAULT: bool = $default;
1214 const ONLY_HOSTS: bool = $host;
1216 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1217 run.suite_path($path)
1220 fn make_run(run: RunConfig<'_>) {
1221 let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
1223 run.builder.ensure($name { compiler, target: run.target });
1226 fn run(self, builder: &Builder<'_>) {
1227 builder.ensure(Compiletest {
1228 compiler: self.compiler,
1229 target: self.target,
1233 compare_mode: $compare_mode,
1240 default_test!(Ui { path: "src/test/ui", mode: "ui", suite: "ui" });
1242 default_test!(RunPassValgrind {
1243 path: "src/test/run-pass-valgrind",
1244 mode: "run-pass-valgrind",
1245 suite: "run-pass-valgrind"
1248 default_test!(MirOpt { path: "src/test/mir-opt", mode: "mir-opt", suite: "mir-opt" });
1250 default_test!(Codegen { path: "src/test/codegen", mode: "codegen", suite: "codegen" });
1252 default_test!(CodegenUnits {
1253 path: "src/test/codegen-units",
1254 mode: "codegen-units",
1255 suite: "codegen-units"
1258 default_test!(Incremental {
1259 path: "src/test/incremental",
1260 mode: "incremental",
1261 suite: "incremental"
1264 default_test_with_compare_mode!(Debuginfo {
1265 path: "src/test/debuginfo",
1268 compare_mode: "split-dwarf"
1271 host_test!(UiFullDeps { path: "src/test/ui-fulldeps", mode: "ui", suite: "ui-fulldeps" });
1273 host_test!(Rustdoc { path: "src/test/rustdoc", mode: "rustdoc", suite: "rustdoc" });
1274 host_test!(RustdocUi { path: "src/test/rustdoc-ui", mode: "ui", suite: "rustdoc-ui" });
1276 host_test!(RustdocJson {
1277 path: "src/test/rustdoc-json",
1278 mode: "rustdoc-json",
1279 suite: "rustdoc-json"
1282 host_test!(Pretty { path: "src/test/pretty", mode: "pretty", suite: "pretty" });
1284 default_test!(RunMake { path: "src/test/run-make", mode: "run-make", suite: "run-make" });
1286 host_test!(RunMakeFullDeps {
1287 path: "src/test/run-make-fulldeps",
1289 suite: "run-make-fulldeps"
1292 default_test!(Assembly { path: "src/test/assembly", mode: "assembly", suite: "assembly" });
1294 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1295 struct Compiletest {
1297 target: TargetSelection,
1299 suite: &'static str,
1301 compare_mode: Option<&'static str>,
1304 impl Step for Compiletest {
1307 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1311 /// Executes the `compiletest` tool to run a suite of tests.
1313 /// Compiles all tests with `compiler` for `target` with the specified
1314 /// compiletest `mode` and `suite` arguments. For example `mode` can be
1315 /// "run-pass" or `suite` can be something like `debuginfo`.
1316 fn run(self, builder: &Builder<'_>) {
1317 if builder.top_stage == 0 && env::var("COMPILETEST_FORCE_STAGE0").is_err() {
1319 error: `--stage 0` runs compiletest on the beta compiler, not your local changes, and will almost always cause tests to fail
1320 help: to test the compiler, use `--stage 1` instead
1321 help: to test the standard library, use `--stage 0 library/std` instead
1322 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`."
1324 crate::detail_exit(1);
1327 let compiler = self.compiler;
1328 let target = self.target;
1329 let mode = self.mode;
1330 let suite = self.suite;
1332 // Path for test suite
1333 let suite_path = self.path;
1335 // Skip codegen tests if they aren't enabled in configuration.
1336 if !builder.config.codegen_tests && suite == "codegen" {
1340 if suite == "debuginfo" {
1342 .ensure(dist::DebuggerScripts { sysroot: builder.sysroot(compiler), host: target });
1345 if suite.ends_with("fulldeps") {
1346 builder.ensure(compile::Rustc::new(compiler, target));
1349 builder.ensure(compile::Std::new(compiler, target));
1350 // ensure that `libproc_macro` is available on the host.
1351 builder.ensure(compile::Std::new(compiler, compiler.host));
1353 // Also provide `rust_test_helpers` for the host.
1354 builder.ensure(native::TestHelpers { target: compiler.host });
1356 // As well as the target, except for plain wasm32, which can't build it
1357 if !target.contains("wasm") || target.contains("emscripten") {
1358 builder.ensure(native::TestHelpers { target });
1361 builder.ensure(RemoteCopyLibs { compiler, target });
1363 let mut cmd = builder.tool_cmd(Tool::Compiletest);
1365 // compiletest currently has... a lot of arguments, so let's just pass all
1368 cmd.arg("--compile-lib-path").arg(builder.rustc_libdir(compiler));
1369 cmd.arg("--run-lib-path").arg(builder.sysroot_libdir(compiler, target));
1370 cmd.arg("--rustc-path").arg(builder.rustc(compiler));
1372 let is_rustdoc = suite.ends_with("rustdoc-ui") || suite.ends_with("rustdoc-js");
1374 // Avoid depending on rustdoc when we don't need it.
1375 if mode == "rustdoc"
1376 || mode == "run-make"
1377 || (mode == "ui" && is_rustdoc)
1378 || mode == "js-doc-test"
1379 || mode == "rustdoc-json"
1381 cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler));
1384 if mode == "rustdoc-json" {
1385 // Use the beta compiler for jsondocck
1386 let json_compiler = compiler.with_stage(0);
1387 cmd.arg("--jsondocck-path")
1388 .arg(builder.ensure(tool::JsonDocCk { compiler: json_compiler, target }));
1389 cmd.arg("--jsondoclint-path")
1390 .arg(builder.ensure(tool::JsonDocLint { compiler: json_compiler, target }));
1393 if mode == "run-make" {
1394 let rust_demangler = builder
1395 .ensure(tool::RustDemangler {
1397 target: compiler.host,
1398 extra_features: Vec::new(),
1400 .expect("in-tree tool");
1401 cmd.arg("--rust-demangler-path").arg(rust_demangler);
1404 cmd.arg("--src-base").arg(builder.src.join("src/test").join(suite));
1405 cmd.arg("--build-base").arg(testdir(builder, compiler.host).join(suite));
1406 cmd.arg("--sysroot-base").arg(builder.sysroot(compiler));
1407 cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target));
1408 cmd.arg("--suite").arg(suite);
1409 cmd.arg("--mode").arg(mode);
1410 cmd.arg("--target").arg(target.rustc_target_arg());
1411 cmd.arg("--host").arg(&*compiler.host.triple);
1412 cmd.arg("--llvm-filecheck").arg(builder.llvm_filecheck(builder.config.build));
1414 if builder.config.cmd.bless() {
1418 if builder.config.cmd.force_rerun() {
1419 cmd.arg("--force-rerun");
1423 builder.config.cmd.compare_mode().or_else(|| {
1424 if builder.config.test_compare_mode { self.compare_mode } else { None }
1427 if let Some(ref pass) = builder.config.cmd.pass() {
1432 if let Some(ref run) = builder.config.cmd.run() {
1437 if let Some(ref nodejs) = builder.config.nodejs {
1438 cmd.arg("--nodejs").arg(nodejs);
1440 if let Some(ref npm) = builder.config.npm {
1441 cmd.arg("--npm").arg(npm);
1443 if builder.config.rust_optimize_tests {
1444 cmd.arg("--optimize-tests");
1446 let mut flags = if is_rustdoc { Vec::new() } else { vec!["-Crpath".to_string()] };
1447 flags.push(format!("-Cdebuginfo={}", builder.config.rust_debuginfo_level_tests));
1448 flags.extend(builder.config.cmd.rustc_args().iter().map(|s| s.to_string()));
1450 if let Some(linker) = builder.linker(target) {
1451 cmd.arg("--linker").arg(linker);
1454 let mut hostflags = flags.clone();
1455 hostflags.push(format!("-Lnative={}", builder.test_helpers_out(compiler.host).display()));
1456 hostflags.extend(builder.lld_flags(compiler.host));
1457 for flag in hostflags {
1458 cmd.arg("--host-rustcflags").arg(flag);
1461 let mut targetflags = flags;
1462 targetflags.push(format!("-Lnative={}", builder.test_helpers_out(target).display()));
1463 targetflags.extend(builder.lld_flags(target));
1464 for flag in targetflags {
1465 cmd.arg("--target-rustcflags").arg(flag);
1468 cmd.arg("--python").arg(builder.python());
1470 if let Some(ref gdb) = builder.config.gdb {
1471 cmd.arg("--gdb").arg(gdb);
1474 let run = |cmd: &mut Command| {
1475 cmd.output().map(|output| {
1476 String::from_utf8_lossy(&output.stdout)
1479 .unwrap_or_else(|| panic!("{:?} failed {:?}", cmd, output))
1483 let lldb_exe = "lldb";
1484 let lldb_version = Command::new(lldb_exe)
1487 .map(|output| String::from_utf8_lossy(&output.stdout).to_string())
1489 if let Some(ref vers) = lldb_version {
1490 cmd.arg("--lldb-version").arg(vers);
1491 let lldb_python_dir = run(Command::new(lldb_exe).arg("-P")).ok();
1492 if let Some(ref dir) = lldb_python_dir {
1493 cmd.arg("--lldb-python-dir").arg(dir);
1497 if util::forcing_clang_based_tests() {
1498 let clang_exe = builder.llvm_out(target).join("bin").join("clang");
1499 cmd.arg("--run-clang-based-tests-with").arg(clang_exe);
1502 for exclude in &builder.config.exclude {
1504 cmd.arg(&exclude.path);
1507 // Get paths from cmd args
1508 let paths = match &builder.config.cmd {
1509 Subcommand::Test { ref paths, .. } => &paths[..],
1513 // Get test-args by striping suite path
1514 let mut test_args: Vec<&str> = paths
1516 .filter_map(|p| util::is_valid_test_suite_arg(p, suite_path, builder))
1519 test_args.append(&mut builder.config.cmd.test_args());
1521 // On Windows, replace forward slashes in test-args by backslashes
1522 // so the correct filters are passed to libtest
1524 let test_args_win: Vec<String> =
1525 test_args.iter().map(|s| s.replace("/", "\\")).collect();
1526 cmd.args(&test_args_win);
1528 cmd.args(&test_args);
1531 if builder.is_verbose() {
1532 cmd.arg("--verbose");
1535 if !builder.config.verbose_tests {
1539 let mut llvm_components_passed = false;
1540 let mut copts_passed = false;
1541 if builder.config.llvm_enabled() {
1542 let llvm_config = builder.ensure(native::Llvm { target: builder.config.build });
1543 if !builder.config.dry_run() {
1544 let llvm_version = output(Command::new(&llvm_config).arg("--version"));
1545 let llvm_components = output(Command::new(&llvm_config).arg("--components"));
1546 // Remove trailing newline from llvm-config output.
1547 cmd.arg("--llvm-version")
1548 .arg(llvm_version.trim())
1549 .arg("--llvm-components")
1550 .arg(llvm_components.trim());
1551 llvm_components_passed = true;
1553 if !builder.is_rust_llvm(target) {
1554 cmd.arg("--system-llvm");
1557 // Tests that use compiler libraries may inherit the `-lLLVM` link
1558 // requirement, but the `-L` library path is not propagated across
1559 // separate compilations. We can add LLVM's library path to the
1560 // platform-specific environment variable as a workaround.
1561 if !builder.config.dry_run() && suite.ends_with("fulldeps") {
1562 let llvm_libdir = output(Command::new(&llvm_config).arg("--libdir"));
1563 add_link_lib_path(vec![llvm_libdir.trim().into()], &mut cmd);
1566 // Only pass correct values for these flags for the `run-make` suite as it
1567 // requires that a C++ compiler was configured which isn't always the case.
1568 if !builder.config.dry_run() && matches!(suite, "run-make" | "run-make-fulldeps") {
1569 // The llvm/bin directory contains many useful cross-platform
1570 // tools. Pass the path to run-make tests so they can use them.
1571 let llvm_bin_path = llvm_config
1573 .expect("Expected llvm-config to be contained in directory");
1574 assert!(llvm_bin_path.is_dir());
1575 cmd.arg("--llvm-bin-dir").arg(llvm_bin_path);
1577 // If LLD is available, add it to the PATH
1578 if builder.config.lld_enabled {
1579 let lld_install_root =
1580 builder.ensure(native::Lld { target: builder.config.build });
1582 let lld_bin_path = lld_install_root.join("bin");
1584 let old_path = env::var_os("PATH").unwrap_or_default();
1585 let new_path = env::join_paths(
1586 std::iter::once(lld_bin_path).chain(env::split_paths(&old_path)),
1588 .expect("Could not add LLD bin path to PATH");
1589 cmd.env("PATH", new_path);
1594 // Only pass correct values for these flags for the `run-make` suite as it
1595 // requires that a C++ compiler was configured which isn't always the case.
1596 if !builder.config.dry_run() && matches!(suite, "run-make" | "run-make-fulldeps") {
1598 .arg(builder.cc(target))
1600 .arg(builder.cxx(target).unwrap())
1602 .arg(builder.cflags(target, GitRepo::Rustc, CLang::C).join(" "))
1604 .arg(builder.cflags(target, GitRepo::Rustc, CLang::Cxx).join(" "));
1605 copts_passed = true;
1606 if let Some(ar) = builder.ar(target) {
1607 cmd.arg("--ar").arg(ar);
1611 if !llvm_components_passed {
1612 cmd.arg("--llvm-components").arg("");
1625 if builder.remote_tested(target) {
1626 cmd.arg("--remote-test-client").arg(builder.tool_exe(Tool::RemoteTestClient));
1629 // Running a C compiler on MSVC requires a few env vars to be set, to be
1630 // sure to set them here.
1632 // Note that if we encounter `PATH` we make sure to append to our own `PATH`
1633 // rather than stomp over it.
1634 if target.contains("msvc") {
1635 for &(ref k, ref v) in builder.cc[&target].env() {
1641 cmd.env("RUSTC_BOOTSTRAP", "1");
1642 // Override the rustc version used in symbol hashes to reduce the amount of normalization
1643 // needed when diffing test output.
1644 cmd.env("RUSTC_FORCE_RUSTC_VERSION", "compiletest");
1645 cmd.env("DOC_RUST_LANG_ORG_CHANNEL", builder.doc_rust_lang_org_channel());
1646 builder.add_rust_test_threads(&mut cmd);
1648 if builder.config.sanitizers_enabled(target) {
1649 cmd.env("RUSTC_SANITIZER_SUPPORT", "1");
1652 if builder.config.profiler_enabled(target) {
1653 cmd.env("RUSTC_PROFILER_SUPPORT", "1");
1656 cmd.env("RUST_TEST_TMPDIR", builder.tempdir());
1658 cmd.arg("--adb-path").arg("adb");
1659 cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
1660 if target.contains("android") {
1661 // Assume that cc for this target comes from the android sysroot
1662 cmd.arg("--android-cross-path")
1663 .arg(builder.cc(target).parent().unwrap().parent().unwrap());
1665 cmd.arg("--android-cross-path").arg("");
1668 if builder.config.cmd.rustfix_coverage() {
1669 cmd.arg("--rustfix-coverage");
1672 cmd.env("BOOTSTRAP_CARGO", &builder.initial_cargo);
1674 cmd.arg("--channel").arg(&builder.config.channel);
1676 if let Some(commit) = builder.config.download_rustc_commit() {
1677 cmd.env("FAKE_DOWNLOAD_RUSTC_PREFIX", format!("/rustc/{commit}"));
1680 builder.ci_env.force_coloring_in_ci(&mut cmd);
1682 builder.info(&format!(
1683 "Check compiletest suite={} mode={} ({} -> {})",
1684 suite, mode, &compiler.host, target
1686 let _time = util::timeit(&builder);
1687 try_run(builder, &mut cmd);
1689 if let Some(compare_mode) = compare_mode {
1690 cmd.arg("--compare-mode").arg(compare_mode);
1691 builder.info(&format!(
1692 "Check compiletest suite={} mode={} compare_mode={} ({} -> {})",
1693 suite, mode, compare_mode, &compiler.host, target
1695 let _time = util::timeit(&builder);
1696 try_run(builder, &mut cmd);
1701 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1709 impl Step for BookTest {
1711 const ONLY_HOSTS: bool = true;
1713 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1717 /// Runs the documentation tests for a book in `src/doc`.
1719 /// This uses the `rustdoc` that sits next to `compiler`.
1720 fn run(self, builder: &Builder<'_>) {
1721 // External docs are different from local because:
1722 // - Some books need pre-processing by mdbook before being tested.
1723 // - They need to save their state to toolstate.
1724 // - They are only tested on the "checktools" builders.
1726 // The local docs are tested by default, and we don't want to pay the
1727 // cost of building mdbook, so they use `rustdoc --test` directly.
1728 // Also, the unstable book is special because SUMMARY.md is generated,
1729 // so it is easier to just run `rustdoc` on its files.
1730 if self.is_ext_doc {
1731 self.run_ext_doc(builder);
1733 self.run_local_doc(builder);
1739 /// This runs the equivalent of `mdbook test` (via the rustbook wrapper)
1740 /// which in turn runs `rustdoc --test` on each file in the book.
1741 fn run_ext_doc(self, builder: &Builder<'_>) {
1742 let compiler = self.compiler;
1744 builder.ensure(compile::Std::new(compiler, compiler.host));
1746 // mdbook just executes a binary named "rustdoc", so we need to update
1747 // PATH so that it points to our rustdoc.
1748 let mut rustdoc_path = builder.rustdoc(compiler);
1750 let old_path = env::var_os("PATH").unwrap_or_default();
1751 let new_path = env::join_paths(iter::once(rustdoc_path).chain(env::split_paths(&old_path)))
1752 .expect("could not add rustdoc to PATH");
1754 let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
1755 let path = builder.src.join(&self.path);
1756 // Books often have feature-gated example text.
1757 rustbook_cmd.env("RUSTC_BOOTSTRAP", "1");
1758 rustbook_cmd.env("PATH", new_path).arg("test").arg(path);
1759 builder.add_rust_test_threads(&mut rustbook_cmd);
1760 builder.info(&format!("Testing rustbook {}", self.path.display()));
1761 let _time = util::timeit(&builder);
1762 let toolstate = if try_run(builder, &mut rustbook_cmd) {
1767 builder.save_toolstate(self.name, toolstate);
1770 /// This runs `rustdoc --test` on all `.md` files in the path.
1771 fn run_local_doc(self, builder: &Builder<'_>) {
1772 let compiler = self.compiler;
1774 builder.ensure(compile::Std::new(compiler, compiler.host));
1776 // Do a breadth-first traversal of the `src/doc` directory and just run
1777 // tests for all files that end in `*.md`
1778 let mut stack = vec![builder.src.join(self.path)];
1779 let _time = util::timeit(&builder);
1780 let mut files = Vec::new();
1781 while let Some(p) = stack.pop() {
1783 stack.extend(t!(p.read_dir()).map(|p| t!(p).path()));
1787 if p.extension().and_then(|s| s.to_str()) != Some("md") {
1797 markdown_test(builder, compiler, &file);
1802 macro_rules! test_book {
1803 ($($name:ident, $path:expr, $book_name:expr, default=$default:expr;)+) => {
1805 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1810 impl Step for $name {
1812 const DEFAULT: bool = $default;
1813 const ONLY_HOSTS: bool = true;
1815 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1819 fn make_run(run: RunConfig<'_>) {
1820 run.builder.ensure($name {
1821 compiler: run.builder.compiler(run.builder.top_stage, run.target),
1825 fn run(self, builder: &Builder<'_>) {
1826 builder.ensure(BookTest {
1827 compiler: self.compiler,
1828 path: PathBuf::from($path),
1830 is_ext_doc: !$default,
1839 Nomicon, "src/doc/nomicon", "nomicon", default=false;
1840 Reference, "src/doc/reference", "reference", default=false;
1841 RustdocBook, "src/doc/rustdoc", "rustdoc", default=true;
1842 RustcBook, "src/doc/rustc", "rustc", default=true;
1843 RustByExample, "src/doc/rust-by-example", "rust-by-example", default=false;
1844 EmbeddedBook, "src/doc/embedded-book", "embedded-book", default=false;
1845 TheBook, "src/doc/book", "book", default=false;
1846 UnstableBook, "src/doc/unstable-book", "unstable-book", default=true;
1847 EditionGuide, "src/doc/edition-guide", "edition-guide", default=false;
1850 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1851 pub struct ErrorIndex {
1855 impl Step for ErrorIndex {
1857 const DEFAULT: bool = true;
1858 const ONLY_HOSTS: bool = true;
1860 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1861 run.path("src/tools/error_index_generator")
1864 fn make_run(run: RunConfig<'_>) {
1865 // error_index_generator depends on librustdoc. Use the compiler that
1866 // is normally used to build rustdoc for other tests (like compiletest
1867 // tests in src/test/rustdoc) so that it shares the same artifacts.
1868 let compiler = run.builder.compiler(run.builder.top_stage, run.builder.config.build);
1869 run.builder.ensure(ErrorIndex { compiler });
1872 /// Runs the error index generator tool to execute the tests located in the error
1875 /// The `error_index_generator` tool lives in `src/tools` and is used to
1876 /// generate a markdown file from the error indexes of the code base which is
1877 /// then passed to `rustdoc --test`.
1878 fn run(self, builder: &Builder<'_>) {
1879 let compiler = self.compiler;
1881 let dir = testdir(builder, compiler.host);
1882 t!(fs::create_dir_all(&dir));
1883 let output = dir.join("error-index.md");
1885 let mut tool = tool::ErrorIndex::command(builder);
1886 tool.arg("markdown").arg(&output);
1888 builder.info(&format!("Testing error-index stage{}", compiler.stage));
1889 let _time = util::timeit(&builder);
1890 builder.run_quiet(&mut tool);
1891 // The tests themselves need to link to std, so make sure it is
1893 builder.ensure(compile::Std::new(compiler, compiler.host));
1894 markdown_test(builder, compiler, &output);
1898 fn markdown_test(builder: &Builder<'_>, compiler: Compiler, markdown: &Path) -> bool {
1899 if let Ok(contents) = fs::read_to_string(markdown) {
1900 if !contents.contains("```") {
1905 builder.info(&format!("doc tests for: {}", markdown.display()));
1906 let mut cmd = builder.rustdoc_cmd(compiler);
1907 builder.add_rust_test_threads(&mut cmd);
1908 // allow for unstable options such as new editions
1910 cmd.arg("unstable-options");
1913 cmd.env("RUSTC_BOOTSTRAP", "1");
1915 let test_args = builder.config.cmd.test_args().join(" ");
1916 cmd.arg("--test-args").arg(test_args);
1918 if builder.config.verbose_tests {
1919 try_run(builder, &mut cmd)
1921 try_run_quiet(builder, &mut cmd)
1925 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1926 pub struct RustcGuide;
1928 impl Step for RustcGuide {
1930 const DEFAULT: bool = false;
1931 const ONLY_HOSTS: bool = true;
1933 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1934 run.path("src/doc/rustc-dev-guide")
1937 fn make_run(run: RunConfig<'_>) {
1938 run.builder.ensure(RustcGuide);
1941 fn run(self, builder: &Builder<'_>) {
1942 let relative_path = Path::new("src").join("doc").join("rustc-dev-guide");
1943 builder.update_submodule(&relative_path);
1945 let src = builder.src.join(relative_path);
1946 let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
1947 let toolstate = if try_run(builder, rustbook_cmd.arg("linkcheck").arg(&src)) {
1952 builder.save_toolstate("rustc-dev-guide", toolstate);
1956 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1957 pub struct CrateLibrustc {
1959 target: TargetSelection,
1960 test_kind: TestKind,
1961 crates: Vec<Interned<String>>,
1964 impl Step for CrateLibrustc {
1966 const DEFAULT: bool = true;
1967 const ONLY_HOSTS: bool = true;
1969 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1970 run.crate_or_deps("rustc-main")
1973 fn make_run(run: RunConfig<'_>) {
1974 let builder = run.builder;
1975 let host = run.build_triple();
1976 let compiler = builder.compiler_for(builder.top_stage, host, host);
1980 .map(|p| builder.crate_paths[&p.assert_single_path().path].clone())
1982 let test_kind = builder.kind.into();
1984 builder.ensure(CrateLibrustc { compiler, target: run.target, test_kind, crates });
1987 fn run(self, builder: &Builder<'_>) {
1988 builder.ensure(Crate {
1989 compiler: self.compiler,
1990 target: self.target,
1992 test_kind: self.test_kind,
1993 crates: self.crates,
1998 #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
2000 pub compiler: Compiler,
2001 pub target: TargetSelection,
2003 pub test_kind: TestKind,
2004 pub crates: Vec<Interned<String>>,
2007 impl Step for Crate {
2009 const DEFAULT: bool = true;
2011 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2012 run.crate_or_deps("test")
2015 fn make_run(run: RunConfig<'_>) {
2016 let builder = run.builder;
2017 let host = run.build_triple();
2018 let compiler = builder.compiler_for(builder.top_stage, host, host);
2019 let test_kind = builder.kind.into();
2023 .map(|p| builder.crate_paths[&p.assert_single_path().path].clone())
2026 builder.ensure(Crate { compiler, target: run.target, mode: Mode::Std, test_kind, crates });
2029 /// Runs all unit tests plus documentation tests for a given crate defined
2030 /// by a `Cargo.toml` (single manifest)
2032 /// This is what runs tests for crates like the standard library, compiler, etc.
2033 /// It essentially is the driver for running `cargo test`.
2035 /// Currently this runs all tests for a DAG by passing a bunch of `-p foo`
2036 /// arguments, and those arguments are discovered from `cargo metadata`.
2037 fn run(self, builder: &Builder<'_>) {
2038 let compiler = self.compiler;
2039 let target = self.target;
2040 let mode = self.mode;
2041 let test_kind = self.test_kind;
2043 builder.ensure(compile::Std::new(compiler, target));
2044 builder.ensure(RemoteCopyLibs { compiler, target });
2046 // If we're not doing a full bootstrap but we're testing a stage2
2047 // version of libstd, then what we're actually testing is the libstd
2048 // produced in stage1. Reflect that here by updating the compiler that
2049 // we're working with automatically.
2050 let compiler = builder.compiler_for(compiler.stage, compiler.host, target);
2053 builder.cargo(compiler, mode, SourceType::InTree, target, test_kind.subcommand());
2056 compile::std_cargo(builder, target, compiler.stage, &mut cargo);
2059 compile::rustc_cargo(builder, &mut cargo, target);
2061 _ => panic!("can only test libraries"),
2064 // Build up the base `cargo test` command.
2066 // Pass in some standard flags then iterate over the graph we've discovered
2067 // in `cargo metadata` with the maps above and figure out what `-p`
2068 // arguments need to get passed.
2069 if test_kind.subcommand() == "test" && !builder.fail_fast {
2070 cargo.arg("--no-fail-fast");
2072 match builder.doc_tests {
2077 cargo.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
2082 for krate in &self.crates {
2083 cargo.arg("-p").arg(krate);
2086 // The tests are going to run with the *target* libraries, so we need to
2087 // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
2089 // Note that to run the compiler we need to run with the *host* libraries,
2090 // but our wrapper scripts arrange for that to be the case anyway.
2091 let mut dylib_path = dylib_path();
2092 dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
2093 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
2096 cargo.args(&builder.config.cmd.test_args());
2098 if !builder.config.verbose_tests {
2099 cargo.arg("--quiet");
2102 if target.contains("emscripten") {
2104 format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)),
2105 builder.config.nodejs.as_ref().expect("nodejs not configured"),
2107 } else if target.starts_with("wasm32") {
2108 let node = builder.config.nodejs.as_ref().expect("nodejs not configured");
2110 format!("{} {}/src/etc/wasm32-shim.js", node.display(), builder.src.display());
2111 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)), &runner);
2112 } else if builder.remote_tested(target) {
2114 format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)),
2115 format!("{} run 0", builder.tool_exe(Tool::RemoteTestClient).display()),
2119 builder.info(&format!(
2120 "{} {:?} stage{} ({} -> {})",
2121 test_kind, self.crates, compiler.stage, &compiler.host, target
2123 let _time = util::timeit(&builder);
2124 try_run(builder, &mut cargo.into());
2128 /// Rustdoc is special in various ways, which is why this step is different from `Crate`.
2129 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2130 pub struct CrateRustdoc {
2131 host: TargetSelection,
2132 test_kind: TestKind,
2135 impl Step for CrateRustdoc {
2137 const DEFAULT: bool = true;
2138 const ONLY_HOSTS: bool = true;
2140 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2141 run.paths(&["src/librustdoc", "src/tools/rustdoc"])
2144 fn make_run(run: RunConfig<'_>) {
2145 let builder = run.builder;
2147 let test_kind = builder.kind.into();
2149 builder.ensure(CrateRustdoc { host: run.target, test_kind });
2152 fn run(self, builder: &Builder<'_>) {
2153 let test_kind = self.test_kind;
2154 let target = self.host;
2156 let compiler = if builder.download_rustc() {
2157 builder.compiler(builder.top_stage, target)
2159 // Use the previous stage compiler to reuse the artifacts that are
2160 // created when running compiletest for src/test/rustdoc. If this used
2161 // `compiler`, then it would cause rustdoc to be built *again*, which
2162 // isn't really necessary.
2163 builder.compiler_for(builder.top_stage, target, target)
2165 builder.ensure(compile::Rustc::new(compiler, target));
2167 let mut cargo = tool::prepare_tool_cargo(
2172 test_kind.subcommand(),
2173 "src/tools/rustdoc",
2177 if test_kind.subcommand() == "test" && !builder.fail_fast {
2178 cargo.arg("--no-fail-fast");
2180 match builder.doc_tests {
2185 cargo.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
2190 cargo.arg("-p").arg("rustdoc:0.0.0");
2193 cargo.args(&builder.config.cmd.test_args());
2195 if self.host.contains("musl") {
2196 cargo.arg("'-Ctarget-feature=-crt-static'");
2199 // This is needed for running doctests on librustdoc. This is a bit of
2200 // an unfortunate interaction with how bootstrap works and how cargo
2201 // sets up the dylib path, and the fact that the doctest (in
2202 // html/markdown.rs) links to rustc-private libs. For stage1, the
2203 // compiler host dylibs (in stage1/lib) are not the same as the target
2204 // dylibs (in stage1/lib/rustlib/...). This is different from a normal
2205 // rust distribution where they are the same.
2207 // On the cargo side, normal tests use `target_process` which handles
2208 // setting up the dylib for a *target* (stage1/lib/rustlib/... in this
2209 // case). However, for doctests it uses `rustdoc_process` which only
2210 // sets up the dylib path for the *host* (stage1/lib), which is the
2213 // Recall that we special-cased `compiler_for(top_stage)` above, so we always use stage1.
2215 // It should be considered to just stop running doctests on
2216 // librustdoc. There is only one test, and it doesn't look too
2217 // important. There might be other ways to avoid this, but it seems
2218 // pretty convoluted.
2220 // See also https://github.com/rust-lang/rust/issues/13983 where the
2221 // host vs target dylibs for rustdoc are consistently tricky to deal
2224 // Note that this set the host libdir for `download_rustc`, which uses a normal rust distribution.
2225 let libdir = if builder.download_rustc() {
2226 builder.rustc_libdir(compiler)
2228 builder.sysroot_libdir(compiler, target).to_path_buf()
2230 let mut dylib_path = dylib_path();
2231 dylib_path.insert(0, PathBuf::from(&*libdir));
2232 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
2234 if !builder.config.verbose_tests {
2235 cargo.arg("--quiet");
2238 builder.info(&format!(
2239 "{} rustdoc stage{} ({} -> {})",
2240 test_kind, compiler.stage, &compiler.host, target
2242 let _time = util::timeit(&builder);
2244 try_run(builder, &mut cargo.into());
2248 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2249 pub struct CrateRustdocJsonTypes {
2250 host: TargetSelection,
2251 test_kind: TestKind,
2254 impl Step for CrateRustdocJsonTypes {
2256 const DEFAULT: bool = true;
2257 const ONLY_HOSTS: bool = true;
2259 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2260 run.path("src/rustdoc-json-types")
2263 fn make_run(run: RunConfig<'_>) {
2264 let builder = run.builder;
2266 let test_kind = builder.kind.into();
2268 builder.ensure(CrateRustdocJsonTypes { host: run.target, test_kind });
2271 fn run(self, builder: &Builder<'_>) {
2272 let test_kind = self.test_kind;
2273 let target = self.host;
2275 // Use the previous stage compiler to reuse the artifacts that are
2276 // created when running compiletest for src/test/rustdoc. If this used
2277 // `compiler`, then it would cause rustdoc to be built *again*, which
2278 // isn't really necessary.
2279 let compiler = builder.compiler_for(builder.top_stage, target, target);
2280 builder.ensure(compile::Rustc::new(compiler, target));
2282 let mut cargo = tool::prepare_tool_cargo(
2287 test_kind.subcommand(),
2288 "src/rustdoc-json-types",
2292 if test_kind.subcommand() == "test" && !builder.fail_fast {
2293 cargo.arg("--no-fail-fast");
2296 cargo.arg("-p").arg("rustdoc-json-types");
2299 cargo.args(&builder.config.cmd.test_args());
2301 if self.host.contains("musl") {
2302 cargo.arg("'-Ctarget-feature=-crt-static'");
2305 if !builder.config.verbose_tests {
2306 cargo.arg("--quiet");
2309 builder.info(&format!(
2310 "{} rustdoc-json-types stage{} ({} -> {})",
2311 test_kind, compiler.stage, &compiler.host, target
2313 let _time = util::timeit(&builder);
2315 try_run(builder, &mut cargo.into());
2319 /// Some test suites are run inside emulators or on remote devices, and most
2320 /// of our test binaries are linked dynamically which means we need to ship
2321 /// the standard library and such to the emulator ahead of time. This step
2322 /// represents this and is a dependency of all test suites.
2324 /// Most of the time this is a no-op. For some steps such as shipping data to
2325 /// QEMU we have to build our own tools so we've got conditional dependencies
2326 /// on those programs as well. Note that the remote test client is built for
2327 /// the build target (us) and the server is built for the target.
2328 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2329 pub struct RemoteCopyLibs {
2331 target: TargetSelection,
2334 impl Step for RemoteCopyLibs {
2337 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2341 fn run(self, builder: &Builder<'_>) {
2342 let compiler = self.compiler;
2343 let target = self.target;
2344 if !builder.remote_tested(target) {
2348 builder.ensure(compile::Std::new(compiler, target));
2350 builder.info(&format!("REMOTE copy libs to emulator ({})", target));
2352 let server = builder.ensure(tool::RemoteTestServer { compiler, target });
2354 // Spawn the emulator and wait for it to come online
2355 let tool = builder.tool_exe(Tool::RemoteTestClient);
2356 let mut cmd = Command::new(&tool);
2357 cmd.arg("spawn-emulator").arg(target.triple).arg(&server).arg(builder.tempdir());
2358 if let Some(rootfs) = builder.qemu_rootfs(target) {
2361 builder.run(&mut cmd);
2363 // Push all our dylibs to the emulator
2364 for f in t!(builder.sysroot_libdir(compiler, target).read_dir()) {
2366 let name = f.file_name().into_string().unwrap();
2367 if util::is_dylib(&name) {
2368 builder.run(Command::new(&tool).arg("push").arg(f.path()));
2374 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2375 pub struct Distcheck;
2377 impl Step for Distcheck {
2380 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2381 run.alias("distcheck")
2384 fn make_run(run: RunConfig<'_>) {
2385 run.builder.ensure(Distcheck);
2388 /// Runs "distcheck", a 'make check' from a tarball
2389 fn run(self, builder: &Builder<'_>) {
2390 builder.info("Distcheck");
2391 let dir = builder.tempdir().join("distcheck");
2392 let _ = fs::remove_dir_all(&dir);
2393 t!(fs::create_dir_all(&dir));
2395 // Guarantee that these are built before we begin running.
2396 builder.ensure(dist::PlainSourceTarball);
2397 builder.ensure(dist::Src);
2399 let mut cmd = Command::new("tar");
2401 .arg(builder.ensure(dist::PlainSourceTarball).tarball())
2402 .arg("--strip-components=1")
2404 builder.run(&mut cmd);
2406 Command::new("./configure")
2407 .args(&builder.config.configure_args)
2408 .arg("--enable-vendor")
2412 Command::new(util::make(&builder.config.build.triple)).arg("check").current_dir(&dir),
2415 // Now make sure that rust-src has all of libstd's dependencies
2416 builder.info("Distcheck rust-src");
2417 let dir = builder.tempdir().join("distcheck-src");
2418 let _ = fs::remove_dir_all(&dir);
2419 t!(fs::create_dir_all(&dir));
2421 let mut cmd = Command::new("tar");
2423 .arg(builder.ensure(dist::Src).tarball())
2424 .arg("--strip-components=1")
2426 builder.run(&mut cmd);
2428 let toml = dir.join("rust-src/lib/rustlib/src/rust/library/std/Cargo.toml");
2430 Command::new(&builder.initial_cargo)
2431 .arg("generate-lockfile")
2432 .arg("--manifest-path")
2439 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2440 pub struct Bootstrap;
2442 impl Step for Bootstrap {
2444 const DEFAULT: bool = true;
2445 const ONLY_HOSTS: bool = true;
2447 /// Tests the build system itself.
2448 fn run(self, builder: &Builder<'_>) {
2449 let mut check_bootstrap = Command::new(&builder.python());
2450 check_bootstrap.arg("bootstrap_test.py").current_dir(builder.src.join("src/bootstrap/"));
2451 try_run(builder, &mut check_bootstrap);
2453 let mut cmd = Command::new(&builder.initial_cargo);
2455 .current_dir(builder.src.join("src/bootstrap"))
2456 .env("RUSTFLAGS", "-Cdebuginfo=2")
2457 .env("CARGO_TARGET_DIR", builder.out.join("bootstrap"))
2458 .env("RUSTC_BOOTSTRAP", "1")
2459 .env("RUSTDOC", builder.rustdoc(builder.compiler(0, builder.build.build)))
2460 .env("RUSTC", &builder.initial_rustc);
2461 if let Some(flags) = option_env!("RUSTFLAGS") {
2462 // Use the same rustc flags for testing as for "normal" compilation,
2463 // so that Cargo doesn’t recompile the entire dependency graph every time:
2464 // https://github.com/rust-lang/rust/issues/49215
2465 cmd.env("RUSTFLAGS", flags);
2467 if !builder.fail_fast {
2468 cmd.arg("--no-fail-fast");
2470 match builder.doc_tests {
2475 cmd.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
2480 cmd.arg("--").args(&builder.config.cmd.test_args());
2481 // rustbuild tests are racy on directory creation so just run them one at a time.
2482 // Since there's not many this shouldn't be a problem.
2483 cmd.arg("--test-threads=1");
2484 try_run(builder, &mut cmd);
2487 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2488 run.path("src/bootstrap")
2491 fn make_run(run: RunConfig<'_>) {
2492 run.builder.ensure(Bootstrap);
2496 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2497 pub struct TierCheck {
2498 pub compiler: Compiler,
2501 impl Step for TierCheck {
2503 const DEFAULT: bool = true;
2504 const ONLY_HOSTS: bool = true;
2506 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2507 run.path("src/tools/tier-check")
2510 fn make_run(run: RunConfig<'_>) {
2512 run.builder.compiler_for(run.builder.top_stage, run.builder.build.build, run.target);
2513 run.builder.ensure(TierCheck { compiler });
2516 /// Tests the Platform Support page in the rustc book.
2517 fn run(self, builder: &Builder<'_>) {
2518 builder.ensure(compile::Std::new(self.compiler, self.compiler.host));
2519 let mut cargo = tool::prepare_tool_cargo(
2525 "src/tools/tier-check",
2529 cargo.arg(builder.src.join("src/doc/rustc/src/platform-support.md"));
2530 cargo.arg(&builder.rustc(self.compiler));
2531 if builder.is_verbose() {
2532 cargo.arg("--verbose");
2535 builder.info("platform support check");
2536 try_run(builder, &mut cargo.into());
2540 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2541 pub struct ReplacePlaceholderTest;
2543 impl Step for ReplacePlaceholderTest {
2545 const ONLY_HOSTS: bool = true;
2546 const DEFAULT: bool = true;
2548 /// Ensure the version placeholder replacement tool builds
2549 fn run(self, builder: &Builder<'_>) {
2550 builder.info("build check for version replacement placeholder");
2552 // Test the version placeholder replacement tool itself.
2553 let bootstrap_host = builder.config.build;
2554 let compiler = builder.compiler(0, bootstrap_host);
2555 let cargo = tool::prepare_tool_cargo(
2558 Mode::ToolBootstrap,
2561 "src/tools/replace-version-placeholder",
2565 try_run(builder, &mut cargo.into());
2568 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2569 run.path("src/tools/replace-version-placeholder")
2572 fn make_run(run: RunConfig<'_>) {
2573 run.builder.ensure(Self);
2577 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2578 pub struct LintDocs {
2579 pub compiler: Compiler,
2580 pub target: TargetSelection,
2583 impl Step for LintDocs {
2585 const DEFAULT: bool = true;
2586 const ONLY_HOSTS: bool = true;
2588 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2589 run.path("src/tools/lint-docs")
2592 fn make_run(run: RunConfig<'_>) {
2593 run.builder.ensure(LintDocs {
2594 compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
2599 /// Tests that the lint examples in the rustc book generate the correct
2600 /// lints and have the expected format.
2601 fn run(self, builder: &Builder<'_>) {
2602 builder.ensure(crate::doc::RustcBook {
2603 compiler: self.compiler,
2604 target: self.target,