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 CrateJsonDocLint {
95 host: TargetSelection,
98 impl Step for CrateJsonDocLint {
100 const ONLY_HOSTS: bool = true;
101 const DEFAULT: bool = true;
103 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
104 run.path("src/tools/jsondoclint")
107 fn make_run(run: RunConfig<'_>) {
108 run.builder.ensure(CrateJsonDocLint { host: run.target });
111 fn run(self, builder: &Builder<'_>) {
112 let bootstrap_host = builder.config.build;
113 let compiler = builder.compiler(0, bootstrap_host);
115 let cargo = tool::prepare_tool_cargo(
121 "src/tools/jsondoclint",
125 try_run(builder, &mut cargo.into());
129 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
130 pub struct Linkcheck {
131 host: TargetSelection,
134 impl Step for Linkcheck {
136 const ONLY_HOSTS: bool = true;
137 const DEFAULT: bool = true;
139 /// Runs the `linkchecker` tool as compiled in `stage` by the `host` compiler.
141 /// This tool in `src/tools` will verify the validity of all our links in the
142 /// documentation to ensure we don't have a bunch of dead ones.
143 fn run(self, builder: &Builder<'_>) {
144 let host = self.host;
145 let hosts = &builder.hosts;
146 let targets = &builder.targets;
148 // if we have different hosts and targets, some things may be built for
149 // the host (e.g. rustc) and others for the target (e.g. std). The
150 // documentation built for each will contain broken links to
151 // docs built for the other platform (e.g. rustc linking to cargo)
152 if (hosts != targets) && !hosts.is_empty() && !targets.is_empty() {
154 "Linkcheck currently does not support builds with different hosts and targets.
155 You can skip linkcheck with --exclude src/tools/linkchecker"
159 builder.info(&format!("Linkcheck ({})", host));
161 // Test the linkchecker itself.
162 let bootstrap_host = builder.config.build;
163 let compiler = builder.compiler(0, bootstrap_host);
164 let cargo = tool::prepare_tool_cargo(
170 "src/tools/linkchecker",
174 try_run(builder, &mut cargo.into());
176 // Build all the default documentation.
177 builder.default_doc(&[]);
179 // Run the linkchecker.
180 let _time = util::timeit(&builder);
183 builder.tool_cmd(Tool::Linkchecker).arg(builder.out.join(host.triple).join("doc")),
187 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
188 let builder = run.builder;
189 let run = run.path("src/tools/linkchecker");
190 run.default_condition(builder.config.docs)
193 fn make_run(run: RunConfig<'_>) {
194 run.builder.ensure(Linkcheck { host: run.target });
198 fn check_if_tidy_is_installed() -> bool {
201 .stdout(Stdio::null())
203 .map_or(false, |status| status.success())
206 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
207 pub struct HtmlCheck {
208 target: TargetSelection,
211 impl Step for HtmlCheck {
213 const DEFAULT: bool = true;
214 const ONLY_HOSTS: bool = true;
216 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
217 let run = run.path("src/tools/html-checker");
218 run.lazy_default_condition(Box::new(check_if_tidy_is_installed))
221 fn make_run(run: RunConfig<'_>) {
222 run.builder.ensure(HtmlCheck { target: run.target });
225 fn run(self, builder: &Builder<'_>) {
226 if !check_if_tidy_is_installed() {
227 eprintln!("not running HTML-check tool because `tidy` is missing");
229 "Note that `tidy` is not the in-tree `src/tools/tidy` but needs to be installed"
231 panic!("Cannot run html-check tests");
233 // Ensure that a few different kinds of documentation are available.
234 builder.default_doc(&[]);
235 builder.ensure(crate::doc::Rustc { target: self.target, stage: builder.top_stage });
237 try_run(builder, builder.tool_cmd(Tool::HtmlChecker).arg(builder.doc_out(self.target)));
241 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
242 pub struct Cargotest {
244 host: TargetSelection,
247 impl Step for Cargotest {
249 const ONLY_HOSTS: bool = true;
251 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
252 run.path("src/tools/cargotest")
255 fn make_run(run: RunConfig<'_>) {
256 run.builder.ensure(Cargotest { stage: run.builder.top_stage, host: run.target });
259 /// Runs the `cargotest` tool as compiled in `stage` by the `host` compiler.
261 /// This tool in `src/tools` will check out a few Rust projects and run `cargo
262 /// test` to ensure that we don't regress the test suites there.
263 fn run(self, builder: &Builder<'_>) {
264 let compiler = builder.compiler(self.stage, self.host);
265 builder.ensure(compile::Rustc::new(compiler, compiler.host));
266 let cargo = builder.ensure(tool::Cargo { compiler, target: compiler.host });
268 // Note that this is a short, cryptic, and not scoped directory name. This
269 // is currently to minimize the length of path on Windows where we otherwise
270 // quickly run into path name limit constraints.
271 let out_dir = builder.out.join("ct");
272 t!(fs::create_dir_all(&out_dir));
274 let _time = util::timeit(&builder);
275 let mut cmd = builder.tool_cmd(Tool::CargoTest);
280 .args(builder.config.cmd.test_args())
281 .env("RUSTC", builder.rustc(compiler))
282 .env("RUSTDOC", builder.rustdoc(compiler)),
287 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
290 host: TargetSelection,
293 impl Step for Cargo {
295 const ONLY_HOSTS: bool = true;
297 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
298 run.path("src/tools/cargo")
301 fn make_run(run: RunConfig<'_>) {
302 run.builder.ensure(Cargo { stage: run.builder.top_stage, host: run.target });
305 /// Runs `cargo test` for `cargo` packaged with Rust.
306 fn run(self, builder: &Builder<'_>) {
307 let compiler = builder.compiler(self.stage, self.host);
309 builder.ensure(tool::Cargo { compiler, target: self.host });
310 let mut cargo = tool::prepare_tool_cargo(
317 SourceType::Submodule,
321 if !builder.fail_fast {
322 cargo.arg("--no-fail-fast");
324 cargo.arg("--").args(builder.config.cmd.test_args());
326 // Don't run cross-compile tests, we may not have cross-compiled libstd libs
328 cargo.env("CFG_DISABLE_CROSS_TESTS", "1");
329 // Forcibly disable tests using nightly features since any changes to
330 // those features won't be able to land.
331 cargo.env("CARGO_TEST_DISABLE_NIGHTLY", "1");
333 cargo.env("PATH", &path_for_cargo(builder, compiler));
335 try_run(builder, &mut cargo.into());
339 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
340 pub struct RustAnalyzer {
342 host: TargetSelection,
345 impl Step for RustAnalyzer {
347 const ONLY_HOSTS: bool = true;
348 const DEFAULT: bool = true;
350 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
351 run.path("src/tools/rust-analyzer")
354 fn make_run(run: RunConfig<'_>) {
355 run.builder.ensure(Self { stage: run.builder.top_stage, host: run.target });
358 /// Runs `cargo test` for rust-analyzer
359 fn run(self, builder: &Builder<'_>) {
360 let stage = self.stage;
361 let host = self.host;
362 let compiler = builder.compiler(stage, host);
364 builder.ensure(tool::RustAnalyzer { compiler, target: self.host }).expect("in-tree tool");
366 let workspace_path = "src/tools/rust-analyzer";
367 // until the whole RA test suite runs on `i686`, we only run
368 // `proc-macro-srv` tests
369 let crate_path = "src/tools/rust-analyzer/crates/proc-macro-srv";
370 let mut cargo = tool::prepare_tool_cargo(
378 &["sysroot-abi".to_owned()],
381 let dir = builder.src.join(workspace_path);
382 // needed by rust-analyzer to find its own text fixtures, cf.
383 // https://github.com/rust-analyzer/expect-test/issues/33
384 cargo.env("CARGO_WORKSPACE_DIR", &dir);
386 // RA's test suite tries to write to the source directory, that can't
388 cargo.env("SKIP_SLOW_TESTS", "1");
390 cargo.add_rustc_lib_path(builder, compiler);
391 cargo.arg("--").args(builder.config.cmd.test_args());
393 builder.run(&mut cargo.into());
397 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
400 host: TargetSelection,
403 impl Step for Rustfmt {
405 const ONLY_HOSTS: bool = true;
407 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
408 run.path("src/tools/rustfmt")
411 fn make_run(run: RunConfig<'_>) {
412 run.builder.ensure(Rustfmt { stage: run.builder.top_stage, host: run.target });
415 /// Runs `cargo test` for rustfmt.
416 fn run(self, builder: &Builder<'_>) {
417 let stage = self.stage;
418 let host = self.host;
419 let compiler = builder.compiler(stage, host);
422 .ensure(tool::Rustfmt { compiler, target: self.host, extra_features: Vec::new() })
423 .expect("in-tree tool");
425 let mut cargo = tool::prepare_tool_cargo(
436 let dir = testdir(builder, compiler.host);
437 t!(fs::create_dir_all(&dir));
438 cargo.env("RUSTFMT_TEST_DIR", dir);
440 cargo.add_rustc_lib_path(builder, compiler);
442 builder.run(&mut cargo.into());
446 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
447 pub struct RustDemangler {
449 host: TargetSelection,
452 impl Step for RustDemangler {
454 const ONLY_HOSTS: bool = true;
456 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
457 run.path("src/tools/rust-demangler")
460 fn make_run(run: RunConfig<'_>) {
461 run.builder.ensure(RustDemangler { stage: run.builder.top_stage, host: run.target });
464 /// Runs `cargo test` for rust-demangler.
465 fn run(self, builder: &Builder<'_>) {
466 let stage = self.stage;
467 let host = self.host;
468 let compiler = builder.compiler(stage, host);
470 let rust_demangler = builder
471 .ensure(tool::RustDemangler { compiler, target: self.host, extra_features: Vec::new() })
472 .expect("in-tree tool");
473 let mut cargo = tool::prepare_tool_cargo(
479 "src/tools/rust-demangler",
484 let dir = testdir(builder, compiler.host);
485 t!(fs::create_dir_all(&dir));
487 cargo.env("RUST_DEMANGLER_DRIVER_PATH", rust_demangler);
489 cargo.arg("--").args(builder.config.cmd.test_args());
491 cargo.add_rustc_lib_path(builder, compiler);
493 builder.run(&mut cargo.into());
497 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
500 host: TargetSelection,
501 target: TargetSelection,
505 /// Run `cargo miri setup` for the given target, return where the Miri sysroot was put.
506 pub fn build_miri_sysroot(
507 builder: &Builder<'_>,
510 target: TargetSelection,
512 let miri_sysroot = builder.out.join(compiler.host.triple).join("miri-sysroot");
513 let mut cargo = tool::prepare_tool_cargo(
519 "src/tools/miri/cargo-miri",
523 cargo.add_rustc_lib_path(builder, compiler);
524 cargo.arg("--").arg("miri").arg("setup");
525 cargo.arg("--target").arg(target.rustc_target_arg());
527 // Tell `cargo miri setup` where to find the sources.
528 cargo.env("MIRI_LIB_SRC", builder.src.join("library"));
529 // Tell it where to find Miri.
530 cargo.env("MIRI", &miri);
531 // Tell it where to put the sysroot.
532 cargo.env("MIRI_SYSROOT", &miri_sysroot);
534 cargo.env("RUST_BACKTRACE", "1");
536 let mut cargo = Command::from(cargo);
537 builder.run(&mut cargo);
539 // # Determine where Miri put its sysroot.
540 // To this end, we run `cargo miri setup --print-sysroot` and capture the output.
541 // (We do this separately from the above so that when the setup actually
542 // happens we get some output.)
543 // We re-use the `cargo` from above.
544 cargo.arg("--print-sysroot");
546 // FIXME: Is there a way in which we can re-use the usual `run` helpers?
547 if builder.config.dry_run() {
550 builder.verbose(&format!("running: {:?}", cargo));
552 cargo.output().expect("We already ran `cargo miri setup` before and that worked");
553 assert!(out.status.success(), "`cargo miri setup` returned with non-0 exit code");
554 // Output is "<sysroot>\n".
555 let stdout = String::from_utf8(out.stdout)
556 .expect("`cargo miri setup` stdout is not valid UTF-8");
557 let sysroot = stdout.trim_end();
558 builder.verbose(&format!("`cargo miri setup --print-sysroot` said: {:?}", sysroot));
566 const ONLY_HOSTS: bool = false;
568 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
569 run.path("src/tools/miri")
572 fn make_run(run: RunConfig<'_>) {
573 run.builder.ensure(Miri {
574 stage: run.builder.top_stage,
575 host: run.build_triple(),
580 /// Runs `cargo test` for miri.
581 fn run(self, builder: &Builder<'_>) {
582 let stage = self.stage;
583 let host = self.host;
584 let target = self.target;
585 let compiler = builder.compiler(stage, host);
586 // We need the stdlib for the *next* stage, as it was built with this compiler that also built Miri.
587 // Except if we are at stage 2, the bootstrap loop is complete and we can stick with our current stage.
588 let compiler_std = builder.compiler(if stage < 2 { stage + 1 } else { stage }, host);
591 .ensure(tool::Miri { compiler, target: self.host, extra_features: Vec::new() })
592 .expect("in-tree tool");
593 let _cargo_miri = builder
594 .ensure(tool::CargoMiri { compiler, target: self.host, extra_features: Vec::new() })
595 .expect("in-tree tool");
596 // The stdlib we need might be at a different stage. And just asking for the
597 // sysroot does not seem to populate it, so we do that first.
598 builder.ensure(compile::Std::new(compiler_std, host));
599 let sysroot = builder.sysroot(compiler_std);
600 // We also need a Miri sysroot.
601 let miri_sysroot = Miri::build_miri_sysroot(builder, compiler, &miri, target);
603 // # Run `cargo test`.
604 let mut cargo = tool::prepare_tool_cargo(
614 cargo.add_rustc_lib_path(builder, compiler);
616 // miri tests need to know about the stage sysroot
617 cargo.env("MIRI_SYSROOT", &miri_sysroot);
618 cargo.env("MIRI_HOST_SYSROOT", sysroot);
619 cargo.env("MIRI", &miri);
621 if builder.config.cmd.bless() {
622 cargo.env("MIRI_BLESS", "Gesundheit");
626 cargo.env("MIRI_TEST_TARGET", target.rustc_target_arg());
627 // Forward test filters.
628 cargo.arg("--").args(builder.config.cmd.test_args());
630 let mut cargo = Command::from(cargo);
631 builder.run(&mut cargo);
633 // # Run `cargo miri test`.
634 // This is just a smoke test (Miri's own CI invokes this in a bunch of different ways and ensures
635 // that we get the desired output), but that is sufficient to make sure that the libtest harness
636 // itself executes properly under Miri.
637 let mut cargo = tool::prepare_tool_cargo(
643 "src/tools/miri/cargo-miri",
644 SourceType::Submodule,
647 cargo.add_rustc_lib_path(builder, compiler);
648 cargo.arg("--").arg("miri").arg("test");
650 .arg("--manifest-path")
651 .arg(builder.src.join("src/tools/miri/test-cargo-miri/Cargo.toml"));
652 cargo.arg("--target").arg(target.rustc_target_arg());
653 cargo.arg("--tests"); // don't run doctests, they are too confused by the staging
654 cargo.arg("--").args(builder.config.cmd.test_args());
656 // Tell `cargo miri` where to find things.
657 cargo.env("MIRI_SYSROOT", &miri_sysroot);
658 cargo.env("MIRI_HOST_SYSROOT", sysroot);
659 cargo.env("MIRI", &miri);
661 cargo.env("RUST_BACKTRACE", "1");
663 let mut cargo = Command::from(cargo);
664 builder.run(&mut cargo);
668 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
669 pub struct CompiletestTest {
670 host: TargetSelection,
673 impl Step for CompiletestTest {
676 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
677 run.path("src/tools/compiletest")
680 fn make_run(run: RunConfig<'_>) {
681 run.builder.ensure(CompiletestTest { host: run.target });
684 /// Runs `cargo test` for compiletest.
685 fn run(self, builder: &Builder<'_>) {
686 let host = self.host;
687 let compiler = builder.compiler(0, host);
689 // We need `ToolStd` for the locally-built sysroot because
690 // compiletest uses unstable features of the `test` crate.
691 builder.ensure(compile::Std::new(compiler, host));
692 let cargo = tool::prepare_tool_cargo(
698 "src/tools/compiletest",
703 try_run(builder, &mut cargo.into());
707 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
710 host: TargetSelection,
713 impl Step for Clippy {
715 const ONLY_HOSTS: bool = true;
716 const DEFAULT: bool = false;
718 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
719 run.path("src/tools/clippy")
722 fn make_run(run: RunConfig<'_>) {
723 run.builder.ensure(Clippy { stage: run.builder.top_stage, host: run.target });
726 /// Runs `cargo test` for clippy.
727 fn run(self, builder: &Builder<'_>) {
728 let stage = self.stage;
729 let host = self.host;
730 let compiler = builder.compiler(stage, host);
733 .ensure(tool::Clippy { compiler, target: self.host, extra_features: Vec::new() })
734 .expect("in-tree tool");
735 let mut cargo = tool::prepare_tool_cargo(
746 cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
747 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
748 let host_libs = builder.stage_out(compiler, Mode::ToolRustc).join(builder.cargo_dir());
749 cargo.env("HOST_LIBS", host_libs);
751 cargo.arg("--").args(builder.config.cmd.test_args());
753 cargo.add_rustc_lib_path(builder, compiler);
755 if builder.try_run(&mut cargo.into()) {
756 // The tests succeeded; nothing to do.
760 if !builder.config.cmd.bless() {
761 crate::detail_exit(1);
764 let mut cargo = builder.cargo(compiler, Mode::ToolRustc, SourceType::InTree, host, "run");
765 cargo.arg("-p").arg("clippy_dev");
766 // clippy_dev gets confused if it can't find `clippy/Cargo.toml`
767 cargo.current_dir(&builder.src.join("src").join("tools").join("clippy"));
768 if builder.config.rust_optimize {
769 cargo.env("PROFILE", "release");
771 cargo.env("PROFILE", "debug");
775 builder.run(&mut cargo.into());
779 fn path_for_cargo(builder: &Builder<'_>, compiler: Compiler) -> OsString {
780 // Configure PATH to find the right rustc. NB. we have to use PATH
781 // and not RUSTC because the Cargo test suite has tests that will
782 // fail if rustc is not spelled `rustc`.
783 let path = builder.sysroot(compiler).join("bin");
784 let old_path = env::var_os("PATH").unwrap_or_default();
785 env::join_paths(iter::once(path).chain(env::split_paths(&old_path))).expect("")
788 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
789 pub struct RustdocTheme {
790 pub compiler: Compiler,
793 impl Step for RustdocTheme {
795 const DEFAULT: bool = true;
796 const ONLY_HOSTS: bool = true;
798 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
799 run.path("src/tools/rustdoc-themes")
802 fn make_run(run: RunConfig<'_>) {
803 let compiler = run.builder.compiler(run.builder.top_stage, run.target);
805 run.builder.ensure(RustdocTheme { compiler });
808 fn run(self, builder: &Builder<'_>) {
809 let rustdoc = builder.bootstrap_out.join("rustdoc");
810 let mut cmd = builder.tool_cmd(Tool::RustdocTheme);
811 cmd.arg(rustdoc.to_str().unwrap())
812 .arg(builder.src.join("src/librustdoc/html/static/css/themes").to_str().unwrap())
813 .env("RUSTC_STAGE", self.compiler.stage.to_string())
814 .env("RUSTC_SYSROOT", builder.sysroot(self.compiler))
815 .env("RUSTDOC_LIBDIR", builder.sysroot_libdir(self.compiler, self.compiler.host))
816 .env("CFG_RELEASE_CHANNEL", &builder.config.channel)
817 .env("RUSTDOC_REAL", builder.rustdoc(self.compiler))
818 .env("RUSTC_BOOTSTRAP", "1");
819 if let Some(linker) = builder.linker(self.compiler.host) {
820 cmd.env("RUSTDOC_LINKER", linker);
822 if builder.is_fuse_ld_lld(self.compiler.host) {
824 "RUSTDOC_LLD_NO_THREADS",
825 util::lld_flag_no_threads(self.compiler.host.contains("windows")),
828 try_run(builder, &mut cmd);
832 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
833 pub struct RustdocJSStd {
834 pub target: TargetSelection,
837 impl Step for RustdocJSStd {
839 const DEFAULT: bool = true;
840 const ONLY_HOSTS: bool = true;
842 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
843 run.suite_path("src/test/rustdoc-js-std")
846 fn make_run(run: RunConfig<'_>) {
847 run.builder.ensure(RustdocJSStd { target: run.target });
850 fn run(self, builder: &Builder<'_>) {
851 if let Some(ref nodejs) = builder.config.nodejs {
852 let mut command = Command::new(nodejs);
854 .arg(builder.src.join("src/tools/rustdoc-js/tester.js"))
857 .arg("--resource-suffix")
858 .arg(&builder.version)
860 .arg(builder.doc_out(self.target))
861 .arg("--test-folder")
862 .arg(builder.src.join("src/test/rustdoc-js-std"));
863 for path in &builder.paths {
865 util::is_valid_test_suite_arg(path, "src/test/rustdoc-js-std", builder)
867 if !p.ends_with(".js") {
868 eprintln!("A non-js file was given: `{}`", path.display());
869 panic!("Cannot run rustdoc-js-std tests");
871 command.arg("--test-file").arg(path);
874 builder.ensure(crate::doc::Std {
876 stage: builder.top_stage,
877 format: DocumentationFormat::HTML,
879 builder.run(&mut command);
881 builder.info("No nodejs found, skipping \"src/test/rustdoc-js-std\" tests");
886 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
887 pub struct RustdocJSNotStd {
888 pub target: TargetSelection,
889 pub compiler: Compiler,
892 impl Step for RustdocJSNotStd {
894 const DEFAULT: bool = true;
895 const ONLY_HOSTS: bool = true;
897 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
898 run.suite_path("src/test/rustdoc-js")
901 fn make_run(run: RunConfig<'_>) {
902 let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
903 run.builder.ensure(RustdocJSNotStd { target: run.target, compiler });
906 fn run(self, builder: &Builder<'_>) {
907 if builder.config.nodejs.is_some() {
908 builder.ensure(Compiletest {
909 compiler: self.compiler,
913 path: "src/test/rustdoc-js",
917 builder.info("No nodejs found, skipping \"src/test/rustdoc-js\" tests");
922 fn get_browser_ui_test_version_inner(npm: &Path, global: bool) -> Option<String> {
923 let mut command = Command::new(&npm);
924 command.arg("list").arg("--parseable").arg("--long").arg("--depth=0");
926 command.arg("--global");
930 .map(|output| String::from_utf8_lossy(&output.stdout).into_owned())
931 .unwrap_or(String::new());
934 .find_map(|l| l.split(':').nth(1)?.strip_prefix("browser-ui-test@"))
935 .map(|v| v.to_owned())
938 fn get_browser_ui_test_version(npm: &Path) -> Option<String> {
939 get_browser_ui_test_version_inner(npm, false)
940 .or_else(|| get_browser_ui_test_version_inner(npm, true))
943 fn compare_browser_ui_test_version(installed_version: &str, src: &Path) {
944 match fs::read_to_string(
945 src.join("src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version"),
948 if v.trim() != installed_version {
950 "⚠️ Installed version of browser-ui-test (`{}`) is different than the \
951 one used in the CI (`{}`)",
955 "You can install this version using `npm update browser-ui-test` or by using \
956 `npm install browser-ui-test@{}`",
961 Err(e) => eprintln!("Couldn't find the CI browser-ui-test version: {:?}", e),
965 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
966 pub struct RustdocGUI {
967 pub target: TargetSelection,
968 pub compiler: Compiler,
971 impl Step for RustdocGUI {
973 const DEFAULT: bool = true;
974 const ONLY_HOSTS: bool = true;
976 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
977 let builder = run.builder;
978 let run = run.suite_path("src/test/rustdoc-gui");
979 run.lazy_default_condition(Box::new(move || {
980 builder.config.nodejs.is_some()
985 .map(|p| get_browser_ui_test_version(p).is_some())
990 fn make_run(run: RunConfig<'_>) {
991 let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
992 run.builder.ensure(RustdocGUI { target: run.target, compiler });
995 fn run(self, builder: &Builder<'_>) {
996 let nodejs = builder.config.nodejs.as_ref().expect("nodejs isn't available");
997 let npm = builder.config.npm.as_ref().expect("npm isn't available");
999 builder.ensure(compile::Std::new(self.compiler, self.target));
1001 // The goal here is to check if the necessary packages are installed, and if not, we
1003 match get_browser_ui_test_version(&npm) {
1005 // We also check the version currently used in CI and emit a warning if it's not the
1007 compare_browser_ui_test_version(&version, &builder.build.src);
1011 "error: rustdoc-gui test suite cannot be run because npm `browser-ui-test` \
1012 dependency is missing",
1015 "If you want to install the `{0}` dependency, run `npm install {0}`",
1018 panic!("Cannot run rustdoc-gui tests");
1022 let out_dir = builder.test_out(self.target).join("rustdoc-gui");
1024 // We remove existing folder to be sure there won't be artifacts remaining.
1025 builder.clear_if_dirty(&out_dir, &builder.rustdoc(self.compiler));
1027 let src_path = builder.build.src.join("src/test/rustdoc-gui/src");
1028 // We generate docs for the libraries present in the rustdoc-gui's src folder.
1029 for entry in src_path.read_dir().expect("read_dir call failed") {
1030 if let Ok(entry) = entry {
1031 let path = entry.path();
1037 let mut cargo = Command::new(&builder.initial_cargo);
1040 .arg("--target-dir")
1042 .env("RUSTC_BOOTSTRAP", "1")
1043 .env("RUSTDOC", builder.rustdoc(self.compiler))
1044 .env("RUSTC", builder.rustc(self.compiler))
1046 // FIXME: implement a `// compile-flags` command or similar
1047 // instead of hard-coding this test
1048 if entry.file_name() == "link_to_definition" {
1049 cargo.env("RUSTDOCFLAGS", "-Zunstable-options --generate-link-to-definition");
1050 } else if entry.file_name() == "scrape_examples" {
1051 cargo.arg("-Zrustdoc-scrape-examples");
1053 builder.run(&mut cargo);
1057 // We now run GUI tests.
1058 let mut command = Command::new(&nodejs);
1060 .arg(builder.build.src.join("src/tools/rustdoc-gui/tester.js"))
1062 .arg(&builder.jobs().to_string())
1063 .arg("--doc-folder")
1064 .arg(out_dir.join("doc"))
1065 .arg("--tests-folder")
1066 .arg(builder.build.src.join("src/test/rustdoc-gui"));
1067 for path in &builder.paths {
1068 if let Some(p) = util::is_valid_test_suite_arg(path, "src/test/rustdoc-gui", builder) {
1069 if !p.ends_with(".goml") {
1070 eprintln!("A non-goml file was given: `{}`", path.display());
1071 panic!("Cannot run rustdoc-gui tests");
1073 if let Some(name) = path.file_name().and_then(|f| f.to_str()) {
1074 command.arg("--file").arg(name);
1078 for test_arg in builder.config.cmd.test_args() {
1079 command.arg(test_arg);
1081 builder.run(&mut command);
1085 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1088 impl Step for Tidy {
1090 const DEFAULT: bool = true;
1091 const ONLY_HOSTS: bool = true;
1093 /// Runs the `tidy` tool.
1095 /// This tool in `src/tools` checks up on various bits and pieces of style and
1096 /// otherwise just implements a few lint-like checks that are specific to the
1097 /// compiler itself.
1099 /// Once tidy passes, this step also runs `fmt --check` if tests are being run
1100 /// for the `dev` or `nightly` channels.
1101 fn run(self, builder: &Builder<'_>) {
1102 let mut cmd = builder.tool_cmd(Tool::Tidy);
1103 cmd.arg(&builder.src);
1104 cmd.arg(&builder.initial_cargo);
1105 cmd.arg(&builder.out);
1106 cmd.arg(builder.jobs().to_string());
1107 if builder.is_verbose() {
1108 cmd.arg("--verbose");
1110 if builder.config.cmd.bless() {
1114 builder.info("tidy check");
1115 try_run(builder, &mut cmd);
1117 if builder.config.channel == "dev" || builder.config.channel == "nightly" {
1118 builder.info("fmt check");
1119 if builder.initial_rustfmt().is_none() {
1120 let inferred_rustfmt_dir = builder.config.initial_rustc.parent().unwrap();
1123 error: no `rustfmt` binary found in {PATH}
1124 info: `rust.channel` is currently set to \"{CHAN}\"
1125 help: if you are testing a beta branch, set `rust.channel` to \"beta\" in the `config.toml` file
1126 help: to skip test's attempt to check tidiness, pass `--exclude src/tools/tidy` to `x.py test`",
1127 PATH = inferred_rustfmt_dir.display(),
1128 CHAN = builder.config.channel,
1130 crate::detail_exit(1);
1132 crate::format::format(&builder, !builder.config.cmd.bless(), &[]);
1136 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1137 run.path("src/tools/tidy")
1140 fn make_run(run: RunConfig<'_>) {
1141 run.builder.ensure(Tidy);
1145 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1146 pub struct ExpandYamlAnchors;
1148 impl Step for ExpandYamlAnchors {
1150 const ONLY_HOSTS: bool = true;
1152 /// Ensure the `generate-ci-config` tool was run locally.
1154 /// The tool in `src/tools` reads the CI definition in `src/ci/builders.yml` and generates the
1155 /// appropriate configuration for all our CI providers. This step ensures the tool was called
1156 /// by the user before committing CI changes.
1157 fn run(self, builder: &Builder<'_>) {
1158 builder.info("Ensuring the YAML anchors in the GitHub Actions config were expanded");
1161 &mut builder.tool_cmd(Tool::ExpandYamlAnchors).arg("check").arg(&builder.src),
1165 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1166 run.path("src/tools/expand-yaml-anchors")
1169 fn make_run(run: RunConfig<'_>) {
1170 run.builder.ensure(ExpandYamlAnchors);
1174 fn testdir(builder: &Builder<'_>, host: TargetSelection) -> PathBuf {
1175 builder.out.join(host.triple).join("test")
1178 macro_rules! default_test {
1179 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
1180 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: false });
1184 macro_rules! default_test_with_compare_mode {
1185 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr,
1186 compare_mode: $compare_mode:expr }) => {
1187 test_with_compare_mode!($name {
1193 compare_mode: $compare_mode
1198 macro_rules! host_test {
1199 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
1200 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: true });
1205 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
1206 host: $host:expr }) => {
1207 test_definitions!($name {
1218 macro_rules! test_with_compare_mode {
1219 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
1220 host: $host:expr, compare_mode: $compare_mode:expr }) => {
1221 test_definitions!($name {
1227 compare_mode: Some($compare_mode)
1232 macro_rules! test_definitions {
1237 default: $default:expr,
1239 compare_mode: $compare_mode:expr
1241 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1243 pub compiler: Compiler,
1244 pub target: TargetSelection,
1247 impl Step for $name {
1249 const DEFAULT: bool = $default;
1250 const ONLY_HOSTS: bool = $host;
1252 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1253 run.suite_path($path)
1256 fn make_run(run: RunConfig<'_>) {
1257 let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
1259 run.builder.ensure($name { compiler, target: run.target });
1262 fn run(self, builder: &Builder<'_>) {
1263 builder.ensure(Compiletest {
1264 compiler: self.compiler,
1265 target: self.target,
1269 compare_mode: $compare_mode,
1276 default_test!(Ui { path: "src/test/ui", mode: "ui", suite: "ui" });
1278 default_test!(RunPassValgrind {
1279 path: "src/test/run-pass-valgrind",
1280 mode: "run-pass-valgrind",
1281 suite: "run-pass-valgrind"
1284 default_test!(MirOpt { path: "src/test/mir-opt", mode: "mir-opt", suite: "mir-opt" });
1286 default_test!(Codegen { path: "src/test/codegen", mode: "codegen", suite: "codegen" });
1288 default_test!(CodegenUnits {
1289 path: "src/test/codegen-units",
1290 mode: "codegen-units",
1291 suite: "codegen-units"
1294 default_test!(Incremental {
1295 path: "src/test/incremental",
1296 mode: "incremental",
1297 suite: "incremental"
1300 default_test_with_compare_mode!(Debuginfo {
1301 path: "src/test/debuginfo",
1304 compare_mode: "split-dwarf"
1307 host_test!(UiFullDeps { path: "src/test/ui-fulldeps", mode: "ui", suite: "ui-fulldeps" });
1309 host_test!(Rustdoc { path: "src/test/rustdoc", mode: "rustdoc", suite: "rustdoc" });
1310 host_test!(RustdocUi { path: "src/test/rustdoc-ui", mode: "ui", suite: "rustdoc-ui" });
1312 host_test!(RustdocJson {
1313 path: "src/test/rustdoc-json",
1314 mode: "rustdoc-json",
1315 suite: "rustdoc-json"
1318 host_test!(Pretty { path: "src/test/pretty", mode: "pretty", suite: "pretty" });
1320 default_test!(RunMake { path: "src/test/run-make", mode: "run-make", suite: "run-make" });
1322 host_test!(RunMakeFullDeps {
1323 path: "src/test/run-make-fulldeps",
1325 suite: "run-make-fulldeps"
1328 default_test!(Assembly { path: "src/test/assembly", mode: "assembly", suite: "assembly" });
1330 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1331 struct Compiletest {
1333 target: TargetSelection,
1335 suite: &'static str,
1337 compare_mode: Option<&'static str>,
1340 impl Step for Compiletest {
1343 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1347 /// Executes the `compiletest` tool to run a suite of tests.
1349 /// Compiles all tests with `compiler` for `target` with the specified
1350 /// compiletest `mode` and `suite` arguments. For example `mode` can be
1351 /// "run-pass" or `suite` can be something like `debuginfo`.
1352 fn run(self, builder: &Builder<'_>) {
1353 if builder.top_stage == 0 && env::var("COMPILETEST_FORCE_STAGE0").is_err() {
1355 error: `--stage 0` runs compiletest on the beta compiler, not your local changes, and will almost always cause tests to fail
1356 help: to test the compiler, use `--stage 1` instead
1357 help: to test the standard library, use `--stage 0 library/std` instead
1358 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`."
1360 crate::detail_exit(1);
1363 let compiler = self.compiler;
1364 let target = self.target;
1365 let mode = self.mode;
1366 let suite = self.suite;
1368 // Path for test suite
1369 let suite_path = self.path;
1371 // Skip codegen tests if they aren't enabled in configuration.
1372 if !builder.config.codegen_tests && suite == "codegen" {
1376 if suite == "debuginfo" {
1378 .ensure(dist::DebuggerScripts { sysroot: builder.sysroot(compiler), host: target });
1381 if suite.ends_with("fulldeps") {
1382 builder.ensure(compile::Rustc::new(compiler, target));
1385 builder.ensure(compile::Std::new(compiler, target));
1386 // ensure that `libproc_macro` is available on the host.
1387 builder.ensure(compile::Std::new(compiler, compiler.host));
1389 // Also provide `rust_test_helpers` for the host.
1390 builder.ensure(native::TestHelpers { target: compiler.host });
1392 // As well as the target, except for plain wasm32, which can't build it
1393 if !target.contains("wasm") || target.contains("emscripten") {
1394 builder.ensure(native::TestHelpers { target });
1397 builder.ensure(RemoteCopyLibs { compiler, target });
1399 let mut cmd = builder.tool_cmd(Tool::Compiletest);
1401 // compiletest currently has... a lot of arguments, so let's just pass all
1404 cmd.arg("--compile-lib-path").arg(builder.rustc_libdir(compiler));
1405 cmd.arg("--run-lib-path").arg(builder.sysroot_libdir(compiler, target));
1406 cmd.arg("--rustc-path").arg(builder.rustc(compiler));
1408 let is_rustdoc = suite.ends_with("rustdoc-ui") || suite.ends_with("rustdoc-js");
1410 // Avoid depending on rustdoc when we don't need it.
1411 if mode == "rustdoc"
1412 || mode == "run-make"
1413 || (mode == "ui" && is_rustdoc)
1414 || mode == "js-doc-test"
1415 || mode == "rustdoc-json"
1417 cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler));
1420 if mode == "rustdoc-json" {
1421 // Use the beta compiler for jsondocck
1422 let json_compiler = compiler.with_stage(0);
1423 cmd.arg("--jsondocck-path")
1424 .arg(builder.ensure(tool::JsonDocCk { compiler: json_compiler, target }));
1425 cmd.arg("--jsondoclint-path")
1426 .arg(builder.ensure(tool::JsonDocLint { compiler: json_compiler, target }));
1429 if mode == "run-make" {
1430 let rust_demangler = builder
1431 .ensure(tool::RustDemangler {
1433 target: compiler.host,
1434 extra_features: Vec::new(),
1436 .expect("in-tree tool");
1437 cmd.arg("--rust-demangler-path").arg(rust_demangler);
1440 cmd.arg("--src-base").arg(builder.src.join("src/test").join(suite));
1441 cmd.arg("--build-base").arg(testdir(builder, compiler.host).join(suite));
1442 cmd.arg("--sysroot-base").arg(builder.sysroot(compiler));
1443 cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target));
1444 cmd.arg("--suite").arg(suite);
1445 cmd.arg("--mode").arg(mode);
1446 cmd.arg("--target").arg(target.rustc_target_arg());
1447 cmd.arg("--host").arg(&*compiler.host.triple);
1448 cmd.arg("--llvm-filecheck").arg(builder.llvm_filecheck(builder.config.build));
1450 if builder.config.cmd.bless() {
1454 if builder.config.cmd.force_rerun() {
1455 cmd.arg("--force-rerun");
1459 builder.config.cmd.compare_mode().or_else(|| {
1460 if builder.config.test_compare_mode { self.compare_mode } else { None }
1463 if let Some(ref pass) = builder.config.cmd.pass() {
1468 if let Some(ref run) = builder.config.cmd.run() {
1473 if let Some(ref nodejs) = builder.config.nodejs {
1474 cmd.arg("--nodejs").arg(nodejs);
1476 if let Some(ref npm) = builder.config.npm {
1477 cmd.arg("--npm").arg(npm);
1479 if builder.config.rust_optimize_tests {
1480 cmd.arg("--optimize-tests");
1482 let mut flags = if is_rustdoc { Vec::new() } else { vec!["-Crpath".to_string()] };
1483 flags.push(format!("-Cdebuginfo={}", builder.config.rust_debuginfo_level_tests));
1484 flags.extend(builder.config.cmd.rustc_args().iter().map(|s| s.to_string()));
1486 if let Some(linker) = builder.linker(target) {
1487 cmd.arg("--linker").arg(linker);
1490 let mut hostflags = flags.clone();
1491 hostflags.push(format!("-Lnative={}", builder.test_helpers_out(compiler.host).display()));
1492 hostflags.extend(builder.lld_flags(compiler.host));
1493 for flag in hostflags {
1494 cmd.arg("--host-rustcflags").arg(flag);
1497 let mut targetflags = flags;
1498 targetflags.push(format!("-Lnative={}", builder.test_helpers_out(target).display()));
1499 targetflags.extend(builder.lld_flags(target));
1500 for flag in targetflags {
1501 cmd.arg("--target-rustcflags").arg(flag);
1504 cmd.arg("--python").arg(builder.python());
1506 if let Some(ref gdb) = builder.config.gdb {
1507 cmd.arg("--gdb").arg(gdb);
1510 let run = |cmd: &mut Command| {
1511 cmd.output().map(|output| {
1512 String::from_utf8_lossy(&output.stdout)
1515 .unwrap_or_else(|| panic!("{:?} failed {:?}", cmd, output))
1519 let lldb_exe = "lldb";
1520 let lldb_version = Command::new(lldb_exe)
1523 .map(|output| String::from_utf8_lossy(&output.stdout).to_string())
1525 if let Some(ref vers) = lldb_version {
1526 cmd.arg("--lldb-version").arg(vers);
1527 let lldb_python_dir = run(Command::new(lldb_exe).arg("-P")).ok();
1528 if let Some(ref dir) = lldb_python_dir {
1529 cmd.arg("--lldb-python-dir").arg(dir);
1533 if util::forcing_clang_based_tests() {
1534 let clang_exe = builder.llvm_out(target).join("bin").join("clang");
1535 cmd.arg("--run-clang-based-tests-with").arg(clang_exe);
1538 for exclude in &builder.config.exclude {
1540 cmd.arg(&exclude.path);
1543 // Get paths from cmd args
1544 let paths = match &builder.config.cmd {
1545 Subcommand::Test { ref paths, .. } => &paths[..],
1549 // Get test-args by striping suite path
1550 let mut test_args: Vec<&str> = paths
1552 .filter_map(|p| util::is_valid_test_suite_arg(p, suite_path, builder))
1555 test_args.append(&mut builder.config.cmd.test_args());
1557 // On Windows, replace forward slashes in test-args by backslashes
1558 // so the correct filters are passed to libtest
1560 let test_args_win: Vec<String> =
1561 test_args.iter().map(|s| s.replace("/", "\\")).collect();
1562 cmd.args(&test_args_win);
1564 cmd.args(&test_args);
1567 if builder.is_verbose() {
1568 cmd.arg("--verbose");
1571 if !builder.config.verbose_tests {
1575 let mut llvm_components_passed = false;
1576 let mut copts_passed = false;
1577 if builder.config.llvm_enabled() {
1578 let native::LlvmResult { llvm_config, .. } =
1579 builder.ensure(native::Llvm { target: builder.config.build });
1580 if !builder.config.dry_run() {
1581 let llvm_version = output(Command::new(&llvm_config).arg("--version"));
1582 let llvm_components = output(Command::new(&llvm_config).arg("--components"));
1583 // Remove trailing newline from llvm-config output.
1584 cmd.arg("--llvm-version")
1585 .arg(llvm_version.trim())
1586 .arg("--llvm-components")
1587 .arg(llvm_components.trim());
1588 llvm_components_passed = true;
1590 if !builder.is_rust_llvm(target) {
1591 cmd.arg("--system-llvm");
1594 // Tests that use compiler libraries may inherit the `-lLLVM` link
1595 // requirement, but the `-L` library path is not propagated across
1596 // separate compilations. We can add LLVM's library path to the
1597 // platform-specific environment variable as a workaround.
1598 if !builder.config.dry_run() && suite.ends_with("fulldeps") {
1599 let llvm_libdir = output(Command::new(&llvm_config).arg("--libdir"));
1600 add_link_lib_path(vec![llvm_libdir.trim().into()], &mut cmd);
1603 // Only pass correct values for these flags for the `run-make` suite as it
1604 // requires that a C++ compiler was configured which isn't always the case.
1605 if !builder.config.dry_run() && matches!(suite, "run-make" | "run-make-fulldeps") {
1606 // The llvm/bin directory contains many useful cross-platform
1607 // tools. Pass the path to run-make tests so they can use them.
1608 let llvm_bin_path = llvm_config
1610 .expect("Expected llvm-config to be contained in directory");
1611 assert!(llvm_bin_path.is_dir());
1612 cmd.arg("--llvm-bin-dir").arg(llvm_bin_path);
1614 // If LLD is available, add it to the PATH
1615 if builder.config.lld_enabled {
1616 let lld_install_root =
1617 builder.ensure(native::Lld { target: builder.config.build });
1619 let lld_bin_path = lld_install_root.join("bin");
1621 let old_path = env::var_os("PATH").unwrap_or_default();
1622 let new_path = env::join_paths(
1623 std::iter::once(lld_bin_path).chain(env::split_paths(&old_path)),
1625 .expect("Could not add LLD bin path to PATH");
1626 cmd.env("PATH", new_path);
1631 // Only pass correct values for these flags for the `run-make` suite as it
1632 // requires that a C++ compiler was configured which isn't always the case.
1633 if !builder.config.dry_run() && matches!(suite, "run-make" | "run-make-fulldeps") {
1635 .arg(builder.cc(target))
1637 .arg(builder.cxx(target).unwrap())
1639 .arg(builder.cflags(target, GitRepo::Rustc, CLang::C).join(" "))
1641 .arg(builder.cflags(target, GitRepo::Rustc, CLang::Cxx).join(" "));
1642 copts_passed = true;
1643 if let Some(ar) = builder.ar(target) {
1644 cmd.arg("--ar").arg(ar);
1648 if !llvm_components_passed {
1649 cmd.arg("--llvm-components").arg("");
1662 if builder.remote_tested(target) {
1663 cmd.arg("--remote-test-client").arg(builder.tool_exe(Tool::RemoteTestClient));
1666 // Running a C compiler on MSVC requires a few env vars to be set, to be
1667 // sure to set them here.
1669 // Note that if we encounter `PATH` we make sure to append to our own `PATH`
1670 // rather than stomp over it.
1671 if target.contains("msvc") {
1672 for &(ref k, ref v) in builder.cc[&target].env() {
1678 cmd.env("RUSTC_BOOTSTRAP", "1");
1679 // Override the rustc version used in symbol hashes to reduce the amount of normalization
1680 // needed when diffing test output.
1681 cmd.env("RUSTC_FORCE_RUSTC_VERSION", "compiletest");
1682 cmd.env("DOC_RUST_LANG_ORG_CHANNEL", builder.doc_rust_lang_org_channel());
1683 builder.add_rust_test_threads(&mut cmd);
1685 if builder.config.sanitizers_enabled(target) {
1686 cmd.env("RUSTC_SANITIZER_SUPPORT", "1");
1689 if builder.config.profiler_enabled(target) {
1690 cmd.env("RUSTC_PROFILER_SUPPORT", "1");
1693 cmd.env("RUST_TEST_TMPDIR", builder.tempdir());
1695 cmd.arg("--adb-path").arg("adb");
1696 cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
1697 if target.contains("android") {
1698 // Assume that cc for this target comes from the android sysroot
1699 cmd.arg("--android-cross-path")
1700 .arg(builder.cc(target).parent().unwrap().parent().unwrap());
1702 cmd.arg("--android-cross-path").arg("");
1705 if builder.config.cmd.rustfix_coverage() {
1706 cmd.arg("--rustfix-coverage");
1709 cmd.env("BOOTSTRAP_CARGO", &builder.initial_cargo);
1711 cmd.arg("--channel").arg(&builder.config.channel);
1713 if let Some(commit) = builder.config.download_rustc_commit() {
1714 cmd.env("FAKE_DOWNLOAD_RUSTC_PREFIX", format!("/rustc/{commit}"));
1717 builder.ci_env.force_coloring_in_ci(&mut cmd);
1719 builder.info(&format!(
1720 "Check compiletest suite={} mode={} ({} -> {})",
1721 suite, mode, &compiler.host, target
1723 let _time = util::timeit(&builder);
1724 try_run(builder, &mut cmd);
1726 if let Some(compare_mode) = compare_mode {
1727 cmd.arg("--compare-mode").arg(compare_mode);
1728 builder.info(&format!(
1729 "Check compiletest suite={} mode={} compare_mode={} ({} -> {})",
1730 suite, mode, compare_mode, &compiler.host, target
1732 let _time = util::timeit(&builder);
1733 try_run(builder, &mut cmd);
1738 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1746 impl Step for BookTest {
1748 const ONLY_HOSTS: bool = true;
1750 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1754 /// Runs the documentation tests for a book in `src/doc`.
1756 /// This uses the `rustdoc` that sits next to `compiler`.
1757 fn run(self, builder: &Builder<'_>) {
1758 // External docs are different from local because:
1759 // - Some books need pre-processing by mdbook before being tested.
1760 // - They need to save their state to toolstate.
1761 // - They are only tested on the "checktools" builders.
1763 // The local docs are tested by default, and we don't want to pay the
1764 // cost of building mdbook, so they use `rustdoc --test` directly.
1765 // Also, the unstable book is special because SUMMARY.md is generated,
1766 // so it is easier to just run `rustdoc` on its files.
1767 if self.is_ext_doc {
1768 self.run_ext_doc(builder);
1770 self.run_local_doc(builder);
1776 /// This runs the equivalent of `mdbook test` (via the rustbook wrapper)
1777 /// which in turn runs `rustdoc --test` on each file in the book.
1778 fn run_ext_doc(self, builder: &Builder<'_>) {
1779 let compiler = self.compiler;
1781 builder.ensure(compile::Std::new(compiler, compiler.host));
1783 // mdbook just executes a binary named "rustdoc", so we need to update
1784 // PATH so that it points to our rustdoc.
1785 let mut rustdoc_path = builder.rustdoc(compiler);
1787 let old_path = env::var_os("PATH").unwrap_or_default();
1788 let new_path = env::join_paths(iter::once(rustdoc_path).chain(env::split_paths(&old_path)))
1789 .expect("could not add rustdoc to PATH");
1791 let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
1792 let path = builder.src.join(&self.path);
1793 // Books often have feature-gated example text.
1794 rustbook_cmd.env("RUSTC_BOOTSTRAP", "1");
1795 rustbook_cmd.env("PATH", new_path).arg("test").arg(path);
1796 builder.add_rust_test_threads(&mut rustbook_cmd);
1797 builder.info(&format!("Testing rustbook {}", self.path.display()));
1798 let _time = util::timeit(&builder);
1799 let toolstate = if try_run(builder, &mut rustbook_cmd) {
1804 builder.save_toolstate(self.name, toolstate);
1807 /// This runs `rustdoc --test` on all `.md` files in the path.
1808 fn run_local_doc(self, builder: &Builder<'_>) {
1809 let compiler = self.compiler;
1811 builder.ensure(compile::Std::new(compiler, compiler.host));
1813 // Do a breadth-first traversal of the `src/doc` directory and just run
1814 // tests for all files that end in `*.md`
1815 let mut stack = vec![builder.src.join(self.path)];
1816 let _time = util::timeit(&builder);
1817 let mut files = Vec::new();
1818 while let Some(p) = stack.pop() {
1820 stack.extend(t!(p.read_dir()).map(|p| t!(p).path()));
1824 if p.extension().and_then(|s| s.to_str()) != Some("md") {
1834 markdown_test(builder, compiler, &file);
1839 macro_rules! test_book {
1840 ($($name:ident, $path:expr, $book_name:expr, default=$default:expr;)+) => {
1842 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1847 impl Step for $name {
1849 const DEFAULT: bool = $default;
1850 const ONLY_HOSTS: bool = true;
1852 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1856 fn make_run(run: RunConfig<'_>) {
1857 run.builder.ensure($name {
1858 compiler: run.builder.compiler(run.builder.top_stage, run.target),
1862 fn run(self, builder: &Builder<'_>) {
1863 builder.ensure(BookTest {
1864 compiler: self.compiler,
1865 path: PathBuf::from($path),
1867 is_ext_doc: !$default,
1876 Nomicon, "src/doc/nomicon", "nomicon", default=false;
1877 Reference, "src/doc/reference", "reference", default=false;
1878 RustdocBook, "src/doc/rustdoc", "rustdoc", default=true;
1879 RustcBook, "src/doc/rustc", "rustc", default=true;
1880 RustByExample, "src/doc/rust-by-example", "rust-by-example", default=false;
1881 EmbeddedBook, "src/doc/embedded-book", "embedded-book", default=false;
1882 TheBook, "src/doc/book", "book", default=false;
1883 UnstableBook, "src/doc/unstable-book", "unstable-book", default=true;
1884 EditionGuide, "src/doc/edition-guide", "edition-guide", default=false;
1887 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1888 pub struct ErrorIndex {
1892 impl Step for ErrorIndex {
1894 const DEFAULT: bool = true;
1895 const ONLY_HOSTS: bool = true;
1897 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1898 run.path("src/tools/error_index_generator")
1901 fn make_run(run: RunConfig<'_>) {
1902 // error_index_generator depends on librustdoc. Use the compiler that
1903 // is normally used to build rustdoc for other tests (like compiletest
1904 // tests in src/test/rustdoc) so that it shares the same artifacts.
1905 let compiler = run.builder.compiler(run.builder.top_stage, run.builder.config.build);
1906 run.builder.ensure(ErrorIndex { compiler });
1909 /// Runs the error index generator tool to execute the tests located in the error
1912 /// The `error_index_generator` tool lives in `src/tools` and is used to
1913 /// generate a markdown file from the error indexes of the code base which is
1914 /// then passed to `rustdoc --test`.
1915 fn run(self, builder: &Builder<'_>) {
1916 let compiler = self.compiler;
1918 let dir = testdir(builder, compiler.host);
1919 t!(fs::create_dir_all(&dir));
1920 let output = dir.join("error-index.md");
1922 let mut tool = tool::ErrorIndex::command(builder);
1923 tool.arg("markdown").arg(&output);
1925 builder.info(&format!("Testing error-index stage{}", compiler.stage));
1926 let _time = util::timeit(&builder);
1927 builder.run_quiet(&mut tool);
1928 // The tests themselves need to link to std, so make sure it is
1930 builder.ensure(compile::Std::new(compiler, compiler.host));
1931 markdown_test(builder, compiler, &output);
1935 fn markdown_test(builder: &Builder<'_>, compiler: Compiler, markdown: &Path) -> bool {
1936 if let Ok(contents) = fs::read_to_string(markdown) {
1937 if !contents.contains("```") {
1942 builder.info(&format!("doc tests for: {}", markdown.display()));
1943 let mut cmd = builder.rustdoc_cmd(compiler);
1944 builder.add_rust_test_threads(&mut cmd);
1945 // allow for unstable options such as new editions
1947 cmd.arg("unstable-options");
1950 cmd.env("RUSTC_BOOTSTRAP", "1");
1952 let test_args = builder.config.cmd.test_args().join(" ");
1953 cmd.arg("--test-args").arg(test_args);
1955 if builder.config.verbose_tests {
1956 try_run(builder, &mut cmd)
1958 try_run_quiet(builder, &mut cmd)
1962 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1963 pub struct RustcGuide;
1965 impl Step for RustcGuide {
1967 const DEFAULT: bool = false;
1968 const ONLY_HOSTS: bool = true;
1970 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1971 run.path("src/doc/rustc-dev-guide")
1974 fn make_run(run: RunConfig<'_>) {
1975 run.builder.ensure(RustcGuide);
1978 fn run(self, builder: &Builder<'_>) {
1979 let relative_path = Path::new("src").join("doc").join("rustc-dev-guide");
1980 builder.update_submodule(&relative_path);
1982 let src = builder.src.join(relative_path);
1983 let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
1984 let toolstate = if try_run(builder, rustbook_cmd.arg("linkcheck").arg(&src)) {
1989 builder.save_toolstate("rustc-dev-guide", toolstate);
1993 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1994 pub struct CrateLibrustc {
1996 target: TargetSelection,
1997 test_kind: TestKind,
1998 crates: Vec<Interned<String>>,
2001 impl Step for CrateLibrustc {
2003 const DEFAULT: bool = true;
2004 const ONLY_HOSTS: bool = true;
2006 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2007 run.crate_or_deps("rustc-main")
2010 fn make_run(run: RunConfig<'_>) {
2011 let builder = run.builder;
2012 let host = run.build_triple();
2013 let compiler = builder.compiler_for(builder.top_stage, host, host);
2017 .map(|p| builder.crate_paths[&p.assert_single_path().path].clone())
2019 let test_kind = builder.kind.into();
2021 builder.ensure(CrateLibrustc { compiler, target: run.target, test_kind, crates });
2024 fn run(self, builder: &Builder<'_>) {
2025 builder.ensure(Crate {
2026 compiler: self.compiler,
2027 target: self.target,
2029 test_kind: self.test_kind,
2030 crates: self.crates,
2035 #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
2037 pub compiler: Compiler,
2038 pub target: TargetSelection,
2040 pub test_kind: TestKind,
2041 pub crates: Vec<Interned<String>>,
2044 impl Step for Crate {
2046 const DEFAULT: bool = true;
2048 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2049 run.crate_or_deps("test")
2052 fn make_run(run: RunConfig<'_>) {
2053 let builder = run.builder;
2054 let host = run.build_triple();
2055 let compiler = builder.compiler_for(builder.top_stage, host, host);
2056 let test_kind = builder.kind.into();
2060 .map(|p| builder.crate_paths[&p.assert_single_path().path].clone())
2063 builder.ensure(Crate { compiler, target: run.target, mode: Mode::Std, test_kind, crates });
2066 /// Runs all unit tests plus documentation tests for a given crate defined
2067 /// by a `Cargo.toml` (single manifest)
2069 /// This is what runs tests for crates like the standard library, compiler, etc.
2070 /// It essentially is the driver for running `cargo test`.
2072 /// Currently this runs all tests for a DAG by passing a bunch of `-p foo`
2073 /// arguments, and those arguments are discovered from `cargo metadata`.
2074 fn run(self, builder: &Builder<'_>) {
2075 let compiler = self.compiler;
2076 let target = self.target;
2077 let mode = self.mode;
2078 let test_kind = self.test_kind;
2080 builder.ensure(compile::Std::new(compiler, target));
2081 builder.ensure(RemoteCopyLibs { compiler, target });
2083 // If we're not doing a full bootstrap but we're testing a stage2
2084 // version of libstd, then what we're actually testing is the libstd
2085 // produced in stage1. Reflect that here by updating the compiler that
2086 // we're working with automatically.
2087 let compiler = builder.compiler_for(compiler.stage, compiler.host, target);
2090 builder.cargo(compiler, mode, SourceType::InTree, target, test_kind.subcommand());
2093 compile::std_cargo(builder, target, compiler.stage, &mut cargo);
2096 compile::rustc_cargo(builder, &mut cargo, target);
2098 _ => panic!("can only test libraries"),
2101 // Build up the base `cargo test` command.
2103 // Pass in some standard flags then iterate over the graph we've discovered
2104 // in `cargo metadata` with the maps above and figure out what `-p`
2105 // arguments need to get passed.
2106 if test_kind.subcommand() == "test" && !builder.fail_fast {
2107 cargo.arg("--no-fail-fast");
2109 match builder.doc_tests {
2114 cargo.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
2119 for krate in &self.crates {
2120 cargo.arg("-p").arg(krate);
2123 // The tests are going to run with the *target* libraries, so we need to
2124 // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
2126 // Note that to run the compiler we need to run with the *host* libraries,
2127 // but our wrapper scripts arrange for that to be the case anyway.
2128 let mut dylib_path = dylib_path();
2129 dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
2130 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
2133 cargo.args(&builder.config.cmd.test_args());
2135 if !builder.config.verbose_tests {
2136 cargo.arg("--quiet");
2139 if target.contains("emscripten") {
2141 format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)),
2142 builder.config.nodejs.as_ref().expect("nodejs not configured"),
2144 } else if target.starts_with("wasm32") {
2145 let node = builder.config.nodejs.as_ref().expect("nodejs not configured");
2147 format!("{} {}/src/etc/wasm32-shim.js", node.display(), builder.src.display());
2148 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)), &runner);
2149 } else if builder.remote_tested(target) {
2151 format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)),
2152 format!("{} run 0", builder.tool_exe(Tool::RemoteTestClient).display()),
2156 builder.info(&format!(
2157 "{} {:?} stage{} ({} -> {})",
2158 test_kind, self.crates, compiler.stage, &compiler.host, target
2160 let _time = util::timeit(&builder);
2161 try_run(builder, &mut cargo.into());
2165 /// Rustdoc is special in various ways, which is why this step is different from `Crate`.
2166 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2167 pub struct CrateRustdoc {
2168 host: TargetSelection,
2169 test_kind: TestKind,
2172 impl Step for CrateRustdoc {
2174 const DEFAULT: bool = true;
2175 const ONLY_HOSTS: bool = true;
2177 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2178 run.paths(&["src/librustdoc", "src/tools/rustdoc"])
2181 fn make_run(run: RunConfig<'_>) {
2182 let builder = run.builder;
2184 let test_kind = builder.kind.into();
2186 builder.ensure(CrateRustdoc { host: run.target, test_kind });
2189 fn run(self, builder: &Builder<'_>) {
2190 let test_kind = self.test_kind;
2191 let target = self.host;
2193 let compiler = if builder.download_rustc() {
2194 builder.compiler(builder.top_stage, target)
2196 // Use the previous stage compiler to reuse the artifacts that are
2197 // created when running compiletest for src/test/rustdoc. If this used
2198 // `compiler`, then it would cause rustdoc to be built *again*, which
2199 // isn't really necessary.
2200 builder.compiler_for(builder.top_stage, target, target)
2202 builder.ensure(compile::Rustc::new(compiler, target));
2204 let mut cargo = tool::prepare_tool_cargo(
2209 test_kind.subcommand(),
2210 "src/tools/rustdoc",
2214 if test_kind.subcommand() == "test" && !builder.fail_fast {
2215 cargo.arg("--no-fail-fast");
2217 match builder.doc_tests {
2222 cargo.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
2227 cargo.arg("-p").arg("rustdoc:0.0.0");
2230 cargo.args(&builder.config.cmd.test_args());
2232 if self.host.contains("musl") {
2233 cargo.arg("'-Ctarget-feature=-crt-static'");
2236 // This is needed for running doctests on librustdoc. This is a bit of
2237 // an unfortunate interaction with how bootstrap works and how cargo
2238 // sets up the dylib path, and the fact that the doctest (in
2239 // html/markdown.rs) links to rustc-private libs. For stage1, the
2240 // compiler host dylibs (in stage1/lib) are not the same as the target
2241 // dylibs (in stage1/lib/rustlib/...). This is different from a normal
2242 // rust distribution where they are the same.
2244 // On the cargo side, normal tests use `target_process` which handles
2245 // setting up the dylib for a *target* (stage1/lib/rustlib/... in this
2246 // case). However, for doctests it uses `rustdoc_process` which only
2247 // sets up the dylib path for the *host* (stage1/lib), which is the
2250 // Recall that we special-cased `compiler_for(top_stage)` above, so we always use stage1.
2252 // It should be considered to just stop running doctests on
2253 // librustdoc. There is only one test, and it doesn't look too
2254 // important. There might be other ways to avoid this, but it seems
2255 // pretty convoluted.
2257 // See also https://github.com/rust-lang/rust/issues/13983 where the
2258 // host vs target dylibs for rustdoc are consistently tricky to deal
2261 // Note that this set the host libdir for `download_rustc`, which uses a normal rust distribution.
2262 let libdir = if builder.download_rustc() {
2263 builder.rustc_libdir(compiler)
2265 builder.sysroot_libdir(compiler, target).to_path_buf()
2267 let mut dylib_path = dylib_path();
2268 dylib_path.insert(0, PathBuf::from(&*libdir));
2269 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
2271 if !builder.config.verbose_tests {
2272 cargo.arg("--quiet");
2275 builder.info(&format!(
2276 "{} rustdoc stage{} ({} -> {})",
2277 test_kind, compiler.stage, &compiler.host, target
2279 let _time = util::timeit(&builder);
2281 try_run(builder, &mut cargo.into());
2285 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2286 pub struct CrateRustdocJsonTypes {
2287 host: TargetSelection,
2288 test_kind: TestKind,
2291 impl Step for CrateRustdocJsonTypes {
2293 const DEFAULT: bool = true;
2294 const ONLY_HOSTS: bool = true;
2296 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2297 run.path("src/rustdoc-json-types")
2300 fn make_run(run: RunConfig<'_>) {
2301 let builder = run.builder;
2303 let test_kind = builder.kind.into();
2305 builder.ensure(CrateRustdocJsonTypes { host: run.target, test_kind });
2308 fn run(self, builder: &Builder<'_>) {
2309 let test_kind = self.test_kind;
2310 let target = self.host;
2312 // Use the previous stage compiler to reuse the artifacts that are
2313 // created when running compiletest for src/test/rustdoc. If this used
2314 // `compiler`, then it would cause rustdoc to be built *again*, which
2315 // isn't really necessary.
2316 let compiler = builder.compiler_for(builder.top_stage, target, target);
2317 builder.ensure(compile::Rustc::new(compiler, target));
2319 let mut cargo = tool::prepare_tool_cargo(
2324 test_kind.subcommand(),
2325 "src/rustdoc-json-types",
2329 if test_kind.subcommand() == "test" && !builder.fail_fast {
2330 cargo.arg("--no-fail-fast");
2333 cargo.arg("-p").arg("rustdoc-json-types");
2336 cargo.args(&builder.config.cmd.test_args());
2338 if self.host.contains("musl") {
2339 cargo.arg("'-Ctarget-feature=-crt-static'");
2342 if !builder.config.verbose_tests {
2343 cargo.arg("--quiet");
2346 builder.info(&format!(
2347 "{} rustdoc-json-types stage{} ({} -> {})",
2348 test_kind, compiler.stage, &compiler.host, target
2350 let _time = util::timeit(&builder);
2352 try_run(builder, &mut cargo.into());
2356 /// Some test suites are run inside emulators or on remote devices, and most
2357 /// of our test binaries are linked dynamically which means we need to ship
2358 /// the standard library and such to the emulator ahead of time. This step
2359 /// represents this and is a dependency of all test suites.
2361 /// Most of the time this is a no-op. For some steps such as shipping data to
2362 /// QEMU we have to build our own tools so we've got conditional dependencies
2363 /// on those programs as well. Note that the remote test client is built for
2364 /// the build target (us) and the server is built for the target.
2365 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2366 pub struct RemoteCopyLibs {
2368 target: TargetSelection,
2371 impl Step for RemoteCopyLibs {
2374 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2378 fn run(self, builder: &Builder<'_>) {
2379 let compiler = self.compiler;
2380 let target = self.target;
2381 if !builder.remote_tested(target) {
2385 builder.ensure(compile::Std::new(compiler, target));
2387 builder.info(&format!("REMOTE copy libs to emulator ({})", target));
2389 let server = builder.ensure(tool::RemoteTestServer { compiler, target });
2391 // Spawn the emulator and wait for it to come online
2392 let tool = builder.tool_exe(Tool::RemoteTestClient);
2393 let mut cmd = Command::new(&tool);
2394 cmd.arg("spawn-emulator").arg(target.triple).arg(&server).arg(builder.tempdir());
2395 if let Some(rootfs) = builder.qemu_rootfs(target) {
2398 builder.run(&mut cmd);
2400 // Push all our dylibs to the emulator
2401 for f in t!(builder.sysroot_libdir(compiler, target).read_dir()) {
2403 let name = f.file_name().into_string().unwrap();
2404 if util::is_dylib(&name) {
2405 builder.run(Command::new(&tool).arg("push").arg(f.path()));
2411 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2412 pub struct Distcheck;
2414 impl Step for Distcheck {
2417 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2418 run.alias("distcheck")
2421 fn make_run(run: RunConfig<'_>) {
2422 run.builder.ensure(Distcheck);
2425 /// Runs "distcheck", a 'make check' from a tarball
2426 fn run(self, builder: &Builder<'_>) {
2427 builder.info("Distcheck");
2428 let dir = builder.tempdir().join("distcheck");
2429 let _ = fs::remove_dir_all(&dir);
2430 t!(fs::create_dir_all(&dir));
2432 // Guarantee that these are built before we begin running.
2433 builder.ensure(dist::PlainSourceTarball);
2434 builder.ensure(dist::Src);
2436 let mut cmd = Command::new("tar");
2438 .arg(builder.ensure(dist::PlainSourceTarball).tarball())
2439 .arg("--strip-components=1")
2441 builder.run(&mut cmd);
2443 Command::new("./configure")
2444 .args(&builder.config.configure_args)
2445 .arg("--enable-vendor")
2449 Command::new(util::make(&builder.config.build.triple)).arg("check").current_dir(&dir),
2452 // Now make sure that rust-src has all of libstd's dependencies
2453 builder.info("Distcheck rust-src");
2454 let dir = builder.tempdir().join("distcheck-src");
2455 let _ = fs::remove_dir_all(&dir);
2456 t!(fs::create_dir_all(&dir));
2458 let mut cmd = Command::new("tar");
2460 .arg(builder.ensure(dist::Src).tarball())
2461 .arg("--strip-components=1")
2463 builder.run(&mut cmd);
2465 let toml = dir.join("rust-src/lib/rustlib/src/rust/library/std/Cargo.toml");
2467 Command::new(&builder.initial_cargo)
2468 .arg("generate-lockfile")
2469 .arg("--manifest-path")
2476 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2477 pub struct Bootstrap;
2479 impl Step for Bootstrap {
2481 const DEFAULT: bool = true;
2482 const ONLY_HOSTS: bool = true;
2484 /// Tests the build system itself.
2485 fn run(self, builder: &Builder<'_>) {
2486 let mut check_bootstrap = Command::new(&builder.python());
2487 check_bootstrap.arg("bootstrap_test.py").current_dir(builder.src.join("src/bootstrap/"));
2488 try_run(builder, &mut check_bootstrap);
2490 let mut cmd = Command::new(&builder.initial_cargo);
2492 .current_dir(builder.src.join("src/bootstrap"))
2493 .env("RUSTFLAGS", "-Cdebuginfo=2")
2494 .env("CARGO_TARGET_DIR", builder.out.join("bootstrap"))
2495 .env("RUSTC_BOOTSTRAP", "1")
2496 .env("RUSTDOC", builder.rustdoc(builder.compiler(0, builder.build.build)))
2497 .env("RUSTC", &builder.initial_rustc);
2498 if let Some(flags) = option_env!("RUSTFLAGS") {
2499 // Use the same rustc flags for testing as for "normal" compilation,
2500 // so that Cargo doesn’t recompile the entire dependency graph every time:
2501 // https://github.com/rust-lang/rust/issues/49215
2502 cmd.env("RUSTFLAGS", flags);
2504 if !builder.fail_fast {
2505 cmd.arg("--no-fail-fast");
2507 match builder.doc_tests {
2512 cmd.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
2517 cmd.arg("--").args(&builder.config.cmd.test_args());
2518 // rustbuild tests are racy on directory creation so just run them one at a time.
2519 // Since there's not many this shouldn't be a problem.
2520 cmd.arg("--test-threads=1");
2521 try_run(builder, &mut cmd);
2524 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2525 run.path("src/bootstrap")
2528 fn make_run(run: RunConfig<'_>) {
2529 run.builder.ensure(Bootstrap);
2533 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2534 pub struct TierCheck {
2535 pub compiler: Compiler,
2538 impl Step for TierCheck {
2540 const DEFAULT: bool = true;
2541 const ONLY_HOSTS: bool = true;
2543 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2544 run.path("src/tools/tier-check")
2547 fn make_run(run: RunConfig<'_>) {
2549 run.builder.compiler_for(run.builder.top_stage, run.builder.build.build, run.target);
2550 run.builder.ensure(TierCheck { compiler });
2553 /// Tests the Platform Support page in the rustc book.
2554 fn run(self, builder: &Builder<'_>) {
2555 builder.ensure(compile::Std::new(self.compiler, self.compiler.host));
2556 let mut cargo = tool::prepare_tool_cargo(
2562 "src/tools/tier-check",
2566 cargo.arg(builder.src.join("src/doc/rustc/src/platform-support.md"));
2567 cargo.arg(&builder.rustc(self.compiler));
2568 if builder.is_verbose() {
2569 cargo.arg("--verbose");
2572 builder.info("platform support check");
2573 try_run(builder, &mut cargo.into());
2577 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2578 pub struct ReplacePlaceholderTest;
2580 impl Step for ReplacePlaceholderTest {
2582 const ONLY_HOSTS: bool = true;
2583 const DEFAULT: bool = true;
2585 /// Ensure the version placeholder replacement tool builds
2586 fn run(self, builder: &Builder<'_>) {
2587 builder.info("build check for version replacement placeholder");
2589 // Test the version placeholder replacement tool itself.
2590 let bootstrap_host = builder.config.build;
2591 let compiler = builder.compiler(0, bootstrap_host);
2592 let cargo = tool::prepare_tool_cargo(
2595 Mode::ToolBootstrap,
2598 "src/tools/replace-version-placeholder",
2602 try_run(builder, &mut cargo.into());
2605 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2606 run.path("src/tools/replace-version-placeholder")
2609 fn make_run(run: RunConfig<'_>) {
2610 run.builder.ensure(Self);
2614 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2615 pub struct LintDocs {
2616 pub compiler: Compiler,
2617 pub target: TargetSelection,
2620 impl Step for LintDocs {
2622 const DEFAULT: bool = true;
2623 const ONLY_HOSTS: bool = true;
2625 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2626 run.path("src/tools/lint-docs")
2629 fn make_run(run: RunConfig<'_>) {
2630 run.builder.ensure(LintDocs {
2631 compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
2636 /// Tests that the lint examples in the rustc book generate the correct
2637 /// lints and have the expected format.
2638 fn run(self, builder: &Builder<'_>) {
2639 builder.ensure(crate::doc::RustcBook {
2640 compiler: self.compiler,
2641 target: self.target,