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