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