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::flags::Subcommand;
21 use crate::tool::{self, SourceType, Tool};
22 use crate::toolstate::ToolState;
23 use crate::util::{self, add_link_lib_path, dylib_path, dylib_path_var, output, t};
24 use crate::{envify, CLang, DocTests, GitRepo, Mode};
26 const ADB_TEST_DIR: &str = "/data/local/tmp/work";
28 /// The two modes of the test runner; tests or benchmarks.
29 #[derive(Debug, PartialEq, Eq, Hash, Copy, Clone, PartialOrd, Ord)]
33 /// Run `cargo bench`.
37 impl From<Kind> for TestKind {
38 fn from(kind: Kind) -> Self {
40 Kind::Test => TestKind::Test,
41 Kind::Bench => TestKind::Bench,
42 _ => panic!("unexpected kind in crate: {:?}", kind),
48 // Return the cargo subcommand for this test kind
49 fn subcommand(self) -> &'static str {
51 TestKind::Test => "test",
52 TestKind::Bench => "bench",
57 impl fmt::Display for TestKind {
58 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
59 f.write_str(match *self {
60 TestKind::Test => "Testing",
61 TestKind::Bench => "Benchmarking",
66 fn try_run(builder: &Builder<'_>, cmd: &mut Command) -> bool {
67 if !builder.fail_fast {
68 if !builder.try_run(cmd) {
69 let mut failures = builder.delayed_failures.borrow_mut();
70 failures.push(format!("{:?}", cmd));
79 fn try_run_quiet(builder: &Builder<'_>, cmd: &mut Command) -> bool {
80 if !builder.fail_fast {
81 if !builder.try_run_quiet(cmd) {
82 let mut failures = builder.delayed_failures.borrow_mut();
83 failures.push(format!("{:?}", cmd));
87 builder.run_quiet(cmd);
92 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
93 pub struct Linkcheck {
94 host: TargetSelection,
97 impl Step for Linkcheck {
99 const ONLY_HOSTS: bool = true;
100 const DEFAULT: bool = true;
102 /// Runs the `linkchecker` tool as compiled in `stage` by the `host` compiler.
104 /// This tool in `src/tools` will verify the validity of all our links in the
105 /// documentation to ensure we don't have a bunch of dead ones.
106 fn run(self, builder: &Builder<'_>) {
107 let host = self.host;
108 let hosts = &builder.hosts;
109 let targets = &builder.targets;
111 // if we have different hosts and targets, some things may be built for
112 // the host (e.g. rustc) and others for the target (e.g. std). The
113 // documentation built for each will contain broken links to
114 // docs built for the other platform (e.g. rustc linking to cargo)
115 if (hosts != targets) && !hosts.is_empty() && !targets.is_empty() {
117 "Linkcheck currently does not support builds with different hosts and targets.
118 You can skip linkcheck with --exclude src/tools/linkchecker"
122 builder.info(&format!("Linkcheck ({})", host));
124 // Test the linkchecker itself.
125 let bootstrap_host = builder.config.build;
126 let compiler = builder.compiler(0, bootstrap_host);
127 let cargo = tool::prepare_tool_cargo(
133 "src/tools/linkchecker",
137 try_run(builder, &mut cargo.into());
139 // Build all the default documentation.
140 builder.default_doc(&[]);
142 // Run the linkchecker.
143 let _time = util::timeit(&builder);
146 builder.tool_cmd(Tool::Linkchecker).arg(builder.out.join(host.triple).join("doc")),
150 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
151 let builder = run.builder;
152 let run = run.path("src/tools/linkchecker");
153 run.default_condition(builder.config.docs)
156 fn make_run(run: RunConfig<'_>) {
157 run.builder.ensure(Linkcheck { host: run.target });
161 fn check_if_tidy_is_installed() -> bool {
164 .stdout(Stdio::null())
166 .map_or(false, |status| status.success())
169 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
170 pub struct HtmlCheck {
171 target: TargetSelection,
174 impl Step for HtmlCheck {
176 const DEFAULT: bool = true;
177 const ONLY_HOSTS: bool = true;
179 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
180 let run = run.path("src/tools/html-checker");
181 run.lazy_default_condition(Box::new(check_if_tidy_is_installed))
184 fn make_run(run: RunConfig<'_>) {
185 run.builder.ensure(HtmlCheck { target: run.target });
188 fn run(self, builder: &Builder<'_>) {
189 if !check_if_tidy_is_installed() {
190 eprintln!("not running HTML-check tool because `tidy` is missing");
192 "Note that `tidy` is not the in-tree `src/tools/tidy` but needs to be installed"
194 panic!("Cannot run html-check tests");
196 // Ensure that a few different kinds of documentation are available.
197 builder.default_doc(&[]);
198 builder.ensure(crate::doc::Rustc { target: self.target, stage: builder.top_stage });
200 try_run(builder, builder.tool_cmd(Tool::HtmlChecker).arg(builder.doc_out(self.target)));
204 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
205 pub struct Cargotest {
207 host: TargetSelection,
210 impl Step for Cargotest {
212 const ONLY_HOSTS: bool = true;
214 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
215 run.path("src/tools/cargotest")
218 fn make_run(run: RunConfig<'_>) {
219 run.builder.ensure(Cargotest { stage: run.builder.top_stage, host: run.target });
222 /// Runs the `cargotest` tool as compiled in `stage` by the `host` compiler.
224 /// This tool in `src/tools` will check out a few Rust projects and run `cargo
225 /// test` to ensure that we don't regress the test suites there.
226 fn run(self, builder: &Builder<'_>) {
227 let compiler = builder.compiler(self.stage, self.host);
228 builder.ensure(compile::Rustc::new(compiler, compiler.host));
229 let cargo = builder.ensure(tool::Cargo { compiler, target: compiler.host });
231 // Note that this is a short, cryptic, and not scoped directory name. This
232 // is currently to minimize the length of path on Windows where we otherwise
233 // quickly run into path name limit constraints.
234 let out_dir = builder.out.join("ct");
235 t!(fs::create_dir_all(&out_dir));
237 let _time = util::timeit(&builder);
238 let mut cmd = builder.tool_cmd(Tool::CargoTest);
243 .args(builder.config.cmd.test_args())
244 .env("RUSTC", builder.rustc(compiler))
245 .env("RUSTDOC", builder.rustdoc(compiler)),
250 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
253 host: TargetSelection,
256 impl Step for Cargo {
258 const ONLY_HOSTS: bool = true;
260 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
261 run.path("src/tools/cargo")
264 fn make_run(run: RunConfig<'_>) {
265 run.builder.ensure(Cargo { stage: run.builder.top_stage, host: run.target });
268 /// Runs `cargo test` for `cargo` packaged with Rust.
269 fn run(self, builder: &Builder<'_>) {
270 let compiler = builder.compiler(self.stage, self.host);
272 builder.ensure(tool::Cargo { compiler, target: self.host });
273 let mut cargo = tool::prepare_tool_cargo(
280 SourceType::Submodule,
284 if !builder.fail_fast {
285 cargo.arg("--no-fail-fast");
287 cargo.arg("--").args(builder.config.cmd.test_args());
289 // Don't run cross-compile tests, we may not have cross-compiled libstd libs
291 cargo.env("CFG_DISABLE_CROSS_TESTS", "1");
292 // Forcibly disable tests using nightly features since any changes to
293 // those features won't be able to land.
294 cargo.env("CARGO_TEST_DISABLE_NIGHTLY", "1");
296 cargo.env("PATH", &path_for_cargo(builder, compiler));
298 try_run(builder, &mut cargo.into());
302 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
303 pub struct RustAnalyzer {
305 host: TargetSelection,
308 impl Step for RustAnalyzer {
310 const ONLY_HOSTS: bool = true;
311 const DEFAULT: bool = true;
313 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
314 run.path("src/tools/rust-analyzer")
317 fn make_run(run: RunConfig<'_>) {
318 run.builder.ensure(Self { stage: run.builder.top_stage, host: run.target });
321 /// Runs `cargo test` for rust-analyzer
322 fn run(self, builder: &Builder<'_>) {
323 let stage = self.stage;
324 let host = self.host;
325 let compiler = builder.compiler(stage, host);
327 builder.ensure(tool::RustAnalyzer { compiler, target: self.host }).expect("in-tree tool");
329 let workspace_path = "src/tools/rust-analyzer";
330 // until the whole RA test suite runs on `i686`, we only run
331 // `proc-macro-srv` tests
332 let crate_path = "src/tools/rust-analyzer/crates/proc-macro-srv";
333 let mut cargo = tool::prepare_tool_cargo(
341 &["sysroot-abi".to_owned()],
344 let dir = builder.src.join(workspace_path);
345 // needed by rust-analyzer to find its own text fixtures, cf.
346 // https://github.com/rust-analyzer/expect-test/issues/33
347 cargo.env("CARGO_WORKSPACE_DIR", &dir);
349 // RA's test suite tries to write to the source directory, that can't
351 cargo.env("SKIP_SLOW_TESTS", "1");
353 cargo.add_rustc_lib_path(builder, compiler);
354 cargo.arg("--").args(builder.config.cmd.test_args());
356 builder.run(&mut cargo.into());
360 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
363 host: TargetSelection,
366 impl Step for Rustfmt {
368 const ONLY_HOSTS: bool = true;
370 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
371 run.path("src/tools/rustfmt")
374 fn make_run(run: RunConfig<'_>) {
375 run.builder.ensure(Rustfmt { stage: run.builder.top_stage, host: run.target });
378 /// Runs `cargo test` for rustfmt.
379 fn run(self, builder: &Builder<'_>) {
380 let stage = self.stage;
381 let host = self.host;
382 let compiler = builder.compiler(stage, host);
385 .ensure(tool::Rustfmt { compiler, target: self.host, extra_features: Vec::new() })
386 .expect("in-tree tool");
388 let mut cargo = tool::prepare_tool_cargo(
399 let dir = testdir(builder, compiler.host);
400 t!(fs::create_dir_all(&dir));
401 cargo.env("RUSTFMT_TEST_DIR", dir);
403 cargo.add_rustc_lib_path(builder, compiler);
405 builder.run(&mut cargo.into());
409 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
410 pub struct RustDemangler {
412 host: TargetSelection,
415 impl Step for RustDemangler {
417 const ONLY_HOSTS: bool = true;
419 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
420 run.path("src/tools/rust-demangler")
423 fn make_run(run: RunConfig<'_>) {
424 run.builder.ensure(RustDemangler { stage: run.builder.top_stage, host: run.target });
427 /// Runs `cargo test` for rust-demangler.
428 fn run(self, builder: &Builder<'_>) {
429 let stage = self.stage;
430 let host = self.host;
431 let compiler = builder.compiler(stage, host);
433 let rust_demangler = builder
434 .ensure(tool::RustDemangler { compiler, target: self.host, extra_features: Vec::new() })
435 .expect("in-tree tool");
436 let mut cargo = tool::prepare_tool_cargo(
442 "src/tools/rust-demangler",
447 let dir = testdir(builder, compiler.host);
448 t!(fs::create_dir_all(&dir));
450 cargo.env("RUST_DEMANGLER_DRIVER_PATH", rust_demangler);
452 cargo.arg("--").args(builder.config.cmd.test_args());
454 cargo.add_rustc_lib_path(builder, compiler);
456 builder.run(&mut cargo.into());
460 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
463 host: TargetSelection,
464 target: TargetSelection,
469 const ONLY_HOSTS: bool = false;
471 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
472 run.path("src/tools/miri")
475 fn make_run(run: RunConfig<'_>) {
476 run.builder.ensure(Miri {
477 stage: run.builder.top_stage,
478 host: run.build_triple(),
483 /// Runs `cargo test` for miri.
484 fn run(self, builder: &Builder<'_>) {
485 let stage = self.stage;
486 let host = self.host;
487 let target = self.target;
488 let compiler = builder.compiler(stage, host);
489 // We need the stdlib for the *next* stage, as it was built with this compiler that also built Miri.
490 // Except if we are at stage 2, the bootstrap loop is complete and we can stick with our current stage.
491 let compiler_std = builder.compiler(if stage < 2 { stage + 1 } else { stage }, host);
494 .ensure(tool::Miri { compiler, target: self.host, extra_features: Vec::new() })
495 .expect("in-tree tool");
496 let _cargo_miri = builder
497 .ensure(tool::CargoMiri { compiler, target: self.host, extra_features: Vec::new() })
498 .expect("in-tree tool");
499 // The stdlib we need might be at a different stage. And just asking for the
500 // sysroot does not seem to populate it, so we do that first.
501 builder.ensure(compile::Std::new(compiler_std, host));
502 let sysroot = builder.sysroot(compiler_std);
504 // # Run `cargo miri setup` for the given target.
505 let mut cargo = tool::prepare_tool_cargo(
511 "src/tools/miri/cargo-miri",
515 cargo.add_rustc_lib_path(builder, compiler);
516 cargo.arg("--").arg("miri").arg("setup");
517 cargo.arg("--target").arg(target.rustc_target_arg());
519 // Tell `cargo miri setup` where to find the sources.
520 cargo.env("MIRI_LIB_SRC", builder.src.join("library"));
521 // Tell it where to find Miri.
522 cargo.env("MIRI", &miri);
524 cargo.env("RUST_BACKTRACE", "1");
526 let mut cargo = Command::from(cargo);
527 builder.run(&mut cargo);
529 // # Determine where Miri put its sysroot.
530 // To this end, we run `cargo miri setup --print-sysroot` and capture the output.
531 // (We do this separately from the above so that when the setup actually
532 // happens we get some output.)
533 // We re-use the `cargo` from above.
534 cargo.arg("--print-sysroot");
536 // FIXME: Is there a way in which we can re-use the usual `run` helpers?
537 let miri_sysroot = if builder.config.dry_run {
540 builder.verbose(&format!("running: {:?}", cargo));
542 cargo.output().expect("We already ran `cargo miri setup` before and that worked");
543 assert!(out.status.success(), "`cargo miri setup` returned with non-0 exit code");
544 // Output is "<sysroot>\n".
545 let stdout = String::from_utf8(out.stdout)
546 .expect("`cargo miri setup` stdout is not valid UTF-8");
547 let sysroot = stdout.trim_end();
548 builder.verbose(&format!("`cargo miri setup --print-sysroot` said: {:?}", sysroot));
552 // # Run `cargo test`.
553 let mut cargo = tool::prepare_tool_cargo(
563 cargo.add_rustc_lib_path(builder, compiler);
565 // miri tests need to know about the stage sysroot
566 cargo.env("MIRI_SYSROOT", &miri_sysroot);
567 cargo.env("MIRI_HOST_SYSROOT", sysroot);
568 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
569 cargo.env("MIRI", &miri);
571 if builder.config.cmd.bless() {
572 cargo.env("MIRI_BLESS", "Gesundheit");
576 cargo.env("MIRI_TEST_TARGET", target.rustc_target_arg());
577 // Forward test filters.
578 cargo.arg("--").args(builder.config.cmd.test_args());
580 let mut cargo = Command::from(cargo);
581 builder.run(&mut cargo);
583 // # Run `cargo miri test`.
584 // This is just a smoke test (Miri's own CI invokes this in a bunch of different ways and ensures
585 // that we get the desired output), but that is sufficient to make sure that the libtest harness
586 // itself executes properly under Miri.
587 let mut cargo = tool::prepare_tool_cargo(
593 "src/tools/miri/cargo-miri",
594 SourceType::Submodule,
597 cargo.add_rustc_lib_path(builder, compiler);
598 cargo.arg("--").arg("miri").arg("test");
600 .arg("--manifest-path")
601 .arg(builder.src.join("src/tools/miri/test-cargo-miri/Cargo.toml"));
602 cargo.arg("--target").arg(target.rustc_target_arg());
603 cargo.arg("--tests"); // don't run doctests, they are too confused by the staging
604 cargo.arg("--").args(builder.config.cmd.test_args());
606 // Tell `cargo miri` where to find things.
607 cargo.env("MIRI_SYSROOT", &miri_sysroot);
608 cargo.env("MIRI_HOST_SYSROOT", sysroot);
609 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
610 cargo.env("MIRI", &miri);
612 cargo.env("RUST_BACKTRACE", "1");
614 let mut cargo = Command::from(cargo);
615 builder.run(&mut cargo);
619 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
620 pub struct CompiletestTest {
621 host: TargetSelection,
624 impl Step for CompiletestTest {
627 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
628 run.path("src/tools/compiletest")
631 fn make_run(run: RunConfig<'_>) {
632 run.builder.ensure(CompiletestTest { host: run.target });
635 /// Runs `cargo test` for compiletest.
636 fn run(self, builder: &Builder<'_>) {
637 let host = self.host;
638 let compiler = builder.compiler(0, host);
640 // We need `ToolStd` for the locally-built sysroot because
641 // compiletest uses unstable features of the `test` crate.
642 builder.ensure(compile::Std::new(compiler, host));
643 let cargo = tool::prepare_tool_cargo(
649 "src/tools/compiletest",
654 try_run(builder, &mut cargo.into());
658 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
661 host: TargetSelection,
664 impl Step for Clippy {
666 const ONLY_HOSTS: bool = true;
667 const DEFAULT: bool = false;
669 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
670 run.path("src/tools/clippy")
673 fn make_run(run: RunConfig<'_>) {
674 run.builder.ensure(Clippy { stage: run.builder.top_stage, host: run.target });
677 /// Runs `cargo test` for clippy.
678 fn run(self, builder: &Builder<'_>) {
679 let stage = self.stage;
680 let host = self.host;
681 let compiler = builder.compiler(stage, host);
684 .ensure(tool::Clippy { compiler, target: self.host, extra_features: Vec::new() })
685 .expect("in-tree tool");
686 let mut cargo = tool::prepare_tool_cargo(
697 cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
698 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
699 let host_libs = builder.stage_out(compiler, Mode::ToolRustc).join(builder.cargo_dir());
700 cargo.env("HOST_LIBS", host_libs);
702 cargo.arg("--").args(builder.config.cmd.test_args());
704 cargo.add_rustc_lib_path(builder, compiler);
706 if builder.try_run(&mut cargo.into()) {
707 // The tests succeeded; nothing to do.
711 if !builder.config.cmd.bless() {
712 crate::detail_exit(1);
715 let mut cargo = builder.cargo(compiler, Mode::ToolRustc, SourceType::InTree, host, "run");
716 cargo.arg("-p").arg("clippy_dev");
717 // clippy_dev gets confused if it can't find `clippy/Cargo.toml`
718 cargo.current_dir(&builder.src.join("src").join("tools").join("clippy"));
719 if builder.config.rust_optimize {
720 cargo.env("PROFILE", "release");
722 cargo.env("PROFILE", "debug");
726 builder.run(&mut cargo.into());
730 fn path_for_cargo(builder: &Builder<'_>, compiler: Compiler) -> OsString {
731 // Configure PATH to find the right rustc. NB. we have to use PATH
732 // and not RUSTC because the Cargo test suite has tests that will
733 // fail if rustc is not spelled `rustc`.
734 let path = builder.sysroot(compiler).join("bin");
735 let old_path = env::var_os("PATH").unwrap_or_default();
736 env::join_paths(iter::once(path).chain(env::split_paths(&old_path))).expect("")
739 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
740 pub struct RustdocTheme {
741 pub compiler: Compiler,
744 impl Step for RustdocTheme {
746 const DEFAULT: bool = true;
747 const ONLY_HOSTS: bool = true;
749 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
750 run.path("src/tools/rustdoc-themes")
753 fn make_run(run: RunConfig<'_>) {
754 let compiler = run.builder.compiler(run.builder.top_stage, run.target);
756 run.builder.ensure(RustdocTheme { compiler });
759 fn run(self, builder: &Builder<'_>) {
760 let rustdoc = builder.bootstrap_out.join("rustdoc");
761 let mut cmd = builder.tool_cmd(Tool::RustdocTheme);
762 cmd.arg(rustdoc.to_str().unwrap())
763 .arg(builder.src.join("src/librustdoc/html/static/css/themes").to_str().unwrap())
764 .env("RUSTC_STAGE", self.compiler.stage.to_string())
765 .env("RUSTC_SYSROOT", builder.sysroot(self.compiler))
766 .env("RUSTDOC_LIBDIR", builder.sysroot_libdir(self.compiler, self.compiler.host))
767 .env("CFG_RELEASE_CHANNEL", &builder.config.channel)
768 .env("RUSTDOC_REAL", builder.rustdoc(self.compiler))
769 .env("RUSTC_BOOTSTRAP", "1");
770 if let Some(linker) = builder.linker(self.compiler.host) {
771 cmd.env("RUSTDOC_LINKER", linker);
773 if builder.is_fuse_ld_lld(self.compiler.host) {
775 "RUSTDOC_LLD_NO_THREADS",
776 util::lld_flag_no_threads(self.compiler.host.contains("windows")),
779 try_run(builder, &mut cmd);
783 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
784 pub struct RustdocJSStd {
785 pub target: TargetSelection,
788 impl Step for RustdocJSStd {
790 const DEFAULT: bool = true;
791 const ONLY_HOSTS: bool = true;
793 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
794 run.suite_path("src/test/rustdoc-js-std")
797 fn make_run(run: RunConfig<'_>) {
798 run.builder.ensure(RustdocJSStd { target: run.target });
801 fn run(self, builder: &Builder<'_>) {
802 if let Some(ref nodejs) = builder.config.nodejs {
803 let mut command = Command::new(nodejs);
805 .arg(builder.src.join("src/tools/rustdoc-js/tester.js"))
808 .arg("--resource-suffix")
809 .arg(&builder.version)
811 .arg(builder.doc_out(self.target))
812 .arg("--test-folder")
813 .arg(builder.src.join("src/test/rustdoc-js-std"));
814 for path in &builder.paths {
816 util::is_valid_test_suite_arg(path, "src/test/rustdoc-js-std", builder)
818 if !p.ends_with(".js") {
819 eprintln!("A non-js file was given: `{}`", path.display());
820 panic!("Cannot run rustdoc-js-std tests");
822 command.arg("--test-file").arg(path);
825 builder.ensure(crate::doc::Std { target: self.target, stage: builder.top_stage });
826 builder.run(&mut command);
828 builder.info("No nodejs found, skipping \"src/test/rustdoc-js-std\" tests");
833 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
834 pub struct RustdocJSNotStd {
835 pub target: TargetSelection,
836 pub compiler: Compiler,
839 impl Step for RustdocJSNotStd {
841 const DEFAULT: bool = true;
842 const ONLY_HOSTS: bool = true;
844 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
845 run.suite_path("src/test/rustdoc-js")
848 fn make_run(run: RunConfig<'_>) {
849 let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
850 run.builder.ensure(RustdocJSNotStd { target: run.target, compiler });
853 fn run(self, builder: &Builder<'_>) {
854 if builder.config.nodejs.is_some() {
855 builder.ensure(Compiletest {
856 compiler: self.compiler,
860 path: "src/test/rustdoc-js",
864 builder.info("No nodejs found, skipping \"src/test/rustdoc-js\" tests");
869 fn get_browser_ui_test_version_inner(npm: &Path, global: bool) -> Option<String> {
870 let mut command = Command::new(&npm);
871 command.arg("list").arg("--parseable").arg("--long").arg("--depth=0");
873 command.arg("--global");
877 .map(|output| String::from_utf8_lossy(&output.stdout).into_owned())
878 .unwrap_or(String::new());
881 .find_map(|l| l.split(':').nth(1)?.strip_prefix("browser-ui-test@"))
882 .map(|v| v.to_owned())
885 fn get_browser_ui_test_version(npm: &Path) -> Option<String> {
886 get_browser_ui_test_version_inner(npm, false)
887 .or_else(|| get_browser_ui_test_version_inner(npm, true))
890 fn compare_browser_ui_test_version(installed_version: &str, src: &Path) {
891 match fs::read_to_string(
892 src.join("src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version"),
895 if v.trim() != installed_version {
897 "⚠️ Installed version of browser-ui-test (`{}`) is different than the \
898 one used in the CI (`{}`)",
902 "You can install this version using `npm update browser-ui-test` or by using \
903 `npm install browser-ui-test@{}`",
908 Err(e) => eprintln!("Couldn't find the CI browser-ui-test version: {:?}", e),
912 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
913 pub struct RustdocGUI {
914 pub target: TargetSelection,
915 pub compiler: Compiler,
918 impl Step for RustdocGUI {
920 const DEFAULT: bool = true;
921 const ONLY_HOSTS: bool = true;
923 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
924 let builder = run.builder;
925 let run = run.suite_path("src/test/rustdoc-gui");
926 run.lazy_default_condition(Box::new(move || {
927 builder.config.nodejs.is_some()
932 .map(|p| get_browser_ui_test_version(p).is_some())
937 fn make_run(run: RunConfig<'_>) {
938 let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
939 run.builder.ensure(RustdocGUI { target: run.target, compiler });
942 fn run(self, builder: &Builder<'_>) {
943 let nodejs = builder.config.nodejs.as_ref().expect("nodejs isn't available");
944 let npm = builder.config.npm.as_ref().expect("npm isn't available");
946 builder.ensure(compile::Std::new(self.compiler, self.target));
948 // The goal here is to check if the necessary packages are installed, and if not, we
950 match get_browser_ui_test_version(&npm) {
952 // We also check the version currently used in CI and emit a warning if it's not the
954 compare_browser_ui_test_version(&version, &builder.build.src);
958 "error: rustdoc-gui test suite cannot be run because npm `browser-ui-test` \
959 dependency is missing",
962 "If you want to install the `{0}` dependency, run `npm install {0}`",
965 panic!("Cannot run rustdoc-gui tests");
969 let out_dir = builder.test_out(self.target).join("rustdoc-gui");
971 // We remove existing folder to be sure there won't be artifacts remaining.
972 builder.clear_if_dirty(&out_dir, &builder.rustdoc(self.compiler));
974 let src_path = builder.build.src.join("src/test/rustdoc-gui/src");
975 // We generate docs for the libraries present in the rustdoc-gui's src folder.
976 for entry in src_path.read_dir().expect("read_dir call failed") {
977 if let Ok(entry) = entry {
978 let path = entry.path();
984 let mut cargo = Command::new(&builder.initial_cargo);
989 .env("RUSTC_BOOTSTRAP", "1")
990 .env("RUSTDOC", builder.rustdoc(self.compiler))
991 .env("RUSTC", builder.rustc(self.compiler))
993 // FIXME: implement a `// compile-flags` command or similar
994 // instead of hard-coding this test
995 if entry.file_name() == "link_to_definition" {
996 cargo.env("RUSTDOCFLAGS", "-Zunstable-options --generate-link-to-definition");
998 builder.run(&mut cargo);
1002 // We now run GUI tests.
1003 let mut command = Command::new(&nodejs);
1005 .arg(builder.build.src.join("src/tools/rustdoc-gui/tester.js"))
1007 .arg(&builder.jobs().to_string())
1008 .arg("--doc-folder")
1009 .arg(out_dir.join("doc"))
1010 .arg("--tests-folder")
1011 .arg(builder.build.src.join("src/test/rustdoc-gui"));
1012 for path in &builder.paths {
1013 if let Some(p) = util::is_valid_test_suite_arg(path, "src/test/rustdoc-gui", builder) {
1014 if !p.ends_with(".goml") {
1015 eprintln!("A non-goml file was given: `{}`", path.display());
1016 panic!("Cannot run rustdoc-gui tests");
1018 if let Some(name) = path.file_name().and_then(|f| f.to_str()) {
1019 command.arg("--file").arg(name);
1023 for test_arg in builder.config.cmd.test_args() {
1024 command.arg(test_arg);
1026 builder.run(&mut command);
1030 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1033 impl Step for Tidy {
1035 const DEFAULT: bool = true;
1036 const ONLY_HOSTS: bool = true;
1038 /// Runs the `tidy` tool.
1040 /// This tool in `src/tools` checks up on various bits and pieces of style and
1041 /// otherwise just implements a few lint-like checks that are specific to the
1042 /// compiler itself.
1044 /// Once tidy passes, this step also runs `fmt --check` if tests are being run
1045 /// for the `dev` or `nightly` channels.
1046 fn run(self, builder: &Builder<'_>) {
1047 let mut cmd = builder.tool_cmd(Tool::Tidy);
1048 cmd.arg(&builder.src);
1049 cmd.arg(&builder.initial_cargo);
1050 cmd.arg(&builder.out);
1051 cmd.arg(builder.jobs().to_string());
1052 if builder.is_verbose() {
1053 cmd.arg("--verbose");
1056 builder.info("tidy check");
1057 try_run(builder, &mut cmd);
1059 if builder.config.channel == "dev" || builder.config.channel == "nightly" {
1060 builder.info("fmt check");
1061 if builder.initial_rustfmt().is_none() {
1062 let inferred_rustfmt_dir = builder.config.initial_rustc.parent().unwrap();
1065 error: no `rustfmt` binary found in {PATH}
1066 info: `rust.channel` is currently set to \"{CHAN}\"
1067 help: if you are testing a beta branch, set `rust.channel` to \"beta\" in the `config.toml` file
1068 help: to skip test's attempt to check tidiness, pass `--exclude src/tools/tidy` to `x.py test`",
1069 PATH = inferred_rustfmt_dir.display(),
1070 CHAN = builder.config.channel,
1072 crate::detail_exit(1);
1074 crate::format::format(&builder, !builder.config.cmd.bless(), &[]);
1078 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1079 run.path("src/tools/tidy")
1082 fn make_run(run: RunConfig<'_>) {
1083 run.builder.ensure(Tidy);
1087 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1088 pub struct ExpandYamlAnchors;
1090 impl Step for ExpandYamlAnchors {
1092 const ONLY_HOSTS: bool = true;
1094 /// Ensure the `generate-ci-config` tool was run locally.
1096 /// The tool in `src/tools` reads the CI definition in `src/ci/builders.yml` and generates the
1097 /// appropriate configuration for all our CI providers. This step ensures the tool was called
1098 /// by the user before committing CI changes.
1099 fn run(self, builder: &Builder<'_>) {
1100 builder.info("Ensuring the YAML anchors in the GitHub Actions config were expanded");
1103 &mut builder.tool_cmd(Tool::ExpandYamlAnchors).arg("check").arg(&builder.src),
1107 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1108 run.path("src/tools/expand-yaml-anchors")
1111 fn make_run(run: RunConfig<'_>) {
1112 run.builder.ensure(ExpandYamlAnchors);
1116 fn testdir(builder: &Builder<'_>, host: TargetSelection) -> PathBuf {
1117 builder.out.join(host.triple).join("test")
1120 macro_rules! default_test {
1121 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
1122 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: false });
1126 macro_rules! default_test_with_compare_mode {
1127 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr,
1128 compare_mode: $compare_mode:expr }) => {
1129 test_with_compare_mode!($name {
1135 compare_mode: $compare_mode
1140 macro_rules! host_test {
1141 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
1142 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: true });
1147 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
1148 host: $host:expr }) => {
1149 test_definitions!($name {
1160 macro_rules! test_with_compare_mode {
1161 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
1162 host: $host:expr, compare_mode: $compare_mode:expr }) => {
1163 test_definitions!($name {
1169 compare_mode: Some($compare_mode)
1174 macro_rules! test_definitions {
1179 default: $default:expr,
1181 compare_mode: $compare_mode:expr
1183 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1185 pub compiler: Compiler,
1186 pub target: TargetSelection,
1189 impl Step for $name {
1191 const DEFAULT: bool = $default;
1192 const ONLY_HOSTS: bool = $host;
1194 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1195 run.suite_path($path)
1198 fn make_run(run: RunConfig<'_>) {
1199 let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
1201 run.builder.ensure($name { compiler, target: run.target });
1204 fn run(self, builder: &Builder<'_>) {
1205 builder.ensure(Compiletest {
1206 compiler: self.compiler,
1207 target: self.target,
1211 compare_mode: $compare_mode,
1218 default_test!(Ui { path: "src/test/ui", mode: "ui", suite: "ui" });
1220 default_test!(RunPassValgrind {
1221 path: "src/test/run-pass-valgrind",
1222 mode: "run-pass-valgrind",
1223 suite: "run-pass-valgrind"
1226 default_test!(MirOpt { path: "src/test/mir-opt", mode: "mir-opt", suite: "mir-opt" });
1228 default_test!(Codegen { path: "src/test/codegen", mode: "codegen", suite: "codegen" });
1230 default_test!(CodegenUnits {
1231 path: "src/test/codegen-units",
1232 mode: "codegen-units",
1233 suite: "codegen-units"
1236 default_test!(Incremental {
1237 path: "src/test/incremental",
1238 mode: "incremental",
1239 suite: "incremental"
1242 default_test_with_compare_mode!(Debuginfo {
1243 path: "src/test/debuginfo",
1246 compare_mode: "split-dwarf"
1249 host_test!(UiFullDeps { path: "src/test/ui-fulldeps", mode: "ui", suite: "ui-fulldeps" });
1251 host_test!(Rustdoc { path: "src/test/rustdoc", mode: "rustdoc", suite: "rustdoc" });
1252 host_test!(RustdocUi { path: "src/test/rustdoc-ui", mode: "ui", suite: "rustdoc-ui" });
1254 host_test!(RustdocJson {
1255 path: "src/test/rustdoc-json",
1256 mode: "rustdoc-json",
1257 suite: "rustdoc-json"
1260 host_test!(Pretty { path: "src/test/pretty", mode: "pretty", suite: "pretty" });
1262 default_test!(RunMake { path: "src/test/run-make", mode: "run-make", suite: "run-make" });
1264 host_test!(RunMakeFullDeps {
1265 path: "src/test/run-make-fulldeps",
1267 suite: "run-make-fulldeps"
1270 default_test!(Assembly { path: "src/test/assembly", mode: "assembly", suite: "assembly" });
1272 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1273 struct Compiletest {
1275 target: TargetSelection,
1277 suite: &'static str,
1279 compare_mode: Option<&'static str>,
1282 impl Step for Compiletest {
1285 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1289 /// Executes the `compiletest` tool to run a suite of tests.
1291 /// Compiles all tests with `compiler` for `target` with the specified
1292 /// compiletest `mode` and `suite` arguments. For example `mode` can be
1293 /// "run-pass" or `suite` can be something like `debuginfo`.
1294 fn run(self, builder: &Builder<'_>) {
1295 if builder.top_stage == 0 && env::var("COMPILETEST_FORCE_STAGE0").is_err() {
1297 error: `--stage 0` runs compiletest on the beta compiler, not your local changes, and will almost always cause tests to fail
1298 help: to test the compiler, use `--stage 1` instead
1299 help: to test the standard library, use `--stage 0 library/std` instead
1300 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`."
1302 crate::detail_exit(1);
1305 let compiler = self.compiler;
1306 let target = self.target;
1307 let mode = self.mode;
1308 let suite = self.suite;
1310 // Path for test suite
1311 let suite_path = self.path;
1313 // Skip codegen tests if they aren't enabled in configuration.
1314 if !builder.config.codegen_tests && suite == "codegen" {
1318 if suite == "debuginfo" {
1320 .ensure(dist::DebuggerScripts { sysroot: builder.sysroot(compiler), host: target });
1323 if suite.ends_with("fulldeps") {
1324 builder.ensure(compile::Rustc::new(compiler, target));
1327 builder.ensure(compile::Std::new(compiler, target));
1328 // ensure that `libproc_macro` is available on the host.
1329 builder.ensure(compile::Std::new(compiler, compiler.host));
1331 // Also provide `rust_test_helpers` for the host.
1332 builder.ensure(native::TestHelpers { target: compiler.host });
1334 // As well as the target, except for plain wasm32, which can't build it
1335 if !target.contains("wasm") || target.contains("emscripten") {
1336 builder.ensure(native::TestHelpers { target });
1339 builder.ensure(RemoteCopyLibs { compiler, target });
1341 let mut cmd = builder.tool_cmd(Tool::Compiletest);
1343 // compiletest currently has... a lot of arguments, so let's just pass all
1346 cmd.arg("--compile-lib-path").arg(builder.rustc_libdir(compiler));
1347 cmd.arg("--run-lib-path").arg(builder.sysroot_libdir(compiler, target));
1348 cmd.arg("--rustc-path").arg(builder.rustc(compiler));
1350 let is_rustdoc = suite.ends_with("rustdoc-ui") || suite.ends_with("rustdoc-js");
1352 // Avoid depending on rustdoc when we don't need it.
1353 if mode == "rustdoc"
1354 || mode == "run-make"
1355 || (mode == "ui" && is_rustdoc)
1356 || mode == "js-doc-test"
1357 || mode == "rustdoc-json"
1359 cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler));
1362 if mode == "rustdoc-json" {
1363 // Use the beta compiler for jsondocck
1364 let json_compiler = compiler.with_stage(0);
1365 cmd.arg("--jsondocck-path")
1366 .arg(builder.ensure(tool::JsonDocCk { compiler: json_compiler, target }));
1367 cmd.arg("--jsondoclint-path")
1368 .arg(builder.ensure(tool::JsonDocLint { compiler: json_compiler, target }));
1371 if mode == "run-make" {
1372 let rust_demangler = builder
1373 .ensure(tool::RustDemangler {
1375 target: compiler.host,
1376 extra_features: Vec::new(),
1378 .expect("in-tree tool");
1379 cmd.arg("--rust-demangler-path").arg(rust_demangler);
1382 cmd.arg("--src-base").arg(builder.src.join("src/test").join(suite));
1383 cmd.arg("--build-base").arg(testdir(builder, compiler.host).join(suite));
1384 cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target));
1385 cmd.arg("--suite").arg(suite);
1386 cmd.arg("--mode").arg(mode);
1387 cmd.arg("--target").arg(target.rustc_target_arg());
1388 cmd.arg("--host").arg(&*compiler.host.triple);
1389 cmd.arg("--llvm-filecheck").arg(builder.llvm_filecheck(builder.config.build));
1391 if builder.config.cmd.bless() {
1395 if builder.config.cmd.force_rerun() {
1396 cmd.arg("--force-rerun");
1400 builder.config.cmd.compare_mode().or_else(|| {
1401 if builder.config.test_compare_mode { self.compare_mode } else { None }
1404 if let Some(ref pass) = builder.config.cmd.pass() {
1409 if let Some(ref run) = builder.config.cmd.run() {
1414 if let Some(ref nodejs) = builder.config.nodejs {
1415 cmd.arg("--nodejs").arg(nodejs);
1417 if let Some(ref npm) = builder.config.npm {
1418 cmd.arg("--npm").arg(npm);
1420 if builder.config.rust_optimize_tests {
1421 cmd.arg("--optimize-tests");
1423 let mut flags = if is_rustdoc { Vec::new() } else { vec!["-Crpath".to_string()] };
1424 flags.push(format!("-Cdebuginfo={}", builder.config.rust_debuginfo_level_tests));
1425 flags.extend(builder.config.cmd.rustc_args().iter().map(|s| s.to_string()));
1427 if let Some(linker) = builder.linker(target) {
1428 cmd.arg("--linker").arg(linker);
1431 let mut hostflags = flags.clone();
1432 hostflags.push(format!("-Lnative={}", builder.test_helpers_out(compiler.host).display()));
1433 hostflags.extend(builder.lld_flags(compiler.host));
1434 for flag in hostflags {
1435 cmd.arg("--host-rustcflags").arg(flag);
1438 let mut targetflags = flags;
1439 targetflags.push(format!("-Lnative={}", builder.test_helpers_out(target).display()));
1440 targetflags.extend(builder.lld_flags(target));
1441 for flag in targetflags {
1442 cmd.arg("--target-rustcflags").arg(flag);
1445 cmd.arg("--python").arg(builder.python());
1447 if let Some(ref gdb) = builder.config.gdb {
1448 cmd.arg("--gdb").arg(gdb);
1451 let run = |cmd: &mut Command| {
1452 cmd.output().map(|output| {
1453 String::from_utf8_lossy(&output.stdout)
1456 .unwrap_or_else(|| panic!("{:?} failed {:?}", cmd, output))
1460 let lldb_exe = "lldb";
1461 let lldb_version = Command::new(lldb_exe)
1464 .map(|output| String::from_utf8_lossy(&output.stdout).to_string())
1466 if let Some(ref vers) = lldb_version {
1467 cmd.arg("--lldb-version").arg(vers);
1468 let lldb_python_dir = run(Command::new(lldb_exe).arg("-P")).ok();
1469 if let Some(ref dir) = lldb_python_dir {
1470 cmd.arg("--lldb-python-dir").arg(dir);
1474 if util::forcing_clang_based_tests() {
1475 let clang_exe = builder.llvm_out(target).join("bin").join("clang");
1476 cmd.arg("--run-clang-based-tests-with").arg(clang_exe);
1479 for exclude in &builder.config.exclude {
1481 cmd.arg(&exclude.path);
1484 // Get paths from cmd args
1485 let paths = match &builder.config.cmd {
1486 Subcommand::Test { ref paths, .. } => &paths[..],
1490 // Get test-args by striping suite path
1491 let mut test_args: Vec<&str> = paths
1493 .filter_map(|p| util::is_valid_test_suite_arg(p, suite_path, builder))
1496 test_args.append(&mut builder.config.cmd.test_args());
1498 // On Windows, replace forward slashes in test-args by backslashes
1499 // so the correct filters are passed to libtest
1501 let test_args_win: Vec<String> =
1502 test_args.iter().map(|s| s.replace("/", "\\")).collect();
1503 cmd.args(&test_args_win);
1505 cmd.args(&test_args);
1508 if builder.is_verbose() {
1509 cmd.arg("--verbose");
1512 if !builder.config.verbose_tests {
1516 let mut llvm_components_passed = false;
1517 let mut copts_passed = false;
1518 if builder.config.llvm_enabled() {
1519 let llvm_config = builder.ensure(native::Llvm { target: builder.config.build });
1520 if !builder.config.dry_run {
1521 let llvm_version = output(Command::new(&llvm_config).arg("--version"));
1522 let llvm_components = output(Command::new(&llvm_config).arg("--components"));
1523 // Remove trailing newline from llvm-config output.
1524 cmd.arg("--llvm-version")
1525 .arg(llvm_version.trim())
1526 .arg("--llvm-components")
1527 .arg(llvm_components.trim());
1528 llvm_components_passed = true;
1530 if !builder.is_rust_llvm(target) {
1531 cmd.arg("--system-llvm");
1534 // Tests that use compiler libraries may inherit the `-lLLVM` link
1535 // requirement, but the `-L` library path is not propagated across
1536 // separate compilations. We can add LLVM's library path to the
1537 // platform-specific environment variable as a workaround.
1538 if !builder.config.dry_run && suite.ends_with("fulldeps") {
1539 let llvm_libdir = output(Command::new(&llvm_config).arg("--libdir"));
1540 add_link_lib_path(vec![llvm_libdir.trim().into()], &mut cmd);
1543 // Only pass correct values for these flags for the `run-make` suite as it
1544 // requires that a C++ compiler was configured which isn't always the case.
1545 if !builder.config.dry_run && matches!(suite, "run-make" | "run-make-fulldeps") {
1546 // The llvm/bin directory contains many useful cross-platform
1547 // tools. Pass the path to run-make tests so they can use them.
1548 let llvm_bin_path = llvm_config
1550 .expect("Expected llvm-config to be contained in directory");
1551 assert!(llvm_bin_path.is_dir());
1552 cmd.arg("--llvm-bin-dir").arg(llvm_bin_path);
1554 // If LLD is available, add it to the PATH
1555 if builder.config.lld_enabled {
1556 let lld_install_root =
1557 builder.ensure(native::Lld { target: builder.config.build });
1559 let lld_bin_path = lld_install_root.join("bin");
1561 let old_path = env::var_os("PATH").unwrap_or_default();
1562 let new_path = env::join_paths(
1563 std::iter::once(lld_bin_path).chain(env::split_paths(&old_path)),
1565 .expect("Could not add LLD bin path to PATH");
1566 cmd.env("PATH", new_path);
1571 // Only pass correct values for these flags for the `run-make` suite as it
1572 // requires that a C++ compiler was configured which isn't always the case.
1573 if !builder.config.dry_run && matches!(suite, "run-make" | "run-make-fulldeps") {
1575 .arg(builder.cc(target))
1577 .arg(builder.cxx(target).unwrap())
1579 .arg(builder.cflags(target, GitRepo::Rustc, CLang::C).join(" "))
1581 .arg(builder.cflags(target, GitRepo::Rustc, CLang::Cxx).join(" "));
1582 copts_passed = true;
1583 if let Some(ar) = builder.ar(target) {
1584 cmd.arg("--ar").arg(ar);
1588 if !llvm_components_passed {
1589 cmd.arg("--llvm-components").arg("");
1602 if builder.remote_tested(target) {
1603 cmd.arg("--remote-test-client").arg(builder.tool_exe(Tool::RemoteTestClient));
1606 // Running a C compiler on MSVC requires a few env vars to be set, to be
1607 // sure to set them here.
1609 // Note that if we encounter `PATH` we make sure to append to our own `PATH`
1610 // rather than stomp over it.
1611 if target.contains("msvc") {
1612 for &(ref k, ref v) in builder.cc[&target].env() {
1618 cmd.env("RUSTC_BOOTSTRAP", "1");
1619 // Override the rustc version used in symbol hashes to reduce the amount of normalization
1620 // needed when diffing test output.
1621 cmd.env("RUSTC_FORCE_RUSTC_VERSION", "compiletest");
1622 cmd.env("DOC_RUST_LANG_ORG_CHANNEL", builder.doc_rust_lang_org_channel());
1623 builder.add_rust_test_threads(&mut cmd);
1625 if builder.config.sanitizers_enabled(target) {
1626 cmd.env("RUSTC_SANITIZER_SUPPORT", "1");
1629 if builder.config.profiler_enabled(target) {
1630 cmd.env("RUSTC_PROFILER_SUPPORT", "1");
1633 cmd.env("RUST_TEST_TMPDIR", builder.tempdir());
1635 cmd.arg("--adb-path").arg("adb");
1636 cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
1637 if target.contains("android") {
1638 // Assume that cc for this target comes from the android sysroot
1639 cmd.arg("--android-cross-path")
1640 .arg(builder.cc(target).parent().unwrap().parent().unwrap());
1642 cmd.arg("--android-cross-path").arg("");
1645 if builder.config.cmd.rustfix_coverage() {
1646 cmd.arg("--rustfix-coverage");
1649 cmd.env("BOOTSTRAP_CARGO", &builder.initial_cargo);
1651 cmd.arg("--channel").arg(&builder.config.channel);
1653 builder.ci_env.force_coloring_in_ci(&mut cmd);
1655 builder.info(&format!(
1656 "Check compiletest suite={} mode={} ({} -> {})",
1657 suite, mode, &compiler.host, target
1659 let _time = util::timeit(&builder);
1660 try_run(builder, &mut cmd);
1662 if let Some(compare_mode) = compare_mode {
1663 cmd.arg("--compare-mode").arg(compare_mode);
1664 builder.info(&format!(
1665 "Check compiletest suite={} mode={} compare_mode={} ({} -> {})",
1666 suite, mode, compare_mode, &compiler.host, target
1668 let _time = util::timeit(&builder);
1669 try_run(builder, &mut cmd);
1674 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1682 impl Step for BookTest {
1684 const ONLY_HOSTS: bool = true;
1686 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1690 /// Runs the documentation tests for a book in `src/doc`.
1692 /// This uses the `rustdoc` that sits next to `compiler`.
1693 fn run(self, builder: &Builder<'_>) {
1694 // External docs are different from local because:
1695 // - Some books need pre-processing by mdbook before being tested.
1696 // - They need to save their state to toolstate.
1697 // - They are only tested on the "checktools" builders.
1699 // The local docs are tested by default, and we don't want to pay the
1700 // cost of building mdbook, so they use `rustdoc --test` directly.
1701 // Also, the unstable book is special because SUMMARY.md is generated,
1702 // so it is easier to just run `rustdoc` on its files.
1703 if self.is_ext_doc {
1704 self.run_ext_doc(builder);
1706 self.run_local_doc(builder);
1712 /// This runs the equivalent of `mdbook test` (via the rustbook wrapper)
1713 /// which in turn runs `rustdoc --test` on each file in the book.
1714 fn run_ext_doc(self, builder: &Builder<'_>) {
1715 let compiler = self.compiler;
1717 builder.ensure(compile::Std::new(compiler, compiler.host));
1719 // mdbook just executes a binary named "rustdoc", so we need to update
1720 // PATH so that it points to our rustdoc.
1721 let mut rustdoc_path = builder.rustdoc(compiler);
1723 let old_path = env::var_os("PATH").unwrap_or_default();
1724 let new_path = env::join_paths(iter::once(rustdoc_path).chain(env::split_paths(&old_path)))
1725 .expect("could not add rustdoc to PATH");
1727 let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
1728 let path = builder.src.join(&self.path);
1729 // Books often have feature-gated example text.
1730 rustbook_cmd.env("RUSTC_BOOTSTRAP", "1");
1731 rustbook_cmd.env("PATH", new_path).arg("test").arg(path);
1732 builder.add_rust_test_threads(&mut rustbook_cmd);
1733 builder.info(&format!("Testing rustbook {}", self.path.display()));
1734 let _time = util::timeit(&builder);
1735 let toolstate = if try_run(builder, &mut rustbook_cmd) {
1740 builder.save_toolstate(self.name, toolstate);
1743 /// This runs `rustdoc --test` on all `.md` files in the path.
1744 fn run_local_doc(self, builder: &Builder<'_>) {
1745 let compiler = self.compiler;
1747 builder.ensure(compile::Std::new(compiler, compiler.host));
1749 // Do a breadth-first traversal of the `src/doc` directory and just run
1750 // tests for all files that end in `*.md`
1751 let mut stack = vec![builder.src.join(self.path)];
1752 let _time = util::timeit(&builder);
1753 let mut files = Vec::new();
1754 while let Some(p) = stack.pop() {
1756 stack.extend(t!(p.read_dir()).map(|p| t!(p).path()));
1760 if p.extension().and_then(|s| s.to_str()) != Some("md") {
1770 markdown_test(builder, compiler, &file);
1775 macro_rules! test_book {
1776 ($($name:ident, $path:expr, $book_name:expr, default=$default:expr;)+) => {
1778 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1783 impl Step for $name {
1785 const DEFAULT: bool = $default;
1786 const ONLY_HOSTS: bool = true;
1788 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1792 fn make_run(run: RunConfig<'_>) {
1793 run.builder.ensure($name {
1794 compiler: run.builder.compiler(run.builder.top_stage, run.target),
1798 fn run(self, builder: &Builder<'_>) {
1799 builder.ensure(BookTest {
1800 compiler: self.compiler,
1801 path: PathBuf::from($path),
1803 is_ext_doc: !$default,
1812 Nomicon, "src/doc/nomicon", "nomicon", default=false;
1813 Reference, "src/doc/reference", "reference", default=false;
1814 RustdocBook, "src/doc/rustdoc", "rustdoc", default=true;
1815 RustcBook, "src/doc/rustc", "rustc", default=true;
1816 RustByExample, "src/doc/rust-by-example", "rust-by-example", default=false;
1817 EmbeddedBook, "src/doc/embedded-book", "embedded-book", default=false;
1818 TheBook, "src/doc/book", "book", default=false;
1819 UnstableBook, "src/doc/unstable-book", "unstable-book", default=true;
1820 EditionGuide, "src/doc/edition-guide", "edition-guide", default=false;
1823 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1824 pub struct ErrorIndex {
1828 impl Step for ErrorIndex {
1830 const DEFAULT: bool = true;
1831 const ONLY_HOSTS: bool = true;
1833 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1834 run.path("src/tools/error_index_generator")
1837 fn make_run(run: RunConfig<'_>) {
1838 // error_index_generator depends on librustdoc. Use the compiler that
1839 // is normally used to build rustdoc for other tests (like compiletest
1840 // tests in src/test/rustdoc) so that it shares the same artifacts.
1841 let compiler = run.builder.compiler(run.builder.top_stage, run.builder.config.build);
1842 run.builder.ensure(ErrorIndex { compiler });
1845 /// Runs the error index generator tool to execute the tests located in the error
1848 /// The `error_index_generator` tool lives in `src/tools` and is used to
1849 /// generate a markdown file from the error indexes of the code base which is
1850 /// then passed to `rustdoc --test`.
1851 fn run(self, builder: &Builder<'_>) {
1852 let compiler = self.compiler;
1854 let dir = testdir(builder, compiler.host);
1855 t!(fs::create_dir_all(&dir));
1856 let output = dir.join("error-index.md");
1858 let mut tool = tool::ErrorIndex::command(builder);
1859 tool.arg("markdown").arg(&output);
1861 builder.info(&format!("Testing error-index stage{}", compiler.stage));
1862 let _time = util::timeit(&builder);
1863 builder.run_quiet(&mut tool);
1864 // The tests themselves need to link to std, so make sure it is
1866 builder.ensure(compile::Std::new(compiler, compiler.host));
1867 markdown_test(builder, compiler, &output);
1871 fn markdown_test(builder: &Builder<'_>, compiler: Compiler, markdown: &Path) -> bool {
1872 if let Ok(contents) = fs::read_to_string(markdown) {
1873 if !contents.contains("```") {
1878 builder.info(&format!("doc tests for: {}", markdown.display()));
1879 let mut cmd = builder.rustdoc_cmd(compiler);
1880 builder.add_rust_test_threads(&mut cmd);
1881 // allow for unstable options such as new editions
1883 cmd.arg("unstable-options");
1886 cmd.env("RUSTC_BOOTSTRAP", "1");
1888 let test_args = builder.config.cmd.test_args().join(" ");
1889 cmd.arg("--test-args").arg(test_args);
1891 if builder.config.verbose_tests {
1892 try_run(builder, &mut cmd)
1894 try_run_quiet(builder, &mut cmd)
1898 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1899 pub struct RustcGuide;
1901 impl Step for RustcGuide {
1903 const DEFAULT: bool = false;
1904 const ONLY_HOSTS: bool = true;
1906 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1907 run.path("src/doc/rustc-dev-guide")
1910 fn make_run(run: RunConfig<'_>) {
1911 run.builder.ensure(RustcGuide);
1914 fn run(self, builder: &Builder<'_>) {
1915 let relative_path = Path::new("src").join("doc").join("rustc-dev-guide");
1916 builder.update_submodule(&relative_path);
1918 let src = builder.src.join(relative_path);
1919 let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
1920 let toolstate = if try_run(builder, rustbook_cmd.arg("linkcheck").arg(&src)) {
1925 builder.save_toolstate("rustc-dev-guide", toolstate);
1929 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1930 pub struct CrateLibrustc {
1932 target: TargetSelection,
1933 test_kind: TestKind,
1934 crates: Vec<Interned<String>>,
1937 impl Step for CrateLibrustc {
1939 const DEFAULT: bool = true;
1940 const ONLY_HOSTS: bool = true;
1942 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1943 run.crate_or_deps("rustc-main")
1946 fn make_run(run: RunConfig<'_>) {
1947 let builder = run.builder;
1948 let host = run.build_triple();
1949 let compiler = builder.compiler_for(builder.top_stage, host, host);
1953 .map(|p| builder.crate_paths[&p.assert_single_path().path].clone())
1955 let test_kind = builder.kind.into();
1957 builder.ensure(CrateLibrustc { compiler, target: run.target, test_kind, crates });
1960 fn run(self, builder: &Builder<'_>) {
1961 builder.ensure(Crate {
1962 compiler: self.compiler,
1963 target: self.target,
1965 test_kind: self.test_kind,
1966 crates: self.crates,
1971 #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
1973 pub compiler: Compiler,
1974 pub target: TargetSelection,
1976 pub test_kind: TestKind,
1977 pub crates: Vec<Interned<String>>,
1980 impl Step for Crate {
1982 const DEFAULT: bool = true;
1984 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1985 run.crate_or_deps("test")
1988 fn make_run(run: RunConfig<'_>) {
1989 let builder = run.builder;
1990 let host = run.build_triple();
1991 let compiler = builder.compiler_for(builder.top_stage, host, host);
1992 let test_kind = builder.kind.into();
1996 .map(|p| builder.crate_paths[&p.assert_single_path().path].clone())
1999 builder.ensure(Crate { compiler, target: run.target, mode: Mode::Std, test_kind, crates });
2002 /// Runs all unit tests plus documentation tests for a given crate defined
2003 /// by a `Cargo.toml` (single manifest)
2005 /// This is what runs tests for crates like the standard library, compiler, etc.
2006 /// It essentially is the driver for running `cargo test`.
2008 /// Currently this runs all tests for a DAG by passing a bunch of `-p foo`
2009 /// arguments, and those arguments are discovered from `cargo metadata`.
2010 fn run(self, builder: &Builder<'_>) {
2011 let compiler = self.compiler;
2012 let target = self.target;
2013 let mode = self.mode;
2014 let test_kind = self.test_kind;
2016 builder.ensure(compile::Std::new(compiler, target));
2017 builder.ensure(RemoteCopyLibs { compiler, target });
2019 // If we're not doing a full bootstrap but we're testing a stage2
2020 // version of libstd, then what we're actually testing is the libstd
2021 // produced in stage1. Reflect that here by updating the compiler that
2022 // we're working with automatically.
2023 let compiler = builder.compiler_for(compiler.stage, compiler.host, target);
2026 builder.cargo(compiler, mode, SourceType::InTree, target, test_kind.subcommand());
2029 compile::std_cargo(builder, target, compiler.stage, &mut cargo);
2032 compile::rustc_cargo(builder, &mut cargo, target);
2034 _ => panic!("can only test libraries"),
2037 // Build up the base `cargo test` command.
2039 // Pass in some standard flags then iterate over the graph we've discovered
2040 // in `cargo metadata` with the maps above and figure out what `-p`
2041 // arguments need to get passed.
2042 if test_kind.subcommand() == "test" && !builder.fail_fast {
2043 cargo.arg("--no-fail-fast");
2045 match builder.doc_tests {
2050 cargo.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
2055 for krate in &self.crates {
2056 cargo.arg("-p").arg(krate);
2059 // The tests are going to run with the *target* libraries, so we need to
2060 // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
2062 // Note that to run the compiler we need to run with the *host* libraries,
2063 // but our wrapper scripts arrange for that to be the case anyway.
2064 let mut dylib_path = dylib_path();
2065 dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
2066 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
2069 cargo.args(&builder.config.cmd.test_args());
2071 if !builder.config.verbose_tests {
2072 cargo.arg("--quiet");
2075 if target.contains("emscripten") {
2077 format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)),
2078 builder.config.nodejs.as_ref().expect("nodejs not configured"),
2080 } else if target.starts_with("wasm32") {
2081 let node = builder.config.nodejs.as_ref().expect("nodejs not configured");
2083 format!("{} {}/src/etc/wasm32-shim.js", node.display(), builder.src.display());
2084 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)), &runner);
2085 } else if builder.remote_tested(target) {
2087 format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)),
2088 format!("{} run 0", builder.tool_exe(Tool::RemoteTestClient).display()),
2092 builder.info(&format!(
2093 "{} {:?} stage{} ({} -> {})",
2094 test_kind, self.crates, compiler.stage, &compiler.host, target
2096 let _time = util::timeit(&builder);
2097 try_run(builder, &mut cargo.into());
2101 /// Rustdoc is special in various ways, which is why this step is different from `Crate`.
2102 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2103 pub struct CrateRustdoc {
2104 host: TargetSelection,
2105 test_kind: TestKind,
2108 impl Step for CrateRustdoc {
2110 const DEFAULT: bool = true;
2111 const ONLY_HOSTS: bool = true;
2113 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2114 run.paths(&["src/librustdoc", "src/tools/rustdoc"])
2117 fn make_run(run: RunConfig<'_>) {
2118 let builder = run.builder;
2120 let test_kind = builder.kind.into();
2122 builder.ensure(CrateRustdoc { host: run.target, test_kind });
2125 fn run(self, builder: &Builder<'_>) {
2126 let test_kind = self.test_kind;
2127 let target = self.host;
2129 let compiler = if builder.download_rustc() {
2130 builder.compiler(builder.top_stage, target)
2132 // Use the previous stage compiler to reuse the artifacts that are
2133 // created when running compiletest for src/test/rustdoc. If this used
2134 // `compiler`, then it would cause rustdoc to be built *again*, which
2135 // isn't really necessary.
2136 builder.compiler_for(builder.top_stage, target, target)
2138 builder.ensure(compile::Rustc::new(compiler, target));
2140 let mut cargo = tool::prepare_tool_cargo(
2145 test_kind.subcommand(),
2146 "src/tools/rustdoc",
2150 if test_kind.subcommand() == "test" && !builder.fail_fast {
2151 cargo.arg("--no-fail-fast");
2153 match builder.doc_tests {
2158 cargo.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
2163 cargo.arg("-p").arg("rustdoc:0.0.0");
2166 cargo.args(&builder.config.cmd.test_args());
2168 if self.host.contains("musl") {
2169 cargo.arg("'-Ctarget-feature=-crt-static'");
2172 // This is needed for running doctests on librustdoc. This is a bit of
2173 // an unfortunate interaction with how bootstrap works and how cargo
2174 // sets up the dylib path, and the fact that the doctest (in
2175 // html/markdown.rs) links to rustc-private libs. For stage1, the
2176 // compiler host dylibs (in stage1/lib) are not the same as the target
2177 // dylibs (in stage1/lib/rustlib/...). This is different from a normal
2178 // rust distribution where they are the same.
2180 // On the cargo side, normal tests use `target_process` which handles
2181 // setting up the dylib for a *target* (stage1/lib/rustlib/... in this
2182 // case). However, for doctests it uses `rustdoc_process` which only
2183 // sets up the dylib path for the *host* (stage1/lib), which is the
2186 // Recall that we special-cased `compiler_for(top_stage)` above, so we always use stage1.
2188 // It should be considered to just stop running doctests on
2189 // librustdoc. There is only one test, and it doesn't look too
2190 // important. There might be other ways to avoid this, but it seems
2191 // pretty convoluted.
2193 // See also https://github.com/rust-lang/rust/issues/13983 where the
2194 // host vs target dylibs for rustdoc are consistently tricky to deal
2197 // Note that this set the host libdir for `download_rustc`, which uses a normal rust distribution.
2198 let libdir = if builder.download_rustc() {
2199 builder.rustc_libdir(compiler)
2201 builder.sysroot_libdir(compiler, target).to_path_buf()
2203 let mut dylib_path = dylib_path();
2204 dylib_path.insert(0, PathBuf::from(&*libdir));
2205 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
2207 if !builder.config.verbose_tests {
2208 cargo.arg("--quiet");
2211 builder.info(&format!(
2212 "{} rustdoc stage{} ({} -> {})",
2213 test_kind, compiler.stage, &compiler.host, target
2215 let _time = util::timeit(&builder);
2217 try_run(builder, &mut cargo.into());
2221 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2222 pub struct CrateRustdocJsonTypes {
2223 host: TargetSelection,
2224 test_kind: TestKind,
2227 impl Step for CrateRustdocJsonTypes {
2229 const DEFAULT: bool = true;
2230 const ONLY_HOSTS: bool = true;
2232 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2233 run.path("src/rustdoc-json-types")
2236 fn make_run(run: RunConfig<'_>) {
2237 let builder = run.builder;
2239 let test_kind = builder.kind.into();
2241 builder.ensure(CrateRustdocJsonTypes { host: run.target, test_kind });
2244 fn run(self, builder: &Builder<'_>) {
2245 let test_kind = self.test_kind;
2246 let target = self.host;
2248 // Use the previous stage compiler to reuse the artifacts that are
2249 // created when running compiletest for src/test/rustdoc. If this used
2250 // `compiler`, then it would cause rustdoc to be built *again*, which
2251 // isn't really necessary.
2252 let compiler = builder.compiler_for(builder.top_stage, target, target);
2253 builder.ensure(compile::Rustc::new(compiler, target));
2255 let mut cargo = tool::prepare_tool_cargo(
2260 test_kind.subcommand(),
2261 "src/rustdoc-json-types",
2265 if test_kind.subcommand() == "test" && !builder.fail_fast {
2266 cargo.arg("--no-fail-fast");
2269 cargo.arg("-p").arg("rustdoc-json-types");
2272 cargo.args(&builder.config.cmd.test_args());
2274 if self.host.contains("musl") {
2275 cargo.arg("'-Ctarget-feature=-crt-static'");
2278 if !builder.config.verbose_tests {
2279 cargo.arg("--quiet");
2282 builder.info(&format!(
2283 "{} rustdoc-json-types stage{} ({} -> {})",
2284 test_kind, compiler.stage, &compiler.host, target
2286 let _time = util::timeit(&builder);
2288 try_run(builder, &mut cargo.into());
2292 /// Some test suites are run inside emulators or on remote devices, and most
2293 /// of our test binaries are linked dynamically which means we need to ship
2294 /// the standard library and such to the emulator ahead of time. This step
2295 /// represents this and is a dependency of all test suites.
2297 /// Most of the time this is a no-op. For some steps such as shipping data to
2298 /// QEMU we have to build our own tools so we've got conditional dependencies
2299 /// on those programs as well. Note that the remote test client is built for
2300 /// the build target (us) and the server is built for the target.
2301 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2302 pub struct RemoteCopyLibs {
2304 target: TargetSelection,
2307 impl Step for RemoteCopyLibs {
2310 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2314 fn run(self, builder: &Builder<'_>) {
2315 let compiler = self.compiler;
2316 let target = self.target;
2317 if !builder.remote_tested(target) {
2321 builder.ensure(compile::Std::new(compiler, target));
2323 builder.info(&format!("REMOTE copy libs to emulator ({})", target));
2325 let server = builder.ensure(tool::RemoteTestServer { compiler, target });
2327 // Spawn the emulator and wait for it to come online
2328 let tool = builder.tool_exe(Tool::RemoteTestClient);
2329 let mut cmd = Command::new(&tool);
2330 cmd.arg("spawn-emulator").arg(target.triple).arg(&server).arg(builder.tempdir());
2331 if let Some(rootfs) = builder.qemu_rootfs(target) {
2334 builder.run(&mut cmd);
2336 // Push all our dylibs to the emulator
2337 for f in t!(builder.sysroot_libdir(compiler, target).read_dir()) {
2339 let name = f.file_name().into_string().unwrap();
2340 if util::is_dylib(&name) {
2341 builder.run(Command::new(&tool).arg("push").arg(f.path()));
2347 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2348 pub struct Distcheck;
2350 impl Step for Distcheck {
2353 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2354 run.alias("distcheck")
2357 fn make_run(run: RunConfig<'_>) {
2358 run.builder.ensure(Distcheck);
2361 /// Runs "distcheck", a 'make check' from a tarball
2362 fn run(self, builder: &Builder<'_>) {
2363 builder.info("Distcheck");
2364 let dir = builder.tempdir().join("distcheck");
2365 let _ = fs::remove_dir_all(&dir);
2366 t!(fs::create_dir_all(&dir));
2368 // Guarantee that these are built before we begin running.
2369 builder.ensure(dist::PlainSourceTarball);
2370 builder.ensure(dist::Src);
2372 let mut cmd = Command::new("tar");
2374 .arg(builder.ensure(dist::PlainSourceTarball).tarball())
2375 .arg("--strip-components=1")
2377 builder.run(&mut cmd);
2379 Command::new("./configure")
2380 .args(&builder.config.configure_args)
2381 .arg("--enable-vendor")
2385 Command::new(util::make(&builder.config.build.triple)).arg("check").current_dir(&dir),
2388 // Now make sure that rust-src has all of libstd's dependencies
2389 builder.info("Distcheck rust-src");
2390 let dir = builder.tempdir().join("distcheck-src");
2391 let _ = fs::remove_dir_all(&dir);
2392 t!(fs::create_dir_all(&dir));
2394 let mut cmd = Command::new("tar");
2396 .arg(builder.ensure(dist::Src).tarball())
2397 .arg("--strip-components=1")
2399 builder.run(&mut cmd);
2401 let toml = dir.join("rust-src/lib/rustlib/src/rust/library/std/Cargo.toml");
2403 Command::new(&builder.initial_cargo)
2404 .arg("generate-lockfile")
2405 .arg("--manifest-path")
2412 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2413 pub struct Bootstrap;
2415 impl Step for Bootstrap {
2417 const DEFAULT: bool = true;
2418 const ONLY_HOSTS: bool = true;
2420 /// Tests the build system itself.
2421 fn run(self, builder: &Builder<'_>) {
2422 let mut check_bootstrap = Command::new(&builder.python());
2423 check_bootstrap.arg("bootstrap_test.py").current_dir(builder.src.join("src/bootstrap/"));
2424 try_run(builder, &mut check_bootstrap);
2426 let mut cmd = Command::new(&builder.initial_cargo);
2428 .current_dir(builder.src.join("src/bootstrap"))
2429 .env("RUSTFLAGS", "-Cdebuginfo=2")
2430 .env("CARGO_TARGET_DIR", builder.out.join("bootstrap"))
2431 .env("RUSTC_BOOTSTRAP", "1")
2432 .env("RUSTDOC", builder.rustdoc(builder.compiler(0, builder.build.build)))
2433 .env("RUSTC", &builder.initial_rustc);
2434 if let Some(flags) = option_env!("RUSTFLAGS") {
2435 // Use the same rustc flags for testing as for "normal" compilation,
2436 // so that Cargo doesn’t recompile the entire dependency graph every time:
2437 // https://github.com/rust-lang/rust/issues/49215
2438 cmd.env("RUSTFLAGS", flags);
2440 if !builder.fail_fast {
2441 cmd.arg("--no-fail-fast");
2443 match builder.doc_tests {
2448 cmd.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
2453 cmd.arg("--").args(&builder.config.cmd.test_args());
2454 // rustbuild tests are racy on directory creation so just run them one at a time.
2455 // Since there's not many this shouldn't be a problem.
2456 cmd.arg("--test-threads=1");
2457 try_run(builder, &mut cmd);
2460 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2461 run.path("src/bootstrap")
2464 fn make_run(run: RunConfig<'_>) {
2465 run.builder.ensure(Bootstrap);
2469 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2470 pub struct TierCheck {
2471 pub compiler: Compiler,
2474 impl Step for TierCheck {
2476 const DEFAULT: bool = true;
2477 const ONLY_HOSTS: bool = true;
2479 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2480 run.path("src/tools/tier-check")
2483 fn make_run(run: RunConfig<'_>) {
2485 run.builder.compiler_for(run.builder.top_stage, run.builder.build.build, run.target);
2486 run.builder.ensure(TierCheck { compiler });
2489 /// Tests the Platform Support page in the rustc book.
2490 fn run(self, builder: &Builder<'_>) {
2491 builder.ensure(compile::Std::new(self.compiler, self.compiler.host));
2492 let mut cargo = tool::prepare_tool_cargo(
2498 "src/tools/tier-check",
2502 cargo.arg(builder.src.join("src/doc/rustc/src/platform-support.md"));
2503 cargo.arg(&builder.rustc(self.compiler));
2504 if builder.is_verbose() {
2505 cargo.arg("--verbose");
2508 builder.info("platform support check");
2509 try_run(builder, &mut cargo.into());
2513 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2514 pub struct ReplacePlaceholderTest;
2516 impl Step for ReplacePlaceholderTest {
2518 const ONLY_HOSTS: bool = true;
2519 const DEFAULT: bool = true;
2521 /// Ensure the version placeholder replacement tool builds
2522 fn run(self, builder: &Builder<'_>) {
2523 builder.info("build check for version replacement placeholder");
2525 // Test the version placeholder replacement tool itself.
2526 let bootstrap_host = builder.config.build;
2527 let compiler = builder.compiler(0, bootstrap_host);
2528 let cargo = tool::prepare_tool_cargo(
2531 Mode::ToolBootstrap,
2534 "src/tools/replace-version-placeholder",
2538 try_run(builder, &mut cargo.into());
2541 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2542 run.path("src/tools/replace-version-placeholder")
2545 fn make_run(run: RunConfig<'_>) {
2546 run.builder.ensure(Self);
2550 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2551 pub struct LintDocs {
2552 pub compiler: Compiler,
2553 pub target: TargetSelection,
2556 impl Step for LintDocs {
2558 const DEFAULT: bool = true;
2559 const ONLY_HOSTS: bool = true;
2561 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2562 run.path("src/tools/lint-docs")
2565 fn make_run(run: RunConfig<'_>) {
2566 run.builder.ensure(LintDocs {
2567 compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
2572 /// Tests that the lint examples in the rustc book generate the correct
2573 /// lints and have the expected format.
2574 fn run(self, builder: &Builder<'_>) {
2575 builder.ensure(crate::doc::RustcBook {
2576 compiler: self.compiler,
2577 target: self.target,