1 //! Implementation of the test-related targets of the build system.
3 //! This file implements the various regression test suites that we execute on
7 use std::ffi::OsString;
11 use std::path::{Path, PathBuf};
12 use std::process::{Command, Stdio};
14 use crate::builder::{Builder, Compiler, Kind, RunConfig, ShouldRun, Step};
15 use crate::cache::Interned;
17 use crate::config::TargetSelection;
19 use crate::doc::DocumentationFormat;
20 use crate::flags::Subcommand;
22 use crate::tool::{self, SourceType, Tool};
23 use crate::toolstate::ToolState;
24 use crate::util::{self, add_link_lib_path, dylib_path, dylib_path_var, output, t};
25 use crate::{envify, CLang, DocTests, GitRepo, Mode};
27 const ADB_TEST_DIR: &str = "/data/local/tmp/work";
29 /// The two modes of the test runner; tests or benchmarks.
30 #[derive(Debug, PartialEq, Eq, Hash, Copy, Clone, PartialOrd, Ord)]
34 /// Run `cargo bench`.
38 impl From<Kind> for TestKind {
39 fn from(kind: Kind) -> Self {
41 Kind::Test => TestKind::Test,
42 Kind::Bench => TestKind::Bench,
43 _ => panic!("unexpected kind in crate: {:?}", kind),
49 // Return the cargo subcommand for this test kind
50 fn subcommand(self) -> &'static str {
52 TestKind::Test => "test",
53 TestKind::Bench => "bench",
58 impl fmt::Display for TestKind {
59 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
60 f.write_str(match *self {
61 TestKind::Test => "Testing",
62 TestKind::Bench => "Benchmarking",
67 fn try_run(builder: &Builder<'_>, cmd: &mut Command) -> bool {
68 if !builder.fail_fast {
69 if !builder.try_run(cmd) {
70 let mut failures = builder.delayed_failures.borrow_mut();
71 failures.push(format!("{:?}", cmd));
80 fn try_run_quiet(builder: &Builder<'_>, cmd: &mut Command) -> bool {
81 if !builder.fail_fast {
82 if !builder.try_run_quiet(cmd) {
83 let mut failures = builder.delayed_failures.borrow_mut();
84 failures.push(format!("{:?}", cmd));
88 builder.run_quiet(cmd);
93 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
94 pub struct Linkcheck {
95 host: TargetSelection,
98 impl Step for Linkcheck {
100 const ONLY_HOSTS: bool = true;
101 const DEFAULT: bool = true;
103 /// Runs the `linkchecker` tool as compiled in `stage` by the `host` compiler.
105 /// This tool in `src/tools` will verify the validity of all our links in the
106 /// documentation to ensure we don't have a bunch of dead ones.
107 fn run(self, builder: &Builder<'_>) {
108 let host = self.host;
109 let hosts = &builder.hosts;
110 let targets = &builder.targets;
112 // if we have different hosts and targets, some things may be built for
113 // the host (e.g. rustc) and others for the target (e.g. std). The
114 // documentation built for each will contain broken links to
115 // docs built for the other platform (e.g. rustc linking to cargo)
116 if (hosts != targets) && !hosts.is_empty() && !targets.is_empty() {
118 "Linkcheck currently does not support builds with different hosts and targets.
119 You can skip linkcheck with --exclude src/tools/linkchecker"
123 builder.info(&format!("Linkcheck ({})", host));
125 // Test the linkchecker itself.
126 let bootstrap_host = builder.config.build;
127 let compiler = builder.compiler(0, bootstrap_host);
128 let cargo = tool::prepare_tool_cargo(
134 "src/tools/linkchecker",
138 try_run(builder, &mut cargo.into());
140 // Build all the default documentation.
141 builder.default_doc(&[]);
143 // Run the linkchecker.
144 let _time = util::timeit(&builder);
147 builder.tool_cmd(Tool::Linkchecker).arg(builder.out.join(host.triple).join("doc")),
151 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
152 let builder = run.builder;
153 let run = run.path("src/tools/linkchecker");
154 run.default_condition(builder.config.docs)
157 fn make_run(run: RunConfig<'_>) {
158 run.builder.ensure(Linkcheck { host: run.target });
162 fn check_if_tidy_is_installed() -> bool {
165 .stdout(Stdio::null())
167 .map_or(false, |status| status.success())
170 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
171 pub struct HtmlCheck {
172 target: TargetSelection,
175 impl Step for HtmlCheck {
177 const DEFAULT: bool = true;
178 const ONLY_HOSTS: bool = true;
180 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
181 let run = run.path("src/tools/html-checker");
182 run.lazy_default_condition(Box::new(check_if_tidy_is_installed))
185 fn make_run(run: RunConfig<'_>) {
186 run.builder.ensure(HtmlCheck { target: run.target });
189 fn run(self, builder: &Builder<'_>) {
190 if !check_if_tidy_is_installed() {
191 eprintln!("not running HTML-check tool because `tidy` is missing");
193 "Note that `tidy` is not the in-tree `src/tools/tidy` but needs to be installed"
195 panic!("Cannot run html-check tests");
197 // Ensure that a few different kinds of documentation are available.
198 builder.default_doc(&[]);
199 builder.ensure(crate::doc::Rustc { target: self.target, stage: builder.top_stage });
201 try_run(builder, builder.tool_cmd(Tool::HtmlChecker).arg(builder.doc_out(self.target)));
205 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
206 pub struct Cargotest {
208 host: TargetSelection,
211 impl Step for Cargotest {
213 const ONLY_HOSTS: bool = true;
215 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
216 run.path("src/tools/cargotest")
219 fn make_run(run: RunConfig<'_>) {
220 run.builder.ensure(Cargotest { stage: run.builder.top_stage, host: run.target });
223 /// Runs the `cargotest` tool as compiled in `stage` by the `host` compiler.
225 /// This tool in `src/tools` will check out a few Rust projects and run `cargo
226 /// test` to ensure that we don't regress the test suites there.
227 fn run(self, builder: &Builder<'_>) {
228 let compiler = builder.compiler(self.stage, self.host);
229 builder.ensure(compile::Rustc::new(compiler, compiler.host));
230 let cargo = builder.ensure(tool::Cargo { compiler, target: compiler.host });
232 // Note that this is a short, cryptic, and not scoped directory name. This
233 // is currently to minimize the length of path on Windows where we otherwise
234 // quickly run into path name limit constraints.
235 let out_dir = builder.out.join("ct");
236 t!(fs::create_dir_all(&out_dir));
238 let _time = util::timeit(&builder);
239 let mut cmd = builder.tool_cmd(Tool::CargoTest);
244 .args(builder.config.cmd.test_args())
245 .env("RUSTC", builder.rustc(compiler))
246 .env("RUSTDOC", builder.rustdoc(compiler)),
251 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
254 host: TargetSelection,
257 impl Step for Cargo {
259 const ONLY_HOSTS: bool = true;
261 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
262 run.path("src/tools/cargo")
265 fn make_run(run: RunConfig<'_>) {
266 run.builder.ensure(Cargo { stage: run.builder.top_stage, host: run.target });
269 /// Runs `cargo test` for `cargo` packaged with Rust.
270 fn run(self, builder: &Builder<'_>) {
271 let compiler = builder.compiler(self.stage, self.host);
273 builder.ensure(tool::Cargo { compiler, target: self.host });
274 let mut cargo = tool::prepare_tool_cargo(
281 SourceType::Submodule,
285 if !builder.fail_fast {
286 cargo.arg("--no-fail-fast");
288 cargo.arg("--").args(builder.config.cmd.test_args());
290 // Don't run cross-compile tests, we may not have cross-compiled libstd libs
292 cargo.env("CFG_DISABLE_CROSS_TESTS", "1");
293 // Forcibly disable tests using nightly features since any changes to
294 // those features won't be able to land.
295 cargo.env("CARGO_TEST_DISABLE_NIGHTLY", "1");
297 cargo.env("PATH", &path_for_cargo(builder, compiler));
299 try_run(builder, &mut cargo.into());
303 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
304 pub struct RustAnalyzer {
306 host: TargetSelection,
309 impl Step for RustAnalyzer {
311 const ONLY_HOSTS: bool = true;
312 const DEFAULT: bool = true;
314 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
315 run.path("src/tools/rust-analyzer")
318 fn make_run(run: RunConfig<'_>) {
319 run.builder.ensure(Self { stage: run.builder.top_stage, host: run.target });
322 /// Runs `cargo test` for rust-analyzer
323 fn run(self, builder: &Builder<'_>) {
324 let stage = self.stage;
325 let host = self.host;
326 let compiler = builder.compiler(stage, host);
328 builder.ensure(tool::RustAnalyzer { compiler, target: self.host }).expect("in-tree tool");
330 let workspace_path = "src/tools/rust-analyzer";
331 // until the whole RA test suite runs on `i686`, we only run
332 // `proc-macro-srv` tests
333 let crate_path = "src/tools/rust-analyzer/crates/proc-macro-srv";
334 let mut cargo = tool::prepare_tool_cargo(
342 &["sysroot-abi".to_owned()],
345 let dir = builder.src.join(workspace_path);
346 // needed by rust-analyzer to find its own text fixtures, cf.
347 // https://github.com/rust-analyzer/expect-test/issues/33
348 cargo.env("CARGO_WORKSPACE_DIR", &dir);
350 // RA's test suite tries to write to the source directory, that can't
352 cargo.env("SKIP_SLOW_TESTS", "1");
354 cargo.add_rustc_lib_path(builder, compiler);
355 cargo.arg("--").args(builder.config.cmd.test_args());
357 builder.run(&mut cargo.into());
361 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
364 host: TargetSelection,
367 impl Step for Rustfmt {
369 const ONLY_HOSTS: bool = true;
371 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
372 run.path("src/tools/rustfmt")
375 fn make_run(run: RunConfig<'_>) {
376 run.builder.ensure(Rustfmt { stage: run.builder.top_stage, host: run.target });
379 /// Runs `cargo test` for rustfmt.
380 fn run(self, builder: &Builder<'_>) {
381 let stage = self.stage;
382 let host = self.host;
383 let compiler = builder.compiler(stage, host);
386 .ensure(tool::Rustfmt { compiler, target: self.host, extra_features: Vec::new() })
387 .expect("in-tree tool");
389 let mut cargo = tool::prepare_tool_cargo(
400 let dir = testdir(builder, compiler.host);
401 t!(fs::create_dir_all(&dir));
402 cargo.env("RUSTFMT_TEST_DIR", dir);
404 cargo.add_rustc_lib_path(builder, compiler);
406 builder.run(&mut cargo.into());
410 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
411 pub struct RustDemangler {
413 host: TargetSelection,
416 impl Step for RustDemangler {
418 const ONLY_HOSTS: bool = true;
420 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
421 run.path("src/tools/rust-demangler")
424 fn make_run(run: RunConfig<'_>) {
425 run.builder.ensure(RustDemangler { stage: run.builder.top_stage, host: run.target });
428 /// Runs `cargo test` for rust-demangler.
429 fn run(self, builder: &Builder<'_>) {
430 let stage = self.stage;
431 let host = self.host;
432 let compiler = builder.compiler(stage, host);
434 let rust_demangler = builder
435 .ensure(tool::RustDemangler { compiler, target: self.host, extra_features: Vec::new() })
436 .expect("in-tree tool");
437 let mut cargo = tool::prepare_tool_cargo(
443 "src/tools/rust-demangler",
448 let dir = testdir(builder, compiler.host);
449 t!(fs::create_dir_all(&dir));
451 cargo.env("RUST_DEMANGLER_DRIVER_PATH", rust_demangler);
453 cargo.arg("--").args(builder.config.cmd.test_args());
455 cargo.add_rustc_lib_path(builder, compiler);
457 builder.run(&mut cargo.into());
461 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
464 host: TargetSelection,
465 target: TargetSelection,
470 const ONLY_HOSTS: bool = false;
472 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
473 run.path("src/tools/miri")
476 fn make_run(run: RunConfig<'_>) {
477 run.builder.ensure(Miri {
478 stage: run.builder.top_stage,
479 host: run.build_triple(),
484 /// Runs `cargo test` for miri.
485 fn run(self, builder: &Builder<'_>) {
486 let stage = self.stage;
487 let host = self.host;
488 let target = self.target;
489 let compiler = builder.compiler(stage, host);
490 // We need the stdlib for the *next* stage, as it was built with this compiler that also built Miri.
491 // Except if we are at stage 2, the bootstrap loop is complete and we can stick with our current stage.
492 let compiler_std = builder.compiler(if stage < 2 { stage + 1 } else { stage }, host);
495 .ensure(tool::Miri { compiler, target: self.host, extra_features: Vec::new() })
496 .expect("in-tree tool");
497 let _cargo_miri = builder
498 .ensure(tool::CargoMiri { compiler, target: self.host, extra_features: Vec::new() })
499 .expect("in-tree tool");
500 // The stdlib we need might be at a different stage. And just asking for the
501 // sysroot does not seem to populate it, so we do that first.
502 builder.ensure(compile::Std::new(compiler_std, host));
503 let sysroot = builder.sysroot(compiler_std);
505 // # Run `cargo miri setup` for the given target.
506 let mut cargo = tool::prepare_tool_cargo(
512 "src/tools/miri/cargo-miri",
516 cargo.add_rustc_lib_path(builder, compiler);
517 cargo.arg("--").arg("miri").arg("setup");
518 cargo.arg("--target").arg(target.rustc_target_arg());
520 // Tell `cargo miri setup` where to find the sources.
521 cargo.env("MIRI_LIB_SRC", builder.src.join("library"));
522 // Tell it where to find Miri.
523 cargo.env("MIRI", &miri);
525 cargo.env("RUST_BACKTRACE", "1");
527 let mut cargo = Command::from(cargo);
528 builder.run(&mut cargo);
530 // # Determine where Miri put its sysroot.
531 // To this end, we run `cargo miri setup --print-sysroot` and capture the output.
532 // (We do this separately from the above so that when the setup actually
533 // happens we get some output.)
534 // We re-use the `cargo` from above.
535 cargo.arg("--print-sysroot");
537 // FIXME: Is there a way in which we can re-use the usual `run` helpers?
538 let miri_sysroot = if builder.config.dry_run {
541 builder.verbose(&format!("running: {:?}", cargo));
543 cargo.output().expect("We already ran `cargo miri setup` before and that worked");
544 assert!(out.status.success(), "`cargo miri setup` returned with non-0 exit code");
545 // Output is "<sysroot>\n".
546 let stdout = String::from_utf8(out.stdout)
547 .expect("`cargo miri setup` stdout is not valid UTF-8");
548 let sysroot = stdout.trim_end();
549 builder.verbose(&format!("`cargo miri setup --print-sysroot` said: {:?}", sysroot));
553 // # Run `cargo test`.
554 let mut cargo = tool::prepare_tool_cargo(
564 cargo.add_rustc_lib_path(builder, compiler);
566 // miri tests need to know about the stage sysroot
567 cargo.env("MIRI_SYSROOT", &miri_sysroot);
568 cargo.env("MIRI_HOST_SYSROOT", sysroot);
569 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
570 cargo.env("MIRI", &miri);
572 if builder.config.cmd.bless() {
573 cargo.env("MIRI_BLESS", "Gesundheit");
577 cargo.env("MIRI_TEST_TARGET", target.rustc_target_arg());
578 // Forward test filters.
579 cargo.arg("--").args(builder.config.cmd.test_args());
581 let mut cargo = Command::from(cargo);
582 builder.run(&mut cargo);
584 // # Run `cargo miri test`.
585 // This is just a smoke test (Miri's own CI invokes this in a bunch of different ways and ensures
586 // that we get the desired output), but that is sufficient to make sure that the libtest harness
587 // itself executes properly under Miri.
588 let mut cargo = tool::prepare_tool_cargo(
594 "src/tools/miri/cargo-miri",
595 SourceType::Submodule,
598 cargo.add_rustc_lib_path(builder, compiler);
599 cargo.arg("--").arg("miri").arg("test");
601 .arg("--manifest-path")
602 .arg(builder.src.join("src/tools/miri/test-cargo-miri/Cargo.toml"));
603 cargo.arg("--target").arg(target.rustc_target_arg());
604 cargo.arg("--tests"); // don't run doctests, they are too confused by the staging
605 cargo.arg("--").args(builder.config.cmd.test_args());
607 // Tell `cargo miri` where to find things.
608 cargo.env("MIRI_SYSROOT", &miri_sysroot);
609 cargo.env("MIRI_HOST_SYSROOT", sysroot);
610 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
611 cargo.env("MIRI", &miri);
613 cargo.env("RUST_BACKTRACE", "1");
615 let mut cargo = Command::from(cargo);
616 builder.run(&mut cargo);
620 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
621 pub struct CompiletestTest {
622 host: TargetSelection,
625 impl Step for CompiletestTest {
628 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
629 run.path("src/tools/compiletest")
632 fn make_run(run: RunConfig<'_>) {
633 run.builder.ensure(CompiletestTest { host: run.target });
636 /// Runs `cargo test` for compiletest.
637 fn run(self, builder: &Builder<'_>) {
638 let host = self.host;
639 let compiler = builder.compiler(0, host);
641 // We need `ToolStd` for the locally-built sysroot because
642 // compiletest uses unstable features of the `test` crate.
643 builder.ensure(compile::Std::new(compiler, host));
644 let cargo = tool::prepare_tool_cargo(
650 "src/tools/compiletest",
655 try_run(builder, &mut cargo.into());
659 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
662 host: TargetSelection,
665 impl Step for Clippy {
667 const ONLY_HOSTS: bool = true;
668 const DEFAULT: bool = false;
670 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
671 run.path("src/tools/clippy")
674 fn make_run(run: RunConfig<'_>) {
675 run.builder.ensure(Clippy { stage: run.builder.top_stage, host: run.target });
678 /// Runs `cargo test` for clippy.
679 fn run(self, builder: &Builder<'_>) {
680 let stage = self.stage;
681 let host = self.host;
682 let compiler = builder.compiler(stage, host);
685 .ensure(tool::Clippy { compiler, target: self.host, extra_features: Vec::new() })
686 .expect("in-tree tool");
687 let mut cargo = tool::prepare_tool_cargo(
698 cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
699 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
700 let host_libs = builder.stage_out(compiler, Mode::ToolRustc).join(builder.cargo_dir());
701 cargo.env("HOST_LIBS", host_libs);
703 cargo.arg("--").args(builder.config.cmd.test_args());
705 cargo.add_rustc_lib_path(builder, compiler);
707 if builder.try_run(&mut cargo.into()) {
708 // The tests succeeded; nothing to do.
712 if !builder.config.cmd.bless() {
713 crate::detail_exit(1);
716 let mut cargo = builder.cargo(compiler, Mode::ToolRustc, SourceType::InTree, host, "run");
717 cargo.arg("-p").arg("clippy_dev");
718 // clippy_dev gets confused if it can't find `clippy/Cargo.toml`
719 cargo.current_dir(&builder.src.join("src").join("tools").join("clippy"));
720 if builder.config.rust_optimize {
721 cargo.env("PROFILE", "release");
723 cargo.env("PROFILE", "debug");
727 builder.run(&mut cargo.into());
731 fn path_for_cargo(builder: &Builder<'_>, compiler: Compiler) -> OsString {
732 // Configure PATH to find the right rustc. NB. we have to use PATH
733 // and not RUSTC because the Cargo test suite has tests that will
734 // fail if rustc is not spelled `rustc`.
735 let path = builder.sysroot(compiler).join("bin");
736 let old_path = env::var_os("PATH").unwrap_or_default();
737 env::join_paths(iter::once(path).chain(env::split_paths(&old_path))).expect("")
740 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
741 pub struct RustdocTheme {
742 pub compiler: Compiler,
745 impl Step for RustdocTheme {
747 const DEFAULT: bool = true;
748 const ONLY_HOSTS: bool = true;
750 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
751 run.path("src/tools/rustdoc-themes")
754 fn make_run(run: RunConfig<'_>) {
755 let compiler = run.builder.compiler(run.builder.top_stage, run.target);
757 run.builder.ensure(RustdocTheme { compiler });
760 fn run(self, builder: &Builder<'_>) {
761 let rustdoc = builder.bootstrap_out.join("rustdoc");
762 let mut cmd = builder.tool_cmd(Tool::RustdocTheme);
763 cmd.arg(rustdoc.to_str().unwrap())
764 .arg(builder.src.join("src/librustdoc/html/static/css/themes").to_str().unwrap())
765 .env("RUSTC_STAGE", self.compiler.stage.to_string())
766 .env("RUSTC_SYSROOT", builder.sysroot(self.compiler))
767 .env("RUSTDOC_LIBDIR", builder.sysroot_libdir(self.compiler, self.compiler.host))
768 .env("CFG_RELEASE_CHANNEL", &builder.config.channel)
769 .env("RUSTDOC_REAL", builder.rustdoc(self.compiler))
770 .env("RUSTC_BOOTSTRAP", "1");
771 if let Some(linker) = builder.linker(self.compiler.host) {
772 cmd.env("RUSTDOC_LINKER", linker);
774 if builder.is_fuse_ld_lld(self.compiler.host) {
776 "RUSTDOC_LLD_NO_THREADS",
777 util::lld_flag_no_threads(self.compiler.host.contains("windows")),
780 try_run(builder, &mut cmd);
784 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
785 pub struct RustdocJSStd {
786 pub target: TargetSelection,
789 impl Step for RustdocJSStd {
791 const DEFAULT: bool = true;
792 const ONLY_HOSTS: bool = true;
794 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
795 run.suite_path("src/test/rustdoc-js-std")
798 fn make_run(run: RunConfig<'_>) {
799 run.builder.ensure(RustdocJSStd { target: run.target });
802 fn run(self, builder: &Builder<'_>) {
803 if let Some(ref nodejs) = builder.config.nodejs {
804 let mut command = Command::new(nodejs);
806 .arg(builder.src.join("src/tools/rustdoc-js/tester.js"))
809 .arg("--resource-suffix")
810 .arg(&builder.version)
812 .arg(builder.doc_out(self.target))
813 .arg("--test-folder")
814 .arg(builder.src.join("src/test/rustdoc-js-std"));
815 for path in &builder.paths {
817 util::is_valid_test_suite_arg(path, "src/test/rustdoc-js-std", builder)
819 if !p.ends_with(".js") {
820 eprintln!("A non-js file was given: `{}`", path.display());
821 panic!("Cannot run rustdoc-js-std tests");
823 command.arg("--test-file").arg(path);
826 builder.ensure(crate::doc::Std {
828 stage: builder.top_stage,
829 format: DocumentationFormat::HTML,
831 builder.run(&mut command);
833 builder.info("No nodejs found, skipping \"src/test/rustdoc-js-std\" tests");
838 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
839 pub struct RustdocJSNotStd {
840 pub target: TargetSelection,
841 pub compiler: Compiler,
844 impl Step for RustdocJSNotStd {
846 const DEFAULT: bool = true;
847 const ONLY_HOSTS: bool = true;
849 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
850 run.suite_path("src/test/rustdoc-js")
853 fn make_run(run: RunConfig<'_>) {
854 let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
855 run.builder.ensure(RustdocJSNotStd { target: run.target, compiler });
858 fn run(self, builder: &Builder<'_>) {
859 if builder.config.nodejs.is_some() {
860 builder.ensure(Compiletest {
861 compiler: self.compiler,
865 path: "src/test/rustdoc-js",
869 builder.info("No nodejs found, skipping \"src/test/rustdoc-js\" tests");
874 fn get_browser_ui_test_version_inner(npm: &Path, global: bool) -> Option<String> {
875 let mut command = Command::new(&npm);
876 command.arg("list").arg("--parseable").arg("--long").arg("--depth=0");
878 command.arg("--global");
882 .map(|output| String::from_utf8_lossy(&output.stdout).into_owned())
883 .unwrap_or(String::new());
886 .find_map(|l| l.split(':').nth(1)?.strip_prefix("browser-ui-test@"))
887 .map(|v| v.to_owned())
890 fn get_browser_ui_test_version(npm: &Path) -> Option<String> {
891 get_browser_ui_test_version_inner(npm, false)
892 .or_else(|| get_browser_ui_test_version_inner(npm, true))
895 fn compare_browser_ui_test_version(installed_version: &str, src: &Path) {
896 match fs::read_to_string(
897 src.join("src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version"),
900 if v.trim() != installed_version {
902 "⚠️ Installed version of browser-ui-test (`{}`) is different than the \
903 one used in the CI (`{}`)",
907 "You can install this version using `npm update browser-ui-test` or by using \
908 `npm install browser-ui-test@{}`",
913 Err(e) => eprintln!("Couldn't find the CI browser-ui-test version: {:?}", e),
917 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
918 pub struct RustdocGUI {
919 pub target: TargetSelection,
920 pub compiler: Compiler,
923 impl Step for RustdocGUI {
925 const DEFAULT: bool = true;
926 const ONLY_HOSTS: bool = true;
928 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
929 let builder = run.builder;
930 let run = run.suite_path("src/test/rustdoc-gui");
931 run.lazy_default_condition(Box::new(move || {
932 builder.config.nodejs.is_some()
937 .map(|p| get_browser_ui_test_version(p).is_some())
942 fn make_run(run: RunConfig<'_>) {
943 let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
944 run.builder.ensure(RustdocGUI { target: run.target, compiler });
947 fn run(self, builder: &Builder<'_>) {
948 let nodejs = builder.config.nodejs.as_ref().expect("nodejs isn't available");
949 let npm = builder.config.npm.as_ref().expect("npm isn't available");
951 builder.ensure(compile::Std::new(self.compiler, self.target));
953 // The goal here is to check if the necessary packages are installed, and if not, we
955 match get_browser_ui_test_version(&npm) {
957 // We also check the version currently used in CI and emit a warning if it's not the
959 compare_browser_ui_test_version(&version, &builder.build.src);
963 "error: rustdoc-gui test suite cannot be run because npm `browser-ui-test` \
964 dependency is missing",
967 "If you want to install the `{0}` dependency, run `npm install {0}`",
970 panic!("Cannot run rustdoc-gui tests");
974 let out_dir = builder.test_out(self.target).join("rustdoc-gui");
976 // We remove existing folder to be sure there won't be artifacts remaining.
977 builder.clear_if_dirty(&out_dir, &builder.rustdoc(self.compiler));
979 let src_path = builder.build.src.join("src/test/rustdoc-gui/src");
980 // We generate docs for the libraries present in the rustdoc-gui's src folder.
981 for entry in src_path.read_dir().expect("read_dir call failed") {
982 if let Ok(entry) = entry {
983 let path = entry.path();
989 let mut cargo = Command::new(&builder.initial_cargo);
994 .env("RUSTC_BOOTSTRAP", "1")
995 .env("RUSTDOC", builder.rustdoc(self.compiler))
996 .env("RUSTC", builder.rustc(self.compiler))
998 // FIXME: implement a `// compile-flags` command or similar
999 // instead of hard-coding this test
1000 if entry.file_name() == "link_to_definition" {
1001 cargo.env("RUSTDOCFLAGS", "-Zunstable-options --generate-link-to-definition");
1003 builder.run(&mut cargo);
1007 // We now run GUI tests.
1008 let mut command = Command::new(&nodejs);
1010 .arg(builder.build.src.join("src/tools/rustdoc-gui/tester.js"))
1012 .arg(&builder.jobs().to_string())
1013 .arg("--doc-folder")
1014 .arg(out_dir.join("doc"))
1015 .arg("--tests-folder")
1016 .arg(builder.build.src.join("src/test/rustdoc-gui"));
1017 for path in &builder.paths {
1018 if let Some(p) = util::is_valid_test_suite_arg(path, "src/test/rustdoc-gui", builder) {
1019 if !p.ends_with(".goml") {
1020 eprintln!("A non-goml file was given: `{}`", path.display());
1021 panic!("Cannot run rustdoc-gui tests");
1023 if let Some(name) = path.file_name().and_then(|f| f.to_str()) {
1024 command.arg("--file").arg(name);
1028 for test_arg in builder.config.cmd.test_args() {
1029 command.arg(test_arg);
1031 builder.run(&mut command);
1035 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1038 impl Step for Tidy {
1040 const DEFAULT: bool = true;
1041 const ONLY_HOSTS: bool = true;
1043 /// Runs the `tidy` tool.
1045 /// This tool in `src/tools` checks up on various bits and pieces of style and
1046 /// otherwise just implements a few lint-like checks that are specific to the
1047 /// compiler itself.
1049 /// Once tidy passes, this step also runs `fmt --check` if tests are being run
1050 /// for the `dev` or `nightly` channels.
1051 fn run(self, builder: &Builder<'_>) {
1052 let mut cmd = builder.tool_cmd(Tool::Tidy);
1053 cmd.arg(&builder.src);
1054 cmd.arg(&builder.initial_cargo);
1055 cmd.arg(&builder.out);
1056 cmd.arg(builder.jobs().to_string());
1057 if builder.is_verbose() {
1058 cmd.arg("--verbose");
1061 builder.info("tidy check");
1062 try_run(builder, &mut cmd);
1064 if builder.config.channel == "dev" || builder.config.channel == "nightly" {
1065 builder.info("fmt check");
1066 if builder.initial_rustfmt().is_none() {
1067 let inferred_rustfmt_dir = builder.config.initial_rustc.parent().unwrap();
1070 error: no `rustfmt` binary found in {PATH}
1071 info: `rust.channel` is currently set to \"{CHAN}\"
1072 help: if you are testing a beta branch, set `rust.channel` to \"beta\" in the `config.toml` file
1073 help: to skip test's attempt to check tidiness, pass `--exclude src/tools/tidy` to `x.py test`",
1074 PATH = inferred_rustfmt_dir.display(),
1075 CHAN = builder.config.channel,
1077 crate::detail_exit(1);
1079 crate::format::format(&builder, !builder.config.cmd.bless(), &[]);
1083 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1084 run.path("src/tools/tidy")
1087 fn make_run(run: RunConfig<'_>) {
1088 run.builder.ensure(Tidy);
1092 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1093 pub struct ExpandYamlAnchors;
1095 impl Step for ExpandYamlAnchors {
1097 const ONLY_HOSTS: bool = true;
1099 /// Ensure the `generate-ci-config` tool was run locally.
1101 /// The tool in `src/tools` reads the CI definition in `src/ci/builders.yml` and generates the
1102 /// appropriate configuration for all our CI providers. This step ensures the tool was called
1103 /// by the user before committing CI changes.
1104 fn run(self, builder: &Builder<'_>) {
1105 builder.info("Ensuring the YAML anchors in the GitHub Actions config were expanded");
1108 &mut builder.tool_cmd(Tool::ExpandYamlAnchors).arg("check").arg(&builder.src),
1112 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1113 run.path("src/tools/expand-yaml-anchors")
1116 fn make_run(run: RunConfig<'_>) {
1117 run.builder.ensure(ExpandYamlAnchors);
1121 fn testdir(builder: &Builder<'_>, host: TargetSelection) -> PathBuf {
1122 builder.out.join(host.triple).join("test")
1125 macro_rules! default_test {
1126 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
1127 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: false });
1131 macro_rules! default_test_with_compare_mode {
1132 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr,
1133 compare_mode: $compare_mode:expr }) => {
1134 test_with_compare_mode!($name {
1140 compare_mode: $compare_mode
1145 macro_rules! host_test {
1146 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
1147 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: true });
1152 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
1153 host: $host:expr }) => {
1154 test_definitions!($name {
1165 macro_rules! test_with_compare_mode {
1166 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
1167 host: $host:expr, compare_mode: $compare_mode:expr }) => {
1168 test_definitions!($name {
1174 compare_mode: Some($compare_mode)
1179 macro_rules! test_definitions {
1184 default: $default:expr,
1186 compare_mode: $compare_mode:expr
1188 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1190 pub compiler: Compiler,
1191 pub target: TargetSelection,
1194 impl Step for $name {
1196 const DEFAULT: bool = $default;
1197 const ONLY_HOSTS: bool = $host;
1199 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1200 run.suite_path($path)
1203 fn make_run(run: RunConfig<'_>) {
1204 let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
1206 run.builder.ensure($name { compiler, target: run.target });
1209 fn run(self, builder: &Builder<'_>) {
1210 builder.ensure(Compiletest {
1211 compiler: self.compiler,
1212 target: self.target,
1216 compare_mode: $compare_mode,
1223 default_test!(Ui { path: "src/test/ui", mode: "ui", suite: "ui" });
1225 default_test!(RunPassValgrind {
1226 path: "src/test/run-pass-valgrind",
1227 mode: "run-pass-valgrind",
1228 suite: "run-pass-valgrind"
1231 default_test!(MirOpt { path: "src/test/mir-opt", mode: "mir-opt", suite: "mir-opt" });
1233 default_test!(Codegen { path: "src/test/codegen", mode: "codegen", suite: "codegen" });
1235 default_test!(CodegenUnits {
1236 path: "src/test/codegen-units",
1237 mode: "codegen-units",
1238 suite: "codegen-units"
1241 default_test!(Incremental {
1242 path: "src/test/incremental",
1243 mode: "incremental",
1244 suite: "incremental"
1247 default_test_with_compare_mode!(Debuginfo {
1248 path: "src/test/debuginfo",
1251 compare_mode: "split-dwarf"
1254 host_test!(UiFullDeps { path: "src/test/ui-fulldeps", mode: "ui", suite: "ui-fulldeps" });
1256 host_test!(Rustdoc { path: "src/test/rustdoc", mode: "rustdoc", suite: "rustdoc" });
1257 host_test!(RustdocUi { path: "src/test/rustdoc-ui", mode: "ui", suite: "rustdoc-ui" });
1259 host_test!(RustdocJson {
1260 path: "src/test/rustdoc-json",
1261 mode: "rustdoc-json",
1262 suite: "rustdoc-json"
1265 host_test!(Pretty { path: "src/test/pretty", mode: "pretty", suite: "pretty" });
1267 default_test!(RunMake { path: "src/test/run-make", mode: "run-make", suite: "run-make" });
1269 host_test!(RunMakeFullDeps {
1270 path: "src/test/run-make-fulldeps",
1272 suite: "run-make-fulldeps"
1275 default_test!(Assembly { path: "src/test/assembly", mode: "assembly", suite: "assembly" });
1277 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1278 struct Compiletest {
1280 target: TargetSelection,
1282 suite: &'static str,
1284 compare_mode: Option<&'static str>,
1287 impl Step for Compiletest {
1290 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1294 /// Executes the `compiletest` tool to run a suite of tests.
1296 /// Compiles all tests with `compiler` for `target` with the specified
1297 /// compiletest `mode` and `suite` arguments. For example `mode` can be
1298 /// "run-pass" or `suite` can be something like `debuginfo`.
1299 fn run(self, builder: &Builder<'_>) {
1300 if builder.top_stage == 0 && env::var("COMPILETEST_FORCE_STAGE0").is_err() {
1302 error: `--stage 0` runs compiletest on the beta compiler, not your local changes, and will almost always cause tests to fail
1303 help: to test the compiler, use `--stage 1` instead
1304 help: to test the standard library, use `--stage 0 library/std` instead
1305 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`."
1307 crate::detail_exit(1);
1310 let compiler = self.compiler;
1311 let target = self.target;
1312 let mode = self.mode;
1313 let suite = self.suite;
1315 // Path for test suite
1316 let suite_path = self.path;
1318 // Skip codegen tests if they aren't enabled in configuration.
1319 if !builder.config.codegen_tests && suite == "codegen" {
1323 if suite == "debuginfo" {
1325 .ensure(dist::DebuggerScripts { sysroot: builder.sysroot(compiler), host: target });
1328 if suite.ends_with("fulldeps") {
1329 builder.ensure(compile::Rustc::new(compiler, target));
1332 builder.ensure(compile::Std::new(compiler, target));
1333 // ensure that `libproc_macro` is available on the host.
1334 builder.ensure(compile::Std::new(compiler, compiler.host));
1336 // Also provide `rust_test_helpers` for the host.
1337 builder.ensure(native::TestHelpers { target: compiler.host });
1339 // As well as the target, except for plain wasm32, which can't build it
1340 if !target.contains("wasm") || target.contains("emscripten") {
1341 builder.ensure(native::TestHelpers { target });
1344 builder.ensure(RemoteCopyLibs { compiler, target });
1346 let mut cmd = builder.tool_cmd(Tool::Compiletest);
1348 // compiletest currently has... a lot of arguments, so let's just pass all
1351 cmd.arg("--compile-lib-path").arg(builder.rustc_libdir(compiler));
1352 cmd.arg("--run-lib-path").arg(builder.sysroot_libdir(compiler, target));
1353 cmd.arg("--rustc-path").arg(builder.rustc(compiler));
1355 let is_rustdoc = suite.ends_with("rustdoc-ui") || suite.ends_with("rustdoc-js");
1357 // Avoid depending on rustdoc when we don't need it.
1358 if mode == "rustdoc"
1359 || mode == "run-make"
1360 || (mode == "ui" && is_rustdoc)
1361 || mode == "js-doc-test"
1362 || mode == "rustdoc-json"
1364 cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler));
1367 if mode == "rustdoc-json" {
1368 // Use the beta compiler for jsondocck
1369 let json_compiler = compiler.with_stage(0);
1370 cmd.arg("--jsondocck-path")
1371 .arg(builder.ensure(tool::JsonDocCk { compiler: json_compiler, target }));
1372 cmd.arg("--jsondoclint-path")
1373 .arg(builder.ensure(tool::JsonDocLint { compiler: json_compiler, target }));
1376 if mode == "run-make" {
1377 let rust_demangler = builder
1378 .ensure(tool::RustDemangler {
1380 target: compiler.host,
1381 extra_features: Vec::new(),
1383 .expect("in-tree tool");
1384 cmd.arg("--rust-demangler-path").arg(rust_demangler);
1387 cmd.arg("--src-base").arg(builder.src.join("src/test").join(suite));
1388 cmd.arg("--build-base").arg(testdir(builder, compiler.host).join(suite));
1389 cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target));
1390 cmd.arg("--suite").arg(suite);
1391 cmd.arg("--mode").arg(mode);
1392 cmd.arg("--target").arg(target.rustc_target_arg());
1393 cmd.arg("--host").arg(&*compiler.host.triple);
1394 cmd.arg("--llvm-filecheck").arg(builder.llvm_filecheck(builder.config.build));
1396 if builder.config.cmd.bless() {
1400 if builder.config.cmd.force_rerun() {
1401 cmd.arg("--force-rerun");
1405 builder.config.cmd.compare_mode().or_else(|| {
1406 if builder.config.test_compare_mode { self.compare_mode } else { None }
1409 if let Some(ref pass) = builder.config.cmd.pass() {
1414 if let Some(ref run) = builder.config.cmd.run() {
1419 if let Some(ref nodejs) = builder.config.nodejs {
1420 cmd.arg("--nodejs").arg(nodejs);
1422 if let Some(ref npm) = builder.config.npm {
1423 cmd.arg("--npm").arg(npm);
1425 if builder.config.rust_optimize_tests {
1426 cmd.arg("--optimize-tests");
1428 let mut flags = if is_rustdoc { Vec::new() } else { vec!["-Crpath".to_string()] };
1429 flags.push(format!("-Cdebuginfo={}", builder.config.rust_debuginfo_level_tests));
1430 flags.extend(builder.config.cmd.rustc_args().iter().map(|s| s.to_string()));
1432 if let Some(linker) = builder.linker(target) {
1433 cmd.arg("--linker").arg(linker);
1436 let mut hostflags = flags.clone();
1437 hostflags.push(format!("-Lnative={}", builder.test_helpers_out(compiler.host).display()));
1438 hostflags.extend(builder.lld_flags(compiler.host));
1439 for flag in hostflags {
1440 cmd.arg("--host-rustcflags").arg(flag);
1443 let mut targetflags = flags;
1444 targetflags.push(format!("-Lnative={}", builder.test_helpers_out(target).display()));
1445 targetflags.extend(builder.lld_flags(target));
1446 for flag in targetflags {
1447 cmd.arg("--target-rustcflags").arg(flag);
1450 cmd.arg("--python").arg(builder.python());
1452 if let Some(ref gdb) = builder.config.gdb {
1453 cmd.arg("--gdb").arg(gdb);
1456 let run = |cmd: &mut Command| {
1457 cmd.output().map(|output| {
1458 String::from_utf8_lossy(&output.stdout)
1461 .unwrap_or_else(|| panic!("{:?} failed {:?}", cmd, output))
1465 let lldb_exe = "lldb";
1466 let lldb_version = Command::new(lldb_exe)
1469 .map(|output| String::from_utf8_lossy(&output.stdout).to_string())
1471 if let Some(ref vers) = lldb_version {
1472 cmd.arg("--lldb-version").arg(vers);
1473 let lldb_python_dir = run(Command::new(lldb_exe).arg("-P")).ok();
1474 if let Some(ref dir) = lldb_python_dir {
1475 cmd.arg("--lldb-python-dir").arg(dir);
1479 if util::forcing_clang_based_tests() {
1480 let clang_exe = builder.llvm_out(target).join("bin").join("clang");
1481 cmd.arg("--run-clang-based-tests-with").arg(clang_exe);
1484 for exclude in &builder.config.exclude {
1486 cmd.arg(&exclude.path);
1489 // Get paths from cmd args
1490 let paths = match &builder.config.cmd {
1491 Subcommand::Test { ref paths, .. } => &paths[..],
1495 // Get test-args by striping suite path
1496 let mut test_args: Vec<&str> = paths
1498 .filter_map(|p| util::is_valid_test_suite_arg(p, suite_path, builder))
1501 test_args.append(&mut builder.config.cmd.test_args());
1503 // On Windows, replace forward slashes in test-args by backslashes
1504 // so the correct filters are passed to libtest
1506 let test_args_win: Vec<String> =
1507 test_args.iter().map(|s| s.replace("/", "\\")).collect();
1508 cmd.args(&test_args_win);
1510 cmd.args(&test_args);
1513 if builder.is_verbose() {
1514 cmd.arg("--verbose");
1517 if !builder.config.verbose_tests {
1521 let mut llvm_components_passed = false;
1522 let mut copts_passed = false;
1523 if builder.config.llvm_enabled() {
1524 let llvm_config = builder.ensure(native::Llvm { target: builder.config.build });
1525 if !builder.config.dry_run {
1526 let llvm_version = output(Command::new(&llvm_config).arg("--version"));
1527 let llvm_components = output(Command::new(&llvm_config).arg("--components"));
1528 // Remove trailing newline from llvm-config output.
1529 cmd.arg("--llvm-version")
1530 .arg(llvm_version.trim())
1531 .arg("--llvm-components")
1532 .arg(llvm_components.trim());
1533 llvm_components_passed = true;
1535 if !builder.is_rust_llvm(target) {
1536 cmd.arg("--system-llvm");
1539 // Tests that use compiler libraries may inherit the `-lLLVM` link
1540 // requirement, but the `-L` library path is not propagated across
1541 // separate compilations. We can add LLVM's library path to the
1542 // platform-specific environment variable as a workaround.
1543 if !builder.config.dry_run && suite.ends_with("fulldeps") {
1544 let llvm_libdir = output(Command::new(&llvm_config).arg("--libdir"));
1545 add_link_lib_path(vec![llvm_libdir.trim().into()], &mut cmd);
1548 // Only pass correct values for these flags for the `run-make` suite as it
1549 // requires that a C++ compiler was configured which isn't always the case.
1550 if !builder.config.dry_run && matches!(suite, "run-make" | "run-make-fulldeps") {
1551 // The llvm/bin directory contains many useful cross-platform
1552 // tools. Pass the path to run-make tests so they can use them.
1553 let llvm_bin_path = llvm_config
1555 .expect("Expected llvm-config to be contained in directory");
1556 assert!(llvm_bin_path.is_dir());
1557 cmd.arg("--llvm-bin-dir").arg(llvm_bin_path);
1559 // If LLD is available, add it to the PATH
1560 if builder.config.lld_enabled {
1561 let lld_install_root =
1562 builder.ensure(native::Lld { target: builder.config.build });
1564 let lld_bin_path = lld_install_root.join("bin");
1566 let old_path = env::var_os("PATH").unwrap_or_default();
1567 let new_path = env::join_paths(
1568 std::iter::once(lld_bin_path).chain(env::split_paths(&old_path)),
1570 .expect("Could not add LLD bin path to PATH");
1571 cmd.env("PATH", new_path);
1576 // Only pass correct values for these flags for the `run-make` suite as it
1577 // requires that a C++ compiler was configured which isn't always the case.
1578 if !builder.config.dry_run && matches!(suite, "run-make" | "run-make-fulldeps") {
1580 .arg(builder.cc(target))
1582 .arg(builder.cxx(target).unwrap())
1584 .arg(builder.cflags(target, GitRepo::Rustc, CLang::C).join(" "))
1586 .arg(builder.cflags(target, GitRepo::Rustc, CLang::Cxx).join(" "));
1587 copts_passed = true;
1588 if let Some(ar) = builder.ar(target) {
1589 cmd.arg("--ar").arg(ar);
1593 if !llvm_components_passed {
1594 cmd.arg("--llvm-components").arg("");
1607 if builder.remote_tested(target) {
1608 cmd.arg("--remote-test-client").arg(builder.tool_exe(Tool::RemoteTestClient));
1611 // Running a C compiler on MSVC requires a few env vars to be set, to be
1612 // sure to set them here.
1614 // Note that if we encounter `PATH` we make sure to append to our own `PATH`
1615 // rather than stomp over it.
1616 if target.contains("msvc") {
1617 for &(ref k, ref v) in builder.cc[&target].env() {
1623 cmd.env("RUSTC_BOOTSTRAP", "1");
1624 // Override the rustc version used in symbol hashes to reduce the amount of normalization
1625 // needed when diffing test output.
1626 cmd.env("RUSTC_FORCE_RUSTC_VERSION", "compiletest");
1627 cmd.env("DOC_RUST_LANG_ORG_CHANNEL", builder.doc_rust_lang_org_channel());
1628 builder.add_rust_test_threads(&mut cmd);
1630 if builder.config.sanitizers_enabled(target) {
1631 cmd.env("RUSTC_SANITIZER_SUPPORT", "1");
1634 if builder.config.profiler_enabled(target) {
1635 cmd.env("RUSTC_PROFILER_SUPPORT", "1");
1638 cmd.env("RUST_TEST_TMPDIR", builder.tempdir());
1640 cmd.arg("--adb-path").arg("adb");
1641 cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
1642 if target.contains("android") {
1643 // Assume that cc for this target comes from the android sysroot
1644 cmd.arg("--android-cross-path")
1645 .arg(builder.cc(target).parent().unwrap().parent().unwrap());
1647 cmd.arg("--android-cross-path").arg("");
1650 if builder.config.cmd.rustfix_coverage() {
1651 cmd.arg("--rustfix-coverage");
1654 cmd.env("BOOTSTRAP_CARGO", &builder.initial_cargo);
1656 cmd.arg("--channel").arg(&builder.config.channel);
1658 builder.ci_env.force_coloring_in_ci(&mut cmd);
1660 builder.info(&format!(
1661 "Check compiletest suite={} mode={} ({} -> {})",
1662 suite, mode, &compiler.host, target
1664 let _time = util::timeit(&builder);
1665 try_run(builder, &mut cmd);
1667 if let Some(compare_mode) = compare_mode {
1668 cmd.arg("--compare-mode").arg(compare_mode);
1669 builder.info(&format!(
1670 "Check compiletest suite={} mode={} compare_mode={} ({} -> {})",
1671 suite, mode, compare_mode, &compiler.host, target
1673 let _time = util::timeit(&builder);
1674 try_run(builder, &mut cmd);
1679 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1687 impl Step for BookTest {
1689 const ONLY_HOSTS: bool = true;
1691 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1695 /// Runs the documentation tests for a book in `src/doc`.
1697 /// This uses the `rustdoc` that sits next to `compiler`.
1698 fn run(self, builder: &Builder<'_>) {
1699 // External docs are different from local because:
1700 // - Some books need pre-processing by mdbook before being tested.
1701 // - They need to save their state to toolstate.
1702 // - They are only tested on the "checktools" builders.
1704 // The local docs are tested by default, and we don't want to pay the
1705 // cost of building mdbook, so they use `rustdoc --test` directly.
1706 // Also, the unstable book is special because SUMMARY.md is generated,
1707 // so it is easier to just run `rustdoc` on its files.
1708 if self.is_ext_doc {
1709 self.run_ext_doc(builder);
1711 self.run_local_doc(builder);
1717 /// This runs the equivalent of `mdbook test` (via the rustbook wrapper)
1718 /// which in turn runs `rustdoc --test` on each file in the book.
1719 fn run_ext_doc(self, builder: &Builder<'_>) {
1720 let compiler = self.compiler;
1722 builder.ensure(compile::Std::new(compiler, compiler.host));
1724 // mdbook just executes a binary named "rustdoc", so we need to update
1725 // PATH so that it points to our rustdoc.
1726 let mut rustdoc_path = builder.rustdoc(compiler);
1728 let old_path = env::var_os("PATH").unwrap_or_default();
1729 let new_path = env::join_paths(iter::once(rustdoc_path).chain(env::split_paths(&old_path)))
1730 .expect("could not add rustdoc to PATH");
1732 let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
1733 let path = builder.src.join(&self.path);
1734 // Books often have feature-gated example text.
1735 rustbook_cmd.env("RUSTC_BOOTSTRAP", "1");
1736 rustbook_cmd.env("PATH", new_path).arg("test").arg(path);
1737 builder.add_rust_test_threads(&mut rustbook_cmd);
1738 builder.info(&format!("Testing rustbook {}", self.path.display()));
1739 let _time = util::timeit(&builder);
1740 let toolstate = if try_run(builder, &mut rustbook_cmd) {
1745 builder.save_toolstate(self.name, toolstate);
1748 /// This runs `rustdoc --test` on all `.md` files in the path.
1749 fn run_local_doc(self, builder: &Builder<'_>) {
1750 let compiler = self.compiler;
1752 builder.ensure(compile::Std::new(compiler, compiler.host));
1754 // Do a breadth-first traversal of the `src/doc` directory and just run
1755 // tests for all files that end in `*.md`
1756 let mut stack = vec![builder.src.join(self.path)];
1757 let _time = util::timeit(&builder);
1758 let mut files = Vec::new();
1759 while let Some(p) = stack.pop() {
1761 stack.extend(t!(p.read_dir()).map(|p| t!(p).path()));
1765 if p.extension().and_then(|s| s.to_str()) != Some("md") {
1775 markdown_test(builder, compiler, &file);
1780 macro_rules! test_book {
1781 ($($name:ident, $path:expr, $book_name:expr, default=$default:expr;)+) => {
1783 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1788 impl Step for $name {
1790 const DEFAULT: bool = $default;
1791 const ONLY_HOSTS: bool = true;
1793 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1797 fn make_run(run: RunConfig<'_>) {
1798 run.builder.ensure($name {
1799 compiler: run.builder.compiler(run.builder.top_stage, run.target),
1803 fn run(self, builder: &Builder<'_>) {
1804 builder.ensure(BookTest {
1805 compiler: self.compiler,
1806 path: PathBuf::from($path),
1808 is_ext_doc: !$default,
1817 Nomicon, "src/doc/nomicon", "nomicon", default=false;
1818 Reference, "src/doc/reference", "reference", default=false;
1819 RustdocBook, "src/doc/rustdoc", "rustdoc", default=true;
1820 RustcBook, "src/doc/rustc", "rustc", default=true;
1821 RustByExample, "src/doc/rust-by-example", "rust-by-example", default=false;
1822 EmbeddedBook, "src/doc/embedded-book", "embedded-book", default=false;
1823 TheBook, "src/doc/book", "book", default=false;
1824 UnstableBook, "src/doc/unstable-book", "unstable-book", default=true;
1825 EditionGuide, "src/doc/edition-guide", "edition-guide", default=false;
1828 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1829 pub struct ErrorIndex {
1833 impl Step for ErrorIndex {
1835 const DEFAULT: bool = true;
1836 const ONLY_HOSTS: bool = true;
1838 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1839 run.path("src/tools/error_index_generator")
1842 fn make_run(run: RunConfig<'_>) {
1843 // error_index_generator depends on librustdoc. Use the compiler that
1844 // is normally used to build rustdoc for other tests (like compiletest
1845 // tests in src/test/rustdoc) so that it shares the same artifacts.
1846 let compiler = run.builder.compiler(run.builder.top_stage, run.builder.config.build);
1847 run.builder.ensure(ErrorIndex { compiler });
1850 /// Runs the error index generator tool to execute the tests located in the error
1853 /// The `error_index_generator` tool lives in `src/tools` and is used to
1854 /// generate a markdown file from the error indexes of the code base which is
1855 /// then passed to `rustdoc --test`.
1856 fn run(self, builder: &Builder<'_>) {
1857 let compiler = self.compiler;
1859 let dir = testdir(builder, compiler.host);
1860 t!(fs::create_dir_all(&dir));
1861 let output = dir.join("error-index.md");
1863 let mut tool = tool::ErrorIndex::command(builder);
1864 tool.arg("markdown").arg(&output);
1866 builder.info(&format!("Testing error-index stage{}", compiler.stage));
1867 let _time = util::timeit(&builder);
1868 builder.run_quiet(&mut tool);
1869 // The tests themselves need to link to std, so make sure it is
1871 builder.ensure(compile::Std::new(compiler, compiler.host));
1872 markdown_test(builder, compiler, &output);
1876 fn markdown_test(builder: &Builder<'_>, compiler: Compiler, markdown: &Path) -> bool {
1877 if let Ok(contents) = fs::read_to_string(markdown) {
1878 if !contents.contains("```") {
1883 builder.info(&format!("doc tests for: {}", markdown.display()));
1884 let mut cmd = builder.rustdoc_cmd(compiler);
1885 builder.add_rust_test_threads(&mut cmd);
1886 // allow for unstable options such as new editions
1888 cmd.arg("unstable-options");
1891 cmd.env("RUSTC_BOOTSTRAP", "1");
1893 let test_args = builder.config.cmd.test_args().join(" ");
1894 cmd.arg("--test-args").arg(test_args);
1896 if builder.config.verbose_tests {
1897 try_run(builder, &mut cmd)
1899 try_run_quiet(builder, &mut cmd)
1903 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1904 pub struct RustcGuide;
1906 impl Step for RustcGuide {
1908 const DEFAULT: bool = false;
1909 const ONLY_HOSTS: bool = true;
1911 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1912 run.path("src/doc/rustc-dev-guide")
1915 fn make_run(run: RunConfig<'_>) {
1916 run.builder.ensure(RustcGuide);
1919 fn run(self, builder: &Builder<'_>) {
1920 let relative_path = Path::new("src").join("doc").join("rustc-dev-guide");
1921 builder.update_submodule(&relative_path);
1923 let src = builder.src.join(relative_path);
1924 let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
1925 let toolstate = if try_run(builder, rustbook_cmd.arg("linkcheck").arg(&src)) {
1930 builder.save_toolstate("rustc-dev-guide", toolstate);
1934 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1935 pub struct CrateLibrustc {
1937 target: TargetSelection,
1938 test_kind: TestKind,
1939 crates: Vec<Interned<String>>,
1942 impl Step for CrateLibrustc {
1944 const DEFAULT: bool = true;
1945 const ONLY_HOSTS: bool = true;
1947 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1948 run.crate_or_deps("rustc-main")
1951 fn make_run(run: RunConfig<'_>) {
1952 let builder = run.builder;
1953 let host = run.build_triple();
1954 let compiler = builder.compiler_for(builder.top_stage, host, host);
1958 .map(|p| builder.crate_paths[&p.assert_single_path().path].clone())
1960 let test_kind = builder.kind.into();
1962 builder.ensure(CrateLibrustc { compiler, target: run.target, test_kind, crates });
1965 fn run(self, builder: &Builder<'_>) {
1966 builder.ensure(Crate {
1967 compiler: self.compiler,
1968 target: self.target,
1970 test_kind: self.test_kind,
1971 crates: self.crates,
1976 #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
1978 pub compiler: Compiler,
1979 pub target: TargetSelection,
1981 pub test_kind: TestKind,
1982 pub crates: Vec<Interned<String>>,
1985 impl Step for Crate {
1987 const DEFAULT: bool = true;
1989 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1990 run.crate_or_deps("test")
1993 fn make_run(run: RunConfig<'_>) {
1994 let builder = run.builder;
1995 let host = run.build_triple();
1996 let compiler = builder.compiler_for(builder.top_stage, host, host);
1997 let test_kind = builder.kind.into();
2001 .map(|p| builder.crate_paths[&p.assert_single_path().path].clone())
2004 builder.ensure(Crate { compiler, target: run.target, mode: Mode::Std, test_kind, crates });
2007 /// Runs all unit tests plus documentation tests for a given crate defined
2008 /// by a `Cargo.toml` (single manifest)
2010 /// This is what runs tests for crates like the standard library, compiler, etc.
2011 /// It essentially is the driver for running `cargo test`.
2013 /// Currently this runs all tests for a DAG by passing a bunch of `-p foo`
2014 /// arguments, and those arguments are discovered from `cargo metadata`.
2015 fn run(self, builder: &Builder<'_>) {
2016 let compiler = self.compiler;
2017 let target = self.target;
2018 let mode = self.mode;
2019 let test_kind = self.test_kind;
2021 builder.ensure(compile::Std::new(compiler, target));
2022 builder.ensure(RemoteCopyLibs { compiler, target });
2024 // If we're not doing a full bootstrap but we're testing a stage2
2025 // version of libstd, then what we're actually testing is the libstd
2026 // produced in stage1. Reflect that here by updating the compiler that
2027 // we're working with automatically.
2028 let compiler = builder.compiler_for(compiler.stage, compiler.host, target);
2031 builder.cargo(compiler, mode, SourceType::InTree, target, test_kind.subcommand());
2034 compile::std_cargo(builder, target, compiler.stage, &mut cargo);
2037 compile::rustc_cargo(builder, &mut cargo, target);
2039 _ => panic!("can only test libraries"),
2042 // Build up the base `cargo test` command.
2044 // Pass in some standard flags then iterate over the graph we've discovered
2045 // in `cargo metadata` with the maps above and figure out what `-p`
2046 // arguments need to get passed.
2047 if test_kind.subcommand() == "test" && !builder.fail_fast {
2048 cargo.arg("--no-fail-fast");
2050 match builder.doc_tests {
2055 cargo.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
2060 for krate in &self.crates {
2061 cargo.arg("-p").arg(krate);
2064 // The tests are going to run with the *target* libraries, so we need to
2065 // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
2067 // Note that to run the compiler we need to run with the *host* libraries,
2068 // but our wrapper scripts arrange for that to be the case anyway.
2069 let mut dylib_path = dylib_path();
2070 dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
2071 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
2074 cargo.args(&builder.config.cmd.test_args());
2076 if !builder.config.verbose_tests {
2077 cargo.arg("--quiet");
2080 if target.contains("emscripten") {
2082 format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)),
2083 builder.config.nodejs.as_ref().expect("nodejs not configured"),
2085 } else if target.starts_with("wasm32") {
2086 let node = builder.config.nodejs.as_ref().expect("nodejs not configured");
2088 format!("{} {}/src/etc/wasm32-shim.js", node.display(), builder.src.display());
2089 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)), &runner);
2090 } else if builder.remote_tested(target) {
2092 format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)),
2093 format!("{} run 0", builder.tool_exe(Tool::RemoteTestClient).display()),
2097 builder.info(&format!(
2098 "{} {:?} stage{} ({} -> {})",
2099 test_kind, self.crates, compiler.stage, &compiler.host, target
2101 let _time = util::timeit(&builder);
2102 try_run(builder, &mut cargo.into());
2106 /// Rustdoc is special in various ways, which is why this step is different from `Crate`.
2107 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2108 pub struct CrateRustdoc {
2109 host: TargetSelection,
2110 test_kind: TestKind,
2113 impl Step for CrateRustdoc {
2115 const DEFAULT: bool = true;
2116 const ONLY_HOSTS: bool = true;
2118 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2119 run.paths(&["src/librustdoc", "src/tools/rustdoc"])
2122 fn make_run(run: RunConfig<'_>) {
2123 let builder = run.builder;
2125 let test_kind = builder.kind.into();
2127 builder.ensure(CrateRustdoc { host: run.target, test_kind });
2130 fn run(self, builder: &Builder<'_>) {
2131 let test_kind = self.test_kind;
2132 let target = self.host;
2134 let compiler = if builder.download_rustc() {
2135 builder.compiler(builder.top_stage, target)
2137 // Use the previous stage compiler to reuse the artifacts that are
2138 // created when running compiletest for src/test/rustdoc. If this used
2139 // `compiler`, then it would cause rustdoc to be built *again*, which
2140 // isn't really necessary.
2141 builder.compiler_for(builder.top_stage, target, target)
2143 builder.ensure(compile::Rustc::new(compiler, target));
2145 let mut cargo = tool::prepare_tool_cargo(
2150 test_kind.subcommand(),
2151 "src/tools/rustdoc",
2155 if test_kind.subcommand() == "test" && !builder.fail_fast {
2156 cargo.arg("--no-fail-fast");
2158 match builder.doc_tests {
2163 cargo.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
2168 cargo.arg("-p").arg("rustdoc:0.0.0");
2171 cargo.args(&builder.config.cmd.test_args());
2173 if self.host.contains("musl") {
2174 cargo.arg("'-Ctarget-feature=-crt-static'");
2177 // This is needed for running doctests on librustdoc. This is a bit of
2178 // an unfortunate interaction with how bootstrap works and how cargo
2179 // sets up the dylib path, and the fact that the doctest (in
2180 // html/markdown.rs) links to rustc-private libs. For stage1, the
2181 // compiler host dylibs (in stage1/lib) are not the same as the target
2182 // dylibs (in stage1/lib/rustlib/...). This is different from a normal
2183 // rust distribution where they are the same.
2185 // On the cargo side, normal tests use `target_process` which handles
2186 // setting up the dylib for a *target* (stage1/lib/rustlib/... in this
2187 // case). However, for doctests it uses `rustdoc_process` which only
2188 // sets up the dylib path for the *host* (stage1/lib), which is the
2191 // Recall that we special-cased `compiler_for(top_stage)` above, so we always use stage1.
2193 // It should be considered to just stop running doctests on
2194 // librustdoc. There is only one test, and it doesn't look too
2195 // important. There might be other ways to avoid this, but it seems
2196 // pretty convoluted.
2198 // See also https://github.com/rust-lang/rust/issues/13983 where the
2199 // host vs target dylibs for rustdoc are consistently tricky to deal
2202 // Note that this set the host libdir for `download_rustc`, which uses a normal rust distribution.
2203 let libdir = if builder.download_rustc() {
2204 builder.rustc_libdir(compiler)
2206 builder.sysroot_libdir(compiler, target).to_path_buf()
2208 let mut dylib_path = dylib_path();
2209 dylib_path.insert(0, PathBuf::from(&*libdir));
2210 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
2212 if !builder.config.verbose_tests {
2213 cargo.arg("--quiet");
2216 builder.info(&format!(
2217 "{} rustdoc stage{} ({} -> {})",
2218 test_kind, compiler.stage, &compiler.host, target
2220 let _time = util::timeit(&builder);
2222 try_run(builder, &mut cargo.into());
2226 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2227 pub struct CrateRustdocJsonTypes {
2228 host: TargetSelection,
2229 test_kind: TestKind,
2232 impl Step for CrateRustdocJsonTypes {
2234 const DEFAULT: bool = true;
2235 const ONLY_HOSTS: bool = true;
2237 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2238 run.path("src/rustdoc-json-types")
2241 fn make_run(run: RunConfig<'_>) {
2242 let builder = run.builder;
2244 let test_kind = builder.kind.into();
2246 builder.ensure(CrateRustdocJsonTypes { host: run.target, test_kind });
2249 fn run(self, builder: &Builder<'_>) {
2250 let test_kind = self.test_kind;
2251 let target = self.host;
2253 // Use the previous stage compiler to reuse the artifacts that are
2254 // created when running compiletest for src/test/rustdoc. If this used
2255 // `compiler`, then it would cause rustdoc to be built *again*, which
2256 // isn't really necessary.
2257 let compiler = builder.compiler_for(builder.top_stage, target, target);
2258 builder.ensure(compile::Rustc::new(compiler, target));
2260 let mut cargo = tool::prepare_tool_cargo(
2265 test_kind.subcommand(),
2266 "src/rustdoc-json-types",
2270 if test_kind.subcommand() == "test" && !builder.fail_fast {
2271 cargo.arg("--no-fail-fast");
2274 cargo.arg("-p").arg("rustdoc-json-types");
2277 cargo.args(&builder.config.cmd.test_args());
2279 if self.host.contains("musl") {
2280 cargo.arg("'-Ctarget-feature=-crt-static'");
2283 if !builder.config.verbose_tests {
2284 cargo.arg("--quiet");
2287 builder.info(&format!(
2288 "{} rustdoc-json-types stage{} ({} -> {})",
2289 test_kind, compiler.stage, &compiler.host, target
2291 let _time = util::timeit(&builder);
2293 try_run(builder, &mut cargo.into());
2297 /// Some test suites are run inside emulators or on remote devices, and most
2298 /// of our test binaries are linked dynamically which means we need to ship
2299 /// the standard library and such to the emulator ahead of time. This step
2300 /// represents this and is a dependency of all test suites.
2302 /// Most of the time this is a no-op. For some steps such as shipping data to
2303 /// QEMU we have to build our own tools so we've got conditional dependencies
2304 /// on those programs as well. Note that the remote test client is built for
2305 /// the build target (us) and the server is built for the target.
2306 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2307 pub struct RemoteCopyLibs {
2309 target: TargetSelection,
2312 impl Step for RemoteCopyLibs {
2315 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2319 fn run(self, builder: &Builder<'_>) {
2320 let compiler = self.compiler;
2321 let target = self.target;
2322 if !builder.remote_tested(target) {
2326 builder.ensure(compile::Std::new(compiler, target));
2328 builder.info(&format!("REMOTE copy libs to emulator ({})", target));
2330 let server = builder.ensure(tool::RemoteTestServer { compiler, target });
2332 // Spawn the emulator and wait for it to come online
2333 let tool = builder.tool_exe(Tool::RemoteTestClient);
2334 let mut cmd = Command::new(&tool);
2335 cmd.arg("spawn-emulator").arg(target.triple).arg(&server).arg(builder.tempdir());
2336 if let Some(rootfs) = builder.qemu_rootfs(target) {
2339 builder.run(&mut cmd);
2341 // Push all our dylibs to the emulator
2342 for f in t!(builder.sysroot_libdir(compiler, target).read_dir()) {
2344 let name = f.file_name().into_string().unwrap();
2345 if util::is_dylib(&name) {
2346 builder.run(Command::new(&tool).arg("push").arg(f.path()));
2352 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2353 pub struct Distcheck;
2355 impl Step for Distcheck {
2358 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2359 run.alias("distcheck")
2362 fn make_run(run: RunConfig<'_>) {
2363 run.builder.ensure(Distcheck);
2366 /// Runs "distcheck", a 'make check' from a tarball
2367 fn run(self, builder: &Builder<'_>) {
2368 builder.info("Distcheck");
2369 let dir = builder.tempdir().join("distcheck");
2370 let _ = fs::remove_dir_all(&dir);
2371 t!(fs::create_dir_all(&dir));
2373 // Guarantee that these are built before we begin running.
2374 builder.ensure(dist::PlainSourceTarball);
2375 builder.ensure(dist::Src);
2377 let mut cmd = Command::new("tar");
2379 .arg(builder.ensure(dist::PlainSourceTarball).tarball())
2380 .arg("--strip-components=1")
2382 builder.run(&mut cmd);
2384 Command::new("./configure")
2385 .args(&builder.config.configure_args)
2386 .arg("--enable-vendor")
2390 Command::new(util::make(&builder.config.build.triple)).arg("check").current_dir(&dir),
2393 // Now make sure that rust-src has all of libstd's dependencies
2394 builder.info("Distcheck rust-src");
2395 let dir = builder.tempdir().join("distcheck-src");
2396 let _ = fs::remove_dir_all(&dir);
2397 t!(fs::create_dir_all(&dir));
2399 let mut cmd = Command::new("tar");
2401 .arg(builder.ensure(dist::Src).tarball())
2402 .arg("--strip-components=1")
2404 builder.run(&mut cmd);
2406 let toml = dir.join("rust-src/lib/rustlib/src/rust/library/std/Cargo.toml");
2408 Command::new(&builder.initial_cargo)
2409 .arg("generate-lockfile")
2410 .arg("--manifest-path")
2417 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2418 pub struct Bootstrap;
2420 impl Step for Bootstrap {
2422 const DEFAULT: bool = true;
2423 const ONLY_HOSTS: bool = true;
2425 /// Tests the build system itself.
2426 fn run(self, builder: &Builder<'_>) {
2427 let mut check_bootstrap = Command::new(&builder.python());
2428 check_bootstrap.arg("bootstrap_test.py").current_dir(builder.src.join("src/bootstrap/"));
2429 try_run(builder, &mut check_bootstrap);
2431 let mut cmd = Command::new(&builder.initial_cargo);
2433 .current_dir(builder.src.join("src/bootstrap"))
2434 .env("RUSTFLAGS", "-Cdebuginfo=2")
2435 .env("CARGO_TARGET_DIR", builder.out.join("bootstrap"))
2436 .env("RUSTC_BOOTSTRAP", "1")
2437 .env("RUSTDOC", builder.rustdoc(builder.compiler(0, builder.build.build)))
2438 .env("RUSTC", &builder.initial_rustc);
2439 if let Some(flags) = option_env!("RUSTFLAGS") {
2440 // Use the same rustc flags for testing as for "normal" compilation,
2441 // so that Cargo doesn’t recompile the entire dependency graph every time:
2442 // https://github.com/rust-lang/rust/issues/49215
2443 cmd.env("RUSTFLAGS", flags);
2445 if !builder.fail_fast {
2446 cmd.arg("--no-fail-fast");
2448 match builder.doc_tests {
2453 cmd.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
2458 cmd.arg("--").args(&builder.config.cmd.test_args());
2459 // rustbuild tests are racy on directory creation so just run them one at a time.
2460 // Since there's not many this shouldn't be a problem.
2461 cmd.arg("--test-threads=1");
2462 try_run(builder, &mut cmd);
2465 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2466 run.path("src/bootstrap")
2469 fn make_run(run: RunConfig<'_>) {
2470 run.builder.ensure(Bootstrap);
2474 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2475 pub struct TierCheck {
2476 pub compiler: Compiler,
2479 impl Step for TierCheck {
2481 const DEFAULT: bool = true;
2482 const ONLY_HOSTS: bool = true;
2484 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2485 run.path("src/tools/tier-check")
2488 fn make_run(run: RunConfig<'_>) {
2490 run.builder.compiler_for(run.builder.top_stage, run.builder.build.build, run.target);
2491 run.builder.ensure(TierCheck { compiler });
2494 /// Tests the Platform Support page in the rustc book.
2495 fn run(self, builder: &Builder<'_>) {
2496 builder.ensure(compile::Std::new(self.compiler, self.compiler.host));
2497 let mut cargo = tool::prepare_tool_cargo(
2503 "src/tools/tier-check",
2507 cargo.arg(builder.src.join("src/doc/rustc/src/platform-support.md"));
2508 cargo.arg(&builder.rustc(self.compiler));
2509 if builder.is_verbose() {
2510 cargo.arg("--verbose");
2513 builder.info("platform support check");
2514 try_run(builder, &mut cargo.into());
2518 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2519 pub struct ReplacePlaceholderTest;
2521 impl Step for ReplacePlaceholderTest {
2523 const ONLY_HOSTS: bool = true;
2524 const DEFAULT: bool = true;
2526 /// Ensure the version placeholder replacement tool builds
2527 fn run(self, builder: &Builder<'_>) {
2528 builder.info("build check for version replacement placeholder");
2530 // Test the version placeholder replacement tool itself.
2531 let bootstrap_host = builder.config.build;
2532 let compiler = builder.compiler(0, bootstrap_host);
2533 let cargo = tool::prepare_tool_cargo(
2536 Mode::ToolBootstrap,
2539 "src/tools/replace-version-placeholder",
2543 try_run(builder, &mut cargo.into());
2546 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2547 run.path("src/tools/replace-version-placeholder")
2550 fn make_run(run: RunConfig<'_>) {
2551 run.builder.ensure(Self);
2555 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2556 pub struct LintDocs {
2557 pub compiler: Compiler,
2558 pub target: TargetSelection,
2561 impl Step for LintDocs {
2563 const DEFAULT: bool = true;
2564 const ONLY_HOSTS: bool = true;
2566 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2567 run.path("src/tools/lint-docs")
2570 fn make_run(run: RunConfig<'_>) {
2571 run.builder.ensure(LintDocs {
2572 compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
2577 /// Tests that the lint examples in the rustc book generate the correct
2578 /// lints and have the expected format.
2579 fn run(self, builder: &Builder<'_>) {
2580 builder.ensure(crate::doc::RustcBook {
2581 compiler: self.compiler,
2582 target: self.target,