]> git.lizzy.rs Git - rust.git/blob - src/bootstrap/config.rs
Auto merge of #53815 - F001:if-let-guard, r=petrochenkov
[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
90     pub lld_enabled: bool,
91     pub lldb_enabled: bool,
92     pub llvm_tools_enabled: bool,
93
94     // rust codegen options
95     pub rust_optimize: bool,
96     pub rust_codegen_units: Option<u32>,
97     pub rust_debug_assertions: bool,
98     pub rust_debuginfo: bool,
99     pub rust_debuginfo_lines: bool,
100     pub rust_debuginfo_only_std: bool,
101     pub rust_debuginfo_tools: bool,
102     pub rust_rpath: bool,
103     pub rustc_parallel_queries: bool,
104     pub rustc_default_linker: Option<String>,
105     pub rust_optimize_tests: bool,
106     pub rust_debuginfo_tests: bool,
107     pub rust_dist_src: bool,
108     pub rust_codegen_backends: Vec<Interned<String>>,
109     pub rust_codegen_backends_dir: String,
110     pub rust_verify_llvm_ir: 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
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 debug_jemalloc: bool,
124     pub use_jemalloc: bool,
125     pub backtrace: bool, // support for RUST_BACKTRACE
126     pub wasm_syscall: bool,
127
128     // misc
129     pub low_priority: bool,
130     pub channel: String,
131     pub verbose_tests: bool,
132     pub test_miri: bool,
133     pub save_toolstates: Option<PathBuf>,
134     pub print_step_timings: 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 openssl_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     pub jemalloc: 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 qemu_rootfs: Option<PathBuf>,
173     pub no_std: bool,
174 }
175
176 /// Structure of the `config.toml` file that configuration is read from.
177 ///
178 /// This structure uses `Decodable` to automatically decode a TOML configuration
179 /// file into this format, and then this is traversed and written into the above
180 /// `Config` structure.
181 #[derive(Deserialize, Default)]
182 #[serde(deny_unknown_fields, rename_all = "kebab-case")]
183 struct TomlConfig {
184     build: Option<Build>,
185     install: Option<Install>,
186     llvm: Option<Llvm>,
187     rust: Option<Rust>,
188     target: Option<HashMap<String, TomlTarget>>,
189     dist: Option<Dist>,
190 }
191
192 /// TOML representation of various global build decisions.
193 #[derive(Deserialize, Default, Clone)]
194 #[serde(deny_unknown_fields, rename_all = "kebab-case")]
195 struct Build {
196     build: Option<String>,
197     #[serde(default)]
198     host: Vec<String>,
199     #[serde(default)]
200     target: Vec<String>,
201     cargo: Option<String>,
202     rustc: Option<String>,
203     low_priority: Option<bool>,
204     compiler_docs: Option<bool>,
205     docs: Option<bool>,
206     submodules: Option<bool>,
207     fast_submodules: Option<bool>,
208     gdb: Option<String>,
209     locked_deps: Option<bool>,
210     vendor: Option<bool>,
211     nodejs: Option<String>,
212     python: Option<String>,
213     full_bootstrap: Option<bool>,
214     extended: Option<bool>,
215     tools: Option<HashSet<String>>,
216     verbose: Option<usize>,
217     sanitizers: Option<bool>,
218     profiler: Option<bool>,
219     openssl_static: Option<bool>,
220     configure_args: Option<Vec<String>>,
221     local_rebuild: Option<bool>,
222     print_step_timings: Option<bool>,
223 }
224
225 /// TOML representation of various global install decisions.
226 #[derive(Deserialize, Default, Clone)]
227 #[serde(deny_unknown_fields, rename_all = "kebab-case")]
228 struct Install {
229     prefix: Option<String>,
230     sysconfdir: Option<String>,
231     datadir: Option<String>,
232     docdir: Option<String>,
233     bindir: Option<String>,
234     libdir: Option<String>,
235     mandir: Option<String>,
236
237     // standard paths, currently unused
238     infodir: Option<String>,
239     localstatedir: Option<String>,
240 }
241
242 /// TOML representation of how the LLVM build is configured.
243 #[derive(Deserialize, Default)]
244 #[serde(deny_unknown_fields, rename_all = "kebab-case")]
245 struct Llvm {
246     enabled: Option<bool>,
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     clang_cl: Option<String>
260 }
261
262 #[derive(Deserialize, Default, Clone)]
263 #[serde(deny_unknown_fields, rename_all = "kebab-case")]
264 struct Dist {
265     sign_folder: Option<String>,
266     gpg_password_file: Option<String>,
267     upload_addr: Option<String>,
268     src_tarball: Option<bool>,
269 }
270
271 #[derive(Deserialize)]
272 #[serde(untagged)]
273 enum StringOrBool {
274     String(String),
275     Bool(bool),
276 }
277
278 impl Default for StringOrBool {
279     fn default() -> StringOrBool {
280         StringOrBool::Bool(false)
281     }
282 }
283
284 /// TOML representation of how the Rust build is configured.
285 #[derive(Deserialize, Default)]
286 #[serde(deny_unknown_fields, rename_all = "kebab-case")]
287 struct Rust {
288     optimize: Option<bool>,
289     codegen_units: Option<u32>,
290     debug_assertions: Option<bool>,
291     debuginfo: Option<bool>,
292     debuginfo_lines: Option<bool>,
293     debuginfo_only_std: Option<bool>,
294     debuginfo_tools: Option<bool>,
295     experimental_parallel_queries: Option<bool>,
296     debug_jemalloc: Option<bool>,
297     use_jemalloc: Option<bool>,
298     backtrace: Option<bool>,
299     default_linker: Option<String>,
300     channel: Option<String>,
301     musl_root: Option<String>,
302     rpath: Option<bool>,
303     optimize_tests: Option<bool>,
304     debuginfo_tests: Option<bool>,
305     codegen_tests: Option<bool>,
306     ignore_git: Option<bool>,
307     debug: Option<bool>,
308     dist_src: Option<bool>,
309     verbose_tests: Option<bool>,
310     test_miri: Option<bool>,
311     incremental: Option<bool>,
312     save_toolstates: Option<String>,
313     codegen_backends: Option<Vec<String>>,
314     codegen_backends_dir: Option<String>,
315     wasm_syscall: Option<bool>,
316     lld: Option<bool>,
317     lldb: Option<bool>,
318     llvm_tools: Option<bool>,
319     deny_warnings: Option<bool>,
320     backtrace_on_ice: Option<bool>,
321     verify_llvm_ir: Option<bool>,
322 }
323
324 /// TOML representation of how each build target is configured.
325 #[derive(Deserialize, Default)]
326 #[serde(deny_unknown_fields, rename_all = "kebab-case")]
327 struct TomlTarget {
328     llvm_config: Option<String>,
329     jemalloc: Option<String>,
330     cc: Option<String>,
331     cxx: Option<String>,
332     ar: Option<String>,
333     ranlib: Option<String>,
334     linker: Option<String>,
335     android_ndk: Option<String>,
336     crt_static: Option<bool>,
337     musl_root: Option<String>,
338     qemu_rootfs: Option<String>,
339 }
340
341 impl Config {
342     fn path_from_python(var_key: &str) -> PathBuf {
343         match env::var_os(var_key) {
344             // Do not trust paths from Python and normalize them slightly (#49785).
345             Some(var_val) => Path::new(&var_val).components().collect(),
346             _ => panic!("expected '{}' to be set", var_key),
347         }
348     }
349
350     pub fn default_opts() -> Config {
351         let mut config = Config::default();
352         config.llvm_enabled = true;
353         config.llvm_optimize = true;
354         config.llvm_version_check = true;
355         config.use_jemalloc = true;
356         config.backtrace = true;
357         config.rust_optimize = true;
358         config.rust_optimize_tests = true;
359         config.submodules = true;
360         config.fast_submodules = true;
361         config.docs = true;
362         config.rust_rpath = true;
363         config.channel = "dev".to_string();
364         config.codegen_tests = true;
365         config.ignore_git = false;
366         config.rust_dist_src = true;
367         config.test_miri = false;
368         config.rust_codegen_backends = vec![INTERNER.intern_str("llvm")];
369         config.rust_codegen_backends_dir = "codegen-backends".to_owned();
370         config.deny_warnings = true;
371
372         // set by bootstrap.py
373         config.build = INTERNER.intern_str(&env::var("BUILD").expect("'BUILD' to be set"));
374         config.src = Config::path_from_python("SRC");
375         config.out = Config::path_from_python("BUILD_DIR");
376
377         config.initial_rustc = Config::path_from_python("RUSTC");
378         config.initial_cargo = Config::path_from_python("CARGO");
379
380         config
381     }
382
383     pub fn parse(args: &[String]) -> Config {
384         let flags = Flags::parse(&args);
385         let file = flags.config.clone();
386         let mut config = Config::default_opts();
387         config.exclude = flags.exclude;
388         config.rustc_error_format = flags.rustc_error_format;
389         config.on_fail = flags.on_fail;
390         config.stage = flags.stage;
391         config.jobs = flags.jobs;
392         config.cmd = flags.cmd;
393         config.incremental = flags.incremental;
394         config.dry_run = flags.dry_run;
395         config.keep_stage = flags.keep_stage;
396         if let Some(value) = flags.warnings {
397             config.deny_warnings = value;
398         }
399
400         if config.dry_run {
401             let dir = config.out.join("tmp-dry-run");
402             t!(fs::create_dir_all(&dir));
403             config.out = dir;
404         }
405
406         // If --target was specified but --host wasn't specified, don't run any host-only tests.
407         config.run_host_only = !(flags.host.is_empty() && !flags.target.is_empty());
408
409         let toml = file.map(|file| {
410             let mut f = t!(File::open(&file));
411             let mut contents = String::new();
412             t!(f.read_to_string(&mut contents));
413             match toml::from_str(&contents) {
414                 Ok(table) => table,
415                 Err(err) => {
416                     println!("failed to parse TOML configuration '{}': {}",
417                         file.display(), err);
418                     process::exit(2);
419                 }
420             }
421         }).unwrap_or_else(|| TomlConfig::default());
422
423         let build = toml.build.clone().unwrap_or(Build::default());
424         // set by bootstrap.py
425         config.hosts.push(config.build.clone());
426         for host in build.host.iter() {
427             let host = INTERNER.intern_str(host);
428             if !config.hosts.contains(&host) {
429                 config.hosts.push(host);
430             }
431         }
432         for target in config.hosts.iter().cloned()
433             .chain(build.target.iter().map(|s| INTERNER.intern_str(s)))
434         {
435             if !config.targets.contains(&target) {
436                 config.targets.push(target);
437             }
438         }
439         config.hosts = if !flags.host.is_empty() {
440             flags.host
441         } else {
442             config.hosts
443         };
444         config.targets = if !flags.target.is_empty() {
445             flags.target
446         } else {
447             config.targets
448         };
449
450
451         config.nodejs = build.nodejs.map(PathBuf::from);
452         config.gdb = build.gdb.map(PathBuf::from);
453         config.python = build.python.map(PathBuf::from);
454         set(&mut config.low_priority, build.low_priority);
455         set(&mut config.compiler_docs, build.compiler_docs);
456         set(&mut config.docs, build.docs);
457         set(&mut config.submodules, build.submodules);
458         set(&mut config.fast_submodules, build.fast_submodules);
459         set(&mut config.locked_deps, build.locked_deps);
460         set(&mut config.vendor, build.vendor);
461         set(&mut config.full_bootstrap, build.full_bootstrap);
462         set(&mut config.extended, build.extended);
463         config.tools = build.tools;
464         set(&mut config.verbose, build.verbose);
465         set(&mut config.sanitizers, build.sanitizers);
466         set(&mut config.profiler, build.profiler);
467         set(&mut config.openssl_static, build.openssl_static);
468         set(&mut config.configure_args, build.configure_args);
469         set(&mut config.local_rebuild, build.local_rebuild);
470         set(&mut config.print_step_timings, build.print_step_timings);
471         config.verbose = cmp::max(config.verbose, flags.verbose);
472
473         if let Some(ref install) = toml.install {
474             config.prefix = install.prefix.clone().map(PathBuf::from);
475             config.sysconfdir = install.sysconfdir.clone().map(PathBuf::from);
476             config.datadir = install.datadir.clone().map(PathBuf::from);
477             config.docdir = install.docdir.clone().map(PathBuf::from);
478             config.bindir = install.bindir.clone().map(PathBuf::from);
479             config.libdir = install.libdir.clone().map(PathBuf::from);
480             config.mandir = install.mandir.clone().map(PathBuf::from);
481         }
482
483         // Store off these values as options because if they're not provided
484         // we'll infer default values for them later
485         let mut llvm_assertions = None;
486         let mut debuginfo_lines = None;
487         let mut debuginfo_only_std = None;
488         let mut debuginfo_tools = None;
489         let mut debug = None;
490         let mut debug_jemalloc = None;
491         let mut debuginfo = None;
492         let mut debug_assertions = None;
493         let mut optimize = None;
494         let mut ignore_git = None;
495
496         if let Some(ref llvm) = toml.llvm {
497             match llvm.ccache {
498                 Some(StringOrBool::String(ref s)) => {
499                     config.ccache = Some(s.to_string())
500                 }
501                 Some(StringOrBool::Bool(true)) => {
502                     config.ccache = Some("ccache".to_string());
503                 }
504                 Some(StringOrBool::Bool(false)) | None => {}
505             }
506             set(&mut config.ninja, llvm.ninja);
507             set(&mut config.llvm_enabled, llvm.enabled);
508             llvm_assertions = llvm.assertions;
509             set(&mut config.llvm_optimize, llvm.optimize);
510             set(&mut config.llvm_thin_lto, llvm.thin_lto);
511             set(&mut config.llvm_release_debuginfo, llvm.release_debuginfo);
512             set(&mut config.llvm_version_check, llvm.version_check);
513             set(&mut config.llvm_static_stdcpp, llvm.static_libstdcpp);
514             set(&mut config.llvm_link_shared, llvm.link_shared);
515             config.llvm_targets = llvm.targets.clone();
516             config.llvm_experimental_targets = llvm.experimental_targets.clone()
517                 .unwrap_or("WebAssembly;RISCV".to_string());
518             config.llvm_link_jobs = llvm.link_jobs;
519             config.llvm_clang_cl = llvm.clang_cl.clone();
520         }
521
522         if let Some(ref rust) = toml.rust {
523             debug = rust.debug;
524             debug_assertions = rust.debug_assertions;
525             debuginfo = rust.debuginfo;
526             debuginfo_lines = rust.debuginfo_lines;
527             debuginfo_only_std = rust.debuginfo_only_std;
528             debuginfo_tools = rust.debuginfo_tools;
529             optimize = rust.optimize;
530             ignore_git = rust.ignore_git;
531             debug_jemalloc = rust.debug_jemalloc;
532             set(&mut config.rust_optimize_tests, rust.optimize_tests);
533             set(&mut config.rust_debuginfo_tests, rust.debuginfo_tests);
534             set(&mut config.codegen_tests, rust.codegen_tests);
535             set(&mut config.rust_rpath, rust.rpath);
536             set(&mut config.use_jemalloc, rust.use_jemalloc);
537             set(&mut config.backtrace, rust.backtrace);
538             set(&mut config.channel, rust.channel.clone());
539             set(&mut config.rust_dist_src, rust.dist_src);
540             set(&mut config.verbose_tests, rust.verbose_tests);
541             set(&mut config.test_miri, rust.test_miri);
542             // in the case "false" is set explicitly, do not overwrite the command line args
543             if let Some(true) = rust.incremental {
544                 config.incremental = true;
545             }
546             set(&mut config.wasm_syscall, rust.wasm_syscall);
547             set(&mut config.lld_enabled, rust.lld);
548             set(&mut config.lldb_enabled, rust.lldb);
549             set(&mut config.llvm_tools_enabled, rust.llvm_tools);
550             config.rustc_parallel_queries = rust.experimental_parallel_queries.unwrap_or(false);
551             config.rustc_default_linker = rust.default_linker.clone();
552             config.musl_root = rust.musl_root.clone().map(PathBuf::from);
553             config.save_toolstates = rust.save_toolstates.clone().map(PathBuf::from);
554             set(&mut config.deny_warnings, rust.deny_warnings.or(flags.warnings));
555             set(&mut config.backtrace_on_ice, rust.backtrace_on_ice);
556             set(&mut config.rust_verify_llvm_ir, rust.verify_llvm_ir);
557
558             if let Some(ref backends) = rust.codegen_backends {
559                 config.rust_codegen_backends = backends.iter()
560                     .map(|s| INTERNER.intern_str(s))
561                     .collect();
562             }
563
564             set(&mut config.rust_codegen_backends_dir, rust.codegen_backends_dir.clone());
565
566             match rust.codegen_units {
567                 Some(0) => config.rust_codegen_units = Some(num_cpus::get() as u32),
568                 Some(n) => config.rust_codegen_units = Some(n),
569                 None => {}
570             }
571         }
572
573         if let Some(ref t) = toml.target {
574             for (triple, cfg) in t {
575                 let mut target = Target::default();
576
577                 if let Some(ref s) = cfg.llvm_config {
578                     target.llvm_config = Some(config.src.join(s));
579                 }
580                 if let Some(ref s) = cfg.jemalloc {
581                     target.jemalloc = Some(config.src.join(s));
582                 }
583                 if let Some(ref s) = cfg.android_ndk {
584                     target.ndk = Some(config.src.join(s));
585                 }
586                 target.cc = cfg.cc.clone().map(PathBuf::from);
587                 target.cxx = cfg.cxx.clone().map(PathBuf::from);
588                 target.ar = cfg.ar.clone().map(PathBuf::from);
589                 target.ranlib = cfg.ranlib.clone().map(PathBuf::from);
590                 target.linker = cfg.linker.clone().map(PathBuf::from);
591                 target.crt_static = cfg.crt_static.clone();
592                 target.musl_root = cfg.musl_root.clone().map(PathBuf::from);
593                 target.qemu_rootfs = cfg.qemu_rootfs.clone().map(PathBuf::from);
594
595                 config.target_config.insert(INTERNER.intern_string(triple.clone()), target);
596             }
597         }
598
599         if let Some(ref t) = toml.dist {
600             config.dist_sign_folder = t.sign_folder.clone().map(PathBuf::from);
601             config.dist_gpg_password_file = t.gpg_password_file.clone().map(PathBuf::from);
602             config.dist_upload_addr = t.upload_addr.clone();
603             set(&mut config.rust_dist_src, t.src_tarball);
604         }
605
606         // Now that we've reached the end of our configuration, infer the
607         // default values for all options that we haven't otherwise stored yet.
608
609         set(&mut config.initial_rustc, build.rustc.map(PathBuf::from));
610         set(&mut config.initial_cargo, build.cargo.map(PathBuf::from));
611
612         let default = false;
613         config.llvm_assertions = llvm_assertions.unwrap_or(default);
614
615         let default = match &config.channel[..] {
616             "stable" | "beta" | "nightly" => true,
617             _ => false,
618         };
619         config.rust_debuginfo_lines = debuginfo_lines.unwrap_or(default);
620         config.rust_debuginfo_only_std = debuginfo_only_std.unwrap_or(default);
621         config.rust_debuginfo_tools = debuginfo_tools.unwrap_or(false);
622
623         let default = debug == Some(true);
624         config.debug_jemalloc = debug_jemalloc.unwrap_or(default);
625         config.rust_debuginfo = debuginfo.unwrap_or(default);
626         config.rust_debug_assertions = debug_assertions.unwrap_or(default);
627         config.rust_optimize = optimize.unwrap_or(!default);
628
629         let default = config.channel == "dev";
630         config.ignore_git = ignore_git.unwrap_or(default);
631
632         config
633     }
634
635     /// Try to find the relative path of `libdir`.
636     pub fn libdir_relative(&self) -> Option<&Path> {
637         let libdir = self.libdir.as_ref()?;
638         if libdir.is_relative() {
639             Some(libdir)
640         } else {
641             // Try to make it relative to the prefix.
642             libdir.strip_prefix(self.prefix.as_ref()?).ok()
643         }
644     }
645
646     pub fn verbose(&self) -> bool {
647         self.verbose > 0
648     }
649
650     pub fn very_verbose(&self) -> bool {
651         self.verbose > 1
652     }
653 }
654
655 fn set<T>(field: &mut T, val: Option<T>) {
656     if let Some(v) = val {
657         *field = v;
658     }
659 }