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=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 llvm_config = builder.ensure(native::Llvm { target: builder.config.build });
1579 if !builder.config.dry_run() {
1580 let llvm_version = output(Command::new(&llvm_config).arg("--version"));
1581 let llvm_components = output(Command::new(&llvm_config).arg("--components"));
1582 // Remove trailing newline from llvm-config output.
1583 cmd.arg("--llvm-version")
1584 .arg(llvm_version.trim())
1585 .arg("--llvm-components")
1586 .arg(llvm_components.trim());
1587 llvm_components_passed = true;
1589 if !builder.is_rust_llvm(target) {
1590 cmd.arg("--system-llvm");
1593 // Tests that use compiler libraries may inherit the `-lLLVM` link
1594 // requirement, but the `-L` library path is not propagated across
1595 // separate compilations. We can add LLVM's library path to the
1596 // platform-specific environment variable as a workaround.
1597 if !builder.config.dry_run() && suite.ends_with("fulldeps") {
1598 let llvm_libdir = output(Command::new(&llvm_config).arg("--libdir"));
1599 add_link_lib_path(vec![llvm_libdir.trim().into()], &mut cmd);
1602 // Only pass correct values for these flags for the `run-make` suite as it
1603 // requires that a C++ compiler was configured which isn't always the case.
1604 if !builder.config.dry_run() && matches!(suite, "run-make" | "run-make-fulldeps") {
1605 // The llvm/bin directory contains many useful cross-platform
1606 // tools. Pass the path to run-make tests so they can use them.
1607 let llvm_bin_path = llvm_config
1609 .expect("Expected llvm-config to be contained in directory");
1610 assert!(llvm_bin_path.is_dir());
1611 cmd.arg("--llvm-bin-dir").arg(llvm_bin_path);
1613 // If LLD is available, add it to the PATH
1614 if builder.config.lld_enabled {
1615 let lld_install_root =
1616 builder.ensure(native::Lld { target: builder.config.build });
1618 let lld_bin_path = lld_install_root.join("bin");
1620 let old_path = env::var_os("PATH").unwrap_or_default();
1621 let new_path = env::join_paths(
1622 std::iter::once(lld_bin_path).chain(env::split_paths(&old_path)),
1624 .expect("Could not add LLD bin path to PATH");
1625 cmd.env("PATH", new_path);
1630 // Only pass correct values for these flags for the `run-make` suite as it
1631 // requires that a C++ compiler was configured which isn't always the case.
1632 if !builder.config.dry_run() && matches!(suite, "run-make" | "run-make-fulldeps") {
1634 .arg(builder.cc(target))
1636 .arg(builder.cxx(target).unwrap())
1638 .arg(builder.cflags(target, GitRepo::Rustc, CLang::C).join(" "))
1640 .arg(builder.cflags(target, GitRepo::Rustc, CLang::Cxx).join(" "));
1641 copts_passed = true;
1642 if let Some(ar) = builder.ar(target) {
1643 cmd.arg("--ar").arg(ar);
1647 if !llvm_components_passed {
1648 cmd.arg("--llvm-components").arg("");
1661 if builder.remote_tested(target) {
1662 cmd.arg("--remote-test-client").arg(builder.tool_exe(Tool::RemoteTestClient));
1665 // Running a C compiler on MSVC requires a few env vars to be set, to be
1666 // sure to set them here.
1668 // Note that if we encounter `PATH` we make sure to append to our own `PATH`
1669 // rather than stomp over it.
1670 if target.contains("msvc") {
1671 for &(ref k, ref v) in builder.cc[&target].env() {
1677 cmd.env("RUSTC_BOOTSTRAP", "1");
1678 // Override the rustc version used in symbol hashes to reduce the amount of normalization
1679 // needed when diffing test output.
1680 cmd.env("RUSTC_FORCE_RUSTC_VERSION", "compiletest");
1681 cmd.env("DOC_RUST_LANG_ORG_CHANNEL", builder.doc_rust_lang_org_channel());
1682 builder.add_rust_test_threads(&mut cmd);
1684 if builder.config.sanitizers_enabled(target) {
1685 cmd.env("RUSTC_SANITIZER_SUPPORT", "1");
1688 if builder.config.profiler_enabled(target) {
1689 cmd.env("RUSTC_PROFILER_SUPPORT", "1");
1692 cmd.env("RUST_TEST_TMPDIR", builder.tempdir());
1694 cmd.arg("--adb-path").arg("adb");
1695 cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
1696 if target.contains("android") {
1697 // Assume that cc for this target comes from the android sysroot
1698 cmd.arg("--android-cross-path")
1699 .arg(builder.cc(target).parent().unwrap().parent().unwrap());
1701 cmd.arg("--android-cross-path").arg("");
1704 if builder.config.cmd.rustfix_coverage() {
1705 cmd.arg("--rustfix-coverage");
1708 cmd.env("BOOTSTRAP_CARGO", &builder.initial_cargo);
1710 cmd.arg("--channel").arg(&builder.config.channel);
1712 if let Some(commit) = builder.config.download_rustc_commit() {
1713 cmd.env("FAKE_DOWNLOAD_RUSTC_PREFIX", format!("/rustc/{commit}"));
1716 builder.ci_env.force_coloring_in_ci(&mut cmd);
1718 builder.info(&format!(
1719 "Check compiletest suite={} mode={} ({} -> {})",
1720 suite, mode, &compiler.host, target
1722 let _time = util::timeit(&builder);
1723 try_run(builder, &mut cmd);
1725 if let Some(compare_mode) = compare_mode {
1726 cmd.arg("--compare-mode").arg(compare_mode);
1727 builder.info(&format!(
1728 "Check compiletest suite={} mode={} compare_mode={} ({} -> {})",
1729 suite, mode, compare_mode, &compiler.host, target
1731 let _time = util::timeit(&builder);
1732 try_run(builder, &mut cmd);
1737 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1745 impl Step for BookTest {
1747 const ONLY_HOSTS: bool = true;
1749 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1753 /// Runs the documentation tests for a book in `src/doc`.
1755 /// This uses the `rustdoc` that sits next to `compiler`.
1756 fn run(self, builder: &Builder<'_>) {
1757 // External docs are different from local because:
1758 // - Some books need pre-processing by mdbook before being tested.
1759 // - They need to save their state to toolstate.
1760 // - They are only tested on the "checktools" builders.
1762 // The local docs are tested by default, and we don't want to pay the
1763 // cost of building mdbook, so they use `rustdoc --test` directly.
1764 // Also, the unstable book is special because SUMMARY.md is generated,
1765 // so it is easier to just run `rustdoc` on its files.
1766 if self.is_ext_doc {
1767 self.run_ext_doc(builder);
1769 self.run_local_doc(builder);
1775 /// This runs the equivalent of `mdbook test` (via the rustbook wrapper)
1776 /// which in turn runs `rustdoc --test` on each file in the book.
1777 fn run_ext_doc(self, builder: &Builder<'_>) {
1778 let compiler = self.compiler;
1780 builder.ensure(compile::Std::new(compiler, compiler.host));
1782 // mdbook just executes a binary named "rustdoc", so we need to update
1783 // PATH so that it points to our rustdoc.
1784 let mut rustdoc_path = builder.rustdoc(compiler);
1786 let old_path = env::var_os("PATH").unwrap_or_default();
1787 let new_path = env::join_paths(iter::once(rustdoc_path).chain(env::split_paths(&old_path)))
1788 .expect("could not add rustdoc to PATH");
1790 let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
1791 let path = builder.src.join(&self.path);
1792 // Books often have feature-gated example text.
1793 rustbook_cmd.env("RUSTC_BOOTSTRAP", "1");
1794 rustbook_cmd.env("PATH", new_path).arg("test").arg(path);
1795 builder.add_rust_test_threads(&mut rustbook_cmd);
1796 builder.info(&format!("Testing rustbook {}", self.path.display()));
1797 let _time = util::timeit(&builder);
1798 let toolstate = if try_run(builder, &mut rustbook_cmd) {
1803 builder.save_toolstate(self.name, toolstate);
1806 /// This runs `rustdoc --test` on all `.md` files in the path.
1807 fn run_local_doc(self, builder: &Builder<'_>) {
1808 let compiler = self.compiler;
1810 builder.ensure(compile::Std::new(compiler, compiler.host));
1812 // Do a breadth-first traversal of the `src/doc` directory and just run
1813 // tests for all files that end in `*.md`
1814 let mut stack = vec![builder.src.join(self.path)];
1815 let _time = util::timeit(&builder);
1816 let mut files = Vec::new();
1817 while let Some(p) = stack.pop() {
1819 stack.extend(t!(p.read_dir()).map(|p| t!(p).path()));
1823 if p.extension().and_then(|s| s.to_str()) != Some("md") {
1833 markdown_test(builder, compiler, &file);
1838 macro_rules! test_book {
1839 ($($name:ident, $path:expr, $book_name:expr, default=$default:expr;)+) => {
1841 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1846 impl Step for $name {
1848 const DEFAULT: bool = $default;
1849 const ONLY_HOSTS: bool = true;
1851 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1855 fn make_run(run: RunConfig<'_>) {
1856 run.builder.ensure($name {
1857 compiler: run.builder.compiler(run.builder.top_stage, run.target),
1861 fn run(self, builder: &Builder<'_>) {
1862 builder.ensure(BookTest {
1863 compiler: self.compiler,
1864 path: PathBuf::from($path),
1866 is_ext_doc: !$default,
1875 Nomicon, "src/doc/nomicon", "nomicon", default=false;
1876 Reference, "src/doc/reference", "reference", default=false;
1877 RustdocBook, "src/doc/rustdoc", "rustdoc", default=true;
1878 RustcBook, "src/doc/rustc", "rustc", default=true;
1879 RustByExample, "src/doc/rust-by-example", "rust-by-example", default=false;
1880 EmbeddedBook, "src/doc/embedded-book", "embedded-book", default=false;
1881 TheBook, "src/doc/book", "book", default=false;
1882 UnstableBook, "src/doc/unstable-book", "unstable-book", default=true;
1883 EditionGuide, "src/doc/edition-guide", "edition-guide", default=false;
1886 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1887 pub struct ErrorIndex {
1891 impl Step for ErrorIndex {
1893 const DEFAULT: bool = true;
1894 const ONLY_HOSTS: bool = true;
1896 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1897 run.path("src/tools/error_index_generator")
1900 fn make_run(run: RunConfig<'_>) {
1901 // error_index_generator depends on librustdoc. Use the compiler that
1902 // is normally used to build rustdoc for other tests (like compiletest
1903 // tests in src/test/rustdoc) so that it shares the same artifacts.
1904 let compiler = run.builder.compiler(run.builder.top_stage, run.builder.config.build);
1905 run.builder.ensure(ErrorIndex { compiler });
1908 /// Runs the error index generator tool to execute the tests located in the error
1911 /// The `error_index_generator` tool lives in `src/tools` and is used to
1912 /// generate a markdown file from the error indexes of the code base which is
1913 /// then passed to `rustdoc --test`.
1914 fn run(self, builder: &Builder<'_>) {
1915 let compiler = self.compiler;
1917 let dir = testdir(builder, compiler.host);
1918 t!(fs::create_dir_all(&dir));
1919 let output = dir.join("error-index.md");
1921 let mut tool = tool::ErrorIndex::command(builder);
1922 tool.arg("markdown").arg(&output);
1924 builder.info(&format!("Testing error-index stage{}", compiler.stage));
1925 let _time = util::timeit(&builder);
1926 builder.run_quiet(&mut tool);
1927 // The tests themselves need to link to std, so make sure it is
1929 builder.ensure(compile::Std::new(compiler, compiler.host));
1930 markdown_test(builder, compiler, &output);
1934 fn markdown_test(builder: &Builder<'_>, compiler: Compiler, markdown: &Path) -> bool {
1935 if let Ok(contents) = fs::read_to_string(markdown) {
1936 if !contents.contains("```") {
1941 builder.info(&format!("doc tests for: {}", markdown.display()));
1942 let mut cmd = builder.rustdoc_cmd(compiler);
1943 builder.add_rust_test_threads(&mut cmd);
1944 // allow for unstable options such as new editions
1946 cmd.arg("unstable-options");
1949 cmd.env("RUSTC_BOOTSTRAP", "1");
1951 let test_args = builder.config.cmd.test_args().join(" ");
1952 cmd.arg("--test-args").arg(test_args);
1954 if builder.config.verbose_tests {
1955 try_run(builder, &mut cmd)
1957 try_run_quiet(builder, &mut cmd)
1961 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1962 pub struct RustcGuide;
1964 impl Step for RustcGuide {
1966 const DEFAULT: bool = false;
1967 const ONLY_HOSTS: bool = true;
1969 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1970 run.path("src/doc/rustc-dev-guide")
1973 fn make_run(run: RunConfig<'_>) {
1974 run.builder.ensure(RustcGuide);
1977 fn run(self, builder: &Builder<'_>) {
1978 let relative_path = Path::new("src").join("doc").join("rustc-dev-guide");
1979 builder.update_submodule(&relative_path);
1981 let src = builder.src.join(relative_path);
1982 let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
1983 let toolstate = if try_run(builder, rustbook_cmd.arg("linkcheck").arg(&src)) {
1988 builder.save_toolstate("rustc-dev-guide", toolstate);
1992 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1993 pub struct CrateLibrustc {
1995 target: TargetSelection,
1996 test_kind: TestKind,
1997 crates: Vec<Interned<String>>,
2000 impl Step for CrateLibrustc {
2002 const DEFAULT: bool = true;
2003 const ONLY_HOSTS: bool = true;
2005 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2006 run.crate_or_deps("rustc-main")
2009 fn make_run(run: RunConfig<'_>) {
2010 let builder = run.builder;
2011 let host = run.build_triple();
2012 let compiler = builder.compiler_for(builder.top_stage, host, host);
2016 .map(|p| builder.crate_paths[&p.assert_single_path().path].clone())
2018 let test_kind = builder.kind.into();
2020 builder.ensure(CrateLibrustc { compiler, target: run.target, test_kind, crates });
2023 fn run(self, builder: &Builder<'_>) {
2024 builder.ensure(Crate {
2025 compiler: self.compiler,
2026 target: self.target,
2028 test_kind: self.test_kind,
2029 crates: self.crates,
2034 #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
2036 pub compiler: Compiler,
2037 pub target: TargetSelection,
2039 pub test_kind: TestKind,
2040 pub crates: Vec<Interned<String>>,
2043 impl Step for Crate {
2045 const DEFAULT: bool = true;
2047 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2048 run.crate_or_deps("test")
2051 fn make_run(run: RunConfig<'_>) {
2052 let builder = run.builder;
2053 let host = run.build_triple();
2054 let compiler = builder.compiler_for(builder.top_stage, host, host);
2055 let test_kind = builder.kind.into();
2059 .map(|p| builder.crate_paths[&p.assert_single_path().path].clone())
2062 builder.ensure(Crate { compiler, target: run.target, mode: Mode::Std, test_kind, crates });
2065 /// Runs all unit tests plus documentation tests for a given crate defined
2066 /// by a `Cargo.toml` (single manifest)
2068 /// This is what runs tests for crates like the standard library, compiler, etc.
2069 /// It essentially is the driver for running `cargo test`.
2071 /// Currently this runs all tests for a DAG by passing a bunch of `-p foo`
2072 /// arguments, and those arguments are discovered from `cargo metadata`.
2073 fn run(self, builder: &Builder<'_>) {
2074 let compiler = self.compiler;
2075 let target = self.target;
2076 let mode = self.mode;
2077 let test_kind = self.test_kind;
2079 builder.ensure(compile::Std::new(compiler, target));
2080 builder.ensure(RemoteCopyLibs { compiler, target });
2082 // If we're not doing a full bootstrap but we're testing a stage2
2083 // version of libstd, then what we're actually testing is the libstd
2084 // produced in stage1. Reflect that here by updating the compiler that
2085 // we're working with automatically.
2086 let compiler = builder.compiler_for(compiler.stage, compiler.host, target);
2089 builder.cargo(compiler, mode, SourceType::InTree, target, test_kind.subcommand());
2092 compile::std_cargo(builder, target, compiler.stage, &mut cargo);
2095 compile::rustc_cargo(builder, &mut cargo, target);
2097 _ => panic!("can only test libraries"),
2100 // Build up the base `cargo test` command.
2102 // Pass in some standard flags then iterate over the graph we've discovered
2103 // in `cargo metadata` with the maps above and figure out what `-p`
2104 // arguments need to get passed.
2105 if test_kind.subcommand() == "test" && !builder.fail_fast {
2106 cargo.arg("--no-fail-fast");
2108 match builder.doc_tests {
2113 cargo.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
2118 for krate in &self.crates {
2119 cargo.arg("-p").arg(krate);
2122 // The tests are going to run with the *target* libraries, so we need to
2123 // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
2125 // Note that to run the compiler we need to run with the *host* libraries,
2126 // but our wrapper scripts arrange for that to be the case anyway.
2127 let mut dylib_path = dylib_path();
2128 dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
2129 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
2132 cargo.args(&builder.config.cmd.test_args());
2134 if !builder.config.verbose_tests {
2135 cargo.arg("--quiet");
2138 if target.contains("emscripten") {
2140 format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)),
2141 builder.config.nodejs.as_ref().expect("nodejs not configured"),
2143 } else if target.starts_with("wasm32") {
2144 let node = builder.config.nodejs.as_ref().expect("nodejs not configured");
2146 format!("{} {}/src/etc/wasm32-shim.js", node.display(), builder.src.display());
2147 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)), &runner);
2148 } else if builder.remote_tested(target) {
2150 format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)),
2151 format!("{} run 0", builder.tool_exe(Tool::RemoteTestClient).display()),
2155 builder.info(&format!(
2156 "{} {:?} stage{} ({} -> {})",
2157 test_kind, self.crates, compiler.stage, &compiler.host, target
2159 let _time = util::timeit(&builder);
2160 try_run(builder, &mut cargo.into());
2164 /// Rustdoc is special in various ways, which is why this step is different from `Crate`.
2165 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2166 pub struct CrateRustdoc {
2167 host: TargetSelection,
2168 test_kind: TestKind,
2171 impl Step for CrateRustdoc {
2173 const DEFAULT: bool = true;
2174 const ONLY_HOSTS: bool = true;
2176 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2177 run.paths(&["src/librustdoc", "src/tools/rustdoc"])
2180 fn make_run(run: RunConfig<'_>) {
2181 let builder = run.builder;
2183 let test_kind = builder.kind.into();
2185 builder.ensure(CrateRustdoc { host: run.target, test_kind });
2188 fn run(self, builder: &Builder<'_>) {
2189 let test_kind = self.test_kind;
2190 let target = self.host;
2192 let compiler = if builder.download_rustc() {
2193 builder.compiler(builder.top_stage, target)
2195 // Use the previous stage compiler to reuse the artifacts that are
2196 // created when running compiletest for src/test/rustdoc. If this used
2197 // `compiler`, then it would cause rustdoc to be built *again*, which
2198 // isn't really necessary.
2199 builder.compiler_for(builder.top_stage, target, target)
2201 builder.ensure(compile::Rustc::new(compiler, target));
2203 let mut cargo = tool::prepare_tool_cargo(
2208 test_kind.subcommand(),
2209 "src/tools/rustdoc",
2213 if test_kind.subcommand() == "test" && !builder.fail_fast {
2214 cargo.arg("--no-fail-fast");
2216 match builder.doc_tests {
2221 cargo.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
2226 cargo.arg("-p").arg("rustdoc:0.0.0");
2229 cargo.args(&builder.config.cmd.test_args());
2231 if self.host.contains("musl") {
2232 cargo.arg("'-Ctarget-feature=-crt-static'");
2235 // This is needed for running doctests on librustdoc. This is a bit of
2236 // an unfortunate interaction with how bootstrap works and how cargo
2237 // sets up the dylib path, and the fact that the doctest (in
2238 // html/markdown.rs) links to rustc-private libs. For stage1, the
2239 // compiler host dylibs (in stage1/lib) are not the same as the target
2240 // dylibs (in stage1/lib/rustlib/...). This is different from a normal
2241 // rust distribution where they are the same.
2243 // On the cargo side, normal tests use `target_process` which handles
2244 // setting up the dylib for a *target* (stage1/lib/rustlib/... in this
2245 // case). However, for doctests it uses `rustdoc_process` which only
2246 // sets up the dylib path for the *host* (stage1/lib), which is the
2249 // Recall that we special-cased `compiler_for(top_stage)` above, so we always use stage1.
2251 // It should be considered to just stop running doctests on
2252 // librustdoc. There is only one test, and it doesn't look too
2253 // important. There might be other ways to avoid this, but it seems
2254 // pretty convoluted.
2256 // See also https://github.com/rust-lang/rust/issues/13983 where the
2257 // host vs target dylibs for rustdoc are consistently tricky to deal
2260 // Note that this set the host libdir for `download_rustc`, which uses a normal rust distribution.
2261 let libdir = if builder.download_rustc() {
2262 builder.rustc_libdir(compiler)
2264 builder.sysroot_libdir(compiler, target).to_path_buf()
2266 let mut dylib_path = dylib_path();
2267 dylib_path.insert(0, PathBuf::from(&*libdir));
2268 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
2270 if !builder.config.verbose_tests {
2271 cargo.arg("--quiet");
2274 builder.info(&format!(
2275 "{} rustdoc stage{} ({} -> {})",
2276 test_kind, compiler.stage, &compiler.host, target
2278 let _time = util::timeit(&builder);
2280 try_run(builder, &mut cargo.into());
2284 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2285 pub struct CrateRustdocJsonTypes {
2286 host: TargetSelection,
2287 test_kind: TestKind,
2290 impl Step for CrateRustdocJsonTypes {
2292 const DEFAULT: bool = true;
2293 const ONLY_HOSTS: bool = true;
2295 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2296 run.path("src/rustdoc-json-types")
2299 fn make_run(run: RunConfig<'_>) {
2300 let builder = run.builder;
2302 let test_kind = builder.kind.into();
2304 builder.ensure(CrateRustdocJsonTypes { host: run.target, test_kind });
2307 fn run(self, builder: &Builder<'_>) {
2308 let test_kind = self.test_kind;
2309 let target = self.host;
2311 // Use the previous stage compiler to reuse the artifacts that are
2312 // created when running compiletest for src/test/rustdoc. If this used
2313 // `compiler`, then it would cause rustdoc to be built *again*, which
2314 // isn't really necessary.
2315 let compiler = builder.compiler_for(builder.top_stage, target, target);
2316 builder.ensure(compile::Rustc::new(compiler, target));
2318 let mut cargo = tool::prepare_tool_cargo(
2323 test_kind.subcommand(),
2324 "src/rustdoc-json-types",
2328 if test_kind.subcommand() == "test" && !builder.fail_fast {
2329 cargo.arg("--no-fail-fast");
2332 cargo.arg("-p").arg("rustdoc-json-types");
2335 cargo.args(&builder.config.cmd.test_args());
2337 if self.host.contains("musl") {
2338 cargo.arg("'-Ctarget-feature=-crt-static'");
2341 if !builder.config.verbose_tests {
2342 cargo.arg("--quiet");
2345 builder.info(&format!(
2346 "{} rustdoc-json-types stage{} ({} -> {})",
2347 test_kind, compiler.stage, &compiler.host, target
2349 let _time = util::timeit(&builder);
2351 try_run(builder, &mut cargo.into());
2355 /// Some test suites are run inside emulators or on remote devices, and most
2356 /// of our test binaries are linked dynamically which means we need to ship
2357 /// the standard library and such to the emulator ahead of time. This step
2358 /// represents this and is a dependency of all test suites.
2360 /// Most of the time this is a no-op. For some steps such as shipping data to
2361 /// QEMU we have to build our own tools so we've got conditional dependencies
2362 /// on those programs as well. Note that the remote test client is built for
2363 /// the build target (us) and the server is built for the target.
2364 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2365 pub struct RemoteCopyLibs {
2367 target: TargetSelection,
2370 impl Step for RemoteCopyLibs {
2373 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2377 fn run(self, builder: &Builder<'_>) {
2378 let compiler = self.compiler;
2379 let target = self.target;
2380 if !builder.remote_tested(target) {
2384 builder.ensure(compile::Std::new(compiler, target));
2386 builder.info(&format!("REMOTE copy libs to emulator ({})", target));
2388 let server = builder.ensure(tool::RemoteTestServer { compiler, target });
2390 // Spawn the emulator and wait for it to come online
2391 let tool = builder.tool_exe(Tool::RemoteTestClient);
2392 let mut cmd = Command::new(&tool);
2393 cmd.arg("spawn-emulator").arg(target.triple).arg(&server).arg(builder.tempdir());
2394 if let Some(rootfs) = builder.qemu_rootfs(target) {
2397 builder.run(&mut cmd);
2399 // Push all our dylibs to the emulator
2400 for f in t!(builder.sysroot_libdir(compiler, target).read_dir()) {
2402 let name = f.file_name().into_string().unwrap();
2403 if util::is_dylib(&name) {
2404 builder.run(Command::new(&tool).arg("push").arg(f.path()));
2410 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2411 pub struct Distcheck;
2413 impl Step for Distcheck {
2416 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2417 run.alias("distcheck")
2420 fn make_run(run: RunConfig<'_>) {
2421 run.builder.ensure(Distcheck);
2424 /// Runs "distcheck", a 'make check' from a tarball
2425 fn run(self, builder: &Builder<'_>) {
2426 builder.info("Distcheck");
2427 let dir = builder.tempdir().join("distcheck");
2428 let _ = fs::remove_dir_all(&dir);
2429 t!(fs::create_dir_all(&dir));
2431 // Guarantee that these are built before we begin running.
2432 builder.ensure(dist::PlainSourceTarball);
2433 builder.ensure(dist::Src);
2435 let mut cmd = Command::new("tar");
2437 .arg(builder.ensure(dist::PlainSourceTarball).tarball())
2438 .arg("--strip-components=1")
2440 builder.run(&mut cmd);
2442 Command::new("./configure")
2443 .args(&builder.config.configure_args)
2444 .arg("--enable-vendor")
2448 Command::new(util::make(&builder.config.build.triple)).arg("check").current_dir(&dir),
2451 // Now make sure that rust-src has all of libstd's dependencies
2452 builder.info("Distcheck rust-src");
2453 let dir = builder.tempdir().join("distcheck-src");
2454 let _ = fs::remove_dir_all(&dir);
2455 t!(fs::create_dir_all(&dir));
2457 let mut cmd = Command::new("tar");
2459 .arg(builder.ensure(dist::Src).tarball())
2460 .arg("--strip-components=1")
2462 builder.run(&mut cmd);
2464 let toml = dir.join("rust-src/lib/rustlib/src/rust/library/std/Cargo.toml");
2466 Command::new(&builder.initial_cargo)
2467 .arg("generate-lockfile")
2468 .arg("--manifest-path")
2475 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2476 pub struct Bootstrap;
2478 impl Step for Bootstrap {
2480 const DEFAULT: bool = true;
2481 const ONLY_HOSTS: bool = true;
2483 /// Tests the build system itself.
2484 fn run(self, builder: &Builder<'_>) {
2485 let mut check_bootstrap = Command::new(&builder.python());
2486 check_bootstrap.arg("bootstrap_test.py").current_dir(builder.src.join("src/bootstrap/"));
2487 try_run(builder, &mut check_bootstrap);
2489 let mut cmd = Command::new(&builder.initial_cargo);
2491 .current_dir(builder.src.join("src/bootstrap"))
2492 .env("RUSTFLAGS", "-Cdebuginfo=2")
2493 .env("CARGO_TARGET_DIR", builder.out.join("bootstrap"))
2494 .env("RUSTC_BOOTSTRAP", "1")
2495 .env("RUSTDOC", builder.rustdoc(builder.compiler(0, builder.build.build)))
2496 .env("RUSTC", &builder.initial_rustc);
2497 if let Some(flags) = option_env!("RUSTFLAGS") {
2498 // Use the same rustc flags for testing as for "normal" compilation,
2499 // so that Cargo doesn’t recompile the entire dependency graph every time:
2500 // https://github.com/rust-lang/rust/issues/49215
2501 cmd.env("RUSTFLAGS", flags);
2503 if !builder.fail_fast {
2504 cmd.arg("--no-fail-fast");
2506 match builder.doc_tests {
2511 cmd.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
2516 cmd.arg("--").args(&builder.config.cmd.test_args());
2517 // rustbuild tests are racy on directory creation so just run them one at a time.
2518 // Since there's not many this shouldn't be a problem.
2519 cmd.arg("--test-threads=1");
2520 try_run(builder, &mut cmd);
2523 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2524 run.path("src/bootstrap")
2527 fn make_run(run: RunConfig<'_>) {
2528 run.builder.ensure(Bootstrap);
2532 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2533 pub struct TierCheck {
2534 pub compiler: Compiler,
2537 impl Step for TierCheck {
2539 const DEFAULT: bool = true;
2540 const ONLY_HOSTS: bool = true;
2542 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2543 run.path("src/tools/tier-check")
2546 fn make_run(run: RunConfig<'_>) {
2548 run.builder.compiler_for(run.builder.top_stage, run.builder.build.build, run.target);
2549 run.builder.ensure(TierCheck { compiler });
2552 /// Tests the Platform Support page in the rustc book.
2553 fn run(self, builder: &Builder<'_>) {
2554 builder.ensure(compile::Std::new(self.compiler, self.compiler.host));
2555 let mut cargo = tool::prepare_tool_cargo(
2561 "src/tools/tier-check",
2565 cargo.arg(builder.src.join("src/doc/rustc/src/platform-support.md"));
2566 cargo.arg(&builder.rustc(self.compiler));
2567 if builder.is_verbose() {
2568 cargo.arg("--verbose");
2571 builder.info("platform support check");
2572 try_run(builder, &mut cargo.into());
2576 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2577 pub struct ReplacePlaceholderTest;
2579 impl Step for ReplacePlaceholderTest {
2581 const ONLY_HOSTS: bool = true;
2582 const DEFAULT: bool = true;
2584 /// Ensure the version placeholder replacement tool builds
2585 fn run(self, builder: &Builder<'_>) {
2586 builder.info("build check for version replacement placeholder");
2588 // Test the version placeholder replacement tool itself.
2589 let bootstrap_host = builder.config.build;
2590 let compiler = builder.compiler(0, bootstrap_host);
2591 let cargo = tool::prepare_tool_cargo(
2594 Mode::ToolBootstrap,
2597 "src/tools/replace-version-placeholder",
2601 try_run(builder, &mut cargo.into());
2604 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2605 run.path("src/tools/replace-version-placeholder")
2608 fn make_run(run: RunConfig<'_>) {
2609 run.builder.ensure(Self);
2613 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2614 pub struct LintDocs {
2615 pub compiler: Compiler,
2616 pub target: TargetSelection,
2619 impl Step for LintDocs {
2621 const DEFAULT: bool = true;
2622 const ONLY_HOSTS: bool = true;
2624 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2625 run.path("src/tools/lint-docs")
2628 fn make_run(run: RunConfig<'_>) {
2629 run.builder.ensure(LintDocs {
2630 compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
2635 /// Tests that the lint examples in the rustc book generate the correct
2636 /// lints and have the expected format.
2637 fn run(self, builder: &Builder<'_>) {
2638 builder.ensure(crate::doc::RustcBook {
2639 compiler: self.compiler,
2640 target: self.target,