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