1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! Definition of steps of the build system.
13 //! This is where some of the real meat of rustbuild is located, in how we
14 //! define targets and the dependencies amongst them. This file can sort of be
15 //! viewed as just defining targets in a makefile which shell out to predefined
16 //! functions elsewhere about how to execute the target.
18 //! The primary function here you're likely interested in is the `build_rules`
19 //! function. This will create a `Rules` structure which basically just lists
20 //! everything that rustbuild can do. Each rule has a human-readable name, a
21 //! path associated with it, some dependencies, and then a closure of how to
22 //! actually perform the rule.
24 //! All steps below are defined in self-contained units, so adding a new target
25 //! to the build system should just involve adding the meta information here
26 //! along with the actual implementation elsewhere. You can find more comments
27 //! about how to define rules themselves below.
29 use std::collections::{HashMap, HashSet};
32 use check::{self, TestKind};
36 use flags::Subcommand;
39 use {Compiler, Build, Mode};
41 pub fn run(build: &Build) {
42 let rules = build_rules(build);
43 let steps = rules.plan();
47 pub fn build_rules<'a>(build: &'a Build) -> Rules {
48 let mut rules = Rules::new(build);
50 // This is the first rule that we're going to define for rustbuild, which is
51 // used to compile LLVM itself. All rules are added through the `rules`
52 // structure created above and are configured through a builder-style
55 // First up we see the `build` method. This represents a rule that's part of
56 // the top-level `build` subcommand. For example `./x.py build` is what this
57 // is associating with. Note that this is normally only relevant if you flag
58 // a rule as `default`, which we'll talk about later.
60 // Next up we'll see two arguments to this method:
62 // * `llvm` - this is the "human readable" name of this target. This name is
63 // not accessed anywhere outside this file itself (e.g. not in
64 // the CLI nor elsewhere in rustbuild). The purpose of this is to
65 // easily define dependencies between rules. That is, other rules
66 // will depend on this with the name "llvm".
67 // * `src/llvm` - this is the relevant path to the rule that we're working
68 // with. This path is the engine behind how commands like
69 // `./x.py build src/llvm` work. This should typically point
70 // to the relevant component, but if there's not really a
71 // path to be assigned here you can pass something like
72 // `path/to/nowhere` to ignore it.
74 // After we create the rule with the `build` method we can then configure
75 // various aspects of it. For example this LLVM rule uses `.host(true)` to
76 // flag that it's a rule only for host targets. In other words, LLVM isn't
77 // compiled for targets configured through `--target` (e.g. those we're just
78 // building a standard library for).
80 // Next up the `dep` method will add a dependency to this rule. The closure
81 // is yielded the step that represents executing the `llvm` rule itself
82 // (containing information like stage, host, target, ...) and then it must
83 // return a target that the step depends on. Here LLVM is actually
84 // interesting where a cross-compiled LLVM depends on the host LLVM, but
85 // otherwise it has no dependencies.
87 // To handle this we do a bit of dynamic dispatch to see what the dependency
88 // is. If we're building a LLVM for the build triple, then we don't actually
89 // have any dependencies! To do that we return a dependency on the `Step::noop()`
90 // target which does nothing.
92 // If we're build a cross-compiled LLVM, however, we need to assemble the
93 // libraries from the previous compiler. This step has the same name as
94 // ours (llvm) but we want it for a different target, so we use the
95 // builder-style methods on `Step` to configure this target to the build
98 // Finally, to finish off this rule, we define how to actually execute it.
99 // That logic is all defined in the `native` module so we just delegate to
100 // the relevant function there. The argument to the closure passed to `run`
101 // is a `Step` (defined below) which encapsulates information like the
102 // stage, target, host, etc.
103 rules.build("llvm", "src/llvm")
106 if s.target == build.config.build {
109 s.target(&build.config.build)
112 .run(move |s| native::llvm(build, s.target));
114 // Ok! After that example rule that's hopefully enough to explain what's
115 // going on here. You can check out the API docs below and also see a bunch
116 // more examples of rules directly below as well.
118 // the compiler with no target libraries ready to go
119 rules.build("rustc", "src/rustc")
120 .dep(|s| s.name("create-sysroot").target(s.host))
126 .host(&build.config.build)
130 .run(move |s| compile::assemble_rustc(build, s.stage, s.target));
132 // Helper for loading an entire DAG of crates, rooted at `name`
133 let krates = |name: &str| {
134 let mut ret = Vec::new();
135 let mut list = vec![name];
136 let mut visited = HashSet::new();
137 while let Some(krate) = list.pop() {
138 let default = krate == name;
139 let krate = &build.crates[krate];
140 let path = krate.path.strip_prefix(&build.src).unwrap();
141 ret.push((krate, path.to_str().unwrap(), default));
142 for dep in krate.deps.iter() {
143 if visited.insert(dep) && dep != "build_helper" {
151 // ========================================================================
152 // Crate compilations
154 // Tools used during the build system but not shipped
155 rules.build("create-sysroot", "path/to/nowhere")
156 .run(move |s| compile::create_sysroot(build, &s.compiler()));
158 // These rules are "pseudo rules" that don't actually do any work
159 // themselves, but represent a complete sysroot with the relevant compiler
160 // linked into place.
162 // That is, depending on "libstd" means that when the rule is completed then
163 // the `stage` sysroot for the compiler `host` will be available with a
164 // standard library built for `target` linked in place. Not all rules need
165 // the compiler itself to be available, just the standard library, so
166 // there's a distinction between the two.
167 rules.build("libstd", "src/libstd")
168 .dep(|s| s.name("rustc").target(s.host))
169 .dep(|s| s.name("libstd-link"));
170 rules.build("libtest", "src/libtest")
171 .dep(|s| s.name("libstd"))
172 .dep(|s| s.name("libtest-link"))
174 rules.build("librustc", "src/librustc")
175 .dep(|s| s.name("libtest"))
176 .dep(|s| s.name("librustc-link"))
180 // Helper method to define the rules to link a crate into its place in the
183 // The logic here is a little subtle as there's a few cases to consider.
184 // Not all combinations of (stage, host, target) actually require something
185 // to be compiled, but rather libraries could get propagated from a
186 // different location. For example:
188 // * Any crate with a `host` that's not the build triple will not actually
189 // compile something. A different `host` means that the build triple will
190 // actually compile the libraries, and then we'll copy them over from the
191 // build triple to the `host` directory.
193 // * Some crates aren't even compiled by the build triple, but may be copied
194 // from previous stages. For example if we're not doing a full bootstrap
195 // then we may just depend on the stage1 versions of libraries to be
196 // available to get linked forward.
198 // * Finally, there are some cases, however, which do indeed comiple crates
199 // and link them into place afterwards.
201 // The rule definition below mirrors these three cases. The `dep` method
202 // calculates the correct dependency which either comes from stage1, a
203 // different compiler, or from actually building the crate itself (the `dep`
204 // rule). The `run` rule then mirrors these three cases and links the cases
205 // forward into the compiler sysroot specified from the correct location.
206 fn crate_rule<'a, 'b>(build: &'a Build,
207 rules: &'b mut Rules<'a>,
210 link: fn(&Build, &Compiler, &Compiler, &str))
211 -> RuleBuilder<'a, 'b> {
212 let mut rule = rules.build(&krate, "path/to/nowhere");
214 if build.force_use_stage1(&s.compiler(), s.target) {
215 s.host(&build.config.build).stage(1)
216 } else if s.host == build.config.build {
219 s.host(&build.config.build)
223 if build.force_use_stage1(&s.compiler(), s.target) {
225 &s.stage(1).host(&build.config.build).compiler(),
228 } else if s.host == build.config.build {
229 link(build, &s.compiler(), &s.compiler(), s.target)
232 &s.host(&build.config.build).compiler(),
240 // Similar to the `libstd`, `libtest`, and `librustc` rules above, except
241 // these rules only represent the libraries being available in the sysroot,
242 // not the compiler itself. This is done as not all rules need a compiler in
243 // the sysroot, but may just need the libraries.
245 // All of these rules use the helper definition above.
249 "build-crate-std_shim",
251 .dep(|s| s.name("startup-objects"))
252 .dep(|s| s.name("create-sysroot").target(s.host));
256 "build-crate-test_shim",
258 .dep(|s| s.name("libstd-link"));
262 "build-crate-rustc-main",
264 .dep(|s| s.name("libtest-link"));
266 for (krate, path, _default) in krates("std_shim") {
267 rules.build(&krate.build_step, path)
268 .dep(|s| s.name("startup-objects"))
269 .dep(move |s| s.name("rustc").host(&build.config.build).target(s.host))
270 .run(move |s| compile::std(build, s.target, &s.compiler()));
272 for (krate, path, _default) in krates("test_shim") {
273 rules.build(&krate.build_step, path)
274 .dep(|s| s.name("libstd-link"))
275 .run(move |s| compile::test(build, s.target, &s.compiler()));
277 for (krate, path, _default) in krates("rustc-main") {
278 rules.build(&krate.build_step, path)
279 .dep(|s| s.name("libtest-link"))
280 .dep(move |s| s.name("llvm").host(&build.config.build).stage(0))
281 .run(move |s| compile::rustc(build, s.target, &s.compiler()));
284 rules.build("startup-objects", "src/rtstartup")
285 .dep(|s| s.name("create-sysroot").target(s.host))
286 .run(move |s| compile::build_startup_objects(build, &s.compiler(), s.target));
288 // ========================================================================
291 // Various unit tests and tests suites we can run
293 let mut suite = |name, path, mode, dir| {
294 rules.test(name, path)
295 .dep(|s| s.name("libtest"))
296 .dep(|s| s.name("tool-compiletest").target(s.host).stage(0))
297 .dep(|s| s.name("test-helpers"))
298 .dep(|s| s.name("android-copy-libs"))
299 .default(mode != "pretty") // pretty tests don't run everywhere
301 check::compiletest(build, &s.compiler(), s.target, mode, dir)
305 suite("check-rpass", "src/test/run-pass", "run-pass", "run-pass");
306 suite("check-cfail", "src/test/compile-fail", "compile-fail", "compile-fail");
307 suite("check-pfail", "src/test/parse-fail", "parse-fail", "parse-fail");
308 suite("check-rfail", "src/test/run-fail", "run-fail", "run-fail");
309 suite("check-rpass-valgrind", "src/test/run-pass-valgrind",
310 "run-pass-valgrind", "run-pass-valgrind");
311 suite("check-mir-opt", "src/test/mir-opt", "mir-opt", "mir-opt");
312 if build.config.codegen_tests {
313 suite("check-codegen", "src/test/codegen", "codegen", "codegen");
315 suite("check-codegen-units", "src/test/codegen-units", "codegen-units",
317 suite("check-incremental", "src/test/incremental", "incremental",
321 if build.config.build.contains("msvc") {
322 // nothing to do for debuginfo tests
324 rules.test("check-debuginfo-lldb", "src/test/debuginfo-lldb")
325 .dep(|s| s.name("libtest"))
326 .dep(|s| s.name("tool-compiletest").target(s.host).stage(0))
327 .dep(|s| s.name("test-helpers"))
328 .dep(|s| s.name("debugger-scripts"))
329 .run(move |s| check::compiletest(build, &s.compiler(), s.target,
330 "debuginfo-lldb", "debuginfo"));
331 rules.test("check-debuginfo-gdb", "src/test/debuginfo-gdb")
332 .dep(|s| s.name("libtest"))
333 .dep(|s| s.name("tool-compiletest").target(s.host).stage(0))
334 .dep(|s| s.name("test-helpers"))
335 .dep(|s| s.name("debugger-scripts"))
336 .dep(|s| s.name("android-copy-libs"))
337 .run(move |s| check::compiletest(build, &s.compiler(), s.target,
338 "debuginfo-gdb", "debuginfo"));
339 let mut rule = rules.test("check-debuginfo", "src/test/debuginfo");
341 if build.config.build.contains("apple") {
342 rule.dep(|s| s.name("check-debuginfo-lldb"));
344 rule.dep(|s| s.name("check-debuginfo-gdb"));
348 rules.test("debugger-scripts", "src/etc/lldb_batchmode.py")
349 .run(move |s| dist::debugger_scripts(build, &build.sysroot(&s.compiler()),
353 let mut suite = |name, path, mode, dir| {
354 rules.test(name, path)
355 .dep(|s| s.name("librustc"))
356 .dep(|s| s.name("test-helpers"))
357 .dep(|s| s.name("tool-compiletest").target(s.host).stage(0))
358 .default(mode != "pretty")
361 check::compiletest(build, &s.compiler(), s.target, mode, dir)
365 suite("check-ui", "src/test/ui", "ui", "ui");
366 suite("check-rpass-full", "src/test/run-pass-fulldeps",
367 "run-pass", "run-pass-fulldeps");
368 suite("check-rfail-full", "src/test/run-fail-fulldeps",
369 "run-fail", "run-fail-fulldeps");
370 suite("check-cfail-full", "src/test/compile-fail-fulldeps",
371 "compile-fail", "compile-fail-fulldeps");
372 suite("check-rmake", "src/test/run-make", "run-make", "run-make");
373 suite("check-rustdoc", "src/test/rustdoc", "rustdoc", "rustdoc");
374 suite("check-pretty", "src/test/pretty", "pretty", "pretty");
375 suite("check-pretty-rpass", "src/test/run-pass/pretty", "pretty",
377 suite("check-pretty-rfail", "src/test/run-fail/pretty", "pretty",
379 suite("check-pretty-valgrind", "src/test/run-pass-valgrind/pretty", "pretty",
380 "run-pass-valgrind");
381 suite("check-pretty-rpass-full", "src/test/run-pass-fulldeps/pretty",
382 "pretty", "run-pass-fulldeps");
383 suite("check-pretty-rfail-full", "src/test/run-fail-fulldeps/pretty",
384 "pretty", "run-fail-fulldeps");
387 for (krate, path, _default) in krates("std_shim") {
388 rules.test(&krate.test_step, path)
389 .dep(|s| s.name("libtest"))
390 .dep(|s| s.name("android-copy-libs"))
391 .run(move |s| check::krate(build, &s.compiler(), s.target,
392 Mode::Libstd, TestKind::Test,
395 rules.test("check-std-all", "path/to/nowhere")
396 .dep(|s| s.name("libtest"))
397 .dep(|s| s.name("android-copy-libs"))
399 .run(move |s| check::krate(build, &s.compiler(), s.target,
400 Mode::Libstd, TestKind::Test, None));
403 for (krate, path, _default) in krates("std_shim") {
404 rules.bench(&krate.bench_step, path)
405 .dep(|s| s.name("libtest"))
406 .dep(|s| s.name("android-copy-libs"))
407 .run(move |s| check::krate(build, &s.compiler(), s.target,
408 Mode::Libstd, TestKind::Bench,
411 rules.bench("bench-std-all", "path/to/nowhere")
412 .dep(|s| s.name("libtest"))
413 .dep(|s| s.name("android-copy-libs"))
415 .run(move |s| check::krate(build, &s.compiler(), s.target,
416 Mode::Libstd, TestKind::Bench, None));
418 for (krate, path, _default) in krates("test_shim") {
419 rules.test(&krate.test_step, path)
420 .dep(|s| s.name("libtest"))
421 .dep(|s| s.name("android-copy-libs"))
422 .run(move |s| check::krate(build, &s.compiler(), s.target,
423 Mode::Libtest, TestKind::Test,
426 rules.test("check-test-all", "path/to/nowhere")
427 .dep(|s| s.name("libtest"))
428 .dep(|s| s.name("android-copy-libs"))
430 .run(move |s| check::krate(build, &s.compiler(), s.target,
431 Mode::Libtest, TestKind::Test, None));
432 for (krate, path, _default) in krates("rustc-main") {
433 rules.test(&krate.test_step, path)
434 .dep(|s| s.name("librustc"))
435 .dep(|s| s.name("android-copy-libs"))
437 .run(move |s| check::krate(build, &s.compiler(), s.target,
438 Mode::Librustc, TestKind::Test,
441 rules.test("check-rustc-all", "path/to/nowhere")
442 .dep(|s| s.name("librustc"))
443 .dep(|s| s.name("android-copy-libs"))
446 .run(move |s| check::krate(build, &s.compiler(), s.target,
447 Mode::Librustc, TestKind::Test, None));
449 rules.test("check-linkchecker", "src/tools/linkchecker")
450 .dep(|s| s.name("tool-linkchecker").stage(0))
451 .dep(|s| s.name("default:doc"))
454 .run(move |s| check::linkcheck(build, s.target));
455 rules.test("check-cargotest", "src/tools/cargotest")
456 .dep(|s| s.name("tool-cargotest").stage(0))
457 .dep(|s| s.name("librustc"))
459 .run(move |s| check::cargotest(build, s.stage, s.target));
460 rules.test("check-tidy", "src/tools/tidy")
461 .dep(|s| s.name("tool-tidy").stage(0))
465 .run(move |s| check::tidy(build, s.target));
466 rules.test("check-error-index", "src/tools/error_index_generator")
467 .dep(|s| s.name("libstd"))
468 .dep(|s| s.name("tool-error-index").host(s.host).stage(0))
471 .run(move |s| check::error_index(build, &s.compiler()));
472 rules.test("check-docs", "src/doc")
473 .dep(|s| s.name("libtest"))
476 .run(move |s| check::docs(build, &s.compiler()));
477 rules.test("check-distcheck", "distcheck")
478 .dep(|s| s.name("dist-src"))
479 .run(move |_| check::distcheck(build));
482 rules.build("test-helpers", "src/rt/rust_test_helpers.c")
483 .run(move |s| native::test_helpers(build, s.target));
484 rules.test("android-copy-libs", "path/to/nowhere")
485 .dep(|s| s.name("libtest"))
486 .run(move |s| check::android_copy_libs(build, &s.compiler(), s.target));
488 rules.test("check-bootstrap", "src/bootstrap")
492 .run(move |_| check::bootstrap(build));
494 // ========================================================================
497 // Tools used during the build system but not shipped
498 rules.build("tool-rustbook", "src/tools/rustbook")
499 .dep(|s| s.name("librustc"))
500 .run(move |s| compile::tool(build, s.stage, s.target, "rustbook"));
501 rules.build("tool-error-index", "src/tools/error_index_generator")
502 .dep(|s| s.name("librustc"))
503 .run(move |s| compile::tool(build, s.stage, s.target, "error_index_generator"));
504 rules.build("tool-tidy", "src/tools/tidy")
505 .dep(|s| s.name("libstd"))
506 .run(move |s| compile::tool(build, s.stage, s.target, "tidy"));
507 rules.build("tool-linkchecker", "src/tools/linkchecker")
508 .dep(|s| s.name("libstd"))
509 .run(move |s| compile::tool(build, s.stage, s.target, "linkchecker"));
510 rules.build("tool-cargotest", "src/tools/cargotest")
511 .dep(|s| s.name("libstd"))
512 .run(move |s| compile::tool(build, s.stage, s.target, "cargotest"));
513 rules.build("tool-compiletest", "src/tools/compiletest")
514 .dep(|s| s.name("libtest"))
515 .run(move |s| compile::tool(build, s.stage, s.target, "compiletest"));
516 rules.build("tool-build-manifest", "src/tools/build-manifest")
517 .dep(|s| s.name("libstd"))
518 .run(move |s| compile::tool(build, s.stage, s.target, "build-manifest"));
520 // ========================================================================
521 // Documentation targets
522 rules.doc("doc-book", "src/doc/book")
524 s.name("tool-rustbook")
525 .host(&build.config.build)
526 .target(&build.config.build)
529 .default(build.config.docs)
530 .run(move |s| doc::rustbook(build, s.target, "book"));
531 rules.doc("doc-nomicon", "src/doc/nomicon")
533 s.name("tool-rustbook")
534 .host(&build.config.build)
535 .target(&build.config.build)
538 .default(build.config.docs)
539 .run(move |s| doc::rustbook(build, s.target, "nomicon"));
540 rules.doc("doc-standalone", "src/doc")
543 .host(&build.config.build)
544 .target(&build.config.build)
547 .default(build.config.docs)
548 .run(move |s| doc::standalone(build, s.target));
549 rules.doc("doc-error-index", "src/tools/error_index_generator")
550 .dep(move |s| s.name("tool-error-index").target(&build.config.build).stage(0))
551 .dep(move |s| s.name("librustc-link"))
552 .default(build.config.docs)
554 .run(move |s| doc::error_index(build, s.target));
555 for (krate, path, default) in krates("std_shim") {
556 rules.doc(&krate.doc_step, path)
557 .dep(|s| s.name("libstd-link"))
558 .default(default && build.config.docs)
559 .run(move |s| doc::std(build, s.stage, s.target));
561 for (krate, path, default) in krates("test_shim") {
562 rules.doc(&krate.doc_step, path)
563 .dep(|s| s.name("libtest-link"))
564 .default(default && build.config.compiler_docs)
565 .run(move |s| doc::test(build, s.stage, s.target));
567 for (krate, path, default) in krates("rustc-main") {
568 rules.doc(&krate.doc_step, path)
569 .dep(|s| s.name("librustc-link"))
571 .default(default && build.config.compiler_docs)
572 .run(move |s| doc::rustc(build, s.stage, s.target));
575 // ========================================================================
576 // Distribution targets
577 rules.dist("dist-rustc", "src/librustc")
578 .dep(move |s| s.name("rustc").host(&build.config.build))
580 .only_host_build(true)
582 .run(move |s| dist::rustc(build, s.stage, s.target));
583 rules.dist("dist-std", "src/libstd")
585 // We want to package up as many target libraries as possible
586 // for the `rust-std` package, so if this is a host target we
587 // depend on librustc and otherwise we just depend on libtest.
588 if build.config.host.iter().any(|t| t == s.target) {
589 s.name("librustc-link")
591 s.name("libtest-link")
595 .only_host_build(true)
596 .run(move |s| dist::std(build, &s.compiler(), s.target));
597 rules.dist("dist-mingw", "path/to/nowhere")
599 .only_host_build(true)
601 if s.target.contains("pc-windows-gnu") {
602 dist::mingw(build, s.target)
605 rules.dist("dist-src", "src")
609 .only_host_build(true)
610 .run(move |_| dist::rust_src(build));
611 rules.dist("dist-docs", "src/doc")
613 .only_host_build(true)
614 .dep(|s| s.name("default:doc"))
615 .run(move |s| dist::docs(build, s.stage, s.target));
616 rules.dist("dist-analysis", "analysis")
617 .dep(|s| s.name("dist-std"))
619 .only_host_build(true)
620 .run(move |s| dist::analysis(build, &s.compiler(), s.target));
621 rules.dist("install", "path/to/nowhere")
622 .dep(|s| s.name("default:dist"))
623 .run(move |s| install::install(build, s.stage, s.target));
624 rules.dist("dist-cargo", "cargo")
626 .only_host_build(true)
627 .run(move |s| dist::cargo(build, s.stage, s.target));
628 rules.dist("dist-extended", "extended")
629 .default(build.config.extended)
631 .only_host_build(true)
632 .dep(|d| d.name("dist-std"))
633 .dep(|d| d.name("dist-rustc"))
634 .dep(|d| d.name("dist-mingw"))
635 .dep(|d| d.name("dist-docs"))
636 .dep(|d| d.name("dist-cargo"))
637 .run(move |s| dist::extended(build, s.stage, s.target));
639 rules.dist("dist-sign", "hash-and-sign")
642 .only_host_build(true)
643 .dep(move |s| s.name("tool-build-manifest").target(&build.config.build).stage(0))
644 .run(move |_| dist::hash_and_sign(build));
650 #[derive(PartialEq, Eq, Hash, Clone, Debug)]
652 /// Human readable name of the rule this step is executing. Possible names
653 /// are all defined above in `build_rules`.
656 /// The stage this step is executing in. This is typically 0, 1, or 2.
659 /// This step will likely involve a compiler, and the target that compiler
660 /// itself is built for is called the host, this variable. Typically this is
661 /// the target of the build machine itself.
664 /// The target that this step represents generating. If you're building a
665 /// standard library for a new suite of targets, for example, this'll be set
666 /// to those targets.
671 fn noop() -> Step<'a> {
672 Step { name: "", stage: 0, host: "", target: "" }
675 /// Creates a new step which is the same as this, except has a new name.
676 fn name(&self, name: &'a str) -> Step<'a> {
677 Step { name: name, ..*self }
680 /// Creates a new step which is the same as this, except has a new stage.
681 fn stage(&self, stage: u32) -> Step<'a> {
682 Step { stage: stage, ..*self }
685 /// Creates a new step which is the same as this, except has a new host.
686 fn host(&self, host: &'a str) -> Step<'a> {
687 Step { host: host, ..*self }
690 /// Creates a new step which is the same as this, except has a new target.
691 fn target(&self, target: &'a str) -> Step<'a> {
692 Step { target: target, ..*self }
695 /// Returns the `Compiler` structure that this step corresponds to.
696 fn compiler(&self) -> Compiler<'a> {
697 Compiler::new(self.stage, self.host)
702 /// The human readable name of this target, defined in `build_rules`.
705 /// The path associated with this target, used in the `./x.py` driver for
706 /// easy and ergonomic specification of what to do.
709 /// The "kind" of top-level command that this rule is associated with, only
710 /// relevant if this is a default rule.
713 /// List of dependencies this rule has. Each dependency is a function from a
714 /// step that's being executed to another step that should be executed.
715 deps: Vec<Box<Fn(&Step<'a>) -> Step<'a> + 'a>>,
717 /// How to actually execute this rule. Takes a step with contextual
718 /// information and then executes it.
719 run: Box<Fn(&Step<'a>) + 'a>,
721 /// Whether or not this is a "default" rule. That basically means that if
722 /// you run, for example, `./x.py test` whether it's included or not.
725 /// Whether or not this is a "host" rule, or in other words whether this is
726 /// only intended for compiler hosts and not for targets that are being
730 /// Whether this rule is only for steps where the host is the build triple,
731 /// not anything in hosts or targets.
732 only_host_build: bool,
734 /// Whether this rule is only for the build triple, not anything in hosts or
749 fn new(name: &'a str, path: &'a str, kind: Kind) -> Rule<'a> {
753 run: Box::new(|_| ()),
758 only_host_build: false,
764 /// Builder pattern returned from the various methods on `Rules` which will add
765 /// the rule to the internal list on `Drop`.
766 struct RuleBuilder<'a: 'b, 'b> {
767 rules: &'b mut Rules<'a>,
771 impl<'a, 'b> RuleBuilder<'a, 'b> {
772 fn dep<F>(&mut self, f: F) -> &mut Self
773 where F: Fn(&Step<'a>) -> Step<'a> + 'a,
775 self.rule.deps.push(Box::new(f));
779 fn run<F>(&mut self, f: F) -> &mut Self
780 where F: Fn(&Step<'a>) + 'a,
782 self.rule.run = Box::new(f);
786 fn default(&mut self, default: bool) -> &mut Self {
787 self.rule.default = default;
791 fn host(&mut self, host: bool) -> &mut Self {
792 self.rule.host = host;
796 fn only_build(&mut self, only_build: bool) -> &mut Self {
797 self.rule.only_build = only_build;
801 fn only_host_build(&mut self, only_host_build: bool) -> &mut Self {
802 self.rule.only_host_build = only_host_build;
807 impl<'a, 'b> Drop for RuleBuilder<'a, 'b> {
809 let rule = mem::replace(&mut self.rule, Rule::new("", "", Kind::Build));
810 let prev = self.rules.rules.insert(rule.name, rule);
811 if let Some(prev) = prev {
812 panic!("duplicate rule named: {}", prev.name);
817 pub struct Rules<'a> {
820 rules: HashMap<&'a str, Rule<'a>>,
824 fn new(build: &'a Build) -> Rules<'a> {
828 stage: build.flags.stage.unwrap_or(2),
829 target: &build.config.build,
830 host: &build.config.build,
833 rules: HashMap::new(),
837 /// Creates a new rule of `Kind::Build` with the specified human readable
838 /// name and path associated with it.
840 /// The builder returned should be configured further with information such
841 /// as how to actually run this rule.
842 fn build<'b>(&'b mut self, name: &'a str, path: &'a str)
843 -> RuleBuilder<'a, 'b> {
844 self.rule(name, path, Kind::Build)
847 /// Same as `build`, but for `Kind::Test`.
848 fn test<'b>(&'b mut self, name: &'a str, path: &'a str)
849 -> RuleBuilder<'a, 'b> {
850 self.rule(name, path, Kind::Test)
853 /// Same as `build`, but for `Kind::Bench`.
854 fn bench<'b>(&'b mut self, name: &'a str, path: &'a str)
855 -> RuleBuilder<'a, 'b> {
856 self.rule(name, path, Kind::Bench)
859 /// Same as `build`, but for `Kind::Doc`.
860 fn doc<'b>(&'b mut self, name: &'a str, path: &'a str)
861 -> RuleBuilder<'a, 'b> {
862 self.rule(name, path, Kind::Doc)
865 /// Same as `build`, but for `Kind::Dist`.
866 fn dist<'b>(&'b mut self, name: &'a str, path: &'a str)
867 -> RuleBuilder<'a, 'b> {
868 self.rule(name, path, Kind::Dist)
871 fn rule<'b>(&'b mut self,
874 kind: Kind) -> RuleBuilder<'a, 'b> {
877 rule: Rule::new(name, path, kind),
881 /// Verify the dependency graph defined by all our rules are correct, e.g.
882 /// everything points to a valid something else.
884 for rule in self.rules.values() {
885 for dep in rule.deps.iter() {
886 let dep = dep(&self.sbuild.name(rule.name));
887 if self.rules.contains_key(&dep.name) || dep.name.starts_with("default:") {
890 if dep == Step::noop() {
895 invalid rule dependency graph detected, was a rule added and maybe typo'd?
897 `{}` depends on `{}` which does not exist
899 ", rule.name, dep.name);
904 pub fn print_help(&self, command: &str) {
905 let kind = match command {
906 "build" => Kind::Build,
908 "test" => Kind::Test,
909 "bench" => Kind::Bench,
910 "dist" => Kind::Dist,
913 let rules = self.rules.values().filter(|r| r.kind == kind);
914 let rules = rules.filter(|r| !r.path.contains("nowhere"));
915 let mut rules = rules.collect::<Vec<_>>();
916 rules.sort_by_key(|r| r.path);
918 println!("Available paths:\n");
920 print!(" ./x.py {} {}", command, rule.path);
926 /// Construct the top-level build steps that we're going to be executing,
927 /// given the subcommand that our build is performing.
928 fn plan(&self) -> Vec<Step<'a>> {
929 // Ok, the logic here is pretty subtle, and involves quite a few
930 // conditionals. The basic idea here is to:
932 // 1. First, filter all our rules to the relevant ones. This means that
933 // the command specified corresponds to one of our `Kind` variants,
934 // and we filter all rules based on that.
936 // 2. Next, we determine which rules we're actually executing. If a
937 // number of path filters were specified on the command line we look
938 // for those, otherwise we look for anything tagged `default`.
940 // 3. Finally, we generate some steps with host and target information.
942 // The last step is by far the most complicated and subtle. The basic
943 // thinking here is that we want to take the cartesian product of
944 // specified hosts and targets and build rules with that. The list of
945 // hosts and targets, if not specified, come from the how this build was
946 // configured. If the rule we're looking at is a host-only rule the we
947 // ignore the list of targets and instead consider the list of hosts
948 // also the list of targets.
950 // Once the host and target lists are generated we take the cartesian
951 // product of the two and then create a step based off them. Note that
952 // the stage each step is associated was specified with the `--step`
953 // flag on the command line.
954 let (kind, paths) = match self.build.flags.cmd {
955 Subcommand::Build { ref paths } => (Kind::Build, &paths[..]),
956 Subcommand::Doc { ref paths } => (Kind::Doc, &paths[..]),
957 Subcommand::Test { ref paths, test_args: _ } => (Kind::Test, &paths[..]),
958 Subcommand::Bench { ref paths, test_args: _ } => (Kind::Bench, &paths[..]),
959 Subcommand::Dist { ref paths, install } => {
961 return vec![self.sbuild.name("install")]
963 (Kind::Dist, &paths[..])
966 Subcommand::Clean => panic!(),
969 self.rules.values().filter(|rule| rule.kind == kind).filter(|rule| {
970 (paths.len() == 0 && rule.default) || paths.iter().any(|path| {
971 path.ends_with(rule.path)
974 let hosts = if rule.only_host_build || rule.only_build {
975 &self.build.config.host[..1]
976 } else if self.build.flags.host.len() > 0 {
977 &self.build.flags.host
979 &self.build.config.host
981 let targets = if self.build.flags.target.len() > 0 {
982 &self.build.flags.target
984 &self.build.config.target
986 // Determine the actual targets participating in this rule.
987 // NOTE: We should keep the full projection from build triple to
988 // the hosts for the dist steps, now that the hosts array above is
989 // truncated to avoid duplication of work in that case. Therefore
990 // the original non-shadowed hosts array is used below.
991 let arr = if rule.host {
992 // If --target was specified but --host wasn't specified,
993 // don't run any host-only tests. Also, respect any `--host`
994 // overrides as done for `hosts`.
995 if self.build.flags.host.len() > 0 {
996 &self.build.flags.host[..]
997 } else if self.build.flags.target.len() > 0 {
999 } else if rule.only_build {
1000 &self.build.config.host[..1]
1002 &self.build.config.host[..]
1008 hosts.iter().flat_map(move |host| {
1009 arr.iter().map(move |target| {
1010 self.sbuild.name(rule.name).target(target).host(host)
1016 /// Execute all top-level targets indicated by `steps`.
1018 /// This will take the list returned by `plan` and then execute each step
1019 /// along with all required dependencies as it goes up the chain.
1020 fn run(&self, steps: &[Step<'a>]) {
1021 self.build.verbose("bootstrap top targets:");
1022 for step in steps.iter() {
1023 self.build.verbose(&format!("\t{:?}", step));
1026 // Using `steps` as the top-level targets, make a topological ordering
1027 // of what we need to do.
1028 let order = self.expand(steps);
1030 // Print out what we're doing for debugging
1031 self.build.verbose("bootstrap build plan:");
1032 for step in order.iter() {
1033 self.build.verbose(&format!("\t{:?}", step));
1036 // And finally, iterate over everything and execute it.
1037 for step in order.iter() {
1038 if self.build.flags.keep_stage.map_or(false, |s| step.stage <= s) {
1039 self.build.verbose(&format!("keeping step {:?}", step));
1042 self.build.verbose(&format!("executing step {:?}", step));
1043 (self.rules[step.name].run)(step);
1047 /// From the top level targets `steps` generate a topological ordering of
1048 /// all steps needed to run those steps.
1049 fn expand(&self, steps: &[Step<'a>]) -> Vec<Step<'a>> {
1050 let mut order = Vec::new();
1051 let mut added = HashSet::new();
1052 added.insert(Step::noop());
1053 for step in steps.iter().cloned() {
1054 self.fill(step, &mut order, &mut added);
1059 /// Performs topological sort of dependencies rooted at the `step`
1060 /// specified, pushing all results onto the `order` vector provided.
1062 /// In other words, when this method returns, the `order` vector will
1063 /// contain a list of steps which if executed in order will eventually
1064 /// complete the `step` specified as well.
1066 /// The `added` set specified here is the set of steps that are already
1067 /// present in `order` (and hence don't need to be added again).
1070 order: &mut Vec<Step<'a>>,
1071 added: &mut HashSet<Step<'a>>) {
1072 if !added.insert(step.clone()) {
1075 for dep in self.rules[step.name].deps.iter() {
1076 let dep = dep(&step);
1077 if dep.name.starts_with("default:") {
1078 let kind = match &dep.name[8..] {
1080 "dist" => Kind::Dist,
1081 kind => panic!("unknown kind: `{}`", kind),
1083 let host = self.build.config.host.iter().any(|h| h == dep.target);
1084 let rules = self.rules.values().filter(|r| r.default);
1085 for rule in rules.filter(|r| r.kind == kind && (!r.host || host)) {
1086 self.fill(dep.name(rule.name), order, added);
1089 self.fill(dep, order, added);
1105 ($($a:expr),*) => (vec![$($a.to_string()),*])
1108 fn build(args: &[&str],
1109 extra_host: &[&str],
1110 extra_target: &[&str]) -> Build {
1111 let mut args = args.iter().map(|s| s.to_string()).collect::<Vec<_>>();
1112 args.push("--build".to_string());
1113 args.push("A".to_string());
1114 let flags = Flags::parse(&args);
1116 let mut config = Config::default();
1118 config.build = "A".to_string();
1119 config.host = vec![config.build.clone()];
1120 config.host.extend(extra_host.iter().map(|s| s.to_string()));
1121 config.target = config.host.clone();
1122 config.target.extend(extra_target.iter().map(|s| s.to_string()));
1124 let mut build = Build::new(flags, config);
1125 let cwd = env::current_dir().unwrap();
1126 build.crates.insert("std_shim".to_string(), ::Crate {
1127 name: "std_shim".to_string(),
1129 path: cwd.join("src/std_shim"),
1130 doc_step: "doc-std_shim".to_string(),
1131 build_step: "build-crate-std_shim".to_string(),
1132 test_step: "test-std_shim".to_string(),
1133 bench_step: "bench-std_shim".to_string(),
1135 build.crates.insert("test_shim".to_string(), ::Crate {
1136 name: "test_shim".to_string(),
1138 path: cwd.join("src/test_shim"),
1139 doc_step: "doc-test_shim".to_string(),
1140 build_step: "build-crate-test_shim".to_string(),
1141 test_step: "test-test_shim".to_string(),
1142 bench_step: "bench-test_shim".to_string(),
1144 build.crates.insert("rustc-main".to_string(), ::Crate {
1145 name: "rustc-main".to_string(),
1147 path: cwd.join("src/rustc-main"),
1148 doc_step: "doc-rustc-main".to_string(),
1149 build_step: "build-crate-rustc-main".to_string(),
1150 test_step: "test-rustc-main".to_string(),
1151 bench_step: "bench-rustc-main".to_string(),
1157 fn dist_baseline() {
1158 let build = build(&["dist"], &[], &[]);
1159 let rules = super::build_rules(&build);
1160 let plan = rules.plan();
1161 println!("rules: {:#?}", plan);
1162 assert!(plan.iter().all(|s| s.stage == 2));
1163 assert!(plan.iter().all(|s| s.host == "A" ));
1164 assert!(plan.iter().all(|s| s.target == "A" ));
1166 let step = super::Step {
1169 host: &build.config.build,
1170 target: &build.config.build,
1173 assert!(plan.contains(&step.name("dist-docs")));
1174 assert!(plan.contains(&step.name("dist-mingw")));
1175 assert!(plan.contains(&step.name("dist-rustc")));
1176 assert!(plan.contains(&step.name("dist-std")));
1177 assert!(plan.contains(&step.name("dist-src")));
1181 fn dist_with_targets() {
1182 let build = build(&["dist"], &[], &["B"]);
1183 let rules = super::build_rules(&build);
1184 let plan = rules.plan();
1185 println!("rules: {:#?}", plan);
1186 assert!(plan.iter().all(|s| s.stage == 2));
1187 assert!(plan.iter().all(|s| s.host == "A" ));
1189 let step = super::Step {
1192 host: &build.config.build,
1193 target: &build.config.build,
1196 assert!(plan.contains(&step.name("dist-docs")));
1197 assert!(plan.contains(&step.name("dist-mingw")));
1198 assert!(plan.contains(&step.name("dist-rustc")));
1199 assert!(plan.contains(&step.name("dist-std")));
1200 assert!(plan.contains(&step.name("dist-src")));
1202 assert!(plan.contains(&step.target("B").name("dist-docs")));
1203 assert!(plan.contains(&step.target("B").name("dist-mingw")));
1204 assert!(!plan.contains(&step.target("B").name("dist-rustc")));
1205 assert!(plan.contains(&step.target("B").name("dist-std")));
1206 assert!(!plan.contains(&step.target("B").name("dist-src")));
1210 fn dist_with_hosts() {
1211 let build = build(&["dist"], &["B"], &[]);
1212 let rules = super::build_rules(&build);
1213 let plan = rules.plan();
1214 println!("rules: {:#?}", plan);
1215 assert!(plan.iter().all(|s| s.stage == 2));
1217 let step = super::Step {
1220 host: &build.config.build,
1221 target: &build.config.build,
1224 assert!(!plan.iter().any(|s| s.host == "B"));
1226 assert!(plan.contains(&step.name("dist-docs")));
1227 assert!(plan.contains(&step.name("dist-mingw")));
1228 assert!(plan.contains(&step.name("dist-rustc")));
1229 assert!(plan.contains(&step.name("dist-std")));
1230 assert!(plan.contains(&step.name("dist-src")));
1232 assert!(plan.contains(&step.target("B").name("dist-docs")));
1233 assert!(plan.contains(&step.target("B").name("dist-mingw")));
1234 assert!(plan.contains(&step.target("B").name("dist-rustc")));
1235 assert!(plan.contains(&step.target("B").name("dist-std")));
1236 assert!(!plan.contains(&step.target("B").name("dist-src")));
1240 fn dist_with_targets_and_hosts() {
1241 let build = build(&["dist"], &["B"], &["C"]);
1242 let rules = super::build_rules(&build);
1243 let plan = rules.plan();
1244 println!("rules: {:#?}", plan);
1245 assert!(plan.iter().all(|s| s.stage == 2));
1247 let step = super::Step {
1250 host: &build.config.build,
1251 target: &build.config.build,
1254 assert!(!plan.iter().any(|s| s.host == "B"));
1255 assert!(!plan.iter().any(|s| s.host == "C"));
1257 assert!(plan.contains(&step.name("dist-docs")));
1258 assert!(plan.contains(&step.name("dist-mingw")));
1259 assert!(plan.contains(&step.name("dist-rustc")));
1260 assert!(plan.contains(&step.name("dist-std")));
1261 assert!(plan.contains(&step.name("dist-src")));
1263 assert!(plan.contains(&step.target("B").name("dist-docs")));
1264 assert!(plan.contains(&step.target("B").name("dist-mingw")));
1265 assert!(plan.contains(&step.target("B").name("dist-rustc")));
1266 assert!(plan.contains(&step.target("B").name("dist-std")));
1267 assert!(!plan.contains(&step.target("B").name("dist-src")));
1269 assert!(plan.contains(&step.target("C").name("dist-docs")));
1270 assert!(plan.contains(&step.target("C").name("dist-mingw")));
1271 assert!(!plan.contains(&step.target("C").name("dist-rustc")));
1272 assert!(plan.contains(&step.target("C").name("dist-std")));
1273 assert!(!plan.contains(&step.target("C").name("dist-src")));
1277 fn dist_target_with_target_flag() {
1278 let build = build(&["dist", "--target=C"], &["B"], &["C"]);
1279 let rules = super::build_rules(&build);
1280 let plan = rules.plan();
1281 println!("rules: {:#?}", plan);
1282 assert!(plan.iter().all(|s| s.stage == 2));
1284 let step = super::Step {
1287 host: &build.config.build,
1288 target: &build.config.build,
1291 assert!(!plan.iter().any(|s| s.target == "A"));
1292 assert!(!plan.iter().any(|s| s.target == "B"));
1293 assert!(!plan.iter().any(|s| s.host == "B"));
1294 assert!(!plan.iter().any(|s| s.host == "C"));
1296 assert!(plan.contains(&step.target("C").name("dist-docs")));
1297 assert!(plan.contains(&step.target("C").name("dist-mingw")));
1298 assert!(!plan.contains(&step.target("C").name("dist-rustc")));
1299 assert!(plan.contains(&step.target("C").name("dist-std")));
1300 assert!(!plan.contains(&step.target("C").name("dist-src")));
1304 fn dist_host_with_target_flag() {
1305 let build = build(&["dist", "--host=B", "--target=B"], &["B"], &["C"]);
1306 let rules = super::build_rules(&build);
1307 let plan = rules.plan();
1308 println!("rules: {:#?}", plan);
1309 assert!(plan.iter().all(|s| s.stage == 2));
1311 let step = super::Step {
1314 host: &build.config.build,
1315 target: &build.config.build,
1318 assert!(!plan.iter().any(|s| s.target == "A"));
1319 assert!(!plan.iter().any(|s| s.target == "C"));
1320 assert!(!plan.iter().any(|s| s.host == "B"));
1321 assert!(!plan.iter().any(|s| s.host == "C"));
1323 assert!(plan.contains(&step.target("B").name("dist-docs")));
1324 assert!(plan.contains(&step.target("B").name("dist-mingw")));
1325 assert!(plan.contains(&step.target("B").name("dist-rustc")));
1326 assert!(plan.contains(&step.target("B").name("dist-std")));
1327 assert!(plan.contains(&step.target("B").name("dist-src")));
1329 let all = rules.expand(&plan);
1330 println!("all rules: {:#?}", all);
1331 assert!(!all.contains(&step.name("rustc")));
1332 assert!(!all.contains(&step.name("build-crate-std_shim").stage(1)));
1334 // all stage0 compiles should be for the build target, A
1335 for step in all.iter().filter(|s| s.stage == 0) {
1336 if !step.name.contains("build-crate") {
1339 println!("step: {:?}", step);
1340 assert!(step.host != "B");
1341 assert!(step.target != "B");
1342 assert!(step.host != "C");
1343 assert!(step.target != "C");
1348 fn build_default() {
1349 let build = build(&["build"], &["B"], &["C"]);
1350 let rules = super::build_rules(&build);
1351 let plan = rules.plan();
1352 println!("rules: {:#?}", plan);
1353 assert!(plan.iter().all(|s| s.stage == 2));
1355 let step = super::Step {
1358 host: &build.config.build,
1359 target: &build.config.build,
1362 // rustc built for all for of (A, B) x (A, B)
1363 assert!(plan.contains(&step.name("librustc")));
1364 assert!(plan.contains(&step.target("B").name("librustc")));
1365 assert!(plan.contains(&step.host("B").target("A").name("librustc")));
1366 assert!(plan.contains(&step.host("B").target("B").name("librustc")));
1368 // rustc never built for C
1369 assert!(!plan.iter().any(|s| {
1370 s.name.contains("rustc") && (s.host == "C" || s.target == "C")
1373 // test built for everything
1374 assert!(plan.contains(&step.name("libtest")));
1375 assert!(plan.contains(&step.target("B").name("libtest")));
1376 assert!(plan.contains(&step.host("B").target("A").name("libtest")));
1377 assert!(plan.contains(&step.host("B").target("B").name("libtest")));
1378 assert!(plan.contains(&step.host("A").target("C").name("libtest")));
1379 assert!(plan.contains(&step.host("B").target("C").name("libtest")));
1381 let all = rules.expand(&plan);
1382 println!("all rules: {:#?}", all);
1383 assert!(all.contains(&step.name("rustc")));
1384 assert!(all.contains(&step.name("libstd")));
1388 fn build_filtered() {
1389 let build = build(&["build", "--target=C"], &["B"], &["C"]);
1390 let rules = super::build_rules(&build);
1391 let plan = rules.plan();
1392 println!("rules: {:#?}", plan);
1393 assert!(plan.iter().all(|s| s.stage == 2));
1395 assert!(!plan.iter().any(|s| s.name.contains("rustc")));
1396 assert!(plan.iter().all(|s| {
1397 !s.name.contains("test_shim") || s.target == "C"
1403 let build = build(&["test"], &[], &[]);
1404 let rules = super::build_rules(&build);
1405 let plan = rules.plan();
1406 println!("rules: {:#?}", plan);
1407 assert!(plan.iter().all(|s| s.stage == 2));
1408 assert!(plan.iter().all(|s| s.host == "A"));
1409 assert!(plan.iter().all(|s| s.target == "A"));
1411 assert!(plan.iter().any(|s| s.name.contains("-ui")));
1412 assert!(plan.iter().any(|s| s.name.contains("cfail")));
1413 assert!(plan.iter().any(|s| s.name.contains("cfail-full")));
1414 assert!(plan.iter().any(|s| s.name.contains("codegen-units")));
1415 assert!(plan.iter().any(|s| s.name.contains("debuginfo")));
1416 assert!(plan.iter().any(|s| s.name.contains("docs")));
1417 assert!(plan.iter().any(|s| s.name.contains("error-index")));
1418 assert!(plan.iter().any(|s| s.name.contains("incremental")));
1419 assert!(plan.iter().any(|s| s.name.contains("linkchecker")));
1420 assert!(plan.iter().any(|s| s.name.contains("mir-opt")));
1421 assert!(plan.iter().any(|s| s.name.contains("pfail")));
1422 assert!(plan.iter().any(|s| s.name.contains("rfail")));
1423 assert!(plan.iter().any(|s| s.name.contains("rfail-full")));
1424 assert!(plan.iter().any(|s| s.name.contains("rmake")));
1425 assert!(plan.iter().any(|s| s.name.contains("rpass")));
1426 assert!(plan.iter().any(|s| s.name.contains("rpass-full")));
1427 assert!(plan.iter().any(|s| s.name.contains("rustc-all")));
1428 assert!(plan.iter().any(|s| s.name.contains("rustdoc")));
1429 assert!(plan.iter().any(|s| s.name.contains("std-all")));
1430 assert!(plan.iter().any(|s| s.name.contains("test-all")));
1431 assert!(plan.iter().any(|s| s.name.contains("tidy")));
1432 assert!(plan.iter().any(|s| s.name.contains("valgrind")));
1436 fn test_with_a_target() {
1437 let build = build(&["test", "--target=C"], &[], &["C"]);
1438 let rules = super::build_rules(&build);
1439 let plan = rules.plan();
1440 println!("rules: {:#?}", plan);
1441 assert!(plan.iter().all(|s| s.stage == 2));
1442 assert!(plan.iter().all(|s| s.host == "A"));
1443 assert!(plan.iter().all(|s| s.target == "C"));
1445 assert!(!plan.iter().any(|s| s.name.contains("-ui")));
1446 assert!(plan.iter().any(|s| s.name.contains("cfail")));
1447 assert!(!plan.iter().any(|s| s.name.contains("cfail-full")));
1448 assert!(plan.iter().any(|s| s.name.contains("codegen-units")));
1449 assert!(plan.iter().any(|s| s.name.contains("debuginfo")));
1450 assert!(!plan.iter().any(|s| s.name.contains("docs")));
1451 assert!(!plan.iter().any(|s| s.name.contains("error-index")));
1452 assert!(plan.iter().any(|s| s.name.contains("incremental")));
1453 assert!(!plan.iter().any(|s| s.name.contains("linkchecker")));
1454 assert!(plan.iter().any(|s| s.name.contains("mir-opt")));
1455 assert!(plan.iter().any(|s| s.name.contains("pfail")));
1456 assert!(plan.iter().any(|s| s.name.contains("rfail")));
1457 assert!(!plan.iter().any(|s| s.name.contains("rfail-full")));
1458 assert!(!plan.iter().any(|s| s.name.contains("rmake")));
1459 assert!(plan.iter().any(|s| s.name.contains("rpass")));
1460 assert!(!plan.iter().any(|s| s.name.contains("rpass-full")));
1461 assert!(!plan.iter().any(|s| s.name.contains("rustc-all")));
1462 assert!(!plan.iter().any(|s| s.name.contains("rustdoc")));
1463 assert!(plan.iter().any(|s| s.name.contains("std-all")));
1464 assert!(plan.iter().any(|s| s.name.contains("test-all")));
1465 assert!(!plan.iter().any(|s| s.name.contains("tidy")));
1466 assert!(plan.iter().any(|s| s.name.contains("valgrind")));