]> git.lizzy.rs Git - rust.git/blob - src/bootstrap/config.rs
Allow overriding build triple via flag.
[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.channel = "dev".to_string();
294         config.codegen_tests = true;
295         config.rust_dist_src = true;
296
297         config.on_fail = flags.on_fail;
298         config.stage = flags.stage;
299         config.src = flags.src;
300         config.jobs = flags.jobs;
301         config.cmd = flags.cmd;
302         config.incremental = flags.incremental;
303         config.keep_stage = flags.keep_stage;
304
305         let toml = file.map(|file| {
306             let mut f = t!(File::open(&file));
307             let mut contents = String::new();
308             t!(f.read_to_string(&mut contents));
309             match toml::from_str(&contents) {
310                 Ok(table) => table,
311                 Err(err) => {
312                     println!("failed to parse TOML configuration '{}': {}",
313                         file.display(), err);
314                     process::exit(2);
315                 }
316             }
317         }).unwrap_or_else(|| TomlConfig::default());
318
319         let build = toml.build.clone().unwrap_or(Build::default());
320         set(&mut config.build, build.build.clone().map(|x| INTERNER.intern_string(x)));
321         set(&mut config.build, flags.build);
322         if config.build.is_empty() {
323             // set by bootstrap.py
324             config.build = INTERNER.intern_str(&env::var("BUILD").unwrap());
325         }
326         config.hosts.push(config.build.clone());
327         for host in build.host.iter() {
328             let host = INTERNER.intern_str(host);
329             if !config.hosts.contains(&host) {
330                 config.hosts.push(host);
331             }
332         }
333         for target in config.hosts.iter().cloned()
334             .chain(build.target.iter().map(|s| INTERNER.intern_str(s)))
335         {
336             if !config.targets.contains(&target) {
337                 config.targets.push(target);
338             }
339         }
340         config.hosts = if !flags.host.is_empty() {
341             flags.host
342         } else {
343             config.hosts
344         };
345         config.targets = if !flags.target.is_empty() {
346             flags.target
347         } else {
348             config.targets
349         };
350
351         config.nodejs = build.nodejs.map(PathBuf::from);
352         config.gdb = build.gdb.map(PathBuf::from);
353         config.python = build.python.map(PathBuf::from);
354         set(&mut config.low_priority, build.low_priority);
355         set(&mut config.compiler_docs, build.compiler_docs);
356         set(&mut config.docs, build.docs);
357         set(&mut config.submodules, build.submodules);
358         set(&mut config.locked_deps, build.locked_deps);
359         set(&mut config.vendor, build.vendor);
360         set(&mut config.full_bootstrap, build.full_bootstrap);
361         set(&mut config.extended, build.extended);
362         set(&mut config.verbose, build.verbose);
363         set(&mut config.sanitizers, build.sanitizers);
364         set(&mut config.profiler, build.profiler);
365         set(&mut config.openssl_static, build.openssl_static);
366         config.verbose = cmp::max(config.verbose, flags.verbose);
367
368         if let Some(ref install) = toml.install {
369             config.prefix = install.prefix.clone().map(PathBuf::from);
370             config.sysconfdir = install.sysconfdir.clone().map(PathBuf::from);
371             config.docdir = install.docdir.clone().map(PathBuf::from);
372             config.bindir = install.bindir.clone().map(PathBuf::from);
373             config.libdir = install.libdir.clone().map(PathBuf::from);
374             config.mandir = install.mandir.clone().map(PathBuf::from);
375         }
376
377         if let Some(ref llvm) = toml.llvm {
378             match llvm.ccache {
379                 Some(StringOrBool::String(ref s)) => {
380                     config.ccache = Some(s.to_string())
381                 }
382                 Some(StringOrBool::Bool(true)) => {
383                     config.ccache = Some("ccache".to_string());
384                 }
385                 Some(StringOrBool::Bool(false)) | None => {}
386             }
387             set(&mut config.ninja, llvm.ninja);
388             set(&mut config.llvm_enabled, llvm.enabled);
389             set(&mut config.llvm_assertions, llvm.assertions);
390             set(&mut config.llvm_optimize, llvm.optimize);
391             set(&mut config.llvm_release_debuginfo, llvm.release_debuginfo);
392             set(&mut config.llvm_version_check, llvm.version_check);
393             set(&mut config.llvm_static_stdcpp, llvm.static_libstdcpp);
394             config.llvm_targets = llvm.targets.clone();
395             config.llvm_experimental_targets = llvm.experimental_targets.clone();
396             config.llvm_link_jobs = llvm.link_jobs;
397         }
398
399         if let Some(ref rust) = toml.rust {
400             set(&mut config.rust_debug_assertions, rust.debug_assertions);
401             set(&mut config.rust_debuginfo, rust.debuginfo);
402             set(&mut config.rust_debuginfo_lines, rust.debuginfo_lines);
403             set(&mut config.rust_debuginfo_only_std, rust.debuginfo_only_std);
404             set(&mut config.rust_optimize, rust.optimize);
405             set(&mut config.rust_optimize_tests, rust.optimize_tests);
406             set(&mut config.rust_debuginfo_tests, rust.debuginfo_tests);
407             set(&mut config.codegen_tests, rust.codegen_tests);
408             set(&mut config.rust_rpath, rust.rpath);
409             set(&mut config.debug_jemalloc, rust.debug_jemalloc);
410             set(&mut config.use_jemalloc, rust.use_jemalloc);
411             set(&mut config.backtrace, rust.backtrace);
412             set(&mut config.channel, rust.channel.clone());
413             config.rustc_default_linker = rust.default_linker.clone();
414             config.rustc_default_ar = rust.default_ar.clone();
415             config.musl_root = rust.musl_root.clone().map(PathBuf::from);
416
417             match rust.codegen_units {
418                 Some(0) => config.rust_codegen_units = num_cpus::get() as u32,
419                 Some(n) => config.rust_codegen_units = n,
420                 None => {}
421             }
422         }
423
424         if let Some(ref t) = toml.target {
425             for (triple, cfg) in t {
426                 let mut target = Target::default();
427
428                 if let Some(ref s) = cfg.llvm_config {
429                     target.llvm_config = Some(env::current_dir().unwrap().join(s));
430                 }
431                 if let Some(ref s) = cfg.jemalloc {
432                     target.jemalloc = Some(env::current_dir().unwrap().join(s));
433                 }
434                 if let Some(ref s) = cfg.android_ndk {
435                     target.ndk = Some(env::current_dir().unwrap().join(s));
436                 }
437                 target.cxx = cfg.cxx.clone().map(PathBuf::from);
438                 target.cc = cfg.cc.clone().map(PathBuf::from);
439                 target.musl_root = cfg.musl_root.clone().map(PathBuf::from);
440                 target.qemu_rootfs = cfg.qemu_rootfs.clone().map(PathBuf::from);
441
442                 config.target_config.insert(INTERNER.intern_string(triple.clone()), target);
443             }
444         }
445
446         if let Some(ref t) = toml.dist {
447             config.dist_sign_folder = t.sign_folder.clone().map(PathBuf::from);
448             config.dist_gpg_password_file = t.gpg_password_file.clone().map(PathBuf::from);
449             config.dist_upload_addr = t.upload_addr.clone();
450             set(&mut config.rust_dist_src, t.src_tarball);
451         }
452
453         let cwd = t!(env::current_dir());
454         let out = cwd.join("build");
455
456         let stage0_root = out.join(&config.build).join("stage0/bin");
457         config.initial_rustc = match build.rustc {
458             Some(s) => PathBuf::from(s),
459             None => stage0_root.join(exe("rustc", &config.build)),
460         };
461         config.initial_cargo = match build.cargo {
462             Some(s) => PathBuf::from(s),
463             None => stage0_root.join(exe("cargo", &config.build)),
464         };
465
466         // compat with `./configure` while we're still using that
467         if fs::metadata("config.mk").is_ok() {
468             config.update_with_config_mk();
469         }
470
471         config
472     }
473
474     /// "Temporary" routine to parse `config.mk` into this configuration.
475     ///
476     /// While we still have `./configure` this implements the ability to decode
477     /// that configuration into this. This isn't exactly a full-blown makefile
478     /// parser, but hey it gets the job done!
479     fn update_with_config_mk(&mut self) {
480         let mut config = String::new();
481         File::open("config.mk").unwrap().read_to_string(&mut config).unwrap();
482         for line in config.lines() {
483             let mut parts = line.splitn(2, ":=").map(|s| s.trim());
484             let key = parts.next().unwrap();
485             let value = match parts.next() {
486                 Some(n) if n.starts_with('\"') => &n[1..n.len() - 1],
487                 Some(n) => n,
488                 None => continue
489             };
490
491             macro_rules! check {
492                 ($(($name:expr, $val:expr),)*) => {
493                     if value == "1" {
494                         $(
495                             if key == concat!("CFG_ENABLE_", $name) {
496                                 $val = true;
497                                 continue
498                             }
499                             if key == concat!("CFG_DISABLE_", $name) {
500                                 $val = false;
501                                 continue
502                             }
503                         )*
504                     }
505                 }
506             }
507
508             check! {
509                 ("MANAGE_SUBMODULES", self.submodules),
510                 ("COMPILER_DOCS", self.compiler_docs),
511                 ("DOCS", self.docs),
512                 ("LLVM_ASSERTIONS", self.llvm_assertions),
513                 ("LLVM_RELEASE_DEBUGINFO", self.llvm_release_debuginfo),
514                 ("OPTIMIZE_LLVM", self.llvm_optimize),
515                 ("LLVM_VERSION_CHECK", self.llvm_version_check),
516                 ("LLVM_STATIC_STDCPP", self.llvm_static_stdcpp),
517                 ("LLVM_LINK_SHARED", self.llvm_link_shared),
518                 ("OPTIMIZE", self.rust_optimize),
519                 ("DEBUG_ASSERTIONS", self.rust_debug_assertions),
520                 ("DEBUGINFO", self.rust_debuginfo),
521                 ("DEBUGINFO_LINES", self.rust_debuginfo_lines),
522                 ("DEBUGINFO_ONLY_STD", self.rust_debuginfo_only_std),
523                 ("JEMALLOC", self.use_jemalloc),
524                 ("DEBUG_JEMALLOC", self.debug_jemalloc),
525                 ("RPATH", self.rust_rpath),
526                 ("OPTIMIZE_TESTS", self.rust_optimize_tests),
527                 ("DEBUGINFO_TESTS", self.rust_debuginfo_tests),
528                 ("QUIET_TESTS", self.quiet_tests),
529                 ("LOCAL_REBUILD", self.local_rebuild),
530                 ("NINJA", self.ninja),
531                 ("CODEGEN_TESTS", self.codegen_tests),
532                 ("LOCKED_DEPS", self.locked_deps),
533                 ("VENDOR", self.vendor),
534                 ("FULL_BOOTSTRAP", self.full_bootstrap),
535                 ("EXTENDED", self.extended),
536                 ("SANITIZERS", self.sanitizers),
537                 ("PROFILER", self.profiler),
538                 ("DIST_SRC", self.rust_dist_src),
539                 ("CARGO_OPENSSL_STATIC", self.openssl_static),
540             }
541
542             match key {
543                 "CFG_BUILD" if value.len() > 0 => self.build = INTERNER.intern_str(value),
544                 "CFG_HOST" if value.len() > 0 => {
545                     self.hosts.extend(value.split(" ").map(|s| INTERNER.intern_str(s)));
546
547                 }
548                 "CFG_TARGET" if value.len() > 0 => {
549                     self.targets.extend(value.split(" ").map(|s| INTERNER.intern_str(s)));
550                 }
551                 "CFG_EXPERIMENTAL_TARGETS" if value.len() > 0 => {
552                     self.llvm_experimental_targets = Some(value.to_string());
553                 }
554                 "CFG_MUSL_ROOT" if value.len() > 0 => {
555                     self.musl_root = Some(parse_configure_path(value));
556                 }
557                 "CFG_MUSL_ROOT_X86_64" if value.len() > 0 => {
558                     let target = INTERNER.intern_str("x86_64-unknown-linux-musl");
559                     let target = self.target_config.entry(target).or_insert(Target::default());
560                     target.musl_root = Some(parse_configure_path(value));
561                 }
562                 "CFG_MUSL_ROOT_I686" if value.len() > 0 => {
563                     let target = INTERNER.intern_str("i686-unknown-linux-musl");
564                     let target = self.target_config.entry(target).or_insert(Target::default());
565                     target.musl_root = Some(parse_configure_path(value));
566                 }
567                 "CFG_MUSL_ROOT_ARM" if value.len() > 0 => {
568                     let target = INTERNER.intern_str("arm-unknown-linux-musleabi");
569                     let target = self.target_config.entry(target).or_insert(Target::default());
570                     target.musl_root = Some(parse_configure_path(value));
571                 }
572                 "CFG_MUSL_ROOT_ARMHF" if value.len() > 0 => {
573                     let target = INTERNER.intern_str("arm-unknown-linux-musleabihf");
574                     let target = self.target_config.entry(target).or_insert(Target::default());
575                     target.musl_root = Some(parse_configure_path(value));
576                 }
577                 "CFG_MUSL_ROOT_ARMV7" if value.len() > 0 => {
578                     let target = INTERNER.intern_str("armv7-unknown-linux-musleabihf");
579                     let target = self.target_config.entry(target).or_insert(Target::default());
580                     target.musl_root = Some(parse_configure_path(value));
581                 }
582                 "CFG_DEFAULT_AR" if value.len() > 0 => {
583                     self.rustc_default_ar = Some(value.to_string());
584                 }
585                 "CFG_DEFAULT_LINKER" if value.len() > 0 => {
586                     self.rustc_default_linker = Some(value.to_string());
587                 }
588                 "CFG_GDB" if value.len() > 0 => {
589                     self.gdb = Some(parse_configure_path(value));
590                 }
591                 "CFG_RELEASE_CHANNEL" => {
592                     self.channel = value.to_string();
593                 }
594                 "CFG_PREFIX" => {
595                     self.prefix = Some(PathBuf::from(value));
596                 }
597                 "CFG_SYSCONFDIR" => {
598                     self.sysconfdir = Some(PathBuf::from(value));
599                 }
600                 "CFG_DOCDIR" => {
601                     self.docdir = Some(PathBuf::from(value));
602                 }
603                 "CFG_BINDIR" => {
604                     self.bindir = Some(PathBuf::from(value));
605                 }
606                 "CFG_LIBDIR" => {
607                     self.libdir = Some(PathBuf::from(value));
608                 }
609                 "CFG_LIBDIR_RELATIVE" => {
610                     self.libdir_relative = Some(PathBuf::from(value));
611                 }
612                 "CFG_MANDIR" => {
613                     self.mandir = Some(PathBuf::from(value));
614                 }
615                 "CFG_LLVM_ROOT" if value.len() > 0 => {
616                     let target = self.target_config.entry(self.build.clone())
617                                      .or_insert(Target::default());
618                     let root = parse_configure_path(value);
619                     target.llvm_config = Some(push_exe_path(root, &["bin", "llvm-config"]));
620                 }
621                 "CFG_JEMALLOC_ROOT" if value.len() > 0 => {
622                     let target = self.target_config.entry(self.build.clone())
623                                      .or_insert(Target::default());
624                     target.jemalloc = Some(parse_configure_path(value).join("libjemalloc_pic.a"));
625                 }
626                 "CFG_ARM_LINUX_ANDROIDEABI_NDK" if value.len() > 0 => {
627                     let target = INTERNER.intern_str("arm-linux-androideabi");
628                     let target = self.target_config.entry(target).or_insert(Target::default());
629                     target.ndk = Some(parse_configure_path(value));
630                 }
631                 "CFG_ARMV7_LINUX_ANDROIDEABI_NDK" if value.len() > 0 => {
632                     let target = INTERNER.intern_str("armv7-linux-androideabi");
633                     let target = self.target_config.entry(target).or_insert(Target::default());
634                     target.ndk = Some(parse_configure_path(value));
635                 }
636                 "CFG_I686_LINUX_ANDROID_NDK" if value.len() > 0 => {
637                     let target = INTERNER.intern_str("i686-linux-android");
638                     let target = self.target_config.entry(target).or_insert(Target::default());
639                     target.ndk = Some(parse_configure_path(value));
640                 }
641                 "CFG_AARCH64_LINUX_ANDROID_NDK" if value.len() > 0 => {
642                     let target = INTERNER.intern_str("aarch64-linux-android");
643                     let target = self.target_config.entry(target).or_insert(Target::default());
644                     target.ndk = Some(parse_configure_path(value));
645                 }
646                 "CFG_X86_64_LINUX_ANDROID_NDK" if value.len() > 0 => {
647                     let target = INTERNER.intern_str("x86_64-linux-android");
648                     let target = self.target_config.entry(target).or_insert(Target::default());
649                     target.ndk = Some(parse_configure_path(value));
650                 }
651                 "CFG_LOCAL_RUST_ROOT" if value.len() > 0 => {
652                     let path = parse_configure_path(value);
653                     self.initial_rustc = push_exe_path(path.clone(), &["bin", "rustc"]);
654                     self.initial_cargo = push_exe_path(path, &["bin", "cargo"]);
655                 }
656                 "CFG_PYTHON" if value.len() > 0 => {
657                     let path = parse_configure_path(value);
658                     self.python = Some(path);
659                 }
660                 "CFG_ENABLE_CCACHE" if value == "1" => {
661                     self.ccache = Some(exe("ccache", &self.build));
662                 }
663                 "CFG_ENABLE_SCCACHE" if value == "1" => {
664                     self.ccache = Some(exe("sccache", &self.build));
665                 }
666                 "CFG_CONFIGURE_ARGS" if value.len() > 0 => {
667                     self.configure_args = value.split_whitespace()
668                                                .map(|s| s.to_string())
669                                                .collect();
670                 }
671                 "CFG_QEMU_ARMHF_ROOTFS" if value.len() > 0 => {
672                     let target = INTERNER.intern_str("arm-unknown-linux-gnueabihf");
673                     let target = self.target_config.entry(target).or_insert(Target::default());
674                     target.qemu_rootfs = Some(parse_configure_path(value));
675                 }
676                 "CFG_QEMU_AARCH64_ROOTFS" if value.len() > 0 => {
677                     let target = INTERNER.intern_str("aarch64-unknown-linux-gnu");
678                     let target = self.target_config.entry(target).or_insert(Target::default());
679                     target.qemu_rootfs = Some(parse_configure_path(value));
680                 }
681                 _ => {}
682             }
683         }
684     }
685
686     pub fn verbose(&self) -> bool {
687         self.verbose > 0
688     }
689
690     pub fn very_verbose(&self) -> bool {
691         self.verbose > 1
692     }
693 }
694
695 #[cfg(not(windows))]
696 fn parse_configure_path(path: &str) -> PathBuf {
697     path.into()
698 }
699
700 #[cfg(windows)]
701 fn parse_configure_path(path: &str) -> PathBuf {
702     // on windows, configure produces unix style paths e.g. /c/some/path but we
703     // only want real windows paths
704
705     use std::process::Command;
706     use build_helper;
707
708     // '/' is invalid in windows paths, so we can detect unix paths by the presence of it
709     if !path.contains('/') {
710         return path.into();
711     }
712
713     let win_path = build_helper::output(Command::new("cygpath").arg("-w").arg(path));
714     let win_path = win_path.trim();
715
716     win_path.into()
717 }
718
719 fn set<T>(field: &mut T, val: Option<T>) {
720     if let Some(v) = val {
721         *field = v;
722     }
723 }