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/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 // Disable a test that has issues with mingw.
293 cargo.env("CARGO_TEST_DISABLE_GIT_CLI", "1");
294 // Forcibly disable tests using nightly features since any changes to
295 // those features won't be able to land.
296 cargo.env("CARGO_TEST_DISABLE_NIGHTLY", "1");
298 cargo.env("PATH", &path_for_cargo(builder, compiler));
300 try_run(builder, &mut cargo.into());
304 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
307 host: TargetSelection,
312 const ONLY_HOSTS: bool = true;
314 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
315 run.path("src/tools/rls")
318 fn make_run(run: RunConfig<'_>) {
319 run.builder.ensure(Rls { stage: run.builder.top_stage, host: run.target });
322 /// Runs `cargo test` for the rls.
323 fn run(self, builder: &Builder<'_>) {
324 let stage = self.stage;
325 let host = self.host;
326 let compiler = builder.compiler(stage, host);
329 builder.ensure(tool::Rls { compiler, target: self.host, extra_features: Vec::new() });
330 if build_result.is_none() {
331 eprintln!("failed to test rls: could not build");
335 let mut cargo = tool::prepare_tool_cargo(
342 SourceType::Submodule,
346 cargo.add_rustc_lib_path(builder, compiler);
347 cargo.arg("--").args(builder.config.cmd.test_args());
349 if try_run(builder, &mut cargo.into()) {
350 builder.save_toolstate("rls", ToolState::TestPass);
355 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
356 pub struct RustAnalyzer {
358 host: TargetSelection,
361 impl Step for RustAnalyzer {
363 const ONLY_HOSTS: bool = true;
364 const DEFAULT: bool = true;
366 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
367 run.path("src/tools/rust-analyzer")
370 fn make_run(run: RunConfig<'_>) {
371 run.builder.ensure(Self { stage: run.builder.top_stage, host: run.target });
374 /// Runs `cargo test` for rust-analyzer
375 fn run(self, builder: &Builder<'_>) {
376 let stage = self.stage;
377 let host = self.host;
378 let compiler = builder.compiler(stage, host);
380 builder.ensure(tool::RustAnalyzer { compiler, target: self.host }).expect("in-tree tool");
382 let workspace_path = "src/tools/rust-analyzer";
383 // until the whole RA test suite runs on `i686`, we only run
384 // `proc-macro-srv` tests
385 let crate_path = "src/tools/rust-analyzer/crates/proc-macro-srv";
386 let mut cargo = tool::prepare_tool_cargo(
394 &["sysroot-abi".to_owned()],
397 let dir = builder.src.join(workspace_path);
398 // needed by rust-analyzer to find its own text fixtures, cf.
399 // https://github.com/rust-analyzer/expect-test/issues/33
400 cargo.env("CARGO_WORKSPACE_DIR", &dir);
402 // RA's test suite tries to write to the source directory, that can't
404 cargo.env("SKIP_SLOW_TESTS", "1");
406 cargo.add_rustc_lib_path(builder, compiler);
407 cargo.arg("--").args(builder.config.cmd.test_args());
409 builder.run(&mut cargo.into());
413 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
416 host: TargetSelection,
419 impl Step for Rustfmt {
421 const ONLY_HOSTS: bool = true;
423 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
424 run.path("src/tools/rustfmt")
427 fn make_run(run: RunConfig<'_>) {
428 run.builder.ensure(Rustfmt { stage: run.builder.top_stage, host: run.target });
431 /// Runs `cargo test` for rustfmt.
432 fn run(self, builder: &Builder<'_>) {
433 let stage = self.stage;
434 let host = self.host;
435 let compiler = builder.compiler(stage, host);
438 .ensure(tool::Rustfmt { compiler, target: self.host, extra_features: Vec::new() })
439 .expect("in-tree tool");
441 let mut cargo = tool::prepare_tool_cargo(
452 let dir = testdir(builder, compiler.host);
453 t!(fs::create_dir_all(&dir));
454 cargo.env("RUSTFMT_TEST_DIR", dir);
456 cargo.add_rustc_lib_path(builder, compiler);
458 builder.run(&mut cargo.into());
462 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
463 pub struct RustDemangler {
465 host: TargetSelection,
468 impl Step for RustDemangler {
470 const ONLY_HOSTS: bool = true;
472 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
473 run.path("src/tools/rust-demangler")
476 fn make_run(run: RunConfig<'_>) {
477 run.builder.ensure(RustDemangler { stage: run.builder.top_stage, host: run.target });
480 /// Runs `cargo test` for rust-demangler.
481 fn run(self, builder: &Builder<'_>) {
482 let stage = self.stage;
483 let host = self.host;
484 let compiler = builder.compiler(stage, host);
486 let rust_demangler = builder
487 .ensure(tool::RustDemangler { compiler, target: self.host, extra_features: Vec::new() })
488 .expect("in-tree tool");
489 let mut cargo = tool::prepare_tool_cargo(
495 "src/tools/rust-demangler",
500 let dir = testdir(builder, compiler.host);
501 t!(fs::create_dir_all(&dir));
503 cargo.env("RUST_DEMANGLER_DRIVER_PATH", rust_demangler);
505 cargo.arg("--").args(builder.config.cmd.test_args());
507 cargo.add_rustc_lib_path(builder, compiler);
509 builder.run(&mut cargo.into());
513 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
516 host: TargetSelection,
521 const ONLY_HOSTS: bool = true;
523 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
524 run.path("src/tools/miri")
527 fn make_run(run: RunConfig<'_>) {
528 run.builder.ensure(Miri { stage: run.builder.top_stage, host: run.target });
531 /// Runs `cargo test` for miri.
532 fn run(self, builder: &Builder<'_>) {
533 let stage = self.stage;
534 let host = self.host;
535 let compiler = builder.compiler(stage, host);
536 // We need the stdlib for the *next* stage, as it was built with this compiler that also built Miri.
537 // Except if we are at stage 2, the bootstrap loop is complete and we can stick with our current stage.
538 let compiler_std = builder.compiler(if stage < 2 { stage + 1 } else { stage }, host);
541 builder.ensure(tool::Miri { compiler, target: self.host, extra_features: Vec::new() });
542 let cargo_miri = builder.ensure(tool::CargoMiri {
545 extra_features: Vec::new(),
547 // The stdlib we need might be at a different stage. And just asking for the
548 // sysroot does not seem to populate it, so we do that first.
549 builder.ensure(compile::Std::new(compiler_std, host));
550 let sysroot = builder.sysroot(compiler_std);
551 if let (Some(miri), Some(_cargo_miri)) = (miri, cargo_miri) {
553 builder.cargo(compiler, Mode::ToolRustc, SourceType::Submodule, host, "install");
555 // Configure `cargo install` path. cargo adds a `bin/`.
556 cargo.env("CARGO_INSTALL_ROOT", &builder.out);
558 let mut cargo = Command::from(cargo);
559 if !try_run(builder, &mut cargo) {
563 // # Run `cargo miri setup`.
564 let mut cargo = tool::prepare_tool_cargo(
570 "src/tools/miri/cargo-miri",
571 SourceType::Submodule,
574 cargo.add_rustc_lib_path(builder, compiler);
575 cargo.arg("--").arg("miri").arg("setup");
577 // Tell `cargo miri setup` where to find the sources.
578 cargo.env("XARGO_RUST_SRC", builder.src.join("library"));
579 // Tell it where to find Miri.
580 cargo.env("MIRI", &miri);
582 cargo.env("RUST_BACKTRACE", "1");
583 // Let cargo-miri know where xargo ended up.
584 cargo.env("XARGO_CHECK", builder.out.join("bin").join("xargo-check"));
586 let mut cargo = Command::from(cargo);
587 if !try_run(builder, &mut cargo) {
591 // # Determine where Miri put its sysroot.
592 // To this end, we run `cargo miri setup --print-sysroot` and capture the output.
593 // (We do this separately from the above so that when the setup actually
594 // happens we get some output.)
595 // We re-use the `cargo` from above.
596 cargo.arg("--print-sysroot");
598 // FIXME: Is there a way in which we can re-use the usual `run` helpers?
599 let miri_sysroot = if builder.config.dry_run {
602 builder.verbose(&format!("running: {:?}", cargo));
605 .expect("We already ran `cargo miri setup` before and that worked");
606 assert!(out.status.success(), "`cargo miri setup` returned with non-0 exit code");
607 // Output is "<sysroot>\n".
608 let stdout = String::from_utf8(out.stdout)
609 .expect("`cargo miri setup` stdout is not valid UTF-8");
610 let sysroot = stdout.trim_end();
611 builder.verbose(&format!("`cargo miri setup --print-sysroot` said: {:?}", sysroot));
615 // # Run `cargo test`.
616 let mut cargo = tool::prepare_tool_cargo(
623 SourceType::Submodule,
626 cargo.add_rustc_lib_path(builder, compiler);
628 // miri tests need to know about the stage sysroot
629 cargo.env("MIRI_SYSROOT", miri_sysroot);
630 cargo.env("MIRI_HOST_SYSROOT", sysroot);
631 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
632 cargo.env("MIRI", miri);
634 cargo.arg("--").args(builder.config.cmd.test_args());
636 let mut cargo = Command::from(cargo);
637 if !try_run(builder, &mut cargo) {
642 builder.save_toolstate("miri", ToolState::TestPass);
644 eprintln!("failed to test miri: could not build");
649 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
650 pub struct CompiletestTest {
651 host: TargetSelection,
654 impl Step for CompiletestTest {
657 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
658 run.path("src/tools/compiletest")
661 fn make_run(run: RunConfig<'_>) {
662 run.builder.ensure(CompiletestTest { host: run.target });
665 /// Runs `cargo test` for compiletest.
666 fn run(self, builder: &Builder<'_>) {
667 let host = self.host;
668 let compiler = builder.compiler(0, host);
670 // We need `ToolStd` for the locally-built sysroot because
671 // compiletest uses unstable features of the `test` crate.
672 builder.ensure(compile::Std::new(compiler, host));
673 let cargo = tool::prepare_tool_cargo(
679 "src/tools/compiletest",
684 try_run(builder, &mut cargo.into());
688 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
691 host: TargetSelection,
694 impl Step for Clippy {
696 const ONLY_HOSTS: bool = true;
697 const DEFAULT: bool = false;
699 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
700 run.path("src/tools/clippy")
703 fn make_run(run: RunConfig<'_>) {
704 run.builder.ensure(Clippy { stage: run.builder.top_stage, host: run.target });
707 /// Runs `cargo test` for clippy.
708 fn run(self, builder: &Builder<'_>) {
709 let stage = self.stage;
710 let host = self.host;
711 let compiler = builder.compiler(stage, host);
714 .ensure(tool::Clippy { compiler, target: self.host, extra_features: Vec::new() })
715 .expect("in-tree tool");
716 let mut cargo = tool::prepare_tool_cargo(
727 cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
728 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
729 let host_libs = builder.stage_out(compiler, Mode::ToolRustc).join(builder.cargo_dir());
730 cargo.env("HOST_LIBS", host_libs);
732 cargo.arg("--").args(builder.config.cmd.test_args());
734 cargo.add_rustc_lib_path(builder, compiler);
736 if builder.try_run(&mut cargo.into()) {
737 // The tests succeeded; nothing to do.
741 if !builder.config.cmd.bless() {
742 crate::detail_exit(1);
745 let mut cargo = builder.cargo(compiler, Mode::ToolRustc, SourceType::InTree, host, "run");
746 cargo.arg("-p").arg("clippy_dev");
747 // clippy_dev gets confused if it can't find `clippy/Cargo.toml`
748 cargo.current_dir(&builder.src.join("src").join("tools").join("clippy"));
749 if builder.config.rust_optimize {
750 cargo.env("PROFILE", "release");
752 cargo.env("PROFILE", "debug");
756 builder.run(&mut cargo.into());
760 fn path_for_cargo(builder: &Builder<'_>, compiler: Compiler) -> OsString {
761 // Configure PATH to find the right rustc. NB. we have to use PATH
762 // and not RUSTC because the Cargo test suite has tests that will
763 // fail if rustc is not spelled `rustc`.
764 let path = builder.sysroot(compiler).join("bin");
765 let old_path = env::var_os("PATH").unwrap_or_default();
766 env::join_paths(iter::once(path).chain(env::split_paths(&old_path))).expect("")
769 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
770 pub struct RustdocTheme {
771 pub compiler: Compiler,
774 impl Step for RustdocTheme {
776 const DEFAULT: bool = true;
777 const ONLY_HOSTS: bool = true;
779 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
780 run.path("src/tools/rustdoc-themes")
783 fn make_run(run: RunConfig<'_>) {
784 let compiler = run.builder.compiler(run.builder.top_stage, run.target);
786 run.builder.ensure(RustdocTheme { compiler });
789 fn run(self, builder: &Builder<'_>) {
790 let rustdoc = builder.bootstrap_out.join("rustdoc");
791 let mut cmd = builder.tool_cmd(Tool::RustdocTheme);
792 cmd.arg(rustdoc.to_str().unwrap())
793 .arg(builder.src.join("src/librustdoc/html/static/css/themes").to_str().unwrap())
794 .env("RUSTC_STAGE", self.compiler.stage.to_string())
795 .env("RUSTC_SYSROOT", builder.sysroot(self.compiler))
796 .env("RUSTDOC_LIBDIR", builder.sysroot_libdir(self.compiler, self.compiler.host))
797 .env("CFG_RELEASE_CHANNEL", &builder.config.channel)
798 .env("RUSTDOC_REAL", builder.rustdoc(self.compiler))
799 .env("RUSTC_BOOTSTRAP", "1");
800 if let Some(linker) = builder.linker(self.compiler.host) {
801 cmd.env("RUSTDOC_LINKER", linker);
803 if builder.is_fuse_ld_lld(self.compiler.host) {
804 cmd.env("RUSTDOC_FUSE_LD_LLD", "1");
806 try_run(builder, &mut cmd);
810 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
811 pub struct RustdocJSStd {
812 pub target: TargetSelection,
815 impl Step for RustdocJSStd {
817 const DEFAULT: bool = true;
818 const ONLY_HOSTS: bool = true;
820 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
821 run.suite_path("src/test/rustdoc-js-std")
824 fn make_run(run: RunConfig<'_>) {
825 run.builder.ensure(RustdocJSStd { target: run.target });
828 fn run(self, builder: &Builder<'_>) {
829 if let Some(ref nodejs) = builder.config.nodejs {
830 let mut command = Command::new(nodejs);
832 .arg(builder.src.join("src/tools/rustdoc-js/tester.js"))
835 .arg("--resource-suffix")
836 .arg(&builder.version)
838 .arg(builder.doc_out(self.target))
839 .arg("--test-folder")
840 .arg(builder.src.join("src/test/rustdoc-js-std"));
841 for path in &builder.paths {
843 util::is_valid_test_suite_arg(path, "src/test/rustdoc-js-std", builder)
845 if !p.ends_with(".js") {
846 eprintln!("A non-js file was given: `{}`", path.display());
847 panic!("Cannot run rustdoc-js-std tests");
849 command.arg("--test-file").arg(path);
852 builder.ensure(crate::doc::Std { target: self.target, stage: builder.top_stage });
853 builder.run(&mut command);
855 builder.info("No nodejs found, skipping \"src/test/rustdoc-js-std\" tests");
860 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
861 pub struct RustdocJSNotStd {
862 pub target: TargetSelection,
863 pub compiler: Compiler,
866 impl Step for RustdocJSNotStd {
868 const DEFAULT: bool = true;
869 const ONLY_HOSTS: bool = true;
871 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
872 run.suite_path("src/test/rustdoc-js")
875 fn make_run(run: RunConfig<'_>) {
876 let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
877 run.builder.ensure(RustdocJSNotStd { target: run.target, compiler });
880 fn run(self, builder: &Builder<'_>) {
881 if builder.config.nodejs.is_some() {
882 builder.ensure(Compiletest {
883 compiler: self.compiler,
887 path: "src/test/rustdoc-js",
891 builder.info("No nodejs found, skipping \"src/test/rustdoc-js\" tests");
896 fn get_browser_ui_test_version_inner(npm: &Path, global: bool) -> Option<String> {
897 let mut command = Command::new(&npm);
898 command.arg("list").arg("--parseable").arg("--long").arg("--depth=0");
900 command.arg("--global");
904 .map(|output| String::from_utf8_lossy(&output.stdout).into_owned())
905 .unwrap_or(String::new());
906 lines.lines().find_map(|l| l.split(":browser-ui-test@").skip(1).next()).map(|v| v.to_owned())
909 fn get_browser_ui_test_version(npm: &Path) -> Option<String> {
910 get_browser_ui_test_version_inner(npm, false)
911 .or_else(|| get_browser_ui_test_version_inner(npm, true))
914 fn compare_browser_ui_test_version(installed_version: &str, src: &Path) {
915 match fs::read_to_string(
916 src.join("src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version"),
919 if v.trim() != installed_version {
921 "⚠️ Installed version of browser-ui-test (`{}`) is different than the \
922 one used in the CI (`{}`)",
927 Err(e) => eprintln!("Couldn't find the CI browser-ui-test version: {:?}", e),
931 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
932 pub struct RustdocGUI {
933 pub target: TargetSelection,
934 pub compiler: Compiler,
937 impl Step for RustdocGUI {
939 const DEFAULT: bool = true;
940 const ONLY_HOSTS: bool = true;
942 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
943 let builder = run.builder;
944 let run = run.suite_path("src/test/rustdoc-gui");
945 run.lazy_default_condition(Box::new(move || {
946 builder.config.nodejs.is_some()
951 .map(|p| get_browser_ui_test_version(p).is_some())
956 fn make_run(run: RunConfig<'_>) {
957 let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
958 run.builder.ensure(RustdocGUI { target: run.target, compiler });
961 fn run(self, builder: &Builder<'_>) {
962 let nodejs = builder.config.nodejs.as_ref().expect("nodejs isn't available");
963 let npm = builder.config.npm.as_ref().expect("npm isn't available");
965 builder.ensure(compile::Std::new(self.compiler, self.target));
967 // The goal here is to check if the necessary packages are installed, and if not, we
969 match get_browser_ui_test_version(&npm) {
971 // We also check the version currently used in CI and emit a warning if it's not the
973 compare_browser_ui_test_version(&version, &builder.build.src);
977 "error: rustdoc-gui test suite cannot be run because npm `browser-ui-test` \
978 dependency is missing",
981 "If you want to install the `{0}` dependency, run `npm install {0}`",
984 panic!("Cannot run rustdoc-gui tests");
988 let out_dir = builder.test_out(self.target).join("rustdoc-gui");
990 // We remove existing folder to be sure there won't be artifacts remaining.
991 builder.clear_if_dirty(&out_dir, &builder.rustdoc(self.compiler));
993 let src_path = builder.build.src.join("src/test/rustdoc-gui/src");
994 // We generate docs for the libraries present in the rustdoc-gui's src folder.
995 for entry in src_path.read_dir().expect("read_dir call failed") {
996 if let Ok(entry) = entry {
997 let path = entry.path();
1003 let mut cargo = Command::new(&builder.initial_cargo);
1006 .arg("--target-dir")
1008 .env("RUSTDOC", builder.rustdoc(self.compiler))
1009 .env("RUSTC", builder.rustc(self.compiler))
1011 // FIXME: implement a `// compile-flags` command or similar
1012 // instead of hard-coding this test
1013 if entry.file_name() == "link_to_definition" {
1014 cargo.env("RUSTDOCFLAGS", "-Zunstable-options --generate-link-to-definition");
1016 builder.run(&mut cargo);
1020 // We now run GUI tests.
1021 let mut command = Command::new(&nodejs);
1023 .arg(builder.build.src.join("src/tools/rustdoc-gui/tester.js"))
1025 .arg(&builder.jobs().to_string())
1026 .arg("--doc-folder")
1027 .arg(out_dir.join("doc"))
1028 .arg("--tests-folder")
1029 .arg(builder.build.src.join("src/test/rustdoc-gui"));
1030 for path in &builder.paths {
1031 if let Some(p) = util::is_valid_test_suite_arg(path, "src/test/rustdoc-gui", builder) {
1032 if !p.ends_with(".goml") {
1033 eprintln!("A non-goml file was given: `{}`", path.display());
1034 panic!("Cannot run rustdoc-gui tests");
1036 if let Some(name) = path.file_name().and_then(|f| f.to_str()) {
1037 command.arg("--file").arg(name);
1041 for test_arg in builder.config.cmd.test_args() {
1042 command.arg(test_arg);
1044 builder.run(&mut command);
1048 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1051 impl Step for Tidy {
1053 const DEFAULT: bool = true;
1054 const ONLY_HOSTS: bool = true;
1056 /// Runs the `tidy` tool.
1058 /// This tool in `src/tools` checks up on various bits and pieces of style and
1059 /// otherwise just implements a few lint-like checks that are specific to the
1060 /// compiler itself.
1062 /// Once tidy passes, this step also runs `fmt --check` if tests are being run
1063 /// for the `dev` or `nightly` channels.
1064 fn run(self, builder: &Builder<'_>) {
1065 let mut cmd = builder.tool_cmd(Tool::Tidy);
1066 cmd.arg(&builder.src);
1067 cmd.arg(&builder.initial_cargo);
1068 cmd.arg(&builder.out);
1069 cmd.arg(builder.jobs().to_string());
1070 if builder.is_verbose() {
1071 cmd.arg("--verbose");
1074 builder.info("tidy check");
1075 try_run(builder, &mut cmd);
1077 if builder.config.channel == "dev" || builder.config.channel == "nightly" {
1078 builder.info("fmt check");
1079 if builder.initial_rustfmt().is_none() {
1080 let inferred_rustfmt_dir = builder.config.initial_rustc.parent().unwrap();
1083 error: no `rustfmt` binary found in {PATH}
1084 info: `rust.channel` is currently set to \"{CHAN}\"
1085 help: if you are testing a beta branch, set `rust.channel` to \"beta\" in the `config.toml` file
1086 help: to skip test's attempt to check tidiness, pass `--exclude src/tools/tidy` to `x.py test`",
1087 PATH = inferred_rustfmt_dir.display(),
1088 CHAN = builder.config.channel,
1090 crate::detail_exit(1);
1092 crate::format::format(&builder, !builder.config.cmd.bless(), &[]);
1096 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1097 run.path("src/tools/tidy")
1100 fn make_run(run: RunConfig<'_>) {
1101 run.builder.ensure(Tidy);
1105 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1106 pub struct ExpandYamlAnchors;
1108 impl Step for ExpandYamlAnchors {
1110 const ONLY_HOSTS: bool = true;
1112 /// Ensure the `generate-ci-config` tool was run locally.
1114 /// The tool in `src/tools` reads the CI definition in `src/ci/builders.yml` and generates the
1115 /// appropriate configuration for all our CI providers. This step ensures the tool was called
1116 /// by the user before committing CI changes.
1117 fn run(self, builder: &Builder<'_>) {
1118 builder.info("Ensuring the YAML anchors in the GitHub Actions config were expanded");
1121 &mut builder.tool_cmd(Tool::ExpandYamlAnchors).arg("check").arg(&builder.src),
1125 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1126 run.path("src/tools/expand-yaml-anchors")
1129 fn make_run(run: RunConfig<'_>) {
1130 run.builder.ensure(ExpandYamlAnchors);
1134 fn testdir(builder: &Builder<'_>, host: TargetSelection) -> PathBuf {
1135 builder.out.join(host.triple).join("test")
1138 macro_rules! default_test {
1139 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
1140 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: false });
1144 macro_rules! default_test_with_compare_mode {
1145 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr,
1146 compare_mode: $compare_mode:expr }) => {
1147 test_with_compare_mode!($name {
1153 compare_mode: $compare_mode
1158 macro_rules! host_test {
1159 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
1160 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: true });
1165 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
1166 host: $host:expr }) => {
1167 test_definitions!($name {
1178 macro_rules! test_with_compare_mode {
1179 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
1180 host: $host:expr, compare_mode: $compare_mode:expr }) => {
1181 test_definitions!($name {
1187 compare_mode: Some($compare_mode)
1192 macro_rules! test_definitions {
1197 default: $default:expr,
1199 compare_mode: $compare_mode:expr
1201 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1203 pub compiler: Compiler,
1204 pub target: TargetSelection,
1207 impl Step for $name {
1209 const DEFAULT: bool = $default;
1210 const ONLY_HOSTS: bool = $host;
1212 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1213 run.suite_path($path)
1216 fn make_run(run: RunConfig<'_>) {
1217 let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
1219 run.builder.ensure($name { compiler, target: run.target });
1222 fn run(self, builder: &Builder<'_>) {
1223 builder.ensure(Compiletest {
1224 compiler: self.compiler,
1225 target: self.target,
1229 compare_mode: $compare_mode,
1236 default_test!(Ui { path: "src/test/ui", mode: "ui", suite: "ui" });
1238 default_test!(RunPassValgrind {
1239 path: "src/test/run-pass-valgrind",
1240 mode: "run-pass-valgrind",
1241 suite: "run-pass-valgrind"
1244 default_test!(MirOpt { path: "src/test/mir-opt", mode: "mir-opt", suite: "mir-opt" });
1246 default_test!(Codegen { path: "src/test/codegen", mode: "codegen", suite: "codegen" });
1248 default_test!(CodegenUnits {
1249 path: "src/test/codegen-units",
1250 mode: "codegen-units",
1251 suite: "codegen-units"
1254 default_test!(Incremental {
1255 path: "src/test/incremental",
1256 mode: "incremental",
1257 suite: "incremental"
1260 default_test_with_compare_mode!(Debuginfo {
1261 path: "src/test/debuginfo",
1264 compare_mode: "split-dwarf"
1267 host_test!(UiFullDeps { path: "src/test/ui-fulldeps", mode: "ui", suite: "ui-fulldeps" });
1269 host_test!(Rustdoc { path: "src/test/rustdoc", mode: "rustdoc", suite: "rustdoc" });
1270 host_test!(RustdocUi { path: "src/test/rustdoc-ui", mode: "ui", suite: "rustdoc-ui" });
1272 host_test!(RustdocJson {
1273 path: "src/test/rustdoc-json",
1274 mode: "rustdoc-json",
1275 suite: "rustdoc-json"
1278 host_test!(Pretty { path: "src/test/pretty", mode: "pretty", suite: "pretty" });
1280 default_test!(RunMake { path: "src/test/run-make", mode: "run-make", suite: "run-make" });
1282 host_test!(RunMakeFullDeps {
1283 path: "src/test/run-make-fulldeps",
1285 suite: "run-make-fulldeps"
1288 default_test!(Assembly { path: "src/test/assembly", mode: "assembly", suite: "assembly" });
1290 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1291 struct Compiletest {
1293 target: TargetSelection,
1295 suite: &'static str,
1297 compare_mode: Option<&'static str>,
1300 impl Step for Compiletest {
1303 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1307 /// Executes the `compiletest` tool to run a suite of tests.
1309 /// Compiles all tests with `compiler` for `target` with the specified
1310 /// compiletest `mode` and `suite` arguments. For example `mode` can be
1311 /// "run-pass" or `suite` can be something like `debuginfo`.
1312 fn run(self, builder: &Builder<'_>) {
1313 if builder.top_stage == 0 && env::var("COMPILETEST_FORCE_STAGE0").is_err() {
1315 error: `--stage 0` runs compiletest on the beta compiler, not your local changes, and will almost always cause tests to fail
1316 help: to test the compiler, use `--stage 1` instead
1317 help: to test the standard library, use `--stage 0 library/std` instead
1318 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`."
1320 crate::detail_exit(1);
1323 let compiler = self.compiler;
1324 let target = self.target;
1325 let mode = self.mode;
1326 let suite = self.suite;
1328 // Path for test suite
1329 let suite_path = self.path;
1331 // Skip codegen tests if they aren't enabled in configuration.
1332 if !builder.config.codegen_tests && suite == "codegen" {
1336 if suite == "debuginfo" {
1338 .ensure(dist::DebuggerScripts { sysroot: builder.sysroot(compiler), host: target });
1341 if suite.ends_with("fulldeps") {
1342 builder.ensure(compile::Rustc::new(compiler, target));
1345 builder.ensure(compile::Std::new(compiler, target));
1346 // ensure that `libproc_macro` is available on the host.
1347 builder.ensure(compile::Std::new(compiler, compiler.host));
1349 // Also provide `rust_test_helpers` for the host.
1350 builder.ensure(native::TestHelpers { target: compiler.host });
1352 // As well as the target, except for plain wasm32, which can't build it
1353 if !target.contains("wasm") || target.contains("emscripten") {
1354 builder.ensure(native::TestHelpers { target });
1357 builder.ensure(RemoteCopyLibs { compiler, target });
1359 let mut cmd = builder.tool_cmd(Tool::Compiletest);
1361 // compiletest currently has... a lot of arguments, so let's just pass all
1364 cmd.arg("--compile-lib-path").arg(builder.rustc_libdir(compiler));
1365 cmd.arg("--run-lib-path").arg(builder.sysroot_libdir(compiler, target));
1366 cmd.arg("--rustc-path").arg(builder.rustc(compiler));
1368 let is_rustdoc = suite.ends_with("rustdoc-ui") || suite.ends_with("rustdoc-js");
1370 // Avoid depending on rustdoc when we don't need it.
1371 if mode == "rustdoc"
1372 || mode == "run-make"
1373 || (mode == "ui" && is_rustdoc)
1374 || mode == "js-doc-test"
1375 || mode == "rustdoc-json"
1377 cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler));
1380 if mode == "rustdoc-json" {
1381 // Use the beta compiler for jsondocck
1382 let json_compiler = compiler.with_stage(0);
1383 cmd.arg("--jsondocck-path")
1384 .arg(builder.ensure(tool::JsonDocCk { compiler: json_compiler, target }));
1387 if mode == "run-make" {
1388 let rust_demangler = builder
1389 .ensure(tool::RustDemangler {
1391 target: compiler.host,
1392 extra_features: Vec::new(),
1394 .expect("in-tree tool");
1395 cmd.arg("--rust-demangler-path").arg(rust_demangler);
1398 cmd.arg("--src-base").arg(builder.src.join("src/test").join(suite));
1399 cmd.arg("--build-base").arg(testdir(builder, compiler.host).join(suite));
1400 cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target));
1401 cmd.arg("--suite").arg(suite);
1402 cmd.arg("--mode").arg(mode);
1403 cmd.arg("--target").arg(target.rustc_target_arg());
1404 cmd.arg("--host").arg(&*compiler.host.triple);
1405 cmd.arg("--llvm-filecheck").arg(builder.llvm_filecheck(builder.config.build));
1407 if builder.config.cmd.bless() {
1411 if builder.config.cmd.force_rerun() {
1412 cmd.arg("--force-rerun");
1416 builder.config.cmd.compare_mode().or_else(|| {
1417 if builder.config.test_compare_mode { self.compare_mode } else { None }
1420 if let Some(ref pass) = builder.config.cmd.pass() {
1425 if let Some(ref run) = builder.config.cmd.run() {
1430 if let Some(ref nodejs) = builder.config.nodejs {
1431 cmd.arg("--nodejs").arg(nodejs);
1433 if let Some(ref npm) = builder.config.npm {
1434 cmd.arg("--npm").arg(npm);
1436 if builder.config.rust_optimize_tests {
1437 cmd.arg("--optimize-tests");
1439 let mut flags = if is_rustdoc { Vec::new() } else { vec!["-Crpath".to_string()] };
1440 flags.push(format!("-Cdebuginfo={}", builder.config.rust_debuginfo_level_tests));
1441 flags.push(builder.config.cmd.rustc_args().join(" "));
1443 if let Some(linker) = builder.linker(target) {
1444 cmd.arg("--linker").arg(linker);
1447 let mut hostflags = flags.clone();
1448 hostflags.push(format!("-Lnative={}", builder.test_helpers_out(compiler.host).display()));
1449 hostflags.extend(builder.lld_flags(compiler.host));
1450 cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
1452 let mut targetflags = flags;
1453 targetflags.push(format!("-Lnative={}", builder.test_helpers_out(target).display()));
1454 targetflags.extend(builder.lld_flags(target));
1455 cmd.arg("--target-rustcflags").arg(targetflags.join(" "));
1457 cmd.arg("--python").arg(builder.python());
1459 if let Some(ref gdb) = builder.config.gdb {
1460 cmd.arg("--gdb").arg(gdb);
1463 let run = |cmd: &mut Command| {
1464 cmd.output().map(|output| {
1465 String::from_utf8_lossy(&output.stdout)
1468 .unwrap_or_else(|| panic!("{:?} failed {:?}", cmd, output))
1472 let lldb_exe = "lldb";
1473 let lldb_version = Command::new(lldb_exe)
1476 .map(|output| String::from_utf8_lossy(&output.stdout).to_string())
1478 if let Some(ref vers) = lldb_version {
1479 cmd.arg("--lldb-version").arg(vers);
1480 let lldb_python_dir = run(Command::new(lldb_exe).arg("-P")).ok();
1481 if let Some(ref dir) = lldb_python_dir {
1482 cmd.arg("--lldb-python-dir").arg(dir);
1486 if util::forcing_clang_based_tests() {
1487 let clang_exe = builder.llvm_out(target).join("bin").join("clang");
1488 cmd.arg("--run-clang-based-tests-with").arg(clang_exe);
1491 // Get paths from cmd args
1492 let paths = match &builder.config.cmd {
1493 Subcommand::Test { ref paths, .. } => &paths[..],
1497 // Get test-args by striping suite path
1498 let mut test_args: Vec<&str> = paths
1500 .filter_map(|p| util::is_valid_test_suite_arg(p, suite_path, builder))
1503 test_args.append(&mut builder.config.cmd.test_args());
1505 cmd.args(&test_args);
1507 if builder.is_verbose() {
1508 cmd.arg("--verbose");
1511 if !builder.config.verbose_tests {
1515 let mut llvm_components_passed = false;
1516 let mut copts_passed = false;
1517 if builder.config.llvm_enabled() {
1518 let llvm_config = builder.ensure(native::Llvm { target: builder.config.build });
1519 if !builder.config.dry_run {
1520 let llvm_version = output(Command::new(&llvm_config).arg("--version"));
1521 let llvm_components = output(Command::new(&llvm_config).arg("--components"));
1522 // Remove trailing newline from llvm-config output.
1523 cmd.arg("--llvm-version")
1524 .arg(llvm_version.trim())
1525 .arg("--llvm-components")
1526 .arg(llvm_components.trim());
1527 llvm_components_passed = true;
1529 if !builder.is_rust_llvm(target) {
1530 cmd.arg("--system-llvm");
1533 // Tests that use compiler libraries may inherit the `-lLLVM` link
1534 // requirement, but the `-L` library path is not propagated across
1535 // separate compilations. We can add LLVM's library path to the
1536 // platform-specific environment variable as a workaround.
1537 if !builder.config.dry_run && suite.ends_with("fulldeps") {
1538 let llvm_libdir = output(Command::new(&llvm_config).arg("--libdir"));
1539 add_link_lib_path(vec![llvm_libdir.trim().into()], &mut cmd);
1542 // Only pass correct values for these flags for the `run-make` suite as it
1543 // requires that a C++ compiler was configured which isn't always the case.
1544 if !builder.config.dry_run && matches!(suite, "run-make" | "run-make-fulldeps") {
1545 // The llvm/bin directory contains many useful cross-platform
1546 // tools. Pass the path to run-make tests so they can use them.
1547 let llvm_bin_path = llvm_config
1549 .expect("Expected llvm-config to be contained in directory");
1550 assert!(llvm_bin_path.is_dir());
1551 cmd.arg("--llvm-bin-dir").arg(llvm_bin_path);
1553 // If LLD is available, add it to the PATH
1554 if builder.config.lld_enabled {
1555 let lld_install_root =
1556 builder.ensure(native::Lld { target: builder.config.build });
1558 let lld_bin_path = lld_install_root.join("bin");
1560 let old_path = env::var_os("PATH").unwrap_or_default();
1561 let new_path = env::join_paths(
1562 std::iter::once(lld_bin_path).chain(env::split_paths(&old_path)),
1564 .expect("Could not add LLD bin path to PATH");
1565 cmd.env("PATH", new_path);
1570 // Only pass correct values for these flags for the `run-make` suite as it
1571 // requires that a C++ compiler was configured which isn't always the case.
1572 if !builder.config.dry_run && matches!(suite, "run-make" | "run-make-fulldeps") {
1574 .arg(builder.cc(target))
1576 .arg(builder.cxx(target).unwrap())
1578 .arg(builder.cflags(target, GitRepo::Rustc, CLang::C).join(" "))
1580 .arg(builder.cflags(target, GitRepo::Rustc, CLang::Cxx).join(" "));
1581 copts_passed = true;
1582 if let Some(ar) = builder.ar(target) {
1583 cmd.arg("--ar").arg(ar);
1587 if !llvm_components_passed {
1588 cmd.arg("--llvm-components").arg("");
1601 if builder.remote_tested(target) {
1602 cmd.arg("--remote-test-client").arg(builder.tool_exe(Tool::RemoteTestClient));
1605 // Running a C compiler on MSVC requires a few env vars to be set, to be
1606 // sure to set them here.
1608 // Note that if we encounter `PATH` we make sure to append to our own `PATH`
1609 // rather than stomp over it.
1610 if target.contains("msvc") {
1611 for &(ref k, ref v) in builder.cc[&target].env() {
1617 cmd.env("RUSTC_BOOTSTRAP", "1");
1618 // Override the rustc version used in symbol hashes to reduce the amount of normalization
1619 // needed when diffing test output.
1620 cmd.env("RUSTC_FORCE_RUSTC_VERSION", "compiletest");
1621 cmd.env("DOC_RUST_LANG_ORG_CHANNEL", builder.doc_rust_lang_org_channel());
1622 builder.add_rust_test_threads(&mut cmd);
1624 if builder.config.sanitizers_enabled(target) {
1625 cmd.env("RUSTC_SANITIZER_SUPPORT", "1");
1628 if builder.config.profiler_enabled(target) {
1629 cmd.env("RUSTC_PROFILER_SUPPORT", "1");
1632 cmd.env("RUST_TEST_TMPDIR", builder.tempdir());
1634 cmd.arg("--adb-path").arg("adb");
1635 cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
1636 if target.contains("android") {
1637 // Assume that cc for this target comes from the android sysroot
1638 cmd.arg("--android-cross-path")
1639 .arg(builder.cc(target).parent().unwrap().parent().unwrap());
1641 cmd.arg("--android-cross-path").arg("");
1644 if builder.config.cmd.rustfix_coverage() {
1645 cmd.arg("--rustfix-coverage");
1648 cmd.env("BOOTSTRAP_CARGO", &builder.initial_cargo);
1650 cmd.arg("--channel").arg(&builder.config.channel);
1652 builder.ci_env.force_coloring_in_ci(&mut cmd);
1654 builder.info(&format!(
1655 "Check compiletest suite={} mode={} ({} -> {})",
1656 suite, mode, &compiler.host, target
1658 let _time = util::timeit(&builder);
1659 try_run(builder, &mut cmd);
1661 if let Some(compare_mode) = compare_mode {
1662 cmd.arg("--compare-mode").arg(compare_mode);
1663 builder.info(&format!(
1664 "Check compiletest suite={} mode={} compare_mode={} ({} -> {})",
1665 suite, mode, compare_mode, &compiler.host, target
1667 let _time = util::timeit(&builder);
1668 try_run(builder, &mut cmd);
1673 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1681 impl Step for BookTest {
1683 const ONLY_HOSTS: bool = true;
1685 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1689 /// Runs the documentation tests for a book in `src/doc`.
1691 /// This uses the `rustdoc` that sits next to `compiler`.
1692 fn run(self, builder: &Builder<'_>) {
1693 // External docs are different from local because:
1694 // - Some books need pre-processing by mdbook before being tested.
1695 // - They need to save their state to toolstate.
1696 // - They are only tested on the "checktools" builders.
1698 // The local docs are tested by default, and we don't want to pay the
1699 // cost of building mdbook, so they use `rustdoc --test` directly.
1700 // Also, the unstable book is special because SUMMARY.md is generated,
1701 // so it is easier to just run `rustdoc` on its files.
1702 if self.is_ext_doc {
1703 self.run_ext_doc(builder);
1705 self.run_local_doc(builder);
1711 /// This runs the equivalent of `mdbook test` (via the rustbook wrapper)
1712 /// which in turn runs `rustdoc --test` on each file in the book.
1713 fn run_ext_doc(self, builder: &Builder<'_>) {
1714 let compiler = self.compiler;
1716 builder.ensure(compile::Std::new(compiler, compiler.host));
1718 // mdbook just executes a binary named "rustdoc", so we need to update
1719 // PATH so that it points to our rustdoc.
1720 let mut rustdoc_path = builder.rustdoc(compiler);
1722 let old_path = env::var_os("PATH").unwrap_or_default();
1723 let new_path = env::join_paths(iter::once(rustdoc_path).chain(env::split_paths(&old_path)))
1724 .expect("could not add rustdoc to PATH");
1726 let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
1727 let path = builder.src.join(&self.path);
1728 rustbook_cmd.env("PATH", new_path).arg("test").arg(path);
1729 builder.add_rust_test_threads(&mut rustbook_cmd);
1730 builder.info(&format!("Testing rustbook {}", self.path.display()));
1731 let _time = util::timeit(&builder);
1732 let toolstate = if try_run(builder, &mut rustbook_cmd) {
1737 builder.save_toolstate(self.name, toolstate);
1740 /// This runs `rustdoc --test` on all `.md` files in the path.
1741 fn run_local_doc(self, builder: &Builder<'_>) {
1742 let compiler = self.compiler;
1744 builder.ensure(compile::Std::new(compiler, compiler.host));
1746 // Do a breadth-first traversal of the `src/doc` directory and just run
1747 // tests for all files that end in `*.md`
1748 let mut stack = vec![builder.src.join(self.path)];
1749 let _time = util::timeit(&builder);
1750 let mut files = Vec::new();
1751 while let Some(p) = stack.pop() {
1753 stack.extend(t!(p.read_dir()).map(|p| t!(p).path()));
1757 if p.extension().and_then(|s| s.to_str()) != Some("md") {
1767 markdown_test(builder, compiler, &file);
1772 macro_rules! test_book {
1773 ($($name:ident, $path:expr, $book_name:expr, default=$default:expr;)+) => {
1775 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1780 impl Step for $name {
1782 const DEFAULT: bool = $default;
1783 const ONLY_HOSTS: bool = true;
1785 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1789 fn make_run(run: RunConfig<'_>) {
1790 run.builder.ensure($name {
1791 compiler: run.builder.compiler(run.builder.top_stage, run.target),
1795 fn run(self, builder: &Builder<'_>) {
1796 builder.ensure(BookTest {
1797 compiler: self.compiler,
1798 path: PathBuf::from($path),
1800 is_ext_doc: !$default,
1809 Nomicon, "src/doc/nomicon", "nomicon", default=false;
1810 Reference, "src/doc/reference", "reference", default=false;
1811 RustdocBook, "src/doc/rustdoc", "rustdoc", default=true;
1812 RustcBook, "src/doc/rustc", "rustc", default=true;
1813 RustByExample, "src/doc/rust-by-example", "rust-by-example", default=false;
1814 EmbeddedBook, "src/doc/embedded-book", "embedded-book", default=false;
1815 TheBook, "src/doc/book", "book", default=false;
1816 UnstableBook, "src/doc/unstable-book", "unstable-book", default=true;
1817 EditionGuide, "src/doc/edition-guide", "edition-guide", default=false;
1820 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1821 pub struct ErrorIndex {
1825 impl Step for ErrorIndex {
1827 const DEFAULT: bool = true;
1828 const ONLY_HOSTS: bool = true;
1830 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1831 run.path("src/tools/error_index_generator")
1834 fn make_run(run: RunConfig<'_>) {
1835 // error_index_generator depends on librustdoc. Use the compiler that
1836 // is normally used to build rustdoc for other tests (like compiletest
1837 // tests in src/test/rustdoc) so that it shares the same artifacts.
1838 let compiler = run.builder.compiler(run.builder.top_stage, run.builder.config.build);
1839 run.builder.ensure(ErrorIndex { compiler });
1842 /// Runs the error index generator tool to execute the tests located in the error
1845 /// The `error_index_generator` tool lives in `src/tools` and is used to
1846 /// generate a markdown file from the error indexes of the code base which is
1847 /// then passed to `rustdoc --test`.
1848 fn run(self, builder: &Builder<'_>) {
1849 let compiler = self.compiler;
1851 let dir = testdir(builder, compiler.host);
1852 t!(fs::create_dir_all(&dir));
1853 let output = dir.join("error-index.md");
1855 let mut tool = tool::ErrorIndex::command(builder);
1856 tool.arg("markdown").arg(&output);
1858 builder.info(&format!("Testing error-index stage{}", compiler.stage));
1859 let _time = util::timeit(&builder);
1860 builder.run_quiet(&mut tool);
1861 // The tests themselves need to link to std, so make sure it is
1863 builder.ensure(compile::Std::new(compiler, compiler.host));
1864 markdown_test(builder, compiler, &output);
1868 fn markdown_test(builder: &Builder<'_>, compiler: Compiler, markdown: &Path) -> bool {
1869 if let Ok(contents) = fs::read_to_string(markdown) {
1870 if !contents.contains("```") {
1875 builder.info(&format!("doc tests for: {}", markdown.display()));
1876 let mut cmd = builder.rustdoc_cmd(compiler);
1877 builder.add_rust_test_threads(&mut cmd);
1878 // allow for unstable options such as new editions
1880 cmd.arg("unstable-options");
1883 cmd.env("RUSTC_BOOTSTRAP", "1");
1885 let test_args = builder.config.cmd.test_args().join(" ");
1886 cmd.arg("--test-args").arg(test_args);
1888 if builder.config.verbose_tests {
1889 try_run(builder, &mut cmd)
1891 try_run_quiet(builder, &mut cmd)
1895 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1896 pub struct RustcGuide;
1898 impl Step for RustcGuide {
1900 const DEFAULT: bool = false;
1901 const ONLY_HOSTS: bool = true;
1903 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1904 run.path("src/doc/rustc-dev-guide")
1907 fn make_run(run: RunConfig<'_>) {
1908 run.builder.ensure(RustcGuide);
1911 fn run(self, builder: &Builder<'_>) {
1912 let relative_path = Path::new("src").join("doc").join("rustc-dev-guide");
1913 builder.update_submodule(&relative_path);
1915 let src = builder.src.join(relative_path);
1916 let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
1917 let toolstate = if try_run(builder, rustbook_cmd.arg("linkcheck").arg(&src)) {
1922 builder.save_toolstate("rustc-dev-guide", toolstate);
1926 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1927 pub struct CrateLibrustc {
1929 target: TargetSelection,
1930 test_kind: TestKind,
1931 crates: Vec<Interned<String>>,
1934 impl Step for CrateLibrustc {
1936 const DEFAULT: bool = true;
1937 const ONLY_HOSTS: bool = true;
1939 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1940 run.crate_or_deps("rustc-main")
1943 fn make_run(run: RunConfig<'_>) {
1944 let builder = run.builder;
1945 let host = run.build_triple();
1946 let compiler = builder.compiler_for(builder.top_stage, host, host);
1950 .map(|p| builder.crate_paths[&p.assert_single_path().path].clone())
1952 let test_kind = builder.kind.into();
1954 builder.ensure(CrateLibrustc { compiler, target: run.target, test_kind, crates });
1957 fn run(self, builder: &Builder<'_>) {
1958 builder.ensure(Crate {
1959 compiler: self.compiler,
1960 target: self.target,
1962 test_kind: self.test_kind,
1963 crates: self.crates,
1968 #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
1970 pub compiler: Compiler,
1971 pub target: TargetSelection,
1973 pub test_kind: TestKind,
1974 pub crates: Vec<Interned<String>>,
1977 impl Step for Crate {
1979 const DEFAULT: bool = true;
1981 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1982 run.crate_or_deps("test")
1985 fn make_run(run: RunConfig<'_>) {
1986 let builder = run.builder;
1987 let host = run.build_triple();
1988 let compiler = builder.compiler_for(builder.top_stage, host, host);
1989 let test_kind = builder.kind.into();
1993 .map(|p| builder.crate_paths[&p.assert_single_path().path].clone())
1996 builder.ensure(Crate { compiler, target: run.target, mode: Mode::Std, test_kind, crates });
1999 /// Runs all unit tests plus documentation tests for a given crate defined
2000 /// by a `Cargo.toml` (single manifest)
2002 /// This is what runs tests for crates like the standard library, compiler, etc.
2003 /// It essentially is the driver for running `cargo test`.
2005 /// Currently this runs all tests for a DAG by passing a bunch of `-p foo`
2006 /// arguments, and those arguments are discovered from `cargo metadata`.
2007 fn run(self, builder: &Builder<'_>) {
2008 let compiler = self.compiler;
2009 let target = self.target;
2010 let mode = self.mode;
2011 let test_kind = self.test_kind;
2013 builder.ensure(compile::Std::new(compiler, target));
2014 builder.ensure(RemoteCopyLibs { compiler, target });
2016 // If we're not doing a full bootstrap but we're testing a stage2
2017 // version of libstd, then what we're actually testing is the libstd
2018 // produced in stage1. Reflect that here by updating the compiler that
2019 // we're working with automatically.
2020 let compiler = builder.compiler_for(compiler.stage, compiler.host, target);
2023 builder.cargo(compiler, mode, SourceType::InTree, target, test_kind.subcommand());
2026 compile::std_cargo(builder, target, compiler.stage, &mut cargo);
2029 compile::rustc_cargo(builder, &mut cargo, target);
2031 _ => panic!("can only test libraries"),
2034 // Build up the base `cargo test` command.
2036 // Pass in some standard flags then iterate over the graph we've discovered
2037 // in `cargo metadata` with the maps above and figure out what `-p`
2038 // arguments need to get passed.
2039 if test_kind.subcommand() == "test" && !builder.fail_fast {
2040 cargo.arg("--no-fail-fast");
2042 match builder.doc_tests {
2047 cargo.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
2052 for krate in &self.crates {
2053 cargo.arg("-p").arg(krate);
2056 // The tests are going to run with the *target* libraries, so we need to
2057 // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
2059 // Note that to run the compiler we need to run with the *host* libraries,
2060 // but our wrapper scripts arrange for that to be the case anyway.
2061 let mut dylib_path = dylib_path();
2062 dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
2063 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
2066 cargo.args(&builder.config.cmd.test_args());
2068 if !builder.config.verbose_tests {
2069 cargo.arg("--quiet");
2072 if target.contains("emscripten") {
2074 format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)),
2075 builder.config.nodejs.as_ref().expect("nodejs not configured"),
2077 } else if target.starts_with("wasm32") {
2078 let node = builder.config.nodejs.as_ref().expect("nodejs not configured");
2080 format!("{} {}/src/etc/wasm32-shim.js", node.display(), builder.src.display());
2081 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)), &runner);
2082 } else if builder.remote_tested(target) {
2084 format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)),
2085 format!("{} run 0", builder.tool_exe(Tool::RemoteTestClient).display()),
2089 builder.info(&format!(
2090 "{} {:?} stage{} ({} -> {})",
2091 test_kind, self.crates, compiler.stage, &compiler.host, target
2093 let _time = util::timeit(&builder);
2094 try_run(builder, &mut cargo.into());
2098 /// Rustdoc is special in various ways, which is why this step is different from `Crate`.
2099 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2100 pub struct CrateRustdoc {
2101 host: TargetSelection,
2102 test_kind: TestKind,
2105 impl Step for CrateRustdoc {
2107 const DEFAULT: bool = true;
2108 const ONLY_HOSTS: bool = true;
2110 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2111 run.paths(&["src/librustdoc", "src/tools/rustdoc"])
2114 fn make_run(run: RunConfig<'_>) {
2115 let builder = run.builder;
2117 let test_kind = builder.kind.into();
2119 builder.ensure(CrateRustdoc { host: run.target, test_kind });
2122 fn run(self, builder: &Builder<'_>) {
2123 let test_kind = self.test_kind;
2124 let target = self.host;
2126 let compiler = if builder.download_rustc() {
2127 builder.compiler(builder.top_stage, target)
2129 // Use the previous stage compiler to reuse the artifacts that are
2130 // created when running compiletest for src/test/rustdoc. If this used
2131 // `compiler`, then it would cause rustdoc to be built *again*, which
2132 // isn't really necessary.
2133 builder.compiler_for(builder.top_stage, target, target)
2135 builder.ensure(compile::Rustc::new(compiler, target));
2137 let mut cargo = tool::prepare_tool_cargo(
2142 test_kind.subcommand(),
2143 "src/tools/rustdoc",
2147 if test_kind.subcommand() == "test" && !builder.fail_fast {
2148 cargo.arg("--no-fail-fast");
2150 match builder.doc_tests {
2155 cargo.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
2160 cargo.arg("-p").arg("rustdoc:0.0.0");
2163 cargo.args(&builder.config.cmd.test_args());
2165 if self.host.contains("musl") {
2166 cargo.arg("'-Ctarget-feature=-crt-static'");
2169 // This is needed for running doctests on librustdoc. This is a bit of
2170 // an unfortunate interaction with how bootstrap works and how cargo
2171 // sets up the dylib path, and the fact that the doctest (in
2172 // html/markdown.rs) links to rustc-private libs. For stage1, the
2173 // compiler host dylibs (in stage1/lib) are not the same as the target
2174 // dylibs (in stage1/lib/rustlib/...). This is different from a normal
2175 // rust distribution where they are the same.
2177 // On the cargo side, normal tests use `target_process` which handles
2178 // setting up the dylib for a *target* (stage1/lib/rustlib/... in this
2179 // case). However, for doctests it uses `rustdoc_process` which only
2180 // sets up the dylib path for the *host* (stage1/lib), which is the
2183 // Recall that we special-cased `compiler_for(top_stage)` above, so we always use stage1.
2185 // It should be considered to just stop running doctests on
2186 // librustdoc. There is only one test, and it doesn't look too
2187 // important. There might be other ways to avoid this, but it seems
2188 // pretty convoluted.
2190 // See also https://github.com/rust-lang/rust/issues/13983 where the
2191 // host vs target dylibs for rustdoc are consistently tricky to deal
2194 // Note that this set the host libdir for `download_rustc`, which uses a normal rust distribution.
2195 let libdir = if builder.download_rustc() {
2196 builder.rustc_libdir(compiler)
2198 builder.sysroot_libdir(compiler, target).to_path_buf()
2200 let mut dylib_path = dylib_path();
2201 dylib_path.insert(0, PathBuf::from(&*libdir));
2202 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
2204 if !builder.config.verbose_tests {
2205 cargo.arg("--quiet");
2208 builder.info(&format!(
2209 "{} rustdoc stage{} ({} -> {})",
2210 test_kind, compiler.stage, &compiler.host, target
2212 let _time = util::timeit(&builder);
2214 try_run(builder, &mut cargo.into());
2218 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2219 pub struct CrateRustdocJsonTypes {
2220 host: TargetSelection,
2221 test_kind: TestKind,
2224 impl Step for CrateRustdocJsonTypes {
2226 const DEFAULT: bool = true;
2227 const ONLY_HOSTS: bool = true;
2229 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2230 run.path("src/rustdoc-json-types")
2233 fn make_run(run: RunConfig<'_>) {
2234 let builder = run.builder;
2236 let test_kind = builder.kind.into();
2238 builder.ensure(CrateRustdocJsonTypes { host: run.target, test_kind });
2241 fn run(self, builder: &Builder<'_>) {
2242 let test_kind = self.test_kind;
2243 let target = self.host;
2245 // Use the previous stage compiler to reuse the artifacts that are
2246 // created when running compiletest for src/test/rustdoc. If this used
2247 // `compiler`, then it would cause rustdoc to be built *again*, which
2248 // isn't really necessary.
2249 let compiler = builder.compiler_for(builder.top_stage, target, target);
2250 builder.ensure(compile::Rustc::new(compiler, target));
2252 let mut cargo = tool::prepare_tool_cargo(
2257 test_kind.subcommand(),
2258 "src/rustdoc-json-types",
2262 if test_kind.subcommand() == "test" && !builder.fail_fast {
2263 cargo.arg("--no-fail-fast");
2266 cargo.arg("-p").arg("rustdoc-json-types");
2269 cargo.args(&builder.config.cmd.test_args());
2271 if self.host.contains("musl") {
2272 cargo.arg("'-Ctarget-feature=-crt-static'");
2275 if !builder.config.verbose_tests {
2276 cargo.arg("--quiet");
2279 builder.info(&format!(
2280 "{} rustdoc-json-types stage{} ({} -> {})",
2281 test_kind, compiler.stage, &compiler.host, target
2283 let _time = util::timeit(&builder);
2285 try_run(builder, &mut cargo.into());
2289 /// Some test suites are run inside emulators or on remote devices, and most
2290 /// of our test binaries are linked dynamically which means we need to ship
2291 /// the standard library and such to the emulator ahead of time. This step
2292 /// represents this and is a dependency of all test suites.
2294 /// Most of the time this is a no-op. For some steps such as shipping data to
2295 /// QEMU we have to build our own tools so we've got conditional dependencies
2296 /// on those programs as well. Note that the remote test client is built for
2297 /// the build target (us) and the server is built for the target.
2298 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2299 pub struct RemoteCopyLibs {
2301 target: TargetSelection,
2304 impl Step for RemoteCopyLibs {
2307 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2311 fn run(self, builder: &Builder<'_>) {
2312 let compiler = self.compiler;
2313 let target = self.target;
2314 if !builder.remote_tested(target) {
2318 builder.ensure(compile::Std::new(compiler, target));
2320 builder.info(&format!("REMOTE copy libs to emulator ({})", target));
2322 let server = builder.ensure(tool::RemoteTestServer { compiler, target });
2324 // Spawn the emulator and wait for it to come online
2325 let tool = builder.tool_exe(Tool::RemoteTestClient);
2326 let mut cmd = Command::new(&tool);
2327 cmd.arg("spawn-emulator").arg(target.triple).arg(&server).arg(builder.tempdir());
2328 if let Some(rootfs) = builder.qemu_rootfs(target) {
2331 builder.run(&mut cmd);
2333 // Push all our dylibs to the emulator
2334 for f in t!(builder.sysroot_libdir(compiler, target).read_dir()) {
2336 let name = f.file_name().into_string().unwrap();
2337 if util::is_dylib(&name) {
2338 builder.run(Command::new(&tool).arg("push").arg(f.path()));
2344 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2345 pub struct Distcheck;
2347 impl Step for Distcheck {
2350 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2351 run.alias("distcheck")
2354 fn make_run(run: RunConfig<'_>) {
2355 run.builder.ensure(Distcheck);
2358 /// Runs "distcheck", a 'make check' from a tarball
2359 fn run(self, builder: &Builder<'_>) {
2360 builder.info("Distcheck");
2361 let dir = builder.tempdir().join("distcheck");
2362 let _ = fs::remove_dir_all(&dir);
2363 t!(fs::create_dir_all(&dir));
2365 // Guarantee that these are built before we begin running.
2366 builder.ensure(dist::PlainSourceTarball);
2367 builder.ensure(dist::Src);
2369 let mut cmd = Command::new("tar");
2371 .arg(builder.ensure(dist::PlainSourceTarball).tarball())
2372 .arg("--strip-components=1")
2374 builder.run(&mut cmd);
2376 Command::new("./configure")
2377 .args(&builder.config.configure_args)
2378 .arg("--enable-vendor")
2382 Command::new(util::make(&builder.config.build.triple)).arg("check").current_dir(&dir),
2385 // Now make sure that rust-src has all of libstd's dependencies
2386 builder.info("Distcheck rust-src");
2387 let dir = builder.tempdir().join("distcheck-src");
2388 let _ = fs::remove_dir_all(&dir);
2389 t!(fs::create_dir_all(&dir));
2391 let mut cmd = Command::new("tar");
2393 .arg(builder.ensure(dist::Src).tarball())
2394 .arg("--strip-components=1")
2396 builder.run(&mut cmd);
2398 let toml = dir.join("rust-src/lib/rustlib/src/rust/library/std/Cargo.toml");
2400 Command::new(&builder.initial_cargo)
2401 .arg("generate-lockfile")
2402 .arg("--manifest-path")
2409 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2410 pub struct Bootstrap;
2412 impl Step for Bootstrap {
2414 const DEFAULT: bool = true;
2415 const ONLY_HOSTS: bool = true;
2417 /// Tests the build system itself.
2418 fn run(self, builder: &Builder<'_>) {
2419 let mut check_bootstrap = Command::new(&builder.python());
2420 check_bootstrap.arg("bootstrap_test.py").current_dir(builder.src.join("src/bootstrap/"));
2421 try_run(builder, &mut check_bootstrap);
2423 let mut cmd = Command::new(&builder.initial_cargo);
2425 .current_dir(builder.src.join("src/bootstrap"))
2426 .env("RUSTFLAGS", "-Cdebuginfo=2")
2427 .env("CARGO_TARGET_DIR", builder.out.join("bootstrap"))
2428 .env("RUSTC_BOOTSTRAP", "1")
2429 .env("RUSTDOC", builder.rustdoc(builder.compiler(0, builder.build.build)))
2430 .env("RUSTC", &builder.initial_rustc);
2431 if let Some(flags) = option_env!("RUSTFLAGS") {
2432 // Use the same rustc flags for testing as for "normal" compilation,
2433 // so that Cargo doesn’t recompile the entire dependency graph every time:
2434 // https://github.com/rust-lang/rust/issues/49215
2435 cmd.env("RUSTFLAGS", flags);
2437 if !builder.fail_fast {
2438 cmd.arg("--no-fail-fast");
2440 match builder.doc_tests {
2445 cmd.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
2450 cmd.arg("--").args(&builder.config.cmd.test_args());
2451 // rustbuild tests are racy on directory creation so just run them one at a time.
2452 // Since there's not many this shouldn't be a problem.
2453 cmd.arg("--test-threads=1");
2454 try_run(builder, &mut cmd);
2457 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2458 run.path("src/bootstrap")
2461 fn make_run(run: RunConfig<'_>) {
2462 run.builder.ensure(Bootstrap);
2466 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2467 pub struct TierCheck {
2468 pub compiler: Compiler,
2471 impl Step for TierCheck {
2473 const DEFAULT: bool = true;
2474 const ONLY_HOSTS: bool = true;
2476 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2477 run.path("src/tools/tier-check")
2480 fn make_run(run: RunConfig<'_>) {
2482 run.builder.compiler_for(run.builder.top_stage, run.builder.build.build, run.target);
2483 run.builder.ensure(TierCheck { compiler });
2486 /// Tests the Platform Support page in the rustc book.
2487 fn run(self, builder: &Builder<'_>) {
2488 builder.ensure(compile::Std::new(self.compiler, self.compiler.host));
2489 let mut cargo = tool::prepare_tool_cargo(
2495 "src/tools/tier-check",
2499 cargo.arg(builder.src.join("src/doc/rustc/src/platform-support.md"));
2500 cargo.arg(&builder.rustc(self.compiler));
2501 if builder.is_verbose() {
2502 cargo.arg("--verbose");
2505 builder.info("platform support check");
2506 try_run(builder, &mut cargo.into());
2510 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2511 pub struct LintDocs {
2512 pub compiler: Compiler,
2513 pub target: TargetSelection,
2516 impl Step for LintDocs {
2518 const DEFAULT: bool = true;
2519 const ONLY_HOSTS: bool = true;
2521 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2522 run.path("src/tools/lint-docs")
2525 fn make_run(run: RunConfig<'_>) {
2526 run.builder.ensure(LintDocs {
2527 compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
2532 /// Tests that the lint examples in the rustc book generate the correct
2533 /// lints and have the expected format.
2534 fn run(self, builder: &Builder<'_>) {
2535 builder.ensure(crate::doc::RustcBook {
2536 compiler: self.compiler,
2537 target: self.target,