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