]> git.lizzy.rs Git - rust.git/blob - src/bootstrap/config.rs
Auto merge of #43655 - bjorn3:more_doc_comments, r=arielb1
[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.mk` and `config.toml` configuration
14 //! files to tweak how the build runs.
15
16 use std::collections::HashMap;
17 use std::env;
18 use std::fs::{self, File};
19 use std::io::prelude::*;
20 use std::path::PathBuf;
21 use std::process;
22
23 use num_cpus;
24 use toml;
25 use util::{exe, push_exe_path};
26 use cache::{INTERNER, Interned};
27
28 /// Global configuration for the entire build and/or bootstrap.
29 ///
30 /// This structure is derived from a combination of both `config.toml` and
31 /// `config.mk`. As of the time of this writing it's unlikely that `config.toml`
32 /// is used all that much, so this is primarily filled out by `config.mk` which
33 /// is generated from `./configure`.
34 ///
35 /// Note that this structure is not decoded directly into, but rather it is
36 /// filled out from the decoded forms of the structs below. For documentation
37 /// each field, see the corresponding fields in
38 /// `src/bootstrap/config.toml.example`.
39 #[derive(Default)]
40 pub struct Config {
41     pub ccache: Option<String>,
42     pub ninja: bool,
43     pub verbose: usize,
44     pub submodules: bool,
45     pub compiler_docs: bool,
46     pub docs: bool,
47     pub locked_deps: bool,
48     pub vendor: bool,
49     pub target_config: HashMap<Interned<String>, Target>,
50     pub full_bootstrap: bool,
51     pub extended: bool,
52     pub sanitizers: bool,
53     pub profiler: bool,
54
55     // llvm codegen options
56     pub llvm_assertions: bool,
57     pub llvm_optimize: bool,
58     pub llvm_release_debuginfo: bool,
59     pub llvm_version_check: bool,
60     pub llvm_static_stdcpp: bool,
61     pub llvm_link_shared: bool,
62     pub llvm_targets: Option<String>,
63     pub llvm_experimental_targets: Option<String>,
64     pub llvm_link_jobs: Option<u32>,
65
66     // rust codegen options
67     pub rust_optimize: bool,
68     pub rust_codegen_units: u32,
69     pub rust_debug_assertions: bool,
70     pub rust_debuginfo: bool,
71     pub rust_debuginfo_lines: bool,
72     pub rust_debuginfo_only_std: bool,
73     pub rust_rpath: bool,
74     pub rustc_default_linker: Option<String>,
75     pub rustc_default_ar: Option<String>,
76     pub rust_optimize_tests: bool,
77     pub rust_debuginfo_tests: bool,
78     pub rust_dist_src: bool,
79
80     pub build: Interned<String>,
81     pub host: Vec<Interned<String>>,
82     pub target: Vec<Interned<String>>,
83     pub local_rebuild: bool,
84
85     // dist misc
86     pub dist_sign_folder: Option<PathBuf>,
87     pub dist_upload_addr: Option<String>,
88     pub dist_gpg_password_file: Option<PathBuf>,
89
90     // libstd features
91     pub debug_jemalloc: bool,
92     pub use_jemalloc: bool,
93     pub backtrace: bool, // support for RUST_BACKTRACE
94
95     // misc
96     pub low_priority: bool,
97     pub channel: String,
98     pub quiet_tests: bool,
99     // Fallback musl-root for all targets
100     pub musl_root: Option<PathBuf>,
101     pub prefix: Option<PathBuf>,
102     pub sysconfdir: Option<PathBuf>,
103     pub docdir: Option<PathBuf>,
104     pub bindir: Option<PathBuf>,
105     pub libdir: Option<PathBuf>,
106     pub libdir_relative: Option<PathBuf>,
107     pub mandir: Option<PathBuf>,
108     pub codegen_tests: bool,
109     pub nodejs: Option<PathBuf>,
110     pub gdb: Option<PathBuf>,
111     pub python: Option<PathBuf>,
112     pub configure_args: Vec<String>,
113     pub openssl_static: bool,
114
115
116     // These are either the stage0 downloaded binaries or the locally installed ones.
117     pub initial_cargo: PathBuf,
118     pub initial_rustc: PathBuf,
119
120 }
121
122 /// Per-target configuration stored in the global configuration structure.
123 #[derive(Default)]
124 pub struct Target {
125     /// Some(path to llvm-config) if using an external LLVM.
126     pub llvm_config: Option<PathBuf>,
127     pub jemalloc: Option<PathBuf>,
128     pub cc: Option<PathBuf>,
129     pub cxx: Option<PathBuf>,
130     pub ndk: Option<PathBuf>,
131     pub musl_root: Option<PathBuf>,
132     pub qemu_rootfs: Option<PathBuf>,
133 }
134
135 /// Structure of the `config.toml` file that configuration is read from.
136 ///
137 /// This structure uses `Decodable` to automatically decode a TOML configuration
138 /// file into this format, and then this is traversed and written into the above
139 /// `Config` structure.
140 #[derive(Deserialize, Default)]
141 #[serde(deny_unknown_fields, rename_all = "kebab-case")]
142 struct TomlConfig {
143     build: Option<Build>,
144     install: Option<Install>,
145     llvm: Option<Llvm>,
146     rust: Option<Rust>,
147     target: Option<HashMap<String, TomlTarget>>,
148     dist: Option<Dist>,
149 }
150
151 /// TOML representation of various global build decisions.
152 #[derive(Deserialize, Default, Clone)]
153 #[serde(deny_unknown_fields, rename_all = "kebab-case")]
154 struct Build {
155     build: Option<String>,
156     #[serde(default)]
157     host: Vec<String>,
158     #[serde(default)]
159     target: Vec<String>,
160     cargo: Option<String>,
161     rustc: Option<String>,
162     low_priority: Option<bool>,
163     compiler_docs: Option<bool>,
164     docs: Option<bool>,
165     submodules: Option<bool>,
166     gdb: Option<String>,
167     locked_deps: Option<bool>,
168     vendor: Option<bool>,
169     nodejs: Option<String>,
170     python: Option<String>,
171     full_bootstrap: Option<bool>,
172     extended: Option<bool>,
173     verbose: Option<usize>,
174     sanitizers: Option<bool>,
175     profiler: Option<bool>,
176     openssl_static: Option<bool>,
177 }
178
179 /// TOML representation of various global install decisions.
180 #[derive(Deserialize, Default, Clone)]
181 #[serde(deny_unknown_fields, rename_all = "kebab-case")]
182 struct Install {
183     prefix: Option<String>,
184     sysconfdir: Option<String>,
185     docdir: Option<String>,
186     bindir: Option<String>,
187     libdir: Option<String>,
188     mandir: Option<String>,
189 }
190
191 /// TOML representation of how the LLVM build is configured.
192 #[derive(Deserialize, Default)]
193 #[serde(deny_unknown_fields, rename_all = "kebab-case")]
194 struct Llvm {
195     ccache: Option<StringOrBool>,
196     ninja: Option<bool>,
197     assertions: Option<bool>,
198     optimize: Option<bool>,
199     release_debuginfo: Option<bool>,
200     version_check: Option<bool>,
201     static_libstdcpp: Option<bool>,
202     targets: Option<String>,
203     experimental_targets: Option<String>,
204     link_jobs: Option<u32>,
205 }
206
207 #[derive(Deserialize, Default, Clone)]
208 #[serde(deny_unknown_fields, rename_all = "kebab-case")]
209 struct Dist {
210     sign_folder: Option<String>,
211     gpg_password_file: Option<String>,
212     upload_addr: Option<String>,
213     src_tarball: Option<bool>,
214 }
215
216 #[derive(Deserialize)]
217 #[serde(untagged)]
218 enum StringOrBool {
219     String(String),
220     Bool(bool),
221 }
222
223 impl Default for StringOrBool {
224     fn default() -> StringOrBool {
225         StringOrBool::Bool(false)
226     }
227 }
228
229 /// TOML representation of how the Rust build is configured.
230 #[derive(Deserialize, Default)]
231 #[serde(deny_unknown_fields, rename_all = "kebab-case")]
232 struct Rust {
233     optimize: Option<bool>,
234     codegen_units: Option<u32>,
235     debug_assertions: Option<bool>,
236     debuginfo: Option<bool>,
237     debuginfo_lines: Option<bool>,
238     debuginfo_only_std: Option<bool>,
239     debug_jemalloc: Option<bool>,
240     use_jemalloc: Option<bool>,
241     backtrace: Option<bool>,
242     default_linker: Option<String>,
243     default_ar: Option<String>,
244     channel: Option<String>,
245     musl_root: Option<String>,
246     rpath: Option<bool>,
247     optimize_tests: Option<bool>,
248     debuginfo_tests: Option<bool>,
249     codegen_tests: Option<bool>,
250 }
251
252 /// TOML representation of how each build target is configured.
253 #[derive(Deserialize, Default)]
254 #[serde(deny_unknown_fields, rename_all = "kebab-case")]
255 struct TomlTarget {
256     llvm_config: Option<String>,
257     jemalloc: Option<String>,
258     cc: Option<String>,
259     cxx: Option<String>,
260     android_ndk: Option<String>,
261     musl_root: Option<String>,
262     qemu_rootfs: Option<String>,
263 }
264
265 impl Config {
266     pub fn parse(build: &str, file: Option<PathBuf>) -> Config {
267         let mut config = Config::default();
268         config.llvm_optimize = true;
269         config.use_jemalloc = true;
270         config.backtrace = true;
271         config.rust_optimize = true;
272         config.rust_optimize_tests = true;
273         config.submodules = true;
274         config.docs = true;
275         config.rust_rpath = true;
276         config.rust_codegen_units = 1;
277         config.build = INTERNER.intern_str(build);
278         config.channel = "dev".to_string();
279         config.codegen_tests = true;
280         config.rust_dist_src = true;
281
282         let toml = file.map(|file| {
283             let mut f = t!(File::open(&file));
284             let mut contents = String::new();
285             t!(f.read_to_string(&mut contents));
286             match toml::from_str(&contents) {
287                 Ok(table) => table,
288                 Err(err) => {
289                     println!("failed to parse TOML configuration '{}': {}",
290                         file.display(), err);
291                     process::exit(2);
292                 }
293             }
294         }).unwrap_or_else(|| TomlConfig::default());
295
296         let build = toml.build.clone().unwrap_or(Build::default());
297         set(&mut config.build, build.build.clone().map(|x| INTERNER.intern_string(x)));
298         config.host.push(config.build.clone());
299         for host in build.host.iter() {
300             let host = INTERNER.intern_str(host);
301             if !config.host.contains(&host) {
302                 config.host.push(host);
303             }
304         }
305         for target in config.host.iter().cloned()
306             .chain(build.target.iter().map(|s| INTERNER.intern_str(s)))
307         {
308             if !config.target.contains(&target) {
309                 config.target.push(target);
310             }
311         }
312         config.nodejs = build.nodejs.map(PathBuf::from);
313         config.gdb = build.gdb.map(PathBuf::from);
314         config.python = build.python.map(PathBuf::from);
315         set(&mut config.low_priority, build.low_priority);
316         set(&mut config.compiler_docs, build.compiler_docs);
317         set(&mut config.docs, build.docs);
318         set(&mut config.submodules, build.submodules);
319         set(&mut config.locked_deps, build.locked_deps);
320         set(&mut config.vendor, build.vendor);
321         set(&mut config.full_bootstrap, build.full_bootstrap);
322         set(&mut config.extended, build.extended);
323         set(&mut config.verbose, build.verbose);
324         set(&mut config.sanitizers, build.sanitizers);
325         set(&mut config.profiler, build.profiler);
326         set(&mut config.openssl_static, build.openssl_static);
327
328         if let Some(ref install) = toml.install {
329             config.prefix = install.prefix.clone().map(PathBuf::from);
330             config.sysconfdir = install.sysconfdir.clone().map(PathBuf::from);
331             config.docdir = install.docdir.clone().map(PathBuf::from);
332             config.bindir = install.bindir.clone().map(PathBuf::from);
333             config.libdir = install.libdir.clone().map(PathBuf::from);
334             config.mandir = install.mandir.clone().map(PathBuf::from);
335         }
336
337         if let Some(ref llvm) = toml.llvm {
338             match llvm.ccache {
339                 Some(StringOrBool::String(ref s)) => {
340                     config.ccache = Some(s.to_string())
341                 }
342                 Some(StringOrBool::Bool(true)) => {
343                     config.ccache = Some("ccache".to_string());
344                 }
345                 Some(StringOrBool::Bool(false)) | None => {}
346             }
347             set(&mut config.ninja, llvm.ninja);
348             set(&mut config.llvm_assertions, llvm.assertions);
349             set(&mut config.llvm_optimize, llvm.optimize);
350             set(&mut config.llvm_release_debuginfo, llvm.release_debuginfo);
351             set(&mut config.llvm_version_check, llvm.version_check);
352             set(&mut config.llvm_static_stdcpp, llvm.static_libstdcpp);
353             config.llvm_targets = llvm.targets.clone();
354             config.llvm_experimental_targets = llvm.experimental_targets.clone();
355             config.llvm_link_jobs = llvm.link_jobs;
356         }
357
358         if let Some(ref rust) = toml.rust {
359             set(&mut config.rust_debug_assertions, rust.debug_assertions);
360             set(&mut config.rust_debuginfo, rust.debuginfo);
361             set(&mut config.rust_debuginfo_lines, rust.debuginfo_lines);
362             set(&mut config.rust_debuginfo_only_std, rust.debuginfo_only_std);
363             set(&mut config.rust_optimize, rust.optimize);
364             set(&mut config.rust_optimize_tests, rust.optimize_tests);
365             set(&mut config.rust_debuginfo_tests, rust.debuginfo_tests);
366             set(&mut config.codegen_tests, rust.codegen_tests);
367             set(&mut config.rust_rpath, rust.rpath);
368             set(&mut config.debug_jemalloc, rust.debug_jemalloc);
369             set(&mut config.use_jemalloc, rust.use_jemalloc);
370             set(&mut config.backtrace, rust.backtrace);
371             set(&mut config.channel, rust.channel.clone());
372             config.rustc_default_linker = rust.default_linker.clone();
373             config.rustc_default_ar = rust.default_ar.clone();
374             config.musl_root = rust.musl_root.clone().map(PathBuf::from);
375
376             match rust.codegen_units {
377                 Some(0) => config.rust_codegen_units = num_cpus::get() as u32,
378                 Some(n) => config.rust_codegen_units = n,
379                 None => {}
380             }
381         }
382
383         if let Some(ref t) = toml.target {
384             for (triple, cfg) in t {
385                 let mut target = Target::default();
386
387                 if let Some(ref s) = cfg.llvm_config {
388                     target.llvm_config = Some(env::current_dir().unwrap().join(s));
389                 }
390                 if let Some(ref s) = cfg.jemalloc {
391                     target.jemalloc = Some(env::current_dir().unwrap().join(s));
392                 }
393                 if let Some(ref s) = cfg.android_ndk {
394                     target.ndk = Some(env::current_dir().unwrap().join(s));
395                 }
396                 target.cxx = cfg.cxx.clone().map(PathBuf::from);
397                 target.cc = cfg.cc.clone().map(PathBuf::from);
398                 target.musl_root = cfg.musl_root.clone().map(PathBuf::from);
399                 target.qemu_rootfs = cfg.qemu_rootfs.clone().map(PathBuf::from);
400
401                 config.target_config.insert(INTERNER.intern_string(triple.clone()), target);
402             }
403         }
404
405         if let Some(ref t) = toml.dist {
406             config.dist_sign_folder = t.sign_folder.clone().map(PathBuf::from);
407             config.dist_gpg_password_file = t.gpg_password_file.clone().map(PathBuf::from);
408             config.dist_upload_addr = t.upload_addr.clone();
409             set(&mut config.rust_dist_src, t.src_tarball);
410         }
411
412         let cwd = t!(env::current_dir());
413         let out = cwd.join("build");
414
415         let stage0_root = out.join(&config.build).join("stage0/bin");
416         config.initial_rustc = match build.rustc {
417             Some(s) => PathBuf::from(s),
418             None => stage0_root.join(exe("rustc", &config.build)),
419         };
420         config.initial_cargo = match build.cargo {
421             Some(s) => PathBuf::from(s),
422             None => stage0_root.join(exe("cargo", &config.build)),
423         };
424
425         // compat with `./configure` while we're still using that
426         if fs::metadata("config.mk").is_ok() {
427             config.update_with_config_mk();
428         }
429
430         config
431     }
432
433     /// "Temporary" routine to parse `config.mk` into this configuration.
434     ///
435     /// While we still have `./configure` this implements the ability to decode
436     /// that configuration into this. This isn't exactly a full-blown makefile
437     /// parser, but hey it gets the job done!
438     fn update_with_config_mk(&mut self) {
439         let mut config = String::new();
440         File::open("config.mk").unwrap().read_to_string(&mut config).unwrap();
441         for line in config.lines() {
442             let mut parts = line.splitn(2, ":=").map(|s| s.trim());
443             let key = parts.next().unwrap();
444             let value = match parts.next() {
445                 Some(n) if n.starts_with('\"') => &n[1..n.len() - 1],
446                 Some(n) => n,
447                 None => continue
448             };
449
450             macro_rules! check {
451                 ($(($name:expr, $val:expr),)*) => {
452                     if value == "1" {
453                         $(
454                             if key == concat!("CFG_ENABLE_", $name) {
455                                 $val = true;
456                                 continue
457                             }
458                             if key == concat!("CFG_DISABLE_", $name) {
459                                 $val = false;
460                                 continue
461                             }
462                         )*
463                     }
464                 }
465             }
466
467             check! {
468                 ("MANAGE_SUBMODULES", self.submodules),
469                 ("COMPILER_DOCS", self.compiler_docs),
470                 ("DOCS", self.docs),
471                 ("LLVM_ASSERTIONS", self.llvm_assertions),
472                 ("LLVM_RELEASE_DEBUGINFO", self.llvm_release_debuginfo),
473                 ("OPTIMIZE_LLVM", self.llvm_optimize),
474                 ("LLVM_VERSION_CHECK", self.llvm_version_check),
475                 ("LLVM_STATIC_STDCPP", self.llvm_static_stdcpp),
476                 ("LLVM_LINK_SHARED", self.llvm_link_shared),
477                 ("OPTIMIZE", self.rust_optimize),
478                 ("DEBUG_ASSERTIONS", self.rust_debug_assertions),
479                 ("DEBUGINFO", self.rust_debuginfo),
480                 ("DEBUGINFO_LINES", self.rust_debuginfo_lines),
481                 ("DEBUGINFO_ONLY_STD", self.rust_debuginfo_only_std),
482                 ("JEMALLOC", self.use_jemalloc),
483                 ("DEBUG_JEMALLOC", self.debug_jemalloc),
484                 ("RPATH", self.rust_rpath),
485                 ("OPTIMIZE_TESTS", self.rust_optimize_tests),
486                 ("DEBUGINFO_TESTS", self.rust_debuginfo_tests),
487                 ("QUIET_TESTS", self.quiet_tests),
488                 ("LOCAL_REBUILD", self.local_rebuild),
489                 ("NINJA", self.ninja),
490                 ("CODEGEN_TESTS", self.codegen_tests),
491                 ("LOCKED_DEPS", self.locked_deps),
492                 ("VENDOR", self.vendor),
493                 ("FULL_BOOTSTRAP", self.full_bootstrap),
494                 ("EXTENDED", self.extended),
495                 ("SANITIZERS", self.sanitizers),
496                 ("PROFILER", self.profiler),
497                 ("DIST_SRC", self.rust_dist_src),
498                 ("CARGO_OPENSSL_STATIC", self.openssl_static),
499             }
500
501             match key {
502                 "CFG_BUILD" if value.len() > 0 => self.build = INTERNER.intern_str(value),
503                 "CFG_HOST" if value.len() > 0 => {
504                     self.host.extend(value.split(" ").map(|s| INTERNER.intern_str(s)));
505
506                 }
507                 "CFG_TARGET" if value.len() > 0 => {
508                     self.target.extend(value.split(" ").map(|s| INTERNER.intern_str(s)));
509                 }
510                 "CFG_EXPERIMENTAL_TARGETS" if value.len() > 0 => {
511                     self.llvm_experimental_targets = Some(value.to_string());
512                 }
513                 "CFG_MUSL_ROOT" if value.len() > 0 => {
514                     self.musl_root = Some(parse_configure_path(value));
515                 }
516                 "CFG_MUSL_ROOT_X86_64" if value.len() > 0 => {
517                     let target = INTERNER.intern_str("x86_64-unknown-linux-musl");
518                     let target = self.target_config.entry(target).or_insert(Target::default());
519                     target.musl_root = Some(parse_configure_path(value));
520                 }
521                 "CFG_MUSL_ROOT_I686" if value.len() > 0 => {
522                     let target = INTERNER.intern_str("i686-unknown-linux-musl");
523                     let target = self.target_config.entry(target).or_insert(Target::default());
524                     target.musl_root = Some(parse_configure_path(value));
525                 }
526                 "CFG_MUSL_ROOT_ARM" if value.len() > 0 => {
527                     let target = INTERNER.intern_str("arm-unknown-linux-musleabi");
528                     let target = self.target_config.entry(target).or_insert(Target::default());
529                     target.musl_root = Some(parse_configure_path(value));
530                 }
531                 "CFG_MUSL_ROOT_ARMHF" if value.len() > 0 => {
532                     let target = INTERNER.intern_str("arm-unknown-linux-musleabihf");
533                     let target = self.target_config.entry(target).or_insert(Target::default());
534                     target.musl_root = Some(parse_configure_path(value));
535                 }
536                 "CFG_MUSL_ROOT_ARMV7" if value.len() > 0 => {
537                     let target = INTERNER.intern_str("armv7-unknown-linux-musleabihf");
538                     let target = self.target_config.entry(target).or_insert(Target::default());
539                     target.musl_root = Some(parse_configure_path(value));
540                 }
541                 "CFG_DEFAULT_AR" if value.len() > 0 => {
542                     self.rustc_default_ar = Some(value.to_string());
543                 }
544                 "CFG_DEFAULT_LINKER" if value.len() > 0 => {
545                     self.rustc_default_linker = Some(value.to_string());
546                 }
547                 "CFG_GDB" if value.len() > 0 => {
548                     self.gdb = Some(parse_configure_path(value));
549                 }
550                 "CFG_RELEASE_CHANNEL" => {
551                     self.channel = value.to_string();
552                 }
553                 "CFG_PREFIX" => {
554                     self.prefix = Some(PathBuf::from(value));
555                 }
556                 "CFG_SYSCONFDIR" => {
557                     self.sysconfdir = Some(PathBuf::from(value));
558                 }
559                 "CFG_DOCDIR" => {
560                     self.docdir = Some(PathBuf::from(value));
561                 }
562                 "CFG_BINDIR" => {
563                     self.bindir = Some(PathBuf::from(value));
564                 }
565                 "CFG_LIBDIR" => {
566                     self.libdir = Some(PathBuf::from(value));
567                 }
568                 "CFG_LIBDIR_RELATIVE" => {
569                     self.libdir_relative = Some(PathBuf::from(value));
570                 }
571                 "CFG_MANDIR" => {
572                     self.mandir = Some(PathBuf::from(value));
573                 }
574                 "CFG_LLVM_ROOT" if value.len() > 0 => {
575                     let target = self.target_config.entry(self.build.clone())
576                                      .or_insert(Target::default());
577                     let root = parse_configure_path(value);
578                     target.llvm_config = Some(push_exe_path(root, &["bin", "llvm-config"]));
579                 }
580                 "CFG_JEMALLOC_ROOT" if value.len() > 0 => {
581                     let target = self.target_config.entry(self.build.clone())
582                                      .or_insert(Target::default());
583                     target.jemalloc = Some(parse_configure_path(value).join("libjemalloc_pic.a"));
584                 }
585                 "CFG_ARM_LINUX_ANDROIDEABI_NDK" if value.len() > 0 => {
586                     let target = INTERNER.intern_str("arm-linux-androideabi");
587                     let target = self.target_config.entry(target).or_insert(Target::default());
588                     target.ndk = Some(parse_configure_path(value));
589                 }
590                 "CFG_ARMV7_LINUX_ANDROIDEABI_NDK" if value.len() > 0 => {
591                     let target = INTERNER.intern_str("armv7-linux-androideabi");
592                     let target = self.target_config.entry(target).or_insert(Target::default());
593                     target.ndk = Some(parse_configure_path(value));
594                 }
595                 "CFG_I686_LINUX_ANDROID_NDK" if value.len() > 0 => {
596                     let target = INTERNER.intern_str("i686-linux-android");
597                     let target = self.target_config.entry(target).or_insert(Target::default());
598                     target.ndk = Some(parse_configure_path(value));
599                 }
600                 "CFG_AARCH64_LINUX_ANDROID_NDK" if value.len() > 0 => {
601                     let target = INTERNER.intern_str("aarch64-linux-android");
602                     let target = self.target_config.entry(target).or_insert(Target::default());
603                     target.ndk = Some(parse_configure_path(value));
604                 }
605                 "CFG_X86_64_LINUX_ANDROID_NDK" if value.len() > 0 => {
606                     let target = INTERNER.intern_str("x86_64-linux-android");
607                     let target = self.target_config.entry(target).or_insert(Target::default());
608                     target.ndk = Some(parse_configure_path(value));
609                 }
610                 "CFG_LOCAL_RUST_ROOT" if value.len() > 0 => {
611                     let path = parse_configure_path(value);
612                     self.initial_rustc = push_exe_path(path.clone(), &["bin", "rustc"]);
613                     self.initial_cargo = push_exe_path(path, &["bin", "cargo"]);
614                 }
615                 "CFG_PYTHON" if value.len() > 0 => {
616                     let path = parse_configure_path(value);
617                     self.python = Some(path);
618                 }
619                 "CFG_ENABLE_CCACHE" if value == "1" => {
620                     self.ccache = Some(exe("ccache", &self.build));
621                 }
622                 "CFG_ENABLE_SCCACHE" if value == "1" => {
623                     self.ccache = Some(exe("sccache", &self.build));
624                 }
625                 "CFG_CONFIGURE_ARGS" if value.len() > 0 => {
626                     self.configure_args = value.split_whitespace()
627                                                .map(|s| s.to_string())
628                                                .collect();
629                 }
630                 "CFG_QEMU_ARMHF_ROOTFS" if value.len() > 0 => {
631                     let target = INTERNER.intern_str("arm-unknown-linux-gnueabihf");
632                     let target = self.target_config.entry(target).or_insert(Target::default());
633                     target.qemu_rootfs = Some(parse_configure_path(value));
634                 }
635                 "CFG_QEMU_AARCH64_ROOTFS" if value.len() > 0 => {
636                     let target = INTERNER.intern_str("aarch64-unknown-linux-gnu");
637                     let target = self.target_config.entry(target).or_insert(Target::default());
638                     target.qemu_rootfs = Some(parse_configure_path(value));
639                 }
640                 _ => {}
641             }
642         }
643     }
644
645     pub fn verbose(&self) -> bool {
646         self.verbose > 0
647     }
648
649     pub fn very_verbose(&self) -> bool {
650         self.verbose > 1
651     }
652 }
653
654 #[cfg(not(windows))]
655 fn parse_configure_path(path: &str) -> PathBuf {
656     path.into()
657 }
658
659 #[cfg(windows)]
660 fn parse_configure_path(path: &str) -> PathBuf {
661     // on windows, configure produces unix style paths e.g. /c/some/path but we
662     // only want real windows paths
663
664     use std::process::Command;
665     use build_helper;
666
667     // '/' is invalid in windows paths, so we can detect unix paths by the presence of it
668     if !path.contains('/') {
669         return path.into();
670     }
671
672     let win_path = build_helper::output(Command::new("cygpath").arg("-w").arg(path));
673     let win_path = win_path.trim();
674
675     win_path.into()
676 }
677
678 fn set<T>(field: &mut T, val: Option<T>) {
679     if let Some(v) = val {
680         *field = v;
681     }
682 }