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