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