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