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