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::crate_description;
15 use crate::builder::{Builder, Compiler, Kind, RunConfig, ShouldRun, Step};
16 use crate::cache::Interned;
18 use crate::config::TargetSelection;
20 use crate::doc::DocumentationFormat;
21 use crate::flags::Subcommand;
23 use crate::tool::{self, SourceType, Tool};
24 use crate::toolstate::ToolState;
25 use crate::util::{self, add_link_lib_path, dylib_path, dylib_path_var, output, t};
26 use crate::{envify, CLang, DocTests, GitRepo, Mode};
28 const ADB_TEST_DIR: &str = "/data/local/tmp/work";
30 /// The two modes of the test runner; tests or benchmarks.
31 #[derive(Debug, PartialEq, Eq, Hash, Copy, Clone, PartialOrd, Ord)]
35 /// Run `cargo bench`.
39 impl From<Kind> for TestKind {
40 fn from(kind: Kind) -> Self {
42 Kind::Test => TestKind::Test,
43 Kind::Bench => TestKind::Bench,
44 _ => panic!("unexpected kind in crate: {:?}", kind),
50 // Return the cargo subcommand for this test kind
51 fn subcommand(self) -> &'static str {
53 TestKind::Test => "test",
54 TestKind::Bench => "bench",
59 impl fmt::Display for TestKind {
60 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
61 f.write_str(match *self {
62 TestKind::Test => "Testing",
63 TestKind::Bench => "Benchmarking",
68 fn try_run(builder: &Builder<'_>, cmd: &mut Command) -> bool {
69 if !builder.fail_fast {
70 if !builder.try_run(cmd) {
71 let mut failures = builder.delayed_failures.borrow_mut();
72 failures.push(format!("{:?}", cmd));
81 fn try_run_quiet(builder: &Builder<'_>, cmd: &mut Command) -> bool {
82 if !builder.fail_fast {
83 if !builder.try_run_quiet(cmd) {
84 let mut failures = builder.delayed_failures.borrow_mut();
85 failures.push(format!("{:?}", cmd));
89 builder.run_quiet(cmd);
94 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
95 pub struct CrateJsonDocLint {
96 host: TargetSelection,
99 impl Step for CrateJsonDocLint {
101 const ONLY_HOSTS: bool = true;
102 const DEFAULT: bool = true;
104 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
105 run.path("src/tools/jsondoclint")
108 fn make_run(run: RunConfig<'_>) {
109 run.builder.ensure(CrateJsonDocLint { host: run.target });
112 fn run(self, builder: &Builder<'_>) {
113 let bootstrap_host = builder.config.build;
114 let compiler = builder.compiler(0, bootstrap_host);
116 let cargo = tool::prepare_tool_cargo(
122 "src/tools/jsondoclint",
126 try_run(builder, &mut cargo.into());
130 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
131 pub struct Linkcheck {
132 host: TargetSelection,
135 impl Step for Linkcheck {
137 const ONLY_HOSTS: bool = true;
138 const DEFAULT: bool = true;
140 /// Runs the `linkchecker` tool as compiled in `stage` by the `host` compiler.
142 /// This tool in `src/tools` will verify the validity of all our links in the
143 /// documentation to ensure we don't have a bunch of dead ones.
144 fn run(self, builder: &Builder<'_>) {
145 let host = self.host;
146 let hosts = &builder.hosts;
147 let targets = &builder.targets;
149 // if we have different hosts and targets, some things may be built for
150 // the host (e.g. rustc) and others for the target (e.g. std). The
151 // documentation built for each will contain broken links to
152 // docs built for the other platform (e.g. rustc linking to cargo)
153 if (hosts != targets) && !hosts.is_empty() && !targets.is_empty() {
155 "Linkcheck currently does not support builds with different hosts and targets.
156 You can skip linkcheck with --exclude src/tools/linkchecker"
160 builder.info(&format!("Linkcheck ({})", host));
162 // Test the linkchecker itself.
163 let bootstrap_host = builder.config.build;
164 let compiler = builder.compiler(0, bootstrap_host);
165 let cargo = tool::prepare_tool_cargo(
171 "src/tools/linkchecker",
175 try_run(builder, &mut cargo.into());
177 // Build all the default documentation.
178 builder.default_doc(&[]);
180 // Run the linkchecker.
181 let _time = util::timeit(&builder);
184 builder.tool_cmd(Tool::Linkchecker).arg(builder.out.join(host.triple).join("doc")),
188 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
189 let builder = run.builder;
190 let run = run.path("src/tools/linkchecker");
191 run.default_condition(builder.config.docs)
194 fn make_run(run: RunConfig<'_>) {
195 run.builder.ensure(Linkcheck { host: run.target });
199 fn check_if_tidy_is_installed() -> bool {
202 .stdout(Stdio::null())
204 .map_or(false, |status| status.success())
207 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
208 pub struct HtmlCheck {
209 target: TargetSelection,
212 impl Step for HtmlCheck {
214 const DEFAULT: bool = true;
215 const ONLY_HOSTS: bool = true;
217 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
218 let run = run.path("src/tools/html-checker");
219 run.lazy_default_condition(Box::new(check_if_tidy_is_installed))
222 fn make_run(run: RunConfig<'_>) {
223 run.builder.ensure(HtmlCheck { target: run.target });
226 fn run(self, builder: &Builder<'_>) {
227 if !check_if_tidy_is_installed() {
228 eprintln!("not running HTML-check tool because `tidy` is missing");
230 "Note that `tidy` is not the in-tree `src/tools/tidy` but needs to be installed"
232 panic!("Cannot run html-check tests");
234 // Ensure that a few different kinds of documentation are available.
235 builder.default_doc(&[]);
236 builder.ensure(crate::doc::Rustc { target: self.target, stage: builder.top_stage });
238 try_run(builder, builder.tool_cmd(Tool::HtmlChecker).arg(builder.doc_out(self.target)));
242 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
243 pub struct Cargotest {
245 host: TargetSelection,
248 impl Step for Cargotest {
250 const ONLY_HOSTS: bool = true;
252 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
253 run.path("src/tools/cargotest")
256 fn make_run(run: RunConfig<'_>) {
257 run.builder.ensure(Cargotest { stage: run.builder.top_stage, host: run.target });
260 /// Runs the `cargotest` tool as compiled in `stage` by the `host` compiler.
262 /// This tool in `src/tools` will check out a few Rust projects and run `cargo
263 /// test` to ensure that we don't regress the test suites there.
264 fn run(self, builder: &Builder<'_>) {
265 let compiler = builder.compiler(self.stage, self.host);
266 builder.ensure(compile::Rustc::new(compiler, compiler.host));
267 let cargo = builder.ensure(tool::Cargo { compiler, target: compiler.host });
269 // Note that this is a short, cryptic, and not scoped directory name. This
270 // is currently to minimize the length of path on Windows where we otherwise
271 // quickly run into path name limit constraints.
272 let out_dir = builder.out.join("ct");
273 t!(fs::create_dir_all(&out_dir));
275 let _time = util::timeit(&builder);
276 let mut cmd = builder.tool_cmd(Tool::CargoTest);
281 .args(builder.config.cmd.test_args())
282 .env("RUSTC", builder.rustc(compiler))
283 .env("RUSTDOC", builder.rustdoc(compiler)),
288 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
291 host: TargetSelection,
294 impl Step for Cargo {
296 const ONLY_HOSTS: bool = true;
298 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
299 run.path("src/tools/cargo")
302 fn make_run(run: RunConfig<'_>) {
303 run.builder.ensure(Cargo { stage: run.builder.top_stage, host: run.target });
306 /// Runs `cargo test` for `cargo` packaged with Rust.
307 fn run(self, builder: &Builder<'_>) {
308 let compiler = builder.compiler(self.stage, self.host);
310 builder.ensure(tool::Cargo { compiler, target: self.host });
311 let mut cargo = tool::prepare_tool_cargo(
318 SourceType::Submodule,
322 if !builder.fail_fast {
323 cargo.arg("--no-fail-fast");
325 cargo.arg("--").args(builder.config.cmd.test_args());
327 // Don't run cross-compile tests, we may not have cross-compiled libstd libs
329 cargo.env("CFG_DISABLE_CROSS_TESTS", "1");
330 // Forcibly disable tests using nightly features since any changes to
331 // those features won't be able to land.
332 cargo.env("CARGO_TEST_DISABLE_NIGHTLY", "1");
334 cargo.env("PATH", &path_for_cargo(builder, compiler));
336 try_run(builder, &mut cargo.into());
340 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
341 pub struct RustAnalyzer {
343 host: TargetSelection,
346 impl Step for RustAnalyzer {
348 const ONLY_HOSTS: bool = true;
349 const DEFAULT: bool = true;
351 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
352 run.path("src/tools/rust-analyzer")
355 fn make_run(run: RunConfig<'_>) {
356 run.builder.ensure(Self { stage: run.builder.top_stage, host: run.target });
359 /// Runs `cargo test` for rust-analyzer
360 fn run(self, builder: &Builder<'_>) {
361 let stage = self.stage;
362 let host = self.host;
363 let compiler = builder.compiler(stage, host);
365 builder.ensure(tool::RustAnalyzer { compiler, target: self.host }).expect("in-tree tool");
367 let workspace_path = "src/tools/rust-analyzer";
368 // until the whole RA test suite runs on `i686`, we only run
369 // `proc-macro-srv` tests
370 let crate_path = "src/tools/rust-analyzer/crates/proc-macro-srv";
371 let mut cargo = tool::prepare_tool_cargo(
379 &["sysroot-abi".to_owned()],
381 cargo.allow_features(tool::RustAnalyzer::ALLOW_FEATURES);
383 let dir = builder.src.join(workspace_path);
384 // needed by rust-analyzer to find its own text fixtures, cf.
385 // https://github.com/rust-analyzer/expect-test/issues/33
386 cargo.env("CARGO_WORKSPACE_DIR", &dir);
388 // RA's test suite tries to write to the source directory, that can't
390 cargo.env("SKIP_SLOW_TESTS", "1");
392 cargo.add_rustc_lib_path(builder, compiler);
393 cargo.arg("--").args(builder.config.cmd.test_args());
395 builder.run(&mut cargo.into());
399 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
402 host: TargetSelection,
405 impl Step for Rustfmt {
407 const ONLY_HOSTS: bool = true;
409 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
410 run.path("src/tools/rustfmt")
413 fn make_run(run: RunConfig<'_>) {
414 run.builder.ensure(Rustfmt { stage: run.builder.top_stage, host: run.target });
417 /// Runs `cargo test` for rustfmt.
418 fn run(self, builder: &Builder<'_>) {
419 let stage = self.stage;
420 let host = self.host;
421 let compiler = builder.compiler(stage, host);
424 .ensure(tool::Rustfmt { compiler, target: self.host, extra_features: Vec::new() })
425 .expect("in-tree tool");
427 let mut cargo = tool::prepare_tool_cargo(
438 let dir = testdir(builder, compiler.host);
439 t!(fs::create_dir_all(&dir));
440 cargo.env("RUSTFMT_TEST_DIR", dir);
442 cargo.add_rustc_lib_path(builder, compiler);
444 builder.run(&mut cargo.into());
448 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
449 pub struct RustDemangler {
451 host: TargetSelection,
454 impl Step for RustDemangler {
456 const ONLY_HOSTS: bool = true;
458 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
459 run.path("src/tools/rust-demangler")
462 fn make_run(run: RunConfig<'_>) {
463 run.builder.ensure(RustDemangler { stage: run.builder.top_stage, host: run.target });
466 /// Runs `cargo test` for rust-demangler.
467 fn run(self, builder: &Builder<'_>) {
468 let stage = self.stage;
469 let host = self.host;
470 let compiler = builder.compiler(stage, host);
472 let rust_demangler = builder
473 .ensure(tool::RustDemangler { compiler, target: self.host, extra_features: Vec::new() })
474 .expect("in-tree tool");
475 let mut cargo = tool::prepare_tool_cargo(
481 "src/tools/rust-demangler",
486 let dir = testdir(builder, compiler.host);
487 t!(fs::create_dir_all(&dir));
489 cargo.env("RUST_DEMANGLER_DRIVER_PATH", rust_demangler);
491 cargo.arg("--").args(builder.config.cmd.test_args());
493 cargo.add_rustc_lib_path(builder, compiler);
495 builder.run(&mut cargo.into());
499 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
502 host: TargetSelection,
503 target: TargetSelection,
507 /// Run `cargo miri setup` for the given target, return where the Miri sysroot was put.
508 pub fn build_miri_sysroot(
509 builder: &Builder<'_>,
512 target: TargetSelection,
514 let miri_sysroot = builder.out.join(compiler.host.triple).join("miri-sysroot");
515 let mut cargo = tool::prepare_tool_cargo(
521 "src/tools/miri/cargo-miri",
525 cargo.add_rustc_lib_path(builder, compiler);
526 cargo.arg("--").arg("miri").arg("setup");
527 cargo.arg("--target").arg(target.rustc_target_arg());
529 // Tell `cargo miri setup` where to find the sources.
530 cargo.env("MIRI_LIB_SRC", builder.src.join("library"));
531 // Tell it where to find Miri.
532 cargo.env("MIRI", &miri);
533 // Tell it where to put the sysroot.
534 cargo.env("MIRI_SYSROOT", &miri_sysroot);
536 cargo.env("RUST_BACKTRACE", "1");
538 let mut cargo = Command::from(cargo);
539 builder.run(&mut cargo);
541 // # Determine where Miri put its sysroot.
542 // To this end, we run `cargo miri setup --print-sysroot` and capture the output.
543 // (We do this separately from the above so that when the setup actually
544 // happens we get some output.)
545 // We re-use the `cargo` from above.
546 cargo.arg("--print-sysroot");
548 // FIXME: Is there a way in which we can re-use the usual `run` helpers?
549 if builder.config.dry_run() {
552 builder.verbose(&format!("running: {:?}", cargo));
554 cargo.output().expect("We already ran `cargo miri setup` before and that worked");
555 assert!(out.status.success(), "`cargo miri setup` returned with non-0 exit code");
556 // Output is "<sysroot>\n".
557 let stdout = String::from_utf8(out.stdout)
558 .expect("`cargo miri setup` stdout is not valid UTF-8");
559 let sysroot = stdout.trim_end();
560 builder.verbose(&format!("`cargo miri setup --print-sysroot` said: {:?}", sysroot));
568 const ONLY_HOSTS: bool = false;
570 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
571 run.path("src/tools/miri")
574 fn make_run(run: RunConfig<'_>) {
575 run.builder.ensure(Miri {
576 stage: run.builder.top_stage,
577 host: run.build_triple(),
582 /// Runs `cargo test` for miri.
583 fn run(self, builder: &Builder<'_>) {
584 let stage = self.stage;
585 let host = self.host;
586 let target = self.target;
587 let compiler = builder.compiler(stage, host);
588 // We need the stdlib for the *next* stage, as it was built with this compiler that also built Miri.
589 // Except if we are at stage 2, the bootstrap loop is complete and we can stick with our current stage.
590 let compiler_std = builder.compiler(if stage < 2 { stage + 1 } else { stage }, host);
593 .ensure(tool::Miri { compiler, target: self.host, extra_features: Vec::new() })
594 .expect("in-tree tool");
595 let _cargo_miri = builder
596 .ensure(tool::CargoMiri { compiler, target: self.host, extra_features: Vec::new() })
597 .expect("in-tree tool");
598 // The stdlib we need might be at a different stage. And just asking for the
599 // sysroot does not seem to populate it, so we do that first.
600 builder.ensure(compile::Std::new(compiler_std, host));
601 let sysroot = builder.sysroot(compiler_std);
602 // We also need a Miri sysroot.
603 let miri_sysroot = Miri::build_miri_sysroot(builder, compiler, &miri, target);
605 // # Run `cargo test`.
606 let mut cargo = tool::prepare_tool_cargo(
616 cargo.add_rustc_lib_path(builder, compiler);
618 // miri tests need to know about the stage sysroot
619 cargo.env("MIRI_SYSROOT", &miri_sysroot);
620 cargo.env("MIRI_HOST_SYSROOT", sysroot);
621 cargo.env("MIRI", &miri);
623 if builder.config.cmd.bless() {
624 cargo.env("MIRI_BLESS", "Gesundheit");
628 cargo.env("MIRI_TEST_TARGET", target.rustc_target_arg());
629 // Forward test filters.
630 cargo.arg("--").args(builder.config.cmd.test_args());
632 let mut cargo = Command::from(cargo);
633 builder.run(&mut cargo);
635 // # Run `cargo miri test`.
636 // This is just a smoke test (Miri's own CI invokes this in a bunch of different ways and ensures
637 // that we get the desired output), but that is sufficient to make sure that the libtest harness
638 // itself executes properly under Miri.
639 let mut cargo = tool::prepare_tool_cargo(
645 "src/tools/miri/cargo-miri",
646 SourceType::Submodule,
649 cargo.add_rustc_lib_path(builder, compiler);
650 cargo.arg("--").arg("miri").arg("test");
652 .arg("--manifest-path")
653 .arg(builder.src.join("src/tools/miri/test-cargo-miri/Cargo.toml"));
654 cargo.arg("--target").arg(target.rustc_target_arg());
655 cargo.arg("--tests"); // don't run doctests, they are too confused by the staging
656 cargo.arg("--").args(builder.config.cmd.test_args());
658 // Tell `cargo miri` where to find things.
659 cargo.env("MIRI_SYSROOT", &miri_sysroot);
660 cargo.env("MIRI_HOST_SYSROOT", sysroot);
661 cargo.env("MIRI", &miri);
663 cargo.env("RUST_BACKTRACE", "1");
665 let mut cargo = Command::from(cargo);
666 builder.run(&mut cargo);
670 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
671 pub struct CompiletestTest {
672 host: TargetSelection,
675 impl Step for CompiletestTest {
678 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
679 run.path("src/tools/compiletest")
682 fn make_run(run: RunConfig<'_>) {
683 run.builder.ensure(CompiletestTest { host: run.target });
686 /// Runs `cargo test` for compiletest.
687 fn run(self, builder: &Builder<'_>) {
688 let host = self.host;
689 let compiler = builder.compiler(0, host);
691 // We need `ToolStd` for the locally-built sysroot because
692 // compiletest uses unstable features of the `test` crate.
693 builder.ensure(compile::Std::new(compiler, host));
694 let mut cargo = tool::prepare_tool_cargo(
700 "src/tools/compiletest",
704 cargo.allow_features("test");
706 try_run(builder, &mut cargo.into());
710 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
713 host: TargetSelection,
716 impl Step for Clippy {
718 const ONLY_HOSTS: bool = true;
719 const DEFAULT: bool = false;
721 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
722 run.path("src/tools/clippy")
725 fn make_run(run: RunConfig<'_>) {
726 run.builder.ensure(Clippy { stage: run.builder.top_stage, host: run.target });
729 /// Runs `cargo test` for clippy.
730 fn run(self, builder: &Builder<'_>) {
731 let stage = self.stage;
732 let host = self.host;
733 let compiler = builder.compiler(stage, host);
736 .ensure(tool::Clippy { compiler, target: self.host, extra_features: Vec::new() })
737 .expect("in-tree tool");
738 let mut cargo = tool::prepare_tool_cargo(
749 cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
750 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
751 let host_libs = builder.stage_out(compiler, Mode::ToolRustc).join(builder.cargo_dir());
752 cargo.env("HOST_LIBS", host_libs);
754 cargo.arg("--").args(builder.config.cmd.test_args());
756 cargo.add_rustc_lib_path(builder, compiler);
758 if builder.try_run(&mut cargo.into()) {
759 // The tests succeeded; nothing to do.
763 if !builder.config.cmd.bless() {
764 crate::detail_exit(1);
767 let mut cargo = builder.cargo(compiler, Mode::ToolRustc, SourceType::InTree, host, "run");
768 cargo.arg("-p").arg("clippy_dev");
769 // clippy_dev gets confused if it can't find `clippy/Cargo.toml`
770 cargo.current_dir(&builder.src.join("src").join("tools").join("clippy"));
771 if builder.config.rust_optimize {
772 cargo.env("PROFILE", "release");
774 cargo.env("PROFILE", "debug");
778 builder.run(&mut cargo.into());
782 fn path_for_cargo(builder: &Builder<'_>, compiler: Compiler) -> OsString {
783 // Configure PATH to find the right rustc. NB. we have to use PATH
784 // and not RUSTC because the Cargo test suite has tests that will
785 // fail if rustc is not spelled `rustc`.
786 let path = builder.sysroot(compiler).join("bin");
787 let old_path = env::var_os("PATH").unwrap_or_default();
788 env::join_paths(iter::once(path).chain(env::split_paths(&old_path))).expect("")
791 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
792 pub struct RustdocTheme {
793 pub compiler: Compiler,
796 impl Step for RustdocTheme {
798 const DEFAULT: bool = true;
799 const ONLY_HOSTS: bool = true;
801 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
802 run.path("src/tools/rustdoc-themes")
805 fn make_run(run: RunConfig<'_>) {
806 let compiler = run.builder.compiler(run.builder.top_stage, run.target);
808 run.builder.ensure(RustdocTheme { compiler });
811 fn run(self, builder: &Builder<'_>) {
812 let rustdoc = builder.bootstrap_out.join("rustdoc");
813 let mut cmd = builder.tool_cmd(Tool::RustdocTheme);
814 cmd.arg(rustdoc.to_str().unwrap())
815 .arg(builder.src.join("src/librustdoc/html/static/css/themes").to_str().unwrap())
816 .env("RUSTC_STAGE", self.compiler.stage.to_string())
817 .env("RUSTC_SYSROOT", builder.sysroot(self.compiler))
818 .env("RUSTDOC_LIBDIR", builder.sysroot_libdir(self.compiler, self.compiler.host))
819 .env("CFG_RELEASE_CHANNEL", &builder.config.channel)
820 .env("RUSTDOC_REAL", builder.rustdoc(self.compiler))
821 .env("RUSTC_BOOTSTRAP", "1");
822 if let Some(linker) = builder.linker(self.compiler.host) {
823 cmd.env("RUSTDOC_LINKER", linker);
825 if builder.is_fuse_ld_lld(self.compiler.host) {
827 "RUSTDOC_LLD_NO_THREADS",
828 util::lld_flag_no_threads(self.compiler.host.contains("windows")),
831 try_run(builder, &mut cmd);
835 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
836 pub struct RustdocJSStd {
837 pub target: TargetSelection,
840 impl Step for RustdocJSStd {
842 const DEFAULT: bool = true;
843 const ONLY_HOSTS: bool = true;
845 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
846 run.suite_path("tests/rustdoc-js-std")
849 fn make_run(run: RunConfig<'_>) {
850 run.builder.ensure(RustdocJSStd { target: run.target });
853 fn run(self, builder: &Builder<'_>) {
854 if let Some(ref nodejs) = builder.config.nodejs {
855 let mut command = Command::new(nodejs);
857 .arg(builder.src.join("src/tools/rustdoc-js/tester.js"))
860 .arg("--resource-suffix")
861 .arg(&builder.version)
863 .arg(builder.doc_out(self.target))
864 .arg("--test-folder")
865 .arg(builder.src.join("tests/rustdoc-js-std"));
866 for path in &builder.paths {
868 util::is_valid_test_suite_arg(path, "tests/rustdoc-js-std", builder)
870 if !p.ends_with(".js") {
871 eprintln!("A non-js file was given: `{}`", path.display());
872 panic!("Cannot run rustdoc-js-std tests");
874 command.arg("--test-file").arg(path);
877 builder.ensure(crate::doc::Std {
879 stage: builder.top_stage,
880 format: DocumentationFormat::HTML,
882 builder.run(&mut command);
884 builder.info("No nodejs found, skipping \"tests/rustdoc-js-std\" tests");
889 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
890 pub struct RustdocJSNotStd {
891 pub target: TargetSelection,
892 pub compiler: Compiler,
895 impl Step for RustdocJSNotStd {
897 const DEFAULT: bool = true;
898 const ONLY_HOSTS: bool = true;
900 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
901 run.suite_path("tests/rustdoc-js")
904 fn make_run(run: RunConfig<'_>) {
905 let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
906 run.builder.ensure(RustdocJSNotStd { target: run.target, compiler });
909 fn run(self, builder: &Builder<'_>) {
910 if builder.config.nodejs.is_some() {
911 builder.ensure(Compiletest {
912 compiler: self.compiler,
916 path: "tests/rustdoc-js",
920 builder.info("No nodejs found, skipping \"tests/rustdoc-js\" tests");
925 fn get_browser_ui_test_version_inner(npm: &Path, global: bool) -> Option<String> {
926 let mut command = Command::new(&npm);
927 command.arg("list").arg("--parseable").arg("--long").arg("--depth=0");
929 command.arg("--global");
933 .map(|output| String::from_utf8_lossy(&output.stdout).into_owned())
934 .unwrap_or(String::new());
937 .find_map(|l| l.split(':').nth(1)?.strip_prefix("browser-ui-test@"))
938 .map(|v| v.to_owned())
941 fn get_browser_ui_test_version(npm: &Path) -> Option<String> {
942 get_browser_ui_test_version_inner(npm, false)
943 .or_else(|| get_browser_ui_test_version_inner(npm, true))
946 fn compare_browser_ui_test_version(installed_version: &str, src: &Path) {
947 match fs::read_to_string(
948 src.join("src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version"),
951 if v.trim() != installed_version {
953 "⚠️ Installed version of browser-ui-test (`{}`) is different than the \
954 one used in the CI (`{}`)",
958 "You can install this version using `npm update browser-ui-test` or by using \
959 `npm install browser-ui-test@{}`",
964 Err(e) => eprintln!("Couldn't find the CI browser-ui-test version: {:?}", e),
968 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
969 pub struct RustdocGUI {
970 pub target: TargetSelection,
971 pub compiler: Compiler,
974 impl Step for RustdocGUI {
976 const DEFAULT: bool = true;
977 const ONLY_HOSTS: bool = true;
979 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
980 let builder = run.builder;
981 let run = run.suite_path("tests/rustdoc-gui");
982 run.lazy_default_condition(Box::new(move || {
983 builder.config.nodejs.is_some()
988 .map(|p| get_browser_ui_test_version(p).is_some())
993 fn make_run(run: RunConfig<'_>) {
994 let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
995 run.builder.ensure(RustdocGUI { target: run.target, compiler });
998 fn run(self, builder: &Builder<'_>) {
999 let nodejs = builder.config.nodejs.as_ref().expect("nodejs isn't available");
1000 let npm = builder.config.npm.as_ref().expect("npm isn't available");
1002 builder.ensure(compile::Std::new(self.compiler, self.target));
1004 // The goal here is to check if the necessary packages are installed, and if not, we
1006 match get_browser_ui_test_version(&npm) {
1008 // We also check the version currently used in CI and emit a warning if it's not the
1010 compare_browser_ui_test_version(&version, &builder.build.src);
1014 "error: rustdoc-gui test suite cannot be run because npm `browser-ui-test` \
1015 dependency is missing",
1018 "If you want to install the `{0}` dependency, run `npm install {0}`",
1021 panic!("Cannot run rustdoc-gui tests");
1025 let out_dir = builder.test_out(self.target).join("rustdoc-gui");
1027 // We remove existing folder to be sure there won't be artifacts remaining.
1028 builder.clear_if_dirty(&out_dir, &builder.rustdoc(self.compiler));
1030 let src_path = builder.build.src.join("tests/rustdoc-gui/src");
1031 // We generate docs for the libraries present in the rustdoc-gui's src folder.
1032 for entry in src_path.read_dir().expect("read_dir call failed") {
1033 if let Ok(entry) = entry {
1034 let path = entry.path();
1040 let mut cargo = Command::new(&builder.initial_cargo);
1043 .arg("--target-dir")
1045 .env("RUSTC_BOOTSTRAP", "1")
1046 .env("RUSTDOC", builder.rustdoc(self.compiler))
1047 .env("RUSTC", builder.rustc(self.compiler))
1049 // FIXME: implement a `// compile-flags` command or similar
1050 // instead of hard-coding this test
1051 if entry.file_name() == "link_to_definition" {
1052 cargo.env("RUSTDOCFLAGS", "-Zunstable-options --generate-link-to-definition");
1053 } else if entry.file_name() == "scrape_examples" {
1054 cargo.arg("-Zrustdoc-scrape-examples");
1056 builder.run(&mut cargo);
1060 // We now run GUI tests.
1061 let mut command = Command::new(&nodejs);
1063 .arg(builder.build.src.join("src/tools/rustdoc-gui/tester.js"))
1065 .arg(&builder.jobs().to_string())
1066 .arg("--doc-folder")
1067 .arg(out_dir.join("doc"))
1068 .arg("--tests-folder")
1069 .arg(builder.build.src.join("tests/rustdoc-gui"));
1070 for path in &builder.paths {
1071 if let Some(p) = util::is_valid_test_suite_arg(path, "tests/rustdoc-gui", builder) {
1072 if !p.ends_with(".goml") {
1073 eprintln!("A non-goml file was given: `{}`", path.display());
1074 panic!("Cannot run rustdoc-gui tests");
1076 if let Some(name) = path.file_name().and_then(|f| f.to_str()) {
1077 command.arg("--file").arg(name);
1081 for test_arg in builder.config.cmd.test_args() {
1082 command.arg(test_arg);
1084 builder.run(&mut command);
1088 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1091 impl Step for Tidy {
1093 const DEFAULT: bool = true;
1094 const ONLY_HOSTS: bool = true;
1096 /// Runs the `tidy` tool.
1098 /// This tool in `src/tools` checks up on various bits and pieces of style and
1099 /// otherwise just implements a few lint-like checks that are specific to the
1100 /// compiler itself.
1102 /// Once tidy passes, this step also runs `fmt --check` if tests are being run
1103 /// for the `dev` or `nightly` channels.
1104 fn run(self, builder: &Builder<'_>) {
1105 let mut cmd = builder.tool_cmd(Tool::Tidy);
1106 cmd.arg(&builder.src);
1107 cmd.arg(&builder.initial_cargo);
1108 cmd.arg(&builder.out);
1109 cmd.arg(builder.jobs().to_string());
1110 if builder.is_verbose() {
1111 cmd.arg("--verbose");
1113 if builder.config.cmd.bless() {
1117 builder.info("tidy check");
1118 try_run(builder, &mut cmd);
1120 if builder.config.channel == "dev" || builder.config.channel == "nightly" {
1121 builder.info("fmt check");
1122 if builder.initial_rustfmt().is_none() {
1123 let inferred_rustfmt_dir = builder.config.initial_rustc.parent().unwrap();
1126 error: no `rustfmt` binary found in {PATH}
1127 info: `rust.channel` is currently set to \"{CHAN}\"
1128 help: if you are testing a beta branch, set `rust.channel` to \"beta\" in the `config.toml` file
1129 help: to skip test's attempt to check tidiness, pass `--exclude src/tools/tidy` to `x.py test`",
1130 PATH = inferred_rustfmt_dir.display(),
1131 CHAN = builder.config.channel,
1133 crate::detail_exit(1);
1135 crate::format::format(&builder, !builder.config.cmd.bless(), &[]);
1139 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1140 run.path("src/tools/tidy")
1143 fn make_run(run: RunConfig<'_>) {
1144 run.builder.ensure(Tidy);
1148 /// Runs tidy's own tests.
1149 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1150 pub struct TidySelfTest;
1152 impl Step for TidySelfTest {
1154 const DEFAULT: bool = true;
1155 const ONLY_HOSTS: bool = true;
1157 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1158 run.alias("tidyselftest")
1161 fn make_run(run: RunConfig<'_>) {
1162 run.builder.ensure(TidySelfTest);
1165 fn run(self, builder: &Builder<'_>) {
1166 let bootstrap_host = builder.config.build;
1167 let compiler = builder.compiler(0, bootstrap_host);
1168 let cargo = tool::prepare_tool_cargo(
1171 Mode::ToolBootstrap,
1178 try_run(builder, &mut cargo.into());
1182 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1183 pub struct ExpandYamlAnchors;
1185 impl Step for ExpandYamlAnchors {
1187 const ONLY_HOSTS: bool = true;
1189 /// Ensure the `generate-ci-config` tool was run locally.
1191 /// The tool in `src/tools` reads the CI definition in `src/ci/builders.yml` and generates the
1192 /// appropriate configuration for all our CI providers. This step ensures the tool was called
1193 /// by the user before committing CI changes.
1194 fn run(self, builder: &Builder<'_>) {
1195 builder.info("Ensuring the YAML anchors in the GitHub Actions config were expanded");
1198 &mut builder.tool_cmd(Tool::ExpandYamlAnchors).arg("check").arg(&builder.src),
1202 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1203 run.path("src/tools/expand-yaml-anchors")
1206 fn make_run(run: RunConfig<'_>) {
1207 run.builder.ensure(ExpandYamlAnchors);
1211 fn testdir(builder: &Builder<'_>, host: TargetSelection) -> PathBuf {
1212 builder.out.join(host.triple).join("test")
1215 macro_rules! default_test {
1216 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
1217 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: false });
1221 macro_rules! default_test_with_compare_mode {
1222 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr,
1223 compare_mode: $compare_mode:expr }) => {
1224 test_with_compare_mode!($name {
1230 compare_mode: $compare_mode
1235 macro_rules! host_test {
1236 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
1237 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: true });
1242 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
1243 host: $host:expr }) => {
1244 test_definitions!($name {
1255 macro_rules! test_with_compare_mode {
1256 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
1257 host: $host:expr, compare_mode: $compare_mode:expr }) => {
1258 test_definitions!($name {
1264 compare_mode: Some($compare_mode)
1269 macro_rules! test_definitions {
1274 default: $default:expr,
1276 compare_mode: $compare_mode:expr
1278 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1280 pub compiler: Compiler,
1281 pub target: TargetSelection,
1284 impl Step for $name {
1286 const DEFAULT: bool = $default;
1287 const ONLY_HOSTS: bool = $host;
1289 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1290 run.suite_path($path)
1293 fn make_run(run: RunConfig<'_>) {
1294 let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
1296 run.builder.ensure($name { compiler, target: run.target });
1299 fn run(self, builder: &Builder<'_>) {
1300 builder.ensure(Compiletest {
1301 compiler: self.compiler,
1302 target: self.target,
1306 compare_mode: $compare_mode,
1313 default_test!(Ui { path: "tests/ui", mode: "ui", suite: "ui" });
1315 default_test!(RunPassValgrind {
1316 path: "tests/run-pass-valgrind",
1317 mode: "run-pass-valgrind",
1318 suite: "run-pass-valgrind"
1321 default_test!(MirOpt { path: "tests/mir-opt", mode: "mir-opt", suite: "mir-opt" });
1323 default_test!(Codegen { path: "tests/codegen", mode: "codegen", suite: "codegen" });
1325 default_test!(CodegenUnits {
1326 path: "tests/codegen-units",
1327 mode: "codegen-units",
1328 suite: "codegen-units"
1331 default_test!(Incremental { path: "tests/incremental", mode: "incremental", suite: "incremental" });
1333 default_test_with_compare_mode!(Debuginfo {
1334 path: "tests/debuginfo",
1337 compare_mode: "split-dwarf"
1340 host_test!(UiFullDeps { path: "tests/ui-fulldeps", mode: "ui", suite: "ui-fulldeps" });
1342 host_test!(Rustdoc { path: "tests/rustdoc", mode: "rustdoc", suite: "rustdoc" });
1343 host_test!(RustdocUi { path: "tests/rustdoc-ui", mode: "ui", suite: "rustdoc-ui" });
1345 host_test!(RustdocJson { path: "tests/rustdoc-json", mode: "rustdoc-json", suite: "rustdoc-json" });
1347 host_test!(Pretty { path: "tests/pretty", mode: "pretty", suite: "pretty" });
1349 default_test!(RunMake { path: "tests/run-make", mode: "run-make", suite: "run-make" });
1351 host_test!(RunMakeFullDeps {
1352 path: "tests/run-make-fulldeps",
1354 suite: "run-make-fulldeps"
1357 default_test!(Assembly { path: "tests/assembly", mode: "assembly", suite: "assembly" });
1359 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1360 struct Compiletest {
1362 target: TargetSelection,
1364 suite: &'static str,
1366 compare_mode: Option<&'static str>,
1369 impl Step for Compiletest {
1372 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1376 /// Executes the `compiletest` tool to run a suite of tests.
1378 /// Compiles all tests with `compiler` for `target` with the specified
1379 /// compiletest `mode` and `suite` arguments. For example `mode` can be
1380 /// "run-pass" or `suite` can be something like `debuginfo`.
1381 fn run(self, builder: &Builder<'_>) {
1382 if builder.top_stage == 0 && env::var("COMPILETEST_FORCE_STAGE0").is_err() {
1384 error: `--stage 0` runs compiletest on the beta compiler, not your local changes, and will almost always cause tests to fail
1385 help: to test the compiler, use `--stage 1` instead
1386 help: to test the standard library, use `--stage 0 library/std` instead
1387 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`."
1389 crate::detail_exit(1);
1392 let compiler = self.compiler;
1393 let target = self.target;
1394 let mode = self.mode;
1395 let suite = self.suite;
1397 // Path for test suite
1398 let suite_path = self.path;
1400 // Skip codegen tests if they aren't enabled in configuration.
1401 if !builder.config.codegen_tests && suite == "codegen" {
1405 if suite == "debuginfo" {
1407 .ensure(dist::DebuggerScripts { sysroot: builder.sysroot(compiler), host: target });
1410 if suite.ends_with("fulldeps") {
1411 builder.ensure(compile::Rustc::new(compiler, target));
1414 builder.ensure(compile::Std::new(compiler, target));
1415 // ensure that `libproc_macro` is available on the host.
1416 builder.ensure(compile::Std::new(compiler, compiler.host));
1418 // Also provide `rust_test_helpers` for the host.
1419 builder.ensure(native::TestHelpers { target: compiler.host });
1421 // As well as the target, except for plain wasm32, which can't build it
1422 if !target.contains("wasm") || target.contains("emscripten") {
1423 builder.ensure(native::TestHelpers { target });
1426 builder.ensure(RemoteCopyLibs { compiler, target });
1428 let mut cmd = builder.tool_cmd(Tool::Compiletest);
1430 // compiletest currently has... a lot of arguments, so let's just pass all
1433 cmd.arg("--compile-lib-path").arg(builder.rustc_libdir(compiler));
1434 cmd.arg("--run-lib-path").arg(builder.sysroot_libdir(compiler, target));
1435 cmd.arg("--rustc-path").arg(builder.rustc(compiler));
1437 let is_rustdoc = suite.ends_with("rustdoc-ui") || suite.ends_with("rustdoc-js");
1439 // Avoid depending on rustdoc when we don't need it.
1440 if mode == "rustdoc"
1441 || mode == "run-make"
1442 || (mode == "ui" && is_rustdoc)
1443 || mode == "js-doc-test"
1444 || mode == "rustdoc-json"
1446 cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler));
1449 if mode == "rustdoc-json" {
1450 // Use the beta compiler for jsondocck
1451 let json_compiler = compiler.with_stage(0);
1452 cmd.arg("--jsondocck-path")
1453 .arg(builder.ensure(tool::JsonDocCk { compiler: json_compiler, target }));
1454 cmd.arg("--jsondoclint-path")
1455 .arg(builder.ensure(tool::JsonDocLint { compiler: json_compiler, target }));
1458 if mode == "run-make" {
1459 let rust_demangler = builder
1460 .ensure(tool::RustDemangler {
1462 target: compiler.host,
1463 extra_features: Vec::new(),
1465 .expect("in-tree tool");
1466 cmd.arg("--rust-demangler-path").arg(rust_demangler);
1469 cmd.arg("--src-base").arg(builder.src.join("tests").join(suite));
1470 cmd.arg("--build-base").arg(testdir(builder, compiler.host).join(suite));
1471 cmd.arg("--sysroot-base").arg(builder.sysroot(compiler));
1472 cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target));
1473 cmd.arg("--suite").arg(suite);
1474 cmd.arg("--mode").arg(mode);
1475 cmd.arg("--target").arg(target.rustc_target_arg());
1476 cmd.arg("--host").arg(&*compiler.host.triple);
1477 cmd.arg("--llvm-filecheck").arg(builder.llvm_filecheck(builder.config.build));
1479 if builder.config.cmd.bless() {
1483 if builder.config.cmd.force_rerun() {
1484 cmd.arg("--force-rerun");
1488 builder.config.cmd.compare_mode().or_else(|| {
1489 if builder.config.test_compare_mode { self.compare_mode } else { None }
1492 if let Some(ref pass) = builder.config.cmd.pass() {
1497 if let Some(ref run) = builder.config.cmd.run() {
1502 if let Some(ref nodejs) = builder.config.nodejs {
1503 cmd.arg("--nodejs").arg(nodejs);
1505 if let Some(ref npm) = builder.config.npm {
1506 cmd.arg("--npm").arg(npm);
1508 if builder.config.rust_optimize_tests {
1509 cmd.arg("--optimize-tests");
1511 let mut flags = if is_rustdoc { Vec::new() } else { vec!["-Crpath".to_string()] };
1512 flags.push(format!("-Cdebuginfo={}", builder.config.rust_debuginfo_level_tests));
1513 flags.extend(builder.config.cmd.rustc_args().iter().map(|s| s.to_string()));
1515 if let Some(linker) = builder.linker(target) {
1516 cmd.arg("--linker").arg(linker);
1519 let mut hostflags = flags.clone();
1520 hostflags.push(format!("-Lnative={}", builder.test_helpers_out(compiler.host).display()));
1521 hostflags.extend(builder.lld_flags(compiler.host));
1522 for flag in hostflags {
1523 cmd.arg("--host-rustcflags").arg(flag);
1526 let mut targetflags = flags;
1527 targetflags.push(format!("-Lnative={}", builder.test_helpers_out(target).display()));
1528 targetflags.extend(builder.lld_flags(target));
1529 for flag in targetflags {
1530 cmd.arg("--target-rustcflags").arg(flag);
1533 cmd.arg("--python").arg(builder.python());
1535 if let Some(ref gdb) = builder.config.gdb {
1536 cmd.arg("--gdb").arg(gdb);
1539 let run = |cmd: &mut Command| {
1540 cmd.output().map(|output| {
1541 String::from_utf8_lossy(&output.stdout)
1544 .unwrap_or_else(|| panic!("{:?} failed {:?}", cmd, output))
1548 let lldb_exe = "lldb";
1549 let lldb_version = Command::new(lldb_exe)
1552 .map(|output| String::from_utf8_lossy(&output.stdout).to_string())
1554 if let Some(ref vers) = lldb_version {
1555 cmd.arg("--lldb-version").arg(vers);
1556 let lldb_python_dir = run(Command::new(lldb_exe).arg("-P")).ok();
1557 if let Some(ref dir) = lldb_python_dir {
1558 cmd.arg("--lldb-python-dir").arg(dir);
1562 if util::forcing_clang_based_tests() {
1563 let clang_exe = builder.llvm_out(target).join("bin").join("clang");
1564 cmd.arg("--run-clang-based-tests-with").arg(clang_exe);
1567 for exclude in &builder.config.exclude {
1569 cmd.arg(&exclude.path);
1572 // Get paths from cmd args
1573 let paths = match &builder.config.cmd {
1574 Subcommand::Test { ref paths, .. } => &paths[..],
1578 // Get test-args by striping suite path
1579 let mut test_args: Vec<&str> = paths
1581 .filter_map(|p| util::is_valid_test_suite_arg(p, suite_path, builder))
1584 test_args.append(&mut builder.config.cmd.test_args());
1586 // On Windows, replace forward slashes in test-args by backslashes
1587 // so the correct filters are passed to libtest
1589 let test_args_win: Vec<String> =
1590 test_args.iter().map(|s| s.replace("/", "\\")).collect();
1591 cmd.args(&test_args_win);
1593 cmd.args(&test_args);
1596 if builder.is_verbose() {
1597 cmd.arg("--verbose");
1600 if !builder.config.verbose_tests {
1604 let mut llvm_components_passed = false;
1605 let mut copts_passed = false;
1606 if builder.config.llvm_enabled() {
1607 let native::LlvmResult { llvm_config, .. } =
1608 builder.ensure(native::Llvm { target: builder.config.build });
1609 if !builder.config.dry_run() {
1610 let llvm_version = output(Command::new(&llvm_config).arg("--version"));
1611 let llvm_components = output(Command::new(&llvm_config).arg("--components"));
1612 // Remove trailing newline from llvm-config output.
1613 cmd.arg("--llvm-version")
1614 .arg(llvm_version.trim())
1615 .arg("--llvm-components")
1616 .arg(llvm_components.trim());
1617 llvm_components_passed = true;
1619 if !builder.is_rust_llvm(target) {
1620 cmd.arg("--system-llvm");
1623 // Tests that use compiler libraries may inherit the `-lLLVM` link
1624 // requirement, but the `-L` library path is not propagated across
1625 // separate compilations. We can add LLVM's library path to the
1626 // platform-specific environment variable as a workaround.
1627 if !builder.config.dry_run() && suite.ends_with("fulldeps") {
1628 let llvm_libdir = output(Command::new(&llvm_config).arg("--libdir"));
1629 add_link_lib_path(vec![llvm_libdir.trim().into()], &mut cmd);
1632 // Only pass correct values for these flags for the `run-make` suite as it
1633 // requires that a C++ compiler was configured which isn't always the case.
1634 if !builder.config.dry_run() && matches!(suite, "run-make" | "run-make-fulldeps") {
1635 // The llvm/bin directory contains many useful cross-platform
1636 // tools. Pass the path to run-make tests so they can use them.
1637 let llvm_bin_path = llvm_config
1639 .expect("Expected llvm-config to be contained in directory");
1640 assert!(llvm_bin_path.is_dir());
1641 cmd.arg("--llvm-bin-dir").arg(llvm_bin_path);
1643 // If LLD is available, add it to the PATH
1644 if builder.config.lld_enabled {
1645 let lld_install_root =
1646 builder.ensure(native::Lld { target: builder.config.build });
1648 let lld_bin_path = lld_install_root.join("bin");
1650 let old_path = env::var_os("PATH").unwrap_or_default();
1651 let new_path = env::join_paths(
1652 std::iter::once(lld_bin_path).chain(env::split_paths(&old_path)),
1654 .expect("Could not add LLD bin path to PATH");
1655 cmd.env("PATH", new_path);
1660 // Only pass correct values for these flags for the `run-make` suite as it
1661 // requires that a C++ compiler was configured which isn't always the case.
1662 if !builder.config.dry_run() && matches!(suite, "run-make" | "run-make-fulldeps") {
1664 .arg(builder.cc(target))
1666 .arg(builder.cxx(target).unwrap())
1668 .arg(builder.cflags(target, GitRepo::Rustc, CLang::C).join(" "))
1670 .arg(builder.cflags(target, GitRepo::Rustc, CLang::Cxx).join(" "));
1671 copts_passed = true;
1672 if let Some(ar) = builder.ar(target) {
1673 cmd.arg("--ar").arg(ar);
1677 if !llvm_components_passed {
1678 cmd.arg("--llvm-components").arg("");
1691 if builder.remote_tested(target) {
1692 cmd.arg("--remote-test-client").arg(builder.tool_exe(Tool::RemoteTestClient));
1695 // Running a C compiler on MSVC requires a few env vars to be set, to be
1696 // sure to set them here.
1698 // Note that if we encounter `PATH` we make sure to append to our own `PATH`
1699 // rather than stomp over it.
1700 if target.contains("msvc") {
1701 for &(ref k, ref v) in builder.cc[&target].env() {
1707 cmd.env("RUSTC_BOOTSTRAP", "1");
1708 // Override the rustc version used in symbol hashes to reduce the amount of normalization
1709 // needed when diffing test output.
1710 cmd.env("RUSTC_FORCE_RUSTC_VERSION", "compiletest");
1711 cmd.env("DOC_RUST_LANG_ORG_CHANNEL", builder.doc_rust_lang_org_channel());
1712 builder.add_rust_test_threads(&mut cmd);
1714 if builder.config.sanitizers_enabled(target) {
1715 cmd.env("RUSTC_SANITIZER_SUPPORT", "1");
1718 if builder.config.profiler_enabled(target) {
1719 cmd.env("RUSTC_PROFILER_SUPPORT", "1");
1722 cmd.env("RUST_TEST_TMPDIR", builder.tempdir());
1724 cmd.arg("--adb-path").arg("adb");
1725 cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
1726 if target.contains("android") {
1727 // Assume that cc for this target comes from the android sysroot
1728 cmd.arg("--android-cross-path")
1729 .arg(builder.cc(target).parent().unwrap().parent().unwrap());
1731 cmd.arg("--android-cross-path").arg("");
1734 if builder.config.cmd.rustfix_coverage() {
1735 cmd.arg("--rustfix-coverage");
1738 cmd.env("BOOTSTRAP_CARGO", &builder.initial_cargo);
1740 cmd.arg("--channel").arg(&builder.config.channel);
1742 if let Some(commit) = builder.config.download_rustc_commit() {
1743 cmd.env("FAKE_DOWNLOAD_RUSTC_PREFIX", format!("/rustc/{commit}"));
1746 builder.ci_env.force_coloring_in_ci(&mut cmd);
1748 builder.info(&format!(
1749 "Check compiletest suite={} mode={} ({} -> {})",
1750 suite, mode, &compiler.host, target
1752 let _time = util::timeit(&builder);
1753 try_run(builder, &mut cmd);
1755 if let Some(compare_mode) = compare_mode {
1756 cmd.arg("--compare-mode").arg(compare_mode);
1757 builder.info(&format!(
1758 "Check compiletest suite={} mode={} compare_mode={} ({} -> {})",
1759 suite, mode, compare_mode, &compiler.host, target
1761 let _time = util::timeit(&builder);
1762 try_run(builder, &mut cmd);
1767 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1775 impl Step for BookTest {
1777 const ONLY_HOSTS: bool = true;
1779 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1783 /// Runs the documentation tests for a book in `src/doc`.
1785 /// This uses the `rustdoc` that sits next to `compiler`.
1786 fn run(self, builder: &Builder<'_>) {
1787 // External docs are different from local because:
1788 // - Some books need pre-processing by mdbook before being tested.
1789 // - They need to save their state to toolstate.
1790 // - They are only tested on the "checktools" builders.
1792 // The local docs are tested by default, and we don't want to pay the
1793 // cost of building mdbook, so they use `rustdoc --test` directly.
1794 // Also, the unstable book is special because SUMMARY.md is generated,
1795 // so it is easier to just run `rustdoc` on its files.
1796 if self.is_ext_doc {
1797 self.run_ext_doc(builder);
1799 self.run_local_doc(builder);
1805 /// This runs the equivalent of `mdbook test` (via the rustbook wrapper)
1806 /// which in turn runs `rustdoc --test` on each file in the book.
1807 fn run_ext_doc(self, builder: &Builder<'_>) {
1808 let compiler = self.compiler;
1810 builder.ensure(compile::Std::new(compiler, compiler.host));
1812 // mdbook just executes a binary named "rustdoc", so we need to update
1813 // PATH so that it points to our rustdoc.
1814 let mut rustdoc_path = builder.rustdoc(compiler);
1816 let old_path = env::var_os("PATH").unwrap_or_default();
1817 let new_path = env::join_paths(iter::once(rustdoc_path).chain(env::split_paths(&old_path)))
1818 .expect("could not add rustdoc to PATH");
1820 let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
1821 let path = builder.src.join(&self.path);
1822 // Books often have feature-gated example text.
1823 rustbook_cmd.env("RUSTC_BOOTSTRAP", "1");
1824 rustbook_cmd.env("PATH", new_path).arg("test").arg(path);
1825 builder.add_rust_test_threads(&mut rustbook_cmd);
1826 builder.info(&format!("Testing rustbook {}", self.path.display()));
1827 let _time = util::timeit(&builder);
1828 let toolstate = if try_run(builder, &mut rustbook_cmd) {
1833 builder.save_toolstate(self.name, toolstate);
1836 /// This runs `rustdoc --test` on all `.md` files in the path.
1837 fn run_local_doc(self, builder: &Builder<'_>) {
1838 let compiler = self.compiler;
1840 builder.ensure(compile::Std::new(compiler, compiler.host));
1842 // Do a breadth-first traversal of the `src/doc` directory and just run
1843 // tests for all files that end in `*.md`
1844 let mut stack = vec![builder.src.join(self.path)];
1845 let _time = util::timeit(&builder);
1846 let mut files = Vec::new();
1847 while let Some(p) = stack.pop() {
1849 stack.extend(t!(p.read_dir()).map(|p| t!(p).path()));
1853 if p.extension().and_then(|s| s.to_str()) != Some("md") {
1863 markdown_test(builder, compiler, &file);
1868 macro_rules! test_book {
1869 ($($name:ident, $path:expr, $book_name:expr, default=$default:expr;)+) => {
1871 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1876 impl Step for $name {
1878 const DEFAULT: bool = $default;
1879 const ONLY_HOSTS: bool = true;
1881 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1885 fn make_run(run: RunConfig<'_>) {
1886 run.builder.ensure($name {
1887 compiler: run.builder.compiler(run.builder.top_stage, run.target),
1891 fn run(self, builder: &Builder<'_>) {
1892 builder.ensure(BookTest {
1893 compiler: self.compiler,
1894 path: PathBuf::from($path),
1896 is_ext_doc: !$default,
1905 Nomicon, "src/doc/nomicon", "nomicon", default=false;
1906 Reference, "src/doc/reference", "reference", default=false;
1907 RustdocBook, "src/doc/rustdoc", "rustdoc", default=true;
1908 RustcBook, "src/doc/rustc", "rustc", default=true;
1909 RustByExample, "src/doc/rust-by-example", "rust-by-example", default=false;
1910 EmbeddedBook, "src/doc/embedded-book", "embedded-book", default=false;
1911 TheBook, "src/doc/book", "book", default=false;
1912 UnstableBook, "src/doc/unstable-book", "unstable-book", default=true;
1913 EditionGuide, "src/doc/edition-guide", "edition-guide", default=false;
1916 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1917 pub struct ErrorIndex {
1921 impl Step for ErrorIndex {
1923 const DEFAULT: bool = true;
1924 const ONLY_HOSTS: bool = true;
1926 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1927 run.path("src/tools/error_index_generator")
1930 fn make_run(run: RunConfig<'_>) {
1931 // error_index_generator depends on librustdoc. Use the compiler that
1932 // is normally used to build rustdoc for other tests (like compiletest
1933 // tests in tests/rustdoc) so that it shares the same artifacts.
1934 let compiler = run.builder.compiler(run.builder.top_stage, run.builder.config.build);
1935 run.builder.ensure(ErrorIndex { compiler });
1938 /// Runs the error index generator tool to execute the tests located in the error
1941 /// The `error_index_generator` tool lives in `src/tools` and is used to
1942 /// generate a markdown file from the error indexes of the code base which is
1943 /// then passed to `rustdoc --test`.
1944 fn run(self, builder: &Builder<'_>) {
1945 let compiler = self.compiler;
1947 let dir = testdir(builder, compiler.host);
1948 t!(fs::create_dir_all(&dir));
1949 let output = dir.join("error-index.md");
1951 let mut tool = tool::ErrorIndex::command(builder);
1952 tool.arg("markdown").arg(&output);
1954 builder.info(&format!("Testing error-index stage{}", compiler.stage));
1955 let _time = util::timeit(&builder);
1956 builder.run_quiet(&mut tool);
1957 // The tests themselves need to link to std, so make sure it is
1959 builder.ensure(compile::Std::new(compiler, compiler.host));
1960 markdown_test(builder, compiler, &output);
1964 fn markdown_test(builder: &Builder<'_>, compiler: Compiler, markdown: &Path) -> bool {
1965 if let Ok(contents) = fs::read_to_string(markdown) {
1966 if !contents.contains("```") {
1971 builder.info(&format!("doc tests for: {}", markdown.display()));
1972 let mut cmd = builder.rustdoc_cmd(compiler);
1973 builder.add_rust_test_threads(&mut cmd);
1974 // allow for unstable options such as new editions
1976 cmd.arg("unstable-options");
1979 cmd.env("RUSTC_BOOTSTRAP", "1");
1981 let test_args = builder.config.cmd.test_args().join(" ");
1982 cmd.arg("--test-args").arg(test_args);
1984 if builder.config.verbose_tests {
1985 try_run(builder, &mut cmd)
1987 try_run_quiet(builder, &mut cmd)
1991 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1992 pub struct RustcGuide;
1994 impl Step for RustcGuide {
1996 const DEFAULT: bool = false;
1997 const ONLY_HOSTS: bool = true;
1999 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2000 run.path("src/doc/rustc-dev-guide")
2003 fn make_run(run: RunConfig<'_>) {
2004 run.builder.ensure(RustcGuide);
2007 fn run(self, builder: &Builder<'_>) {
2008 let relative_path = Path::new("src").join("doc").join("rustc-dev-guide");
2009 builder.update_submodule(&relative_path);
2011 let src = builder.src.join(relative_path);
2012 let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
2013 let toolstate = if try_run(builder, rustbook_cmd.arg("linkcheck").arg(&src)) {
2018 builder.save_toolstate("rustc-dev-guide", toolstate);
2022 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
2023 pub struct CrateLibrustc {
2025 target: TargetSelection,
2026 test_kind: TestKind,
2027 crates: Vec<Interned<String>>,
2030 impl Step for CrateLibrustc {
2032 const DEFAULT: bool = true;
2033 const ONLY_HOSTS: bool = true;
2035 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2036 run.crate_or_deps("rustc-main")
2039 fn make_run(run: RunConfig<'_>) {
2040 let builder = run.builder;
2041 let host = run.build_triple();
2042 let compiler = builder.compiler_for(builder.top_stage, host, host);
2046 .map(|p| builder.crate_paths[&p.assert_single_path().path].clone())
2048 let test_kind = builder.kind.into();
2050 builder.ensure(CrateLibrustc { compiler, target: run.target, test_kind, crates });
2053 fn run(self, builder: &Builder<'_>) {
2054 builder.ensure(Crate {
2055 compiler: self.compiler,
2056 target: self.target,
2058 test_kind: self.test_kind,
2059 crates: self.crates,
2064 #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
2066 pub compiler: Compiler,
2067 pub target: TargetSelection,
2069 pub test_kind: TestKind,
2070 pub crates: Vec<Interned<String>>,
2073 impl Step for Crate {
2075 const DEFAULT: bool = true;
2077 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2078 run.crate_or_deps("test")
2081 fn make_run(run: RunConfig<'_>) {
2082 let builder = run.builder;
2083 let host = run.build_triple();
2084 let compiler = builder.compiler_for(builder.top_stage, host, host);
2085 let test_kind = builder.kind.into();
2089 .map(|p| builder.crate_paths[&p.assert_single_path().path].clone())
2092 builder.ensure(Crate { compiler, target: run.target, mode: Mode::Std, test_kind, crates });
2095 /// Runs all unit tests plus documentation tests for a given crate defined
2096 /// by a `Cargo.toml` (single manifest)
2098 /// This is what runs tests for crates like the standard library, compiler, etc.
2099 /// It essentially is the driver for running `cargo test`.
2101 /// Currently this runs all tests for a DAG by passing a bunch of `-p foo`
2102 /// arguments, and those arguments are discovered from `cargo metadata`.
2103 fn run(self, builder: &Builder<'_>) {
2104 let compiler = self.compiler;
2105 let target = self.target;
2106 let mode = self.mode;
2107 let test_kind = self.test_kind;
2109 builder.ensure(compile::Std::new(compiler, target));
2110 builder.ensure(RemoteCopyLibs { compiler, target });
2112 // If we're not doing a full bootstrap but we're testing a stage2
2113 // version of libstd, then what we're actually testing is the libstd
2114 // produced in stage1. Reflect that here by updating the compiler that
2115 // we're working with automatically.
2116 let compiler = builder.compiler_for(compiler.stage, compiler.host, target);
2119 builder.cargo(compiler, mode, SourceType::InTree, target, test_kind.subcommand());
2122 compile::std_cargo(builder, target, compiler.stage, &mut cargo);
2125 compile::rustc_cargo(builder, &mut cargo, target);
2127 _ => panic!("can only test libraries"),
2130 // Build up the base `cargo test` command.
2132 // Pass in some standard flags then iterate over the graph we've discovered
2133 // in `cargo metadata` with the maps above and figure out what `-p`
2134 // arguments need to get passed.
2135 if test_kind.subcommand() == "test" && !builder.fail_fast {
2136 cargo.arg("--no-fail-fast");
2138 match builder.doc_tests {
2143 cargo.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
2148 for krate in &self.crates {
2149 cargo.arg("-p").arg(krate);
2152 // The tests are going to run with the *target* libraries, so we need to
2153 // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
2155 // Note that to run the compiler we need to run with the *host* libraries,
2156 // but our wrapper scripts arrange for that to be the case anyway.
2157 let mut dylib_path = dylib_path();
2158 dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
2159 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
2162 cargo.args(&builder.config.cmd.test_args());
2164 if !builder.config.verbose_tests {
2165 cargo.arg("--quiet");
2168 if target.contains("emscripten") {
2170 format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)),
2171 builder.config.nodejs.as_ref().expect("nodejs not configured"),
2173 } else if target.starts_with("wasm32") {
2174 let node = builder.config.nodejs.as_ref().expect("nodejs not configured");
2176 format!("{} {}/src/etc/wasm32-shim.js", node.display(), builder.src.display());
2177 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)), &runner);
2178 } else if builder.remote_tested(target) {
2180 format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)),
2181 format!("{} run 0", builder.tool_exe(Tool::RemoteTestClient).display()),
2185 builder.info(&format!(
2186 "{}{} stage{} ({} -> {})",
2188 crate_description(&self.crates),
2193 let _time = util::timeit(&builder);
2194 try_run(builder, &mut cargo.into());
2198 /// Rustdoc is special in various ways, which is why this step is different from `Crate`.
2199 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2200 pub struct CrateRustdoc {
2201 host: TargetSelection,
2202 test_kind: TestKind,
2205 impl Step for CrateRustdoc {
2207 const DEFAULT: bool = true;
2208 const ONLY_HOSTS: bool = true;
2210 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2211 run.paths(&["src/librustdoc", "src/tools/rustdoc"])
2214 fn make_run(run: RunConfig<'_>) {
2215 let builder = run.builder;
2217 let test_kind = builder.kind.into();
2219 builder.ensure(CrateRustdoc { host: run.target, test_kind });
2222 fn run(self, builder: &Builder<'_>) {
2223 let test_kind = self.test_kind;
2224 let target = self.host;
2226 let compiler = if builder.download_rustc() {
2227 builder.compiler(builder.top_stage, target)
2229 // Use the previous stage compiler to reuse the artifacts that are
2230 // created when running compiletest for tests/rustdoc. If this used
2231 // `compiler`, then it would cause rustdoc to be built *again*, which
2232 // isn't really necessary.
2233 builder.compiler_for(builder.top_stage, target, target)
2235 builder.ensure(compile::Rustc::new(compiler, target));
2237 let mut cargo = tool::prepare_tool_cargo(
2242 test_kind.subcommand(),
2243 "src/tools/rustdoc",
2247 if test_kind.subcommand() == "test" && !builder.fail_fast {
2248 cargo.arg("--no-fail-fast");
2250 match builder.doc_tests {
2255 cargo.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
2260 cargo.arg("-p").arg("rustdoc:0.0.0");
2263 cargo.args(&builder.config.cmd.test_args());
2265 if self.host.contains("musl") {
2266 cargo.arg("'-Ctarget-feature=-crt-static'");
2269 // This is needed for running doctests on librustdoc. This is a bit of
2270 // an unfortunate interaction with how bootstrap works and how cargo
2271 // sets up the dylib path, and the fact that the doctest (in
2272 // html/markdown.rs) links to rustc-private libs. For stage1, the
2273 // compiler host dylibs (in stage1/lib) are not the same as the target
2274 // dylibs (in stage1/lib/rustlib/...). This is different from a normal
2275 // rust distribution where they are the same.
2277 // On the cargo side, normal tests use `target_process` which handles
2278 // setting up the dylib for a *target* (stage1/lib/rustlib/... in this
2279 // case). However, for doctests it uses `rustdoc_process` which only
2280 // sets up the dylib path for the *host* (stage1/lib), which is the
2283 // Recall that we special-cased `compiler_for(top_stage)` above, so we always use stage1.
2285 // It should be considered to just stop running doctests on
2286 // librustdoc. There is only one test, and it doesn't look too
2287 // important. There might be other ways to avoid this, but it seems
2288 // pretty convoluted.
2290 // See also https://github.com/rust-lang/rust/issues/13983 where the
2291 // host vs target dylibs for rustdoc are consistently tricky to deal
2294 // Note that this set the host libdir for `download_rustc`, which uses a normal rust distribution.
2295 let libdir = if builder.download_rustc() {
2296 builder.rustc_libdir(compiler)
2298 builder.sysroot_libdir(compiler, target).to_path_buf()
2300 let mut dylib_path = dylib_path();
2301 dylib_path.insert(0, PathBuf::from(&*libdir));
2302 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
2304 if !builder.config.verbose_tests {
2305 cargo.arg("--quiet");
2308 builder.info(&format!(
2309 "{} rustdoc stage{} ({} -> {})",
2310 test_kind, compiler.stage, &compiler.host, target
2312 let _time = util::timeit(&builder);
2314 try_run(builder, &mut cargo.into());
2318 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2319 pub struct CrateRustdocJsonTypes {
2320 host: TargetSelection,
2321 test_kind: TestKind,
2324 impl Step for CrateRustdocJsonTypes {
2326 const DEFAULT: bool = true;
2327 const ONLY_HOSTS: bool = true;
2329 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2330 run.path("src/rustdoc-json-types")
2333 fn make_run(run: RunConfig<'_>) {
2334 let builder = run.builder;
2336 let test_kind = builder.kind.into();
2338 builder.ensure(CrateRustdocJsonTypes { host: run.target, test_kind });
2341 fn run(self, builder: &Builder<'_>) {
2342 let test_kind = self.test_kind;
2343 let target = self.host;
2345 // Use the previous stage compiler to reuse the artifacts that are
2346 // created when running compiletest for tests/rustdoc. If this used
2347 // `compiler`, then it would cause rustdoc to be built *again*, which
2348 // isn't really necessary.
2349 let compiler = builder.compiler_for(builder.top_stage, target, target);
2350 builder.ensure(compile::Rustc::new(compiler, target));
2352 let mut cargo = tool::prepare_tool_cargo(
2357 test_kind.subcommand(),
2358 "src/rustdoc-json-types",
2362 if test_kind.subcommand() == "test" && !builder.fail_fast {
2363 cargo.arg("--no-fail-fast");
2366 cargo.arg("-p").arg("rustdoc-json-types");
2369 cargo.args(&builder.config.cmd.test_args());
2371 if self.host.contains("musl") {
2372 cargo.arg("'-Ctarget-feature=-crt-static'");
2375 if !builder.config.verbose_tests {
2376 cargo.arg("--quiet");
2379 builder.info(&format!(
2380 "{} rustdoc-json-types stage{} ({} -> {})",
2381 test_kind, compiler.stage, &compiler.host, target
2383 let _time = util::timeit(&builder);
2385 try_run(builder, &mut cargo.into());
2389 /// Some test suites are run inside emulators or on remote devices, and most
2390 /// of our test binaries are linked dynamically which means we need to ship
2391 /// the standard library and such to the emulator ahead of time. This step
2392 /// represents this and is a dependency of all test suites.
2394 /// Most of the time this is a no-op. For some steps such as shipping data to
2395 /// QEMU we have to build our own tools so we've got conditional dependencies
2396 /// on those programs as well. Note that the remote test client is built for
2397 /// the build target (us) and the server is built for the target.
2398 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2399 pub struct RemoteCopyLibs {
2401 target: TargetSelection,
2404 impl Step for RemoteCopyLibs {
2407 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2411 fn run(self, builder: &Builder<'_>) {
2412 let compiler = self.compiler;
2413 let target = self.target;
2414 if !builder.remote_tested(target) {
2418 builder.ensure(compile::Std::new(compiler, target));
2420 builder.info(&format!("REMOTE copy libs to emulator ({})", target));
2422 let server = builder.ensure(tool::RemoteTestServer { compiler, target });
2424 // Spawn the emulator and wait for it to come online
2425 let tool = builder.tool_exe(Tool::RemoteTestClient);
2426 let mut cmd = Command::new(&tool);
2427 cmd.arg("spawn-emulator").arg(target.triple).arg(&server).arg(builder.tempdir());
2428 if let Some(rootfs) = builder.qemu_rootfs(target) {
2431 builder.run(&mut cmd);
2433 // Push all our dylibs to the emulator
2434 for f in t!(builder.sysroot_libdir(compiler, target).read_dir()) {
2436 let name = f.file_name().into_string().unwrap();
2437 if util::is_dylib(&name) {
2438 builder.run(Command::new(&tool).arg("push").arg(f.path()));
2444 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2445 pub struct Distcheck;
2447 impl Step for Distcheck {
2450 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2451 run.alias("distcheck")
2454 fn make_run(run: RunConfig<'_>) {
2455 run.builder.ensure(Distcheck);
2458 /// Runs "distcheck", a 'make check' from a tarball
2459 fn run(self, builder: &Builder<'_>) {
2460 builder.info("Distcheck");
2461 let dir = builder.tempdir().join("distcheck");
2462 let _ = fs::remove_dir_all(&dir);
2463 t!(fs::create_dir_all(&dir));
2465 // Guarantee that these are built before we begin running.
2466 builder.ensure(dist::PlainSourceTarball);
2467 builder.ensure(dist::Src);
2469 let mut cmd = Command::new("tar");
2471 .arg(builder.ensure(dist::PlainSourceTarball).tarball())
2472 .arg("--strip-components=1")
2474 builder.run(&mut cmd);
2476 Command::new("./configure")
2477 .args(&builder.config.configure_args)
2478 .arg("--enable-vendor")
2482 Command::new(util::make(&builder.config.build.triple)).arg("check").current_dir(&dir),
2485 // Now make sure that rust-src has all of libstd's dependencies
2486 builder.info("Distcheck rust-src");
2487 let dir = builder.tempdir().join("distcheck-src");
2488 let _ = fs::remove_dir_all(&dir);
2489 t!(fs::create_dir_all(&dir));
2491 let mut cmd = Command::new("tar");
2493 .arg(builder.ensure(dist::Src).tarball())
2494 .arg("--strip-components=1")
2496 builder.run(&mut cmd);
2498 let toml = dir.join("rust-src/lib/rustlib/src/rust/library/std/Cargo.toml");
2500 Command::new(&builder.initial_cargo)
2501 .arg("generate-lockfile")
2502 .arg("--manifest-path")
2509 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2510 pub struct Bootstrap;
2512 impl Step for Bootstrap {
2514 const DEFAULT: bool = true;
2515 const ONLY_HOSTS: bool = true;
2517 /// Tests the build system itself.
2518 fn run(self, builder: &Builder<'_>) {
2519 let mut check_bootstrap = Command::new(&builder.python());
2520 check_bootstrap.arg("bootstrap_test.py").current_dir(builder.src.join("src/bootstrap/"));
2521 try_run(builder, &mut check_bootstrap);
2523 let mut cmd = Command::new(&builder.initial_cargo);
2525 .current_dir(builder.src.join("src/bootstrap"))
2526 .env("RUSTFLAGS", "-Cdebuginfo=2")
2527 .env("CARGO_TARGET_DIR", builder.out.join("bootstrap"))
2528 .env("RUSTC_BOOTSTRAP", "1")
2529 .env("RUSTDOC", builder.rustdoc(builder.compiler(0, builder.build.build)))
2530 .env("RUSTC", &builder.initial_rustc);
2531 if let Some(flags) = option_env!("RUSTFLAGS") {
2532 // Use the same rustc flags for testing as for "normal" compilation,
2533 // so that Cargo doesn’t recompile the entire dependency graph every time:
2534 // https://github.com/rust-lang/rust/issues/49215
2535 cmd.env("RUSTFLAGS", flags);
2537 if !builder.fail_fast {
2538 cmd.arg("--no-fail-fast");
2540 match builder.doc_tests {
2545 cmd.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
2550 cmd.arg("--").args(&builder.config.cmd.test_args());
2551 // rustbuild tests are racy on directory creation so just run them one at a time.
2552 // Since there's not many this shouldn't be a problem.
2553 cmd.arg("--test-threads=1");
2554 try_run(builder, &mut cmd);
2557 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2558 run.path("src/bootstrap")
2561 fn make_run(run: RunConfig<'_>) {
2562 run.builder.ensure(Bootstrap);
2566 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2567 pub struct TierCheck {
2568 pub compiler: Compiler,
2571 impl Step for TierCheck {
2573 const DEFAULT: bool = true;
2574 const ONLY_HOSTS: bool = true;
2576 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2577 run.path("src/tools/tier-check")
2580 fn make_run(run: RunConfig<'_>) {
2582 run.builder.compiler_for(run.builder.top_stage, run.builder.build.build, run.target);
2583 run.builder.ensure(TierCheck { compiler });
2586 /// Tests the Platform Support page in the rustc book.
2587 fn run(self, builder: &Builder<'_>) {
2588 builder.ensure(compile::Std::new(self.compiler, self.compiler.host));
2589 let mut cargo = tool::prepare_tool_cargo(
2595 "src/tools/tier-check",
2599 cargo.arg(builder.src.join("src/doc/rustc/src/platform-support.md"));
2600 cargo.arg(&builder.rustc(self.compiler));
2601 if builder.is_verbose() {
2602 cargo.arg("--verbose");
2605 builder.info("platform support check");
2606 try_run(builder, &mut cargo.into());
2610 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2611 pub struct ReplacePlaceholderTest;
2613 impl Step for ReplacePlaceholderTest {
2615 const ONLY_HOSTS: bool = true;
2616 const DEFAULT: bool = true;
2618 /// Ensure the version placeholder replacement tool builds
2619 fn run(self, builder: &Builder<'_>) {
2620 builder.info("build check for version replacement placeholder");
2622 // Test the version placeholder replacement tool itself.
2623 let bootstrap_host = builder.config.build;
2624 let compiler = builder.compiler(0, bootstrap_host);
2625 let cargo = tool::prepare_tool_cargo(
2628 Mode::ToolBootstrap,
2631 "src/tools/replace-version-placeholder",
2635 try_run(builder, &mut cargo.into());
2638 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2639 run.path("src/tools/replace-version-placeholder")
2642 fn make_run(run: RunConfig<'_>) {
2643 run.builder.ensure(Self);
2647 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2648 pub struct LintDocs {
2649 pub compiler: Compiler,
2650 pub target: TargetSelection,
2653 impl Step for LintDocs {
2655 const DEFAULT: bool = true;
2656 const ONLY_HOSTS: bool = true;
2658 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2659 run.path("src/tools/lint-docs")
2662 fn make_run(run: RunConfig<'_>) {
2663 run.builder.ensure(LintDocs {
2664 compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
2669 /// Tests that the lint examples in the rustc book generate the correct
2670 /// lints and have the expected format.
2671 fn run(self, builder: &Builder<'_>) {
2672 builder.ensure(crate::doc::RustcBook {
2673 compiler: self.compiler,
2674 target: self.target,