]> git.lizzy.rs Git - rust.git/blob - src/bootstrap/config.rs
3eb6e8d84e877fdfe8a4665b72718a7141b8498d
[rust.git] / src / bootstrap / config.rs
1 // Copyright 2015 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.
4 //
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.
10
11 //! Serialized configuration of a build.
12 //!
13 //! This module implements parsing `config.toml` configuration files to tweak
14 //! how the build runs.
15
16 use std::collections::{HashMap, HashSet};
17 use std::env;
18 use std::fs::{self, File};
19 use std::io::prelude::*;
20 use std::path::{Path, PathBuf};
21 use std::process;
22 use std::cmp;
23
24 use num_cpus;
25 use toml;
26 use cache::{INTERNER, Interned};
27 use flags::Flags;
28 pub use flags::Subcommand;
29
30 /// Global configuration for the entire build and/or bootstrap.
31 ///
32 /// This structure is derived from a combination of both `config.toml` and
33 /// `config.mk`. As of the time of this writing it's unlikely that `config.toml`
34 /// is used all that much, so this is primarily filled out by `config.mk` which
35 /// is generated from `./configure`.
36 ///
37 /// Note that this structure is not decoded directly into, but rather it is
38 /// filled out from the decoded forms of the structs below. For documentation
39 /// each field, see the corresponding fields in
40 /// `config.toml.example`.
41 #[derive(Default)]
42 pub struct Config {
43     pub ccache: Option<String>,
44     pub ninja: bool,
45     pub verbose: usize,
46     pub submodules: bool,
47     pub fast_submodules: bool,
48     pub compiler_docs: bool,
49     pub docs: bool,
50     pub locked_deps: bool,
51     pub vendor: bool,
52     pub target_config: HashMap<Interned<String>, Target>,
53     pub full_bootstrap: bool,
54     pub extended: bool,
55     pub tools: Option<HashSet<String>>,
56     pub sanitizers: bool,
57     pub profiler: bool,
58     pub ignore_git: bool,
59     pub exclude: Vec<PathBuf>,
60     pub rustc_error_format: Option<String>,
61
62     pub run_host_only: bool,
63
64     pub on_fail: Option<String>,
65     pub stage: Option<u32>,
66     pub keep_stage: Vec<u32>,
67     pub src: PathBuf,
68     pub jobs: Option<u32>,
69     pub cmd: Subcommand,
70     pub incremental: bool,
71     pub dry_run: bool,
72
73     pub deny_warnings: bool,
74     pub backtrace_on_ice: bool,
75
76     // llvm codegen options
77     pub llvm_enabled: bool,
78     pub llvm_assertions: bool,
79     pub llvm_optimize: bool,
80     pub llvm_thin_lto: bool,
81     pub llvm_release_debuginfo: bool,
82     pub llvm_version_check: bool,
83     pub llvm_static_stdcpp: bool,
84     pub llvm_link_shared: bool,
85     pub llvm_clang_cl: Option<String>,
86     pub llvm_targets: Option<String>,
87     pub llvm_experimental_targets: String,
88     pub llvm_link_jobs: Option<u32>,
89     pub llvm_version_suffix: Option<String>,
90
91     pub lld_enabled: bool,
92     pub lldb_enabled: bool,
93     pub llvm_tools_enabled: bool,
94
95     // rust codegen options
96     pub rust_optimize: bool,
97     pub rust_codegen_units: Option<u32>,
98     pub rust_codegen_units_std: Option<u32>,
99     pub rust_debug_assertions: bool,
100     pub rust_debuginfo: bool,
101     pub rust_debuginfo_lines: bool,
102     pub rust_debuginfo_only_std: bool,
103     pub rust_debuginfo_tools: bool,
104     pub rust_rpath: bool,
105     pub rustc_parallel_queries: bool,
106     pub rustc_default_linker: Option<String>,
107     pub rust_optimize_tests: bool,
108     pub rust_debuginfo_tests: bool,
109     pub rust_dist_src: bool,
110     pub rust_codegen_backends: Vec<Interned<String>>,
111     pub rust_codegen_backends_dir: String,
112     pub rust_verify_llvm_ir: bool,
113     pub rust_remap_debuginfo: bool,
114
115     pub build: Interned<String>,
116     pub hosts: Vec<Interned<String>>,
117     pub targets: Vec<Interned<String>>,
118     pub local_rebuild: bool,
119
120     // dist misc
121     pub dist_sign_folder: Option<PathBuf>,
122     pub dist_upload_addr: Option<String>,
123     pub dist_gpg_password_file: Option<PathBuf>,
124
125     // libstd features
126     pub debug_jemalloc: bool,
127     pub use_jemalloc: bool,
128     pub backtrace: bool, // support for RUST_BACKTRACE
129     pub wasm_syscall: bool,
130
131     // misc
132     pub low_priority: bool,
133     pub channel: String,
134     pub verbose_tests: bool,
135     pub test_miri: bool,
136     pub save_toolstates: Option<PathBuf>,
137     pub print_step_timings: bool,
138     pub missing_tools: bool,
139
140     // Fallback musl-root for all targets
141     pub musl_root: Option<PathBuf>,
142     pub prefix: Option<PathBuf>,
143     pub sysconfdir: Option<PathBuf>,
144     pub datadir: Option<PathBuf>,
145     pub docdir: Option<PathBuf>,
146     pub bindir: Option<PathBuf>,
147     pub libdir: Option<PathBuf>,
148     pub mandir: Option<PathBuf>,
149     pub codegen_tests: bool,
150     pub nodejs: Option<PathBuf>,
151     pub gdb: Option<PathBuf>,
152     pub python: Option<PathBuf>,
153     pub cargo_native_static: bool,
154     pub configure_args: Vec<String>,
155
156     // These are either the stage0 downloaded binaries or the locally installed ones.
157     pub initial_cargo: PathBuf,
158     pub initial_rustc: PathBuf,
159     pub out: PathBuf,
160 }
161
162 /// Per-target configuration stored in the global configuration structure.
163 #[derive(Default)]
164 pub struct Target {
165     /// Some(path to llvm-config) if using an external LLVM.
166     pub llvm_config: Option<PathBuf>,
167     /// Some(path to FileCheck) if one was specified.
168     pub llvm_filecheck: Option<PathBuf>,
169     pub jemalloc: Option<PathBuf>,
170     pub cc: Option<PathBuf>,
171     pub cxx: Option<PathBuf>,
172     pub ar: Option<PathBuf>,
173     pub ranlib: Option<PathBuf>,
174     pub linker: Option<PathBuf>,
175     pub ndk: Option<PathBuf>,
176     pub crt_static: Option<bool>,
177     pub musl_root: Option<PathBuf>,
178     pub qemu_rootfs: Option<PathBuf>,
179     pub no_std: bool,
180 }
181
182 /// Structure of the `config.toml` file that configuration is read from.
183 ///
184 /// This structure uses `Decodable` to automatically decode a TOML configuration
185 /// file into this format, and then this is traversed and written into the above
186 /// `Config` structure.
187 #[derive(Deserialize, Default)]
188 #[serde(deny_unknown_fields, rename_all = "kebab-case")]
189 struct TomlConfig {
190     build: Option<Build>,
191     install: Option<Install>,
192     llvm: Option<Llvm>,
193     rust: Option<Rust>,
194     target: Option<HashMap<String, TomlTarget>>,
195     dist: Option<Dist>,
196 }
197
198 /// TOML representation of various global build decisions.
199 #[derive(Deserialize, Default, Clone)]
200 #[serde(deny_unknown_fields, rename_all = "kebab-case")]
201 struct Build {
202     build: Option<String>,
203     #[serde(default)]
204     host: Vec<String>,
205     #[serde(default)]
206     target: Vec<String>,
207     cargo: Option<String>,
208     rustc: Option<String>,
209     low_priority: Option<bool>,
210     compiler_docs: Option<bool>,
211     docs: Option<bool>,
212     submodules: Option<bool>,
213     fast_submodules: Option<bool>,
214     gdb: Option<String>,
215     locked_deps: Option<bool>,
216     vendor: Option<bool>,
217     nodejs: Option<String>,
218     python: Option<String>,
219     full_bootstrap: Option<bool>,
220     extended: Option<bool>,
221     tools: Option<HashSet<String>>,
222     verbose: Option<usize>,
223     sanitizers: Option<bool>,
224     profiler: Option<bool>,
225     cargo_native_static: Option<bool>,
226     configure_args: Option<Vec<String>>,
227     local_rebuild: Option<bool>,
228     print_step_timings: Option<bool>,
229 }
230
231 /// TOML representation of various global install decisions.
232 #[derive(Deserialize, Default, Clone)]
233 #[serde(deny_unknown_fields, rename_all = "kebab-case")]
234 struct Install {
235     prefix: Option<String>,
236     sysconfdir: Option<String>,
237     datadir: Option<String>,
238     docdir: Option<String>,
239     bindir: Option<String>,
240     libdir: Option<String>,
241     mandir: Option<String>,
242
243     // standard paths, currently unused
244     infodir: Option<String>,
245     localstatedir: Option<String>,
246 }
247
248 /// TOML representation of how the LLVM build is configured.
249 #[derive(Deserialize, Default)]
250 #[serde(deny_unknown_fields, rename_all = "kebab-case")]
251 struct Llvm {
252     enabled: Option<bool>,
253     ccache: Option<StringOrBool>,
254     ninja: Option<bool>,
255     assertions: Option<bool>,
256     optimize: Option<bool>,
257     thin_lto: Option<bool>,
258     release_debuginfo: Option<bool>,
259     version_check: Option<bool>,
260     static_libstdcpp: Option<bool>,
261     targets: Option<String>,
262     experimental_targets: Option<String>,
263     link_jobs: Option<u32>,
264     link_shared: Option<bool>,
265     version_suffix: Option<String>,
266     clang_cl: Option<String>
267 }
268
269 #[derive(Deserialize, Default, Clone)]
270 #[serde(deny_unknown_fields, rename_all = "kebab-case")]
271 struct Dist {
272     sign_folder: Option<String>,
273     gpg_password_file: Option<String>,
274     upload_addr: Option<String>,
275     src_tarball: Option<bool>,
276     missing_tools: Option<bool>,
277 }
278
279 #[derive(Deserialize)]
280 #[serde(untagged)]
281 enum StringOrBool {
282     String(String),
283     Bool(bool),
284 }
285
286 impl Default for StringOrBool {
287     fn default() -> StringOrBool {
288         StringOrBool::Bool(false)
289     }
290 }
291
292 /// TOML representation of how the Rust build is configured.
293 #[derive(Deserialize, Default)]
294 #[serde(deny_unknown_fields, rename_all = "kebab-case")]
295 struct Rust {
296     optimize: Option<bool>,
297     codegen_units: Option<u32>,
298     codegen_units_std: Option<u32>,
299     debug_assertions: Option<bool>,
300     debuginfo: Option<bool>,
301     debuginfo_lines: Option<bool>,
302     debuginfo_only_std: Option<bool>,
303     debuginfo_tools: Option<bool>,
304     experimental_parallel_queries: Option<bool>,
305     debug_jemalloc: Option<bool>,
306     use_jemalloc: Option<bool>,
307     backtrace: Option<bool>,
308     default_linker: Option<String>,
309     channel: Option<String>,
310     musl_root: Option<String>,
311     rpath: Option<bool>,
312     optimize_tests: Option<bool>,
313     debuginfo_tests: Option<bool>,
314     codegen_tests: Option<bool>,
315     ignore_git: Option<bool>,
316     debug: Option<bool>,
317     dist_src: Option<bool>,
318     verbose_tests: Option<bool>,
319     test_miri: Option<bool>,
320     incremental: Option<bool>,
321     save_toolstates: Option<String>,
322     codegen_backends: Option<Vec<String>>,
323     codegen_backends_dir: Option<String>,
324     wasm_syscall: Option<bool>,
325     lld: Option<bool>,
326     lldb: Option<bool>,
327     llvm_tools: Option<bool>,
328     deny_warnings: Option<bool>,
329     backtrace_on_ice: Option<bool>,
330     verify_llvm_ir: Option<bool>,
331     remap_debuginfo: Option<bool>,
332 }
333
334 /// TOML representation of how each build target is configured.
335 #[derive(Deserialize, Default)]
336 #[serde(deny_unknown_fields, rename_all = "kebab-case")]
337 struct TomlTarget {
338     llvm_config: Option<String>,
339     llvm_filecheck: Option<String>,
340     jemalloc: Option<String>,
341     cc: Option<String>,
342     cxx: Option<String>,
343     ar: Option<String>,
344     ranlib: Option<String>,
345     linker: Option<String>,
346     android_ndk: Option<String>,
347     crt_static: Option<bool>,
348     musl_root: Option<String>,
349     qemu_rootfs: Option<String>,
350 }
351
352 impl Config {
353     fn path_from_python(var_key: &str) -> PathBuf {
354         match env::var_os(var_key) {
355             // Do not trust paths from Python and normalize them slightly (#49785).
356             Some(var_val) => Path::new(&var_val).components().collect(),
357             _ => panic!("expected '{}' to be set", var_key),
358         }
359     }
360
361     pub fn default_opts() -> Config {
362         let mut config = Config::default();
363         config.llvm_enabled = true;
364         config.llvm_optimize = true;
365         config.llvm_version_check = true;
366         config.use_jemalloc = true;
367         config.backtrace = true;
368         config.rust_optimize = true;
369         config.rust_optimize_tests = true;
370         config.submodules = true;
371         config.fast_submodules = true;
372         config.docs = true;
373         config.rust_rpath = true;
374         config.channel = "dev".to_string();
375         config.codegen_tests = true;
376         config.ignore_git = false;
377         config.rust_dist_src = true;
378         config.test_miri = false;
379         config.rust_codegen_backends = vec![INTERNER.intern_str("llvm")];
380         config.rust_codegen_backends_dir = "codegen-backends".to_owned();
381         config.deny_warnings = true;
382         config.missing_tools = false;
383
384         // set by bootstrap.py
385         config.build = INTERNER.intern_str(&env::var("BUILD").expect("'BUILD' to be set"));
386         config.src = Config::path_from_python("SRC");
387         config.out = Config::path_from_python("BUILD_DIR");
388
389         config.initial_rustc = Config::path_from_python("RUSTC");
390         config.initial_cargo = Config::path_from_python("CARGO");
391
392         config
393     }
394
395     pub fn parse(args: &[String]) -> Config {
396         let flags = Flags::parse(&args);
397         let file = flags.config.clone();
398         let mut config = Config::default_opts();
399         config.exclude = flags.exclude;
400         config.rustc_error_format = flags.rustc_error_format;
401         config.on_fail = flags.on_fail;
402         config.stage = flags.stage;
403         config.jobs = flags.jobs;
404         config.cmd = flags.cmd;
405         config.incremental = flags.incremental;
406         config.dry_run = flags.dry_run;
407         config.keep_stage = flags.keep_stage;
408         if let Some(value) = flags.warnings {
409             config.deny_warnings = value;
410         }
411
412         if config.dry_run {
413             let dir = config.out.join("tmp-dry-run");
414             t!(fs::create_dir_all(&dir));
415             config.out = dir;
416         }
417
418         // If --target was specified but --host wasn't specified, don't run any host-only tests.
419         config.run_host_only = !(flags.host.is_empty() && !flags.target.is_empty());
420
421         let toml = file.map(|file| {
422             let mut f = t!(File::open(&file));
423             let mut contents = String::new();
424             t!(f.read_to_string(&mut contents));
425             match toml::from_str(&contents) {
426                 Ok(table) => table,
427                 Err(err) => {
428                     println!("failed to parse TOML configuration '{}': {}",
429                         file.display(), err);
430                     process::exit(2);
431                 }
432             }
433         }).unwrap_or_else(|| TomlConfig::default());
434
435         let build = toml.build.clone().unwrap_or_default();
436         // set by bootstrap.py
437         config.hosts.push(config.build.clone());
438         for host in build.host.iter() {
439             let host = INTERNER.intern_str(host);
440             if !config.hosts.contains(&host) {
441                 config.hosts.push(host);
442             }
443         }
444         for target in config.hosts.iter().cloned()
445             .chain(build.target.iter().map(|s| INTERNER.intern_str(s)))
446         {
447             if !config.targets.contains(&target) {
448                 config.targets.push(target);
449             }
450         }
451         config.hosts = if !flags.host.is_empty() {
452             flags.host
453         } else {
454             config.hosts
455         };
456         config.targets = if !flags.target.is_empty() {
457             flags.target
458         } else {
459             config.targets
460         };
461
462
463         config.nodejs = build.nodejs.map(PathBuf::from);
464         config.gdb = build.gdb.map(PathBuf::from);
465         config.python = build.python.map(PathBuf::from);
466         set(&mut config.low_priority, build.low_priority);
467         set(&mut config.compiler_docs, build.compiler_docs);
468         set(&mut config.docs, build.docs);
469         set(&mut config.submodules, build.submodules);
470         set(&mut config.fast_submodules, build.fast_submodules);
471         set(&mut config.locked_deps, build.locked_deps);
472         set(&mut config.vendor, build.vendor);
473         set(&mut config.full_bootstrap, build.full_bootstrap);
474         set(&mut config.extended, build.extended);
475         config.tools = build.tools;
476         set(&mut config.verbose, build.verbose);
477         set(&mut config.sanitizers, build.sanitizers);
478         set(&mut config.profiler, build.profiler);
479         set(&mut config.cargo_native_static, build.cargo_native_static);
480         set(&mut config.configure_args, build.configure_args);
481         set(&mut config.local_rebuild, build.local_rebuild);
482         set(&mut config.print_step_timings, build.print_step_timings);
483         config.verbose = cmp::max(config.verbose, flags.verbose);
484
485         if let Some(ref install) = toml.install {
486             config.prefix = install.prefix.clone().map(PathBuf::from);
487             config.sysconfdir = install.sysconfdir.clone().map(PathBuf::from);
488             config.datadir = install.datadir.clone().map(PathBuf::from);
489             config.docdir = install.docdir.clone().map(PathBuf::from);
490             config.bindir = install.bindir.clone().map(PathBuf::from);
491             config.libdir = install.libdir.clone().map(PathBuf::from);
492             config.mandir = install.mandir.clone().map(PathBuf::from);
493         }
494
495         // Store off these values as options because if they're not provided
496         // we'll infer default values for them later
497         let mut llvm_assertions = None;
498         let mut debuginfo_lines = None;
499         let mut debuginfo_only_std = None;
500         let mut debuginfo_tools = None;
501         let mut debug = None;
502         let mut debug_jemalloc = None;
503         let mut debuginfo = None;
504         let mut debug_assertions = None;
505         let mut optimize = None;
506         let mut ignore_git = None;
507
508         if let Some(ref llvm) = toml.llvm {
509             match llvm.ccache {
510                 Some(StringOrBool::String(ref s)) => {
511                     config.ccache = Some(s.to_string())
512                 }
513                 Some(StringOrBool::Bool(true)) => {
514                     config.ccache = Some("ccache".to_string());
515                 }
516                 Some(StringOrBool::Bool(false)) | None => {}
517             }
518             set(&mut config.ninja, llvm.ninja);
519             set(&mut config.llvm_enabled, llvm.enabled);
520             llvm_assertions = llvm.assertions;
521             set(&mut config.llvm_optimize, llvm.optimize);
522             set(&mut config.llvm_thin_lto, llvm.thin_lto);
523             set(&mut config.llvm_release_debuginfo, llvm.release_debuginfo);
524             set(&mut config.llvm_version_check, llvm.version_check);
525             set(&mut config.llvm_static_stdcpp, llvm.static_libstdcpp);
526             set(&mut config.llvm_link_shared, llvm.link_shared);
527             config.llvm_targets = llvm.targets.clone();
528             config.llvm_experimental_targets = llvm.experimental_targets.clone()
529                 .unwrap_or_else(|| "WebAssembly;RISCV".to_string());
530             config.llvm_link_jobs = llvm.link_jobs;
531             config.llvm_version_suffix = llvm.version_suffix.clone();
532             config.llvm_clang_cl = llvm.clang_cl.clone();
533         }
534
535         if let Some(ref rust) = toml.rust {
536             debug = rust.debug;
537             debug_assertions = rust.debug_assertions;
538             debuginfo = rust.debuginfo;
539             debuginfo_lines = rust.debuginfo_lines;
540             debuginfo_only_std = rust.debuginfo_only_std;
541             debuginfo_tools = rust.debuginfo_tools;
542             optimize = rust.optimize;
543             ignore_git = rust.ignore_git;
544             debug_jemalloc = rust.debug_jemalloc;
545             set(&mut config.rust_optimize_tests, rust.optimize_tests);
546             set(&mut config.rust_debuginfo_tests, rust.debuginfo_tests);
547             set(&mut config.codegen_tests, rust.codegen_tests);
548             set(&mut config.rust_rpath, rust.rpath);
549             set(&mut config.use_jemalloc, rust.use_jemalloc);
550             set(&mut config.backtrace, rust.backtrace);
551             set(&mut config.channel, rust.channel.clone());
552             set(&mut config.rust_dist_src, rust.dist_src);
553             set(&mut config.verbose_tests, rust.verbose_tests);
554             set(&mut config.test_miri, rust.test_miri);
555             // in the case "false" is set explicitly, do not overwrite the command line args
556             if let Some(true) = rust.incremental {
557                 config.incremental = true;
558             }
559             set(&mut config.wasm_syscall, rust.wasm_syscall);
560             set(&mut config.lld_enabled, rust.lld);
561             set(&mut config.lldb_enabled, rust.lldb);
562             set(&mut config.llvm_tools_enabled, rust.llvm_tools);
563             config.rustc_parallel_queries = rust.experimental_parallel_queries.unwrap_or(false);
564             config.rustc_default_linker = rust.default_linker.clone();
565             config.musl_root = rust.musl_root.clone().map(PathBuf::from);
566             config.save_toolstates = rust.save_toolstates.clone().map(PathBuf::from);
567             set(&mut config.deny_warnings, rust.deny_warnings.or(flags.warnings));
568             set(&mut config.backtrace_on_ice, rust.backtrace_on_ice);
569             set(&mut config.rust_verify_llvm_ir, rust.verify_llvm_ir);
570             set(&mut config.rust_remap_debuginfo, rust.remap_debuginfo);
571
572             if let Some(ref backends) = rust.codegen_backends {
573                 config.rust_codegen_backends = backends.iter()
574                     .map(|s| INTERNER.intern_str(s))
575                     .collect();
576             }
577
578             set(&mut config.rust_codegen_backends_dir, rust.codegen_backends_dir.clone());
579
580             match rust.codegen_units {
581                 Some(0) => config.rust_codegen_units = Some(num_cpus::get() as u32),
582                 Some(n) => config.rust_codegen_units = Some(n),
583                 None => {}
584             }
585
586             config.rust_codegen_units_std = rust.codegen_units_std;
587         }
588
589         if let Some(ref t) = toml.target {
590             for (triple, cfg) in t {
591                 let mut target = Target::default();
592
593                 if let Some(ref s) = cfg.llvm_config {
594                     target.llvm_config = Some(config.src.join(s));
595                 }
596                 if let Some(ref s) = cfg.llvm_filecheck {
597                     target.llvm_filecheck = Some(config.src.join(s));
598                 }
599                 if let Some(ref s) = cfg.jemalloc {
600                     target.jemalloc = Some(config.src.join(s));
601                 }
602                 if let Some(ref s) = cfg.android_ndk {
603                     target.ndk = Some(config.src.join(s));
604                 }
605                 target.cc = cfg.cc.clone().map(PathBuf::from);
606                 target.cxx = cfg.cxx.clone().map(PathBuf::from);
607                 target.ar = cfg.ar.clone().map(PathBuf::from);
608                 target.ranlib = cfg.ranlib.clone().map(PathBuf::from);
609                 target.linker = cfg.linker.clone().map(PathBuf::from);
610                 target.crt_static = cfg.crt_static.clone();
611                 target.musl_root = cfg.musl_root.clone().map(PathBuf::from);
612                 target.qemu_rootfs = cfg.qemu_rootfs.clone().map(PathBuf::from);
613
614                 config.target_config.insert(INTERNER.intern_string(triple.clone()), target);
615             }
616         }
617
618         if let Some(ref t) = toml.dist {
619             config.dist_sign_folder = t.sign_folder.clone().map(PathBuf::from);
620             config.dist_gpg_password_file = t.gpg_password_file.clone().map(PathBuf::from);
621             config.dist_upload_addr = t.upload_addr.clone();
622             set(&mut config.rust_dist_src, t.src_tarball);
623             set(&mut config.missing_tools, t.missing_tools);
624         }
625
626         // Now that we've reached the end of our configuration, infer the
627         // default values for all options that we haven't otherwise stored yet.
628
629         set(&mut config.initial_rustc, build.rustc.map(PathBuf::from));
630         set(&mut config.initial_cargo, build.cargo.map(PathBuf::from));
631
632         let default = false;
633         config.llvm_assertions = llvm_assertions.unwrap_or(default);
634
635         let default = true;
636         config.rust_optimize = optimize.unwrap_or(default);
637
638         let default = match &config.channel[..] {
639             "stable" | "beta" | "nightly" => true,
640             _ => false,
641         };
642         config.rust_debuginfo_lines = debuginfo_lines.unwrap_or(default);
643         config.rust_debuginfo_only_std = debuginfo_only_std.unwrap_or(default);
644         config.rust_debuginfo_tools = debuginfo_tools.unwrap_or(false);
645
646         let default = debug == Some(true);
647         config.debug_jemalloc = debug_jemalloc.unwrap_or(default);
648         config.rust_debuginfo = debuginfo.unwrap_or(default);
649         config.rust_debug_assertions = debug_assertions.unwrap_or(default);
650
651         let default = config.channel == "dev";
652         config.ignore_git = ignore_git.unwrap_or(default);
653
654         config
655     }
656
657     /// Try to find the relative path of `libdir`.
658     pub fn libdir_relative(&self) -> Option<&Path> {
659         let libdir = self.libdir.as_ref()?;
660         if libdir.is_relative() {
661             Some(libdir)
662         } else {
663             // Try to make it relative to the prefix.
664             libdir.strip_prefix(self.prefix.as_ref()?).ok()
665         }
666     }
667
668     pub fn verbose(&self) -> bool {
669         self.verbose > 0
670     }
671
672     pub fn very_verbose(&self) -> bool {
673         self.verbose > 1
674     }
675 }
676
677 fn set<T>(field: &mut T, val: Option<T>) {
678     if let Some(v) = val {
679         *field = v;
680     }
681 }