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