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::{BTreeMap, HashSet, HashMap};
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)
141 // This handles out of tree paths
142 .unwrap_or(&krate.path);
143 ret.push((krate, path.to_str().unwrap(), default));
144 for dep in krate.deps.iter() {
145 if visited.insert(dep) && dep != "build_helper" {
153 // ========================================================================
154 // Crate compilations
156 // Tools used during the build system but not shipped
157 rules.build("create-sysroot", "path/to/nowhere")
158 .run(move |s| compile::create_sysroot(build, &s.compiler()));
160 // These rules are "pseudo rules" that don't actually do any work
161 // themselves, but represent a complete sysroot with the relevant compiler
162 // linked into place.
164 // That is, depending on "libstd" means that when the rule is completed then
165 // the `stage` sysroot for the compiler `host` will be available with a
166 // standard library built for `target` linked in place. Not all rules need
167 // the compiler itself to be available, just the standard library, so
168 // there's a distinction between the two.
169 rules.build("libstd", "src/libstd")
170 .dep(|s| s.name("rustc").target(s.host))
171 .dep(|s| s.name("libstd-link"));
172 rules.build("libtest", "src/libtest")
173 .dep(|s| s.name("libstd"))
174 .dep(|s| s.name("libtest-link"))
176 rules.build("librustc", "src/librustc")
177 .dep(|s| s.name("libtest"))
178 .dep(|s| s.name("librustc-link"))
182 // Helper method to define the rules to link a crate into its place in the
185 // The logic here is a little subtle as there's a few cases to consider.
186 // Not all combinations of (stage, host, target) actually require something
187 // to be compiled, but rather libraries could get propagated from a
188 // different location. For example:
190 // * Any crate with a `host` that's not the build triple will not actually
191 // compile something. A different `host` means that the build triple will
192 // actually compile the libraries, and then we'll copy them over from the
193 // build triple to the `host` directory.
195 // * Some crates aren't even compiled by the build triple, but may be copied
196 // from previous stages. For example if we're not doing a full bootstrap
197 // then we may just depend on the stage1 versions of libraries to be
198 // available to get linked forward.
200 // * Finally, there are some cases, however, which do indeed comiple crates
201 // and link them into place afterwards.
203 // The rule definition below mirrors these three cases. The `dep` method
204 // calculates the correct dependency which either comes from stage1, a
205 // different compiler, or from actually building the crate itself (the `dep`
206 // rule). The `run` rule then mirrors these three cases and links the cases
207 // forward into the compiler sysroot specified from the correct location.
208 fn crate_rule<'a, 'b>(build: &'a Build,
209 rules: &'b mut Rules<'a>,
212 link: fn(&Build, &Compiler, &Compiler, &str))
213 -> RuleBuilder<'a, 'b> {
214 let mut rule = rules.build(&krate, "path/to/nowhere");
216 if build.force_use_stage1(&s.compiler(), s.target) {
217 s.host(&build.config.build).stage(1)
218 } else if s.host == build.config.build {
221 s.host(&build.config.build)
225 if build.force_use_stage1(&s.compiler(), s.target) {
227 &s.stage(1).host(&build.config.build).compiler(),
230 } else if s.host == build.config.build {
231 link(build, &s.compiler(), &s.compiler(), s.target)
234 &s.host(&build.config.build).compiler(),
242 // Similar to the `libstd`, `libtest`, and `librustc` rules above, except
243 // these rules only represent the libraries being available in the sysroot,
244 // not the compiler itself. This is done as not all rules need a compiler in
245 // the sysroot, but may just need the libraries.
247 // All of these rules use the helper definition above.
253 .dep(|s| s.name("startup-objects"))
254 .dep(|s| s.name("create-sysroot").target(s.host));
260 .dep(|s| s.name("libstd-link"));
264 "build-crate-rustc-main",
266 .dep(|s| s.name("libtest-link"));
268 for (krate, path, _default) in krates("std") {
269 rules.build(&krate.build_step, path)
270 .dep(|s| s.name("startup-objects"))
271 .dep(move |s| s.name("rustc").host(&build.config.build).target(s.host))
272 .run(move |s| compile::std(build, s.target, &s.compiler()));
274 for (krate, path, _default) in krates("test") {
275 rules.build(&krate.build_step, path)
276 .dep(|s| s.name("libstd-link"))
277 .run(move |s| compile::test(build, s.target, &s.compiler()));
279 for (krate, path, _default) in krates("rustc-main") {
280 rules.build(&krate.build_step, path)
281 .dep(|s| s.name("libtest-link"))
282 .dep(move |s| s.name("llvm").host(&build.config.build).stage(0))
283 .dep(|s| s.name("may-run-build-script"))
284 .run(move |s| compile::rustc(build, s.target, &s.compiler()));
287 // Crates which have build scripts need to rely on this rule to ensure that
288 // the necessary prerequisites for a build script are linked and located in
290 rules.build("may-run-build-script", "path/to/nowhere")
292 s.name("libstd-link")
293 .host(&build.config.build)
294 .target(&build.config.build)
296 rules.build("startup-objects", "src/rtstartup")
297 .dep(|s| s.name("create-sysroot").target(s.host))
298 .run(move |s| compile::build_startup_objects(build, &s.compiler(), s.target));
300 // ========================================================================
303 // Various unit tests and tests suites we can run
305 let mut suite = |name, path, mode, dir| {
306 rules.test(name, path)
307 .dep(|s| s.name("libtest"))
308 .dep(|s| s.name("tool-compiletest").target(s.host).stage(0))
309 .dep(|s| s.name("test-helpers"))
310 .dep(|s| s.name("emulator-copy-libs"))
311 .default(mode != "pretty") // pretty tests don't run everywhere
313 check::compiletest(build, &s.compiler(), s.target, mode, dir)
317 suite("check-ui", "src/test/ui", "ui", "ui");
318 suite("check-rpass", "src/test/run-pass", "run-pass", "run-pass");
319 suite("check-cfail", "src/test/compile-fail", "compile-fail", "compile-fail");
320 suite("check-pfail", "src/test/parse-fail", "parse-fail", "parse-fail");
321 suite("check-rfail", "src/test/run-fail", "run-fail", "run-fail");
322 suite("check-rpass-valgrind", "src/test/run-pass-valgrind",
323 "run-pass-valgrind", "run-pass-valgrind");
324 suite("check-mir-opt", "src/test/mir-opt", "mir-opt", "mir-opt");
325 if build.config.codegen_tests {
326 suite("check-codegen", "src/test/codegen", "codegen", "codegen");
328 suite("check-codegen-units", "src/test/codegen-units", "codegen-units",
330 suite("check-incremental", "src/test/incremental", "incremental",
334 if build.config.build.contains("msvc") {
335 // nothing to do for debuginfo tests
337 rules.test("check-debuginfo-lldb", "src/test/debuginfo-lldb")
338 .dep(|s| s.name("libtest"))
339 .dep(|s| s.name("tool-compiletest").target(s.host).stage(0))
340 .dep(|s| s.name("test-helpers"))
341 .dep(|s| s.name("debugger-scripts"))
342 .run(move |s| check::compiletest(build, &s.compiler(), s.target,
343 "debuginfo-lldb", "debuginfo"));
344 rules.test("check-debuginfo-gdb", "src/test/debuginfo-gdb")
345 .dep(|s| s.name("libtest"))
346 .dep(|s| s.name("tool-compiletest").target(s.host).stage(0))
347 .dep(|s| s.name("test-helpers"))
348 .dep(|s| s.name("debugger-scripts"))
349 .dep(|s| s.name("emulator-copy-libs"))
350 .run(move |s| check::compiletest(build, &s.compiler(), s.target,
351 "debuginfo-gdb", "debuginfo"));
352 let mut rule = rules.test("check-debuginfo", "src/test/debuginfo");
354 if build.config.build.contains("apple") {
355 rule.dep(|s| s.name("check-debuginfo-lldb"));
357 rule.dep(|s| s.name("check-debuginfo-gdb"));
361 rules.test("debugger-scripts", "src/etc/lldb_batchmode.py")
362 .run(move |s| dist::debugger_scripts(build, &build.sysroot(&s.compiler()),
366 let mut suite = |name, path, mode, dir| {
367 rules.test(name, path)
368 .dep(|s| s.name("librustc"))
369 .dep(|s| s.name("test-helpers"))
370 .dep(|s| s.name("tool-compiletest").target(s.host).stage(0))
371 .default(mode != "pretty")
374 check::compiletest(build, &s.compiler(), s.target, mode, dir)
378 suite("check-ui-full", "src/test/ui-fulldeps", "ui", "ui-fulldeps");
379 suite("check-rpass-full", "src/test/run-pass-fulldeps",
380 "run-pass", "run-pass-fulldeps");
381 suite("check-rfail-full", "src/test/run-fail-fulldeps",
382 "run-fail", "run-fail-fulldeps");
383 suite("check-cfail-full", "src/test/compile-fail-fulldeps",
384 "compile-fail", "compile-fail-fulldeps");
385 suite("check-rmake", "src/test/run-make", "run-make", "run-make");
386 suite("check-rustdoc", "src/test/rustdoc", "rustdoc", "rustdoc");
387 suite("check-pretty", "src/test/pretty", "pretty", "pretty");
388 suite("check-pretty-rpass", "src/test/run-pass/pretty", "pretty",
390 suite("check-pretty-rfail", "src/test/run-fail/pretty", "pretty",
392 suite("check-pretty-valgrind", "src/test/run-pass-valgrind/pretty", "pretty",
393 "run-pass-valgrind");
394 suite("check-pretty-rpass-full", "src/test/run-pass-fulldeps/pretty",
395 "pretty", "run-pass-fulldeps");
396 suite("check-pretty-rfail-full", "src/test/run-fail-fulldeps/pretty",
397 "pretty", "run-fail-fulldeps");
400 for (krate, path, _default) in krates("std") {
401 rules.test(&krate.test_step, path)
402 .dep(|s| s.name("libtest"))
403 .dep(|s| s.name("emulator-copy-libs"))
404 .run(move |s| check::krate(build, &s.compiler(), s.target,
405 Mode::Libstd, TestKind::Test,
408 rules.test("check-std-all", "path/to/nowhere")
409 .dep(|s| s.name("libtest"))
410 .dep(|s| s.name("emulator-copy-libs"))
412 .run(move |s| check::krate(build, &s.compiler(), s.target,
413 Mode::Libstd, TestKind::Test, None));
416 for (krate, path, _default) in krates("std") {
417 rules.bench(&krate.bench_step, path)
418 .dep(|s| s.name("libtest"))
419 .dep(|s| s.name("emulator-copy-libs"))
420 .run(move |s| check::krate(build, &s.compiler(), s.target,
421 Mode::Libstd, TestKind::Bench,
424 rules.bench("bench-std-all", "path/to/nowhere")
425 .dep(|s| s.name("libtest"))
426 .dep(|s| s.name("emulator-copy-libs"))
428 .run(move |s| check::krate(build, &s.compiler(), s.target,
429 Mode::Libstd, TestKind::Bench, None));
431 for (krate, path, _default) in krates("test") {
432 rules.test(&krate.test_step, path)
433 .dep(|s| s.name("libtest"))
434 .dep(|s| s.name("emulator-copy-libs"))
435 .run(move |s| check::krate(build, &s.compiler(), s.target,
436 Mode::Libtest, TestKind::Test,
439 rules.test("check-test-all", "path/to/nowhere")
440 .dep(|s| s.name("libtest"))
441 .dep(|s| s.name("emulator-copy-libs"))
443 .run(move |s| check::krate(build, &s.compiler(), s.target,
444 Mode::Libtest, TestKind::Test, None));
445 for (krate, path, _default) in krates("rustc-main") {
446 rules.test(&krate.test_step, path)
447 .dep(|s| s.name("librustc"))
448 .dep(|s| s.name("emulator-copy-libs"))
450 .run(move |s| check::krate(build, &s.compiler(), s.target,
451 Mode::Librustc, TestKind::Test,
454 rules.test("check-rustc-all", "path/to/nowhere")
455 .dep(|s| s.name("librustc"))
456 .dep(|s| s.name("emulator-copy-libs"))
459 .run(move |s| check::krate(build, &s.compiler(), s.target,
460 Mode::Librustc, TestKind::Test, None));
462 rules.test("check-linkchecker", "src/tools/linkchecker")
463 .dep(|s| s.name("tool-linkchecker").stage(0))
464 .dep(|s| s.name("default:doc"))
467 .run(move |s| check::linkcheck(build, s.target));
468 rules.test("check-cargotest", "src/tools/cargotest")
469 .dep(|s| s.name("tool-cargotest").stage(0))
470 .dep(|s| s.name("librustc"))
472 .run(move |s| check::cargotest(build, s.stage, s.target));
473 rules.test("check-tidy", "src/tools/tidy")
474 .dep(|s| s.name("tool-tidy").stage(0))
478 .run(move |s| check::tidy(build, s.target));
479 rules.test("check-error-index", "src/tools/error_index_generator")
480 .dep(|s| s.name("libstd"))
481 .dep(|s| s.name("tool-error-index").host(s.host).stage(0))
484 .run(move |s| check::error_index(build, &s.compiler()));
485 rules.test("check-docs", "src/doc")
486 .dep(|s| s.name("libtest"))
489 .run(move |s| check::docs(build, &s.compiler()));
490 rules.test("check-distcheck", "distcheck")
491 .dep(|s| s.name("dist-src"))
492 .run(move |_| check::distcheck(build));
494 rules.build("test-helpers", "src/rt/rust_test_helpers.c")
495 .run(move |s| native::test_helpers(build, s.target));
496 rules.build("openssl", "path/to/nowhere")
497 .run(move |s| native::openssl(build, s.target));
499 // Some test suites are run inside emulators, and most of our test binaries
500 // are linked dynamically which means we need to ship the standard library
501 // and such to the emulator ahead of time. This step represents this and is
502 // a dependency of all test suites.
504 // Most of the time this step is a noop (the `check::emulator_copy_libs`
505 // only does work if necessary). For some steps such as shipping data to
506 // QEMU we have to build our own tools so we've got conditional dependencies
507 // on those programs as well. Note that the QEMU client is built for the
508 // build target (us) and the server is built for the target.
509 rules.test("emulator-copy-libs", "path/to/nowhere")
510 .dep(|s| s.name("libtest"))
512 if build.qemu_rootfs(s.target).is_some() {
513 s.name("tool-qemu-test-client").target(s.host).stage(0)
519 if build.qemu_rootfs(s.target).is_some() {
520 s.name("tool-qemu-test-server")
525 .run(move |s| check::emulator_copy_libs(build, &s.compiler(), s.target));
527 rules.test("check-bootstrap", "src/bootstrap")
531 .run(move |_| check::bootstrap(build));
533 // ========================================================================
536 // Tools used during the build system but not shipped
537 rules.build("tool-rustbook", "src/tools/rustbook")
538 .dep(|s| s.name("maybe-clean-tools"))
539 .dep(|s| s.name("librustc-tool"))
540 .run(move |s| compile::tool(build, s.stage, s.target, "rustbook"));
541 rules.build("tool-error-index", "src/tools/error_index_generator")
542 .dep(|s| s.name("maybe-clean-tools"))
543 .dep(|s| s.name("librustc-tool"))
544 .run(move |s| compile::tool(build, s.stage, s.target, "error_index_generator"));
545 rules.build("tool-tidy", "src/tools/tidy")
546 .dep(|s| s.name("maybe-clean-tools"))
547 .dep(|s| s.name("libstd-tool"))
548 .run(move |s| compile::tool(build, s.stage, s.target, "tidy"));
549 rules.build("tool-linkchecker", "src/tools/linkchecker")
550 .dep(|s| s.name("maybe-clean-tools"))
551 .dep(|s| s.name("libstd-tool"))
552 .run(move |s| compile::tool(build, s.stage, s.target, "linkchecker"));
553 rules.build("tool-cargotest", "src/tools/cargotest")
554 .dep(|s| s.name("maybe-clean-tools"))
555 .dep(|s| s.name("libstd-tool"))
556 .run(move |s| compile::tool(build, s.stage, s.target, "cargotest"));
557 rules.build("tool-compiletest", "src/tools/compiletest")
558 .dep(|s| s.name("maybe-clean-tools"))
559 .dep(|s| s.name("libtest-tool"))
560 .run(move |s| compile::tool(build, s.stage, s.target, "compiletest"));
561 rules.build("tool-build-manifest", "src/tools/build-manifest")
562 .dep(|s| s.name("maybe-clean-tools"))
563 .dep(|s| s.name("libstd-tool"))
564 .run(move |s| compile::tool(build, s.stage, s.target, "build-manifest"));
565 rules.build("tool-qemu-test-server", "src/tools/qemu-test-server")
566 .dep(|s| s.name("maybe-clean-tools"))
567 .dep(|s| s.name("libstd-tool"))
568 .run(move |s| compile::tool(build, s.stage, s.target, "qemu-test-server"));
569 rules.build("tool-qemu-test-client", "src/tools/qemu-test-client")
570 .dep(|s| s.name("maybe-clean-tools"))
571 .dep(|s| s.name("libstd-tool"))
572 .run(move |s| compile::tool(build, s.stage, s.target, "qemu-test-client"));
573 rules.build("tool-cargo", "cargo")
574 .dep(|s| s.name("maybe-clean-tools"))
575 .dep(|s| s.name("libstd-tool"))
576 .dep(|s| s.stage(0).host(s.target).name("openssl"))
578 // Cargo depends on procedural macros, which requires a full host
579 // compiler to be available, so we need to depend on that.
580 s.name("librustc-link")
581 .target(&build.config.build)
582 .host(&build.config.build)
584 .run(move |s| compile::tool(build, s.stage, s.target, "cargo"));
585 rules.build("tool-rls", "rls")
587 .dep(|s| s.name("librustc-tool"))
588 .dep(|s| s.stage(0).host(s.target).name("openssl"))
590 // rls, like cargo, uses procedural macros
591 s.name("librustc-link")
592 .target(&build.config.build)
593 .host(&build.config.build)
595 .run(move |s| compile::tool(build, s.stage, s.target, "rls"));
597 // "pseudo rule" which represents completely cleaning out the tools dir in
598 // one stage. This needs to happen whenever a dependency changes (e.g.
599 // libstd, libtest, librustc) and all of the tool compilations above will
600 // be sequenced after this rule.
601 rules.build("maybe-clean-tools", "path/to/nowhere")
602 .after("librustc-tool")
603 .after("libtest-tool")
604 .after("libstd-tool");
606 rules.build("librustc-tool", "path/to/nowhere")
607 .dep(|s| s.name("librustc"))
608 .run(move |s| compile::maybe_clean_tools(build, s.stage, s.target, Mode::Librustc));
609 rules.build("libtest-tool", "path/to/nowhere")
610 .dep(|s| s.name("libtest"))
611 .run(move |s| compile::maybe_clean_tools(build, s.stage, s.target, Mode::Libtest));
612 rules.build("libstd-tool", "path/to/nowhere")
613 .dep(|s| s.name("libstd"))
614 .run(move |s| compile::maybe_clean_tools(build, s.stage, s.target, Mode::Libstd));
616 // ========================================================================
617 // Documentation targets
618 rules.doc("doc-book", "src/doc/book")
620 s.name("tool-rustbook")
621 .host(&build.config.build)
622 .target(&build.config.build)
625 .default(build.config.docs)
626 .run(move |s| doc::book(build, s.target, "book"));
627 rules.doc("doc-nomicon", "src/doc/nomicon")
629 s.name("tool-rustbook")
630 .host(&build.config.build)
631 .target(&build.config.build)
634 .default(build.config.docs)
635 .run(move |s| doc::rustbook(build, s.target, "nomicon"));
636 rules.doc("doc-reference", "src/doc/reference")
638 s.name("tool-rustbook")
639 .host(&build.config.build)
640 .target(&build.config.build)
643 .default(build.config.docs)
644 .run(move |s| doc::rustbook(build, s.target, "reference"));
645 rules.doc("doc-unstable-book", "src/doc/unstable-book")
647 s.name("tool-rustbook")
648 .host(&build.config.build)
649 .target(&build.config.build)
652 .default(build.config.docs)
653 .run(move |s| doc::rustbook(build, s.target, "unstable-book"));
654 rules.doc("doc-standalone", "src/doc")
657 .host(&build.config.build)
658 .target(&build.config.build)
661 .default(build.config.docs)
662 .run(move |s| doc::standalone(build, s.target));
663 rules.doc("doc-error-index", "src/tools/error_index_generator")
664 .dep(move |s| s.name("tool-error-index").target(&build.config.build).stage(0))
665 .dep(move |s| s.name("librustc-link"))
666 .default(build.config.docs)
668 .run(move |s| doc::error_index(build, s.target));
669 for (krate, path, default) in krates("std") {
670 rules.doc(&krate.doc_step, path)
671 .dep(|s| s.name("libstd-link"))
672 .default(default && build.config.docs)
673 .run(move |s| doc::std(build, s.stage, s.target));
675 for (krate, path, default) in krates("test") {
676 rules.doc(&krate.doc_step, path)
677 .dep(|s| s.name("libtest-link"))
678 // Needed so rustdoc generates relative links to std.
679 .dep(|s| s.name("doc-crate-std"))
680 .default(default && build.config.compiler_docs)
681 .run(move |s| doc::test(build, s.stage, s.target));
683 for (krate, path, default) in krates("rustc-main") {
684 rules.doc(&krate.doc_step, path)
685 .dep(|s| s.name("librustc-link"))
686 // Needed so rustdoc generates relative links to std.
687 .dep(|s| s.name("doc-crate-std"))
689 .default(default && build.config.docs)
690 .run(move |s| doc::rustc(build, s.stage, s.target));
693 // ========================================================================
694 // Distribution targets
695 rules.dist("dist-rustc", "src/librustc")
696 .dep(move |s| s.name("rustc").host(&build.config.build))
698 .only_host_build(true)
700 .run(move |s| dist::rustc(build, s.stage, s.target));
701 rules.dist("dist-std", "src/libstd")
703 // We want to package up as many target libraries as possible
704 // for the `rust-std` package, so if this is a host target we
705 // depend on librustc and otherwise we just depend on libtest.
706 if build.config.host.iter().any(|t| t == s.target) {
707 s.name("librustc-link")
709 s.name("libtest-link")
713 .only_host_build(true)
714 .run(move |s| dist::std(build, &s.compiler(), s.target));
715 rules.dist("dist-mingw", "path/to/nowhere")
717 .only_host_build(true)
719 if s.target.contains("pc-windows-gnu") {
720 dist::mingw(build, s.target)
723 rules.dist("dist-src", "src")
727 .only_host_build(true)
728 .run(move |_| dist::rust_src(build));
729 rules.dist("dist-docs", "src/doc")
731 .only_host_build(true)
732 .dep(|s| s.name("default:doc"))
733 .run(move |s| dist::docs(build, s.stage, s.target));
734 rules.dist("dist-analysis", "analysis")
735 .default(build.config.extended)
736 .dep(|s| s.name("dist-std"))
737 .only_host_build(true)
738 .run(move |s| dist::analysis(build, &s.compiler(), s.target));
739 rules.dist("dist-rls", "rls")
741 .only_host_build(true)
742 .dep(|s| s.name("tool-rls"))
743 .run(move |s| dist::rls(build, s.stage, s.target));
744 rules.dist("install", "path/to/nowhere")
745 .dep(|s| s.name("default:dist"))
746 .run(move |s| install::install(build, s.stage, s.target));
747 rules.dist("dist-cargo", "cargo")
749 .only_host_build(true)
750 .dep(|s| s.name("tool-cargo"))
751 .run(move |s| dist::cargo(build, s.stage, s.target));
752 rules.dist("dist-extended", "extended")
753 .default(build.config.extended)
755 .only_host_build(true)
756 .dep(|d| d.name("dist-std"))
757 .dep(|d| d.name("dist-rustc"))
758 .dep(|d| d.name("dist-mingw"))
759 .dep(|d| d.name("dist-docs"))
760 .dep(|d| d.name("dist-cargo"))
761 .dep(|d| d.name("dist-rls"))
762 .dep(|d| d.name("dist-analysis"))
763 .run(move |s| dist::extended(build, s.stage, s.target));
765 rules.dist("dist-sign", "hash-and-sign")
768 .only_host_build(true)
769 .dep(move |s| s.name("tool-build-manifest").target(&build.config.build).stage(0))
770 .run(move |_| dist::hash_and_sign(build));
776 #[derive(PartialEq, Eq, Hash, Clone, Debug)]
778 /// Human readable name of the rule this step is executing. Possible names
779 /// are all defined above in `build_rules`.
782 /// The stage this step is executing in. This is typically 0, 1, or 2.
785 /// This step will likely involve a compiler, and the target that compiler
786 /// itself is built for is called the host, this variable. Typically this is
787 /// the target of the build machine itself.
790 /// The target that this step represents generating. If you're building a
791 /// standard library for a new suite of targets, for example, this'll be set
792 /// to those targets.
797 fn noop() -> Step<'a> {
798 Step { name: "", stage: 0, host: "", target: "" }
801 /// Creates a new step which is the same as this, except has a new name.
802 fn name(&self, name: &'a str) -> Step<'a> {
803 Step { name: name, ..*self }
806 /// Creates a new step which is the same as this, except has a new stage.
807 fn stage(&self, stage: u32) -> Step<'a> {
808 Step { stage: stage, ..*self }
811 /// Creates a new step which is the same as this, except has a new host.
812 fn host(&self, host: &'a str) -> Step<'a> {
813 Step { host: host, ..*self }
816 /// Creates a new step which is the same as this, except has a new target.
817 fn target(&self, target: &'a str) -> Step<'a> {
818 Step { target: target, ..*self }
821 /// Returns the `Compiler` structure that this step corresponds to.
822 fn compiler(&self) -> Compiler<'a> {
823 Compiler::new(self.stage, self.host)
828 /// The human readable name of this target, defined in `build_rules`.
831 /// The path associated with this target, used in the `./x.py` driver for
832 /// easy and ergonomic specification of what to do.
835 /// The "kind" of top-level command that this rule is associated with, only
836 /// relevant if this is a default rule.
839 /// List of dependencies this rule has. Each dependency is a function from a
840 /// step that's being executed to another step that should be executed.
841 deps: Vec<Box<Fn(&Step<'a>) -> Step<'a> + 'a>>,
843 /// How to actually execute this rule. Takes a step with contextual
844 /// information and then executes it.
845 run: Box<Fn(&Step<'a>) + 'a>,
847 /// Whether or not this is a "default" rule. That basically means that if
848 /// you run, for example, `./x.py test` whether it's included or not.
851 /// Whether or not this is a "host" rule, or in other words whether this is
852 /// only intended for compiler hosts and not for targets that are being
856 /// Whether this rule is only for steps where the host is the build triple,
857 /// not anything in hosts or targets.
858 only_host_build: bool,
860 /// Whether this rule is only for the build triple, not anything in hosts or
864 /// A list of "order only" dependencies. This rules does not actually
865 /// depend on these rules, but if they show up in the dependency graph then
866 /// this rule must be executed after all these rules.
880 fn new(name: &'a str, path: &'a str, kind: Kind) -> Rule<'a> {
884 run: Box::new(|_| ()),
889 only_host_build: false,
896 /// Builder pattern returned from the various methods on `Rules` which will add
897 /// the rule to the internal list on `Drop`.
898 struct RuleBuilder<'a: 'b, 'b> {
899 rules: &'b mut Rules<'a>,
903 impl<'a, 'b> RuleBuilder<'a, 'b> {
904 fn dep<F>(&mut self, f: F) -> &mut Self
905 where F: Fn(&Step<'a>) -> Step<'a> + 'a,
907 self.rule.deps.push(Box::new(f));
911 fn after(&mut self, step: &'a str) -> &mut Self {
912 self.rule.after.push(step);
916 fn run<F>(&mut self, f: F) -> &mut Self
917 where F: Fn(&Step<'a>) + 'a,
919 self.rule.run = Box::new(f);
923 fn default(&mut self, default: bool) -> &mut Self {
924 self.rule.default = default;
928 fn host(&mut self, host: bool) -> &mut Self {
929 self.rule.host = host;
933 fn only_build(&mut self, only_build: bool) -> &mut Self {
934 self.rule.only_build = only_build;
938 fn only_host_build(&mut self, only_host_build: bool) -> &mut Self {
939 self.rule.only_host_build = only_host_build;
944 impl<'a, 'b> Drop for RuleBuilder<'a, 'b> {
946 let rule = mem::replace(&mut self.rule, Rule::new("", "", Kind::Build));
947 let prev = self.rules.rules.insert(rule.name, rule);
948 if let Some(prev) = prev {
949 panic!("duplicate rule named: {}", prev.name);
954 pub struct Rules<'a> {
957 rules: BTreeMap<&'a str, Rule<'a>>,
961 fn new(build: &'a Build) -> Rules<'a> {
965 stage: build.flags.stage.unwrap_or(2),
966 target: &build.config.build,
967 host: &build.config.build,
970 rules: BTreeMap::new(),
974 /// Creates a new rule of `Kind::Build` with the specified human readable
975 /// name and path associated with it.
977 /// The builder returned should be configured further with information such
978 /// as how to actually run this rule.
979 fn build<'b>(&'b mut self, name: &'a str, path: &'a str)
980 -> RuleBuilder<'a, 'b> {
981 self.rule(name, path, Kind::Build)
984 /// Same as `build`, but for `Kind::Test`.
985 fn test<'b>(&'b mut self, name: &'a str, path: &'a str)
986 -> RuleBuilder<'a, 'b> {
987 self.rule(name, path, Kind::Test)
990 /// Same as `build`, but for `Kind::Bench`.
991 fn bench<'b>(&'b mut self, name: &'a str, path: &'a str)
992 -> RuleBuilder<'a, 'b> {
993 self.rule(name, path, Kind::Bench)
996 /// Same as `build`, but for `Kind::Doc`.
997 fn doc<'b>(&'b mut self, name: &'a str, path: &'a str)
998 -> RuleBuilder<'a, 'b> {
999 self.rule(name, path, Kind::Doc)
1002 /// Same as `build`, but for `Kind::Dist`.
1003 fn dist<'b>(&'b mut self, name: &'a str, path: &'a str)
1004 -> RuleBuilder<'a, 'b> {
1005 self.rule(name, path, Kind::Dist)
1008 fn rule<'b>(&'b mut self,
1011 kind: Kind) -> RuleBuilder<'a, 'b> {
1014 rule: Rule::new(name, path, kind),
1018 /// Verify the dependency graph defined by all our rules are correct, e.g.
1019 /// everything points to a valid something else.
1021 for rule in self.rules.values() {
1022 for dep in rule.deps.iter() {
1023 let dep = dep(&self.sbuild.name(rule.name));
1024 if self.rules.contains_key(&dep.name) || dep.name.starts_with("default:") {
1027 if dep == Step::noop() {
1032 invalid rule dependency graph detected, was a rule added and maybe typo'd?
1034 `{}` depends on `{}` which does not exist
1036 ", rule.name, dep.name);
1041 pub fn get_help(&self, command: &str) -> Option<String> {
1042 let kind = match command {
1043 "build" => Kind::Build,
1045 "test" => Kind::Test,
1046 "bench" => Kind::Bench,
1047 "dist" => Kind::Dist,
1050 let rules = self.rules.values().filter(|r| r.kind == kind);
1051 let rules = rules.filter(|r| !r.path.contains("nowhere"));
1052 let mut rules = rules.collect::<Vec<_>>();
1053 rules.sort_by_key(|r| r.path);
1055 let mut help_string = String::from("Available paths:\n");
1057 help_string.push_str(format!(" ./x.py {} {}\n", command, rule.path).as_str());
1062 /// Construct the top-level build steps that we're going to be executing,
1063 /// given the subcommand that our build is performing.
1064 fn plan(&self) -> Vec<Step<'a>> {
1065 // Ok, the logic here is pretty subtle, and involves quite a few
1066 // conditionals. The basic idea here is to:
1068 // 1. First, filter all our rules to the relevant ones. This means that
1069 // the command specified corresponds to one of our `Kind` variants,
1070 // and we filter all rules based on that.
1072 // 2. Next, we determine which rules we're actually executing. If a
1073 // number of path filters were specified on the command line we look
1074 // for those, otherwise we look for anything tagged `default`.
1075 // Here we also compute the priority of each rule based on how early
1076 // in the command line the matching path filter showed up.
1078 // 3. Finally, we generate some steps with host and target information.
1080 // The last step is by far the most complicated and subtle. The basic
1081 // thinking here is that we want to take the cartesian product of
1082 // specified hosts and targets and build rules with that. The list of
1083 // hosts and targets, if not specified, come from the how this build was
1084 // configured. If the rule we're looking at is a host-only rule the we
1085 // ignore the list of targets and instead consider the list of hosts
1086 // also the list of targets.
1088 // Once the host and target lists are generated we take the cartesian
1089 // product of the two and then create a step based off them. Note that
1090 // the stage each step is associated was specified with the `--step`
1091 // flag on the command line.
1092 let (kind, paths) = match self.build.flags.cmd {
1093 Subcommand::Build { ref paths } => (Kind::Build, &paths[..]),
1094 Subcommand::Doc { ref paths } => (Kind::Doc, &paths[..]),
1095 Subcommand::Test { ref paths, test_args: _ } => (Kind::Test, &paths[..]),
1096 Subcommand::Bench { ref paths, test_args: _ } => (Kind::Bench, &paths[..]),
1097 Subcommand::Dist { ref paths, install } => {
1099 return vec![self.sbuild.name("install")]
1101 (Kind::Dist, &paths[..])
1104 Subcommand::Clean => panic!(),
1107 let mut rules: Vec<_> = self.rules.values().filter_map(|rule| {
1108 if rule.kind != kind {
1112 if paths.len() == 0 && rule.default {
1115 paths.iter().position(|path| path.ends_with(rule.path))
1116 .map(|priority| (rule, priority))
1120 rules.sort_by_key(|&(_, priority)| priority);
1122 rules.into_iter().flat_map(|(rule, _)| {
1123 let hosts = if rule.only_host_build || rule.only_build {
1124 &self.build.config.host[..1]
1125 } else if self.build.flags.host.len() > 0 {
1126 &self.build.flags.host
1128 &self.build.config.host
1130 let targets = if self.build.flags.target.len() > 0 {
1131 &self.build.flags.target
1133 &self.build.config.target
1135 // Determine the actual targets participating in this rule.
1136 // NOTE: We should keep the full projection from build triple to
1137 // the hosts for the dist steps, now that the hosts array above is
1138 // truncated to avoid duplication of work in that case. Therefore
1139 // the original non-shadowed hosts array is used below.
1140 let arr = if rule.host {
1141 // If --target was specified but --host wasn't specified,
1142 // don't run any host-only tests. Also, respect any `--host`
1143 // overrides as done for `hosts`.
1144 if self.build.flags.host.len() > 0 {
1145 &self.build.flags.host[..]
1146 } else if self.build.flags.target.len() > 0 {
1148 } else if rule.only_build {
1149 &self.build.config.host[..1]
1151 &self.build.config.host[..]
1157 hosts.iter().flat_map(move |host| {
1158 arr.iter().map(move |target| {
1159 self.sbuild.name(rule.name).target(target).host(host)
1165 /// Execute all top-level targets indicated by `steps`.
1167 /// This will take the list returned by `plan` and then execute each step
1168 /// along with all required dependencies as it goes up the chain.
1169 fn run(&self, steps: &[Step<'a>]) {
1170 self.build.verbose("bootstrap top targets:");
1171 for step in steps.iter() {
1172 self.build.verbose(&format!("\t{:?}", step));
1175 // Using `steps` as the top-level targets, make a topological ordering
1176 // of what we need to do.
1177 let order = self.expand(steps);
1179 // Print out what we're doing for debugging
1180 self.build.verbose("bootstrap build plan:");
1181 for step in order.iter() {
1182 self.build.verbose(&format!("\t{:?}", step));
1185 // And finally, iterate over everything and execute it.
1186 for step in order.iter() {
1187 if self.build.flags.keep_stage.map_or(false, |s| step.stage <= s) {
1188 self.build.verbose(&format!("keeping step {:?}", step));
1191 self.build.verbose(&format!("executing step {:?}", step));
1192 (self.rules[step.name].run)(step);
1196 /// From the top level targets `steps` generate a topological ordering of
1197 /// all steps needed to run those steps.
1198 fn expand(&self, steps: &[Step<'a>]) -> Vec<Step<'a>> {
1199 // First up build a graph of steps and their dependencies. The `nodes`
1200 // map is a map from step to a unique number. The `edges` map is a
1201 // map from these unique numbers to a list of other numbers,
1202 // representing dependencies.
1203 let mut nodes = HashMap::new();
1204 nodes.insert(Step::noop(), 0);
1205 let mut edges = HashMap::new();
1206 edges.insert(0, HashSet::new());
1208 self.build_graph(step.clone(), &mut nodes, &mut edges);
1211 // Now that we've built up the actual dependency graph, draw more
1212 // dependency edges to satisfy the `after` dependencies field for each
1214 self.satisfy_after_deps(&nodes, &mut edges);
1216 // And finally, perform a topological sort to return a list of steps to
1218 let mut order = Vec::new();
1219 let mut visited = HashSet::new();
1221 let idx_to_node = nodes.iter().map(|p| (*p.1, p.0)).collect::<HashMap<_, _>>();
1222 for idx in 0..nodes.len() {
1223 self.topo_sort(idx, &idx_to_node, &edges, &mut visited, &mut order);
1228 /// Builds the dependency graph rooted at `step`.
1230 /// The `nodes` and `edges` maps are filled out according to the rule
1231 /// described by `step.name`.
1232 fn build_graph(&self,
1234 nodes: &mut HashMap<Step<'a>, usize>,
1235 edges: &mut HashMap<usize, HashSet<usize>>) -> usize {
1236 use std::collections::hash_map::Entry;
1238 let idx = nodes.len();
1239 match nodes.entry(step.clone()) {
1240 Entry::Vacant(e) => { e.insert(idx); }
1241 Entry::Occupied(e) => return *e.get(),
1244 let mut deps = Vec::new();
1245 for dep in self.rules[step.name].deps.iter() {
1246 let dep = dep(&step);
1247 if dep.name.starts_with("default:") {
1248 let kind = match &dep.name[8..] {
1250 "dist" => Kind::Dist,
1251 kind => panic!("unknown kind: `{}`", kind),
1253 let host = self.build.config.host.iter().any(|h| h == dep.target);
1254 let rules = self.rules.values().filter(|r| r.default);
1255 for rule in rules.filter(|r| r.kind == kind && (!r.host || host)) {
1256 deps.push(self.build_graph(dep.name(rule.name), nodes, edges));
1259 deps.push(self.build_graph(dep, nodes, edges));
1263 edges.entry(idx).or_insert(HashSet::new()).extend(deps);
1267 /// Given a dependency graph with a finished list of `nodes`, fill out more
1268 /// dependency `edges`.
1270 /// This is the step which satisfies all `after` listed dependencies in
1272 fn satisfy_after_deps(&self,
1273 nodes: &HashMap<Step<'a>, usize>,
1274 edges: &mut HashMap<usize, HashSet<usize>>) {
1275 // Reverse map from the name of a step to the node indices that it
1277 let mut name_to_idx = HashMap::new();
1278 for (step, &idx) in nodes {
1279 name_to_idx.entry(step.name).or_insert(Vec::new()).push(idx);
1282 for (step, idx) in nodes {
1283 if *step == Step::noop() {
1286 for after in self.rules[step.name].after.iter() {
1287 // This is the critical piece of an `after` dependency. If the
1288 // dependency isn't actually in our graph then no edge is drawn,
1289 // only if it's already present do we draw the edges.
1290 if let Some(idxs) = name_to_idx.get(after) {
1291 edges.get_mut(idx).unwrap()
1292 .extend(idxs.iter().cloned());
1300 nodes: &HashMap<usize, &Step<'a>>,
1301 edges: &HashMap<usize, HashSet<usize>>,
1302 visited: &mut HashSet<usize>,
1303 order: &mut Vec<Step<'a>>) {
1304 if !visited.insert(cur) {
1307 for dep in edges[&cur].iter() {
1308 self.topo_sort(*dep, nodes, edges, visited, order);
1310 order.push(nodes[&cur].clone());
1323 ($($a:expr),*) => (vec![$($a.to_string()),*])
1326 fn build(args: &[&str],
1327 extra_host: &[&str],
1328 extra_target: &[&str]) -> Build {
1329 let mut args = args.iter().map(|s| s.to_string()).collect::<Vec<_>>();
1330 args.push("--build".to_string());
1331 args.push("A".to_string());
1332 let flags = Flags::parse(&args);
1334 let mut config = Config::default();
1336 config.build = "A".to_string();
1337 config.host = vec![config.build.clone()];
1338 config.host.extend(extra_host.iter().map(|s| s.to_string()));
1339 config.target = config.host.clone();
1340 config.target.extend(extra_target.iter().map(|s| s.to_string()));
1342 let mut build = Build::new(flags, config);
1343 let cwd = env::current_dir().unwrap();
1344 build.crates.insert("std".to_string(), ::Crate {
1345 name: "std".to_string(),
1347 path: cwd.join("src/std"),
1348 doc_step: "doc-crate-std".to_string(),
1349 build_step: "build-crate-std".to_string(),
1350 test_step: "test-crate-std".to_string(),
1351 bench_step: "bench-crate-std".to_string(),
1352 version: String::new(),
1354 build.crates.insert("test".to_string(), ::Crate {
1355 name: "test".to_string(),
1357 path: cwd.join("src/test"),
1358 doc_step: "doc-crate-test".to_string(),
1359 build_step: "build-crate-test".to_string(),
1360 test_step: "test-crate-test".to_string(),
1361 bench_step: "bench-crate-test".to_string(),
1362 version: String::new(),
1364 build.crates.insert("rustc-main".to_string(), ::Crate {
1365 name: "rustc-main".to_string(),
1367 version: String::new(),
1368 path: cwd.join("src/rustc-main"),
1369 doc_step: "doc-crate-rustc-main".to_string(),
1370 build_step: "build-crate-rustc-main".to_string(),
1371 test_step: "test-crate-rustc-main".to_string(),
1372 bench_step: "bench-crate-rustc-main".to_string(),
1378 fn dist_baseline() {
1379 let build = build(&["dist"], &[], &[]);
1380 let rules = super::build_rules(&build);
1381 let plan = rules.plan();
1382 println!("rules: {:#?}", plan);
1383 assert!(plan.iter().all(|s| s.stage == 2));
1384 assert!(plan.iter().all(|s| s.host == "A" ));
1385 assert!(plan.iter().all(|s| s.target == "A" ));
1387 let step = super::Step {
1390 host: &build.config.build,
1391 target: &build.config.build,
1394 assert!(plan.contains(&step.name("dist-docs")));
1395 assert!(plan.contains(&step.name("dist-mingw")));
1396 assert!(plan.contains(&step.name("dist-rustc")));
1397 assert!(plan.contains(&step.name("dist-std")));
1398 assert!(plan.contains(&step.name("dist-src")));
1402 fn dist_with_targets() {
1403 let build = build(&["dist"], &[], &["B"]);
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" ));
1410 let step = super::Step {
1413 host: &build.config.build,
1414 target: &build.config.build,
1417 assert!(plan.contains(&step.name("dist-docs")));
1418 assert!(plan.contains(&step.name("dist-mingw")));
1419 assert!(plan.contains(&step.name("dist-rustc")));
1420 assert!(plan.contains(&step.name("dist-std")));
1421 assert!(plan.contains(&step.name("dist-src")));
1423 assert!(plan.contains(&step.target("B").name("dist-docs")));
1424 assert!(plan.contains(&step.target("B").name("dist-mingw")));
1425 assert!(!plan.contains(&step.target("B").name("dist-rustc")));
1426 assert!(plan.contains(&step.target("B").name("dist-std")));
1427 assert!(!plan.contains(&step.target("B").name("dist-src")));
1431 fn dist_with_hosts() {
1432 let build = build(&["dist"], &["B"], &[]);
1433 let rules = super::build_rules(&build);
1434 let plan = rules.plan();
1435 println!("rules: {:#?}", plan);
1436 assert!(plan.iter().all(|s| s.stage == 2));
1438 let step = super::Step {
1441 host: &build.config.build,
1442 target: &build.config.build,
1445 assert!(!plan.iter().any(|s| s.host == "B"));
1447 assert!(plan.contains(&step.name("dist-docs")));
1448 assert!(plan.contains(&step.name("dist-mingw")));
1449 assert!(plan.contains(&step.name("dist-rustc")));
1450 assert!(plan.contains(&step.name("dist-std")));
1451 assert!(plan.contains(&step.name("dist-src")));
1453 assert!(plan.contains(&step.target("B").name("dist-docs")));
1454 assert!(plan.contains(&step.target("B").name("dist-mingw")));
1455 assert!(plan.contains(&step.target("B").name("dist-rustc")));
1456 assert!(plan.contains(&step.target("B").name("dist-std")));
1457 assert!(!plan.contains(&step.target("B").name("dist-src")));
1461 fn dist_with_targets_and_hosts() {
1462 let build = build(&["dist"], &["B"], &["C"]);
1463 let rules = super::build_rules(&build);
1464 let plan = rules.plan();
1465 println!("rules: {:#?}", plan);
1466 assert!(plan.iter().all(|s| s.stage == 2));
1468 let step = super::Step {
1471 host: &build.config.build,
1472 target: &build.config.build,
1475 assert!(!plan.iter().any(|s| s.host == "B"));
1476 assert!(!plan.iter().any(|s| s.host == "C"));
1478 assert!(plan.contains(&step.name("dist-docs")));
1479 assert!(plan.contains(&step.name("dist-mingw")));
1480 assert!(plan.contains(&step.name("dist-rustc")));
1481 assert!(plan.contains(&step.name("dist-std")));
1482 assert!(plan.contains(&step.name("dist-src")));
1484 assert!(plan.contains(&step.target("B").name("dist-docs")));
1485 assert!(plan.contains(&step.target("B").name("dist-mingw")));
1486 assert!(plan.contains(&step.target("B").name("dist-rustc")));
1487 assert!(plan.contains(&step.target("B").name("dist-std")));
1488 assert!(!plan.contains(&step.target("B").name("dist-src")));
1490 assert!(plan.contains(&step.target("C").name("dist-docs")));
1491 assert!(plan.contains(&step.target("C").name("dist-mingw")));
1492 assert!(!plan.contains(&step.target("C").name("dist-rustc")));
1493 assert!(plan.contains(&step.target("C").name("dist-std")));
1494 assert!(!plan.contains(&step.target("C").name("dist-src")));
1498 fn dist_target_with_target_flag() {
1499 let build = build(&["dist", "--target=C"], &["B"], &["C"]);
1500 let rules = super::build_rules(&build);
1501 let plan = rules.plan();
1502 println!("rules: {:#?}", plan);
1503 assert!(plan.iter().all(|s| s.stage == 2));
1505 let step = super::Step {
1508 host: &build.config.build,
1509 target: &build.config.build,
1512 assert!(!plan.iter().any(|s| s.target == "A"));
1513 assert!(!plan.iter().any(|s| s.target == "B"));
1514 assert!(!plan.iter().any(|s| s.host == "B"));
1515 assert!(!plan.iter().any(|s| s.host == "C"));
1517 assert!(plan.contains(&step.target("C").name("dist-docs")));
1518 assert!(plan.contains(&step.target("C").name("dist-mingw")));
1519 assert!(!plan.contains(&step.target("C").name("dist-rustc")));
1520 assert!(plan.contains(&step.target("C").name("dist-std")));
1521 assert!(!plan.contains(&step.target("C").name("dist-src")));
1525 fn dist_host_with_target_flag() {
1526 let build = build(&["dist", "--host=B", "--target=B"], &["B"], &["C"]);
1527 let rules = super::build_rules(&build);
1528 let plan = rules.plan();
1529 println!("rules: {:#?}", plan);
1530 assert!(plan.iter().all(|s| s.stage == 2));
1532 let step = super::Step {
1535 host: &build.config.build,
1536 target: &build.config.build,
1539 assert!(!plan.iter().any(|s| s.target == "A"));
1540 assert!(!plan.iter().any(|s| s.target == "C"));
1541 assert!(!plan.iter().any(|s| s.host == "B"));
1542 assert!(!plan.iter().any(|s| s.host == "C"));
1544 assert!(plan.contains(&step.target("B").name("dist-docs")));
1545 assert!(plan.contains(&step.target("B").name("dist-mingw")));
1546 assert!(plan.contains(&step.target("B").name("dist-rustc")));
1547 assert!(plan.contains(&step.target("B").name("dist-std")));
1548 assert!(plan.contains(&step.target("B").name("dist-src")));
1550 let all = rules.expand(&plan);
1551 println!("all rules: {:#?}", all);
1552 assert!(!all.contains(&step.name("rustc")));
1553 assert!(!all.contains(&step.name("build-crate-test").stage(1)));
1555 // all stage0 compiles should be for the build target, A
1556 for step in all.iter().filter(|s| s.stage == 0) {
1557 if !step.name.contains("build-crate") {
1560 println!("step: {:?}", step);
1561 assert!(step.host != "B");
1562 assert!(step.target != "B");
1563 assert!(step.host != "C");
1564 assert!(step.target != "C");
1569 fn build_default() {
1570 let build = build(&["build"], &["B"], &["C"]);
1571 let rules = super::build_rules(&build);
1572 let plan = rules.plan();
1573 println!("rules: {:#?}", plan);
1574 assert!(plan.iter().all(|s| s.stage == 2));
1576 let step = super::Step {
1579 host: &build.config.build,
1580 target: &build.config.build,
1583 // rustc built for all for of (A, B) x (A, B)
1584 assert!(plan.contains(&step.name("librustc")));
1585 assert!(plan.contains(&step.target("B").name("librustc")));
1586 assert!(plan.contains(&step.host("B").target("A").name("librustc")));
1587 assert!(plan.contains(&step.host("B").target("B").name("librustc")));
1589 // rustc never built for C
1590 assert!(!plan.iter().any(|s| {
1591 s.name.contains("rustc") && (s.host == "C" || s.target == "C")
1594 // test built for everything
1595 assert!(plan.contains(&step.name("libtest")));
1596 assert!(plan.contains(&step.target("B").name("libtest")));
1597 assert!(plan.contains(&step.host("B").target("A").name("libtest")));
1598 assert!(plan.contains(&step.host("B").target("B").name("libtest")));
1599 assert!(plan.contains(&step.host("A").target("C").name("libtest")));
1600 assert!(plan.contains(&step.host("B").target("C").name("libtest")));
1602 let all = rules.expand(&plan);
1603 println!("all rules: {:#?}", all);
1604 assert!(all.contains(&step.name("rustc")));
1605 assert!(all.contains(&step.name("libstd")));
1609 fn build_filtered() {
1610 let build = build(&["build", "--target=C"], &["B"], &["C"]);
1611 let rules = super::build_rules(&build);
1612 let plan = rules.plan();
1613 println!("rules: {:#?}", plan);
1614 assert!(plan.iter().all(|s| s.stage == 2));
1616 assert!(!plan.iter().any(|s| s.name.contains("rustc")));
1617 assert!(plan.iter().all(|s| {
1618 !s.name.contains("test") || s.target == "C"
1624 let build = build(&["test"], &[], &[]);
1625 let rules = super::build_rules(&build);
1626 let plan = rules.plan();
1627 println!("rules: {:#?}", plan);
1628 assert!(plan.iter().all(|s| s.stage == 2));
1629 assert!(plan.iter().all(|s| s.host == "A"));
1630 assert!(plan.iter().all(|s| s.target == "A"));
1632 assert!(plan.iter().any(|s| s.name.contains("-ui")));
1633 assert!(plan.iter().any(|s| s.name.contains("cfail")));
1634 assert!(plan.iter().any(|s| s.name.contains("cfail-full")));
1635 assert!(plan.iter().any(|s| s.name.contains("codegen-units")));
1636 assert!(plan.iter().any(|s| s.name.contains("debuginfo")));
1637 assert!(plan.iter().any(|s| s.name.contains("docs")));
1638 assert!(plan.iter().any(|s| s.name.contains("error-index")));
1639 assert!(plan.iter().any(|s| s.name.contains("incremental")));
1640 assert!(plan.iter().any(|s| s.name.contains("linkchecker")));
1641 assert!(plan.iter().any(|s| s.name.contains("mir-opt")));
1642 assert!(plan.iter().any(|s| s.name.contains("pfail")));
1643 assert!(plan.iter().any(|s| s.name.contains("rfail")));
1644 assert!(plan.iter().any(|s| s.name.contains("rfail-full")));
1645 assert!(plan.iter().any(|s| s.name.contains("rmake")));
1646 assert!(plan.iter().any(|s| s.name.contains("rpass")));
1647 assert!(plan.iter().any(|s| s.name.contains("rpass-full")));
1648 assert!(plan.iter().any(|s| s.name.contains("rustc-all")));
1649 assert!(plan.iter().any(|s| s.name.contains("rustdoc")));
1650 assert!(plan.iter().any(|s| s.name.contains("std-all")));
1651 assert!(plan.iter().any(|s| s.name.contains("test-all")));
1652 assert!(plan.iter().any(|s| s.name.contains("tidy")));
1653 assert!(plan.iter().any(|s| s.name.contains("valgrind")));
1657 fn test_with_a_target() {
1658 let build = build(&["test", "--target=C"], &[], &["C"]);
1659 let rules = super::build_rules(&build);
1660 let plan = rules.plan();
1661 println!("rules: {:#?}", plan);
1662 assert!(plan.iter().all(|s| s.stage == 2));
1663 assert!(plan.iter().all(|s| s.host == "A"));
1664 assert!(plan.iter().all(|s| s.target == "C"));
1666 assert!(plan.iter().any(|s| s.name.contains("-ui")));
1667 assert!(!plan.iter().any(|s| s.name.contains("ui-full")));
1668 assert!(plan.iter().any(|s| s.name.contains("cfail")));
1669 assert!(!plan.iter().any(|s| s.name.contains("cfail-full")));
1670 assert!(plan.iter().any(|s| s.name.contains("codegen-units")));
1671 assert!(plan.iter().any(|s| s.name.contains("debuginfo")));
1672 assert!(!plan.iter().any(|s| s.name.contains("docs")));
1673 assert!(!plan.iter().any(|s| s.name.contains("error-index")));
1674 assert!(plan.iter().any(|s| s.name.contains("incremental")));
1675 assert!(!plan.iter().any(|s| s.name.contains("linkchecker")));
1676 assert!(plan.iter().any(|s| s.name.contains("mir-opt")));
1677 assert!(plan.iter().any(|s| s.name.contains("pfail")));
1678 assert!(plan.iter().any(|s| s.name.contains("rfail")));
1679 assert!(!plan.iter().any(|s| s.name.contains("rfail-full")));
1680 assert!(!plan.iter().any(|s| s.name.contains("rmake")));
1681 assert!(plan.iter().any(|s| s.name.contains("rpass")));
1682 assert!(!plan.iter().any(|s| s.name.contains("rpass-full")));
1683 assert!(!plan.iter().any(|s| s.name.contains("rustc-all")));
1684 assert!(!plan.iter().any(|s| s.name.contains("rustdoc")));
1685 assert!(plan.iter().any(|s| s.name.contains("std-all")));
1686 assert!(plan.iter().any(|s| s.name.contains("test-all")));
1687 assert!(!plan.iter().any(|s| s.name.contains("tidy")));
1688 assert!(plan.iter().any(|s| s.name.contains("valgrind")));