about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/bootstrap/bootstrap.py16
-rw-r--r--src/bootstrap/build/compile.rs1
-rw-r--r--src/bootstrap/build/config.rs106
3 files changed, 123 insertions, 0 deletions
diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py
index 43530464545..744c30aa08f 100644
--- a/src/bootstrap/bootstrap.py
+++ b/src/bootstrap/bootstrap.py
@@ -135,6 +135,12 @@ class RustBuild:
                 return self.get_string(line)
         return None
 
+    def get_mk(self, key):
+        for line in iter(self.config_mk.splitlines()):
+            if line.startswith(key):
+                return line[line.find(':=') + 2:].strip()
+        return None
+
     def cargo(self):
         config = self.get_toml('cargo')
         if config:
@@ -145,6 +151,9 @@ class RustBuild:
         config = self.get_toml('rustc')
         if config:
             return config
+        config = self.get_mk('CFG_LOCAL_RUST')
+        if config:
+            return config + '/bin/rustc' + self.exe_suffix()
         return os.path.join(self.bin_root(), "bin/rustc" + self.exe_suffix())
 
     def get_string(self, line):
@@ -189,6 +198,9 @@ class RustBuild:
         config = self.get_toml('build')
         if config:
             return config
+        config = self.get_mk('CFG_BUILD')
+        if config:
+            return config
         try:
             ostype = subprocess.check_output(['uname', '-s']).strip()
             cputype = subprocess.check_output(['uname', '-m']).strip()
@@ -279,6 +291,10 @@ try:
         rb.config_toml = config.read()
 except:
     pass
+try:
+    rb.config_mk = open('config.mk').read()
+except:
+    pass
 
 # Fetch/build the bootstrap
 rb.build = rb.build_triple()
diff --git a/src/bootstrap/build/compile.rs b/src/bootstrap/build/compile.rs
index 05b444633b4..c22648b4710 100644
--- a/src/bootstrap/build/compile.rs
+++ b/src/bootstrap/build/compile.rs
@@ -118,6 +118,7 @@ pub fn rustc<'a>(build: &'a Build, stage: u32, target: &str,
          .env("CFG_RELEASE_CHANNEL", &build.config.channel)
          .env("CFG_VERSION", &build.version)
          .env("CFG_BOOTSTRAP_KEY", &build.bootstrap_key)
+         .env("CFG_PREFIX", build.config.prefix.clone().unwrap_or(String::new()))
          .env("RUSTC_BOOTSTRAP_KEY", &build.bootstrap_key)
          .env("CFG_LIBDIR_RELATIVE", "lib");
 
diff --git a/src/bootstrap/build/config.rs b/src/bootstrap/build/config.rs
index 862ee15cb08..1e67c4a9a3e 100644
--- a/src/bootstrap/build/config.rs
+++ b/src/bootstrap/build/config.rs
@@ -65,6 +65,7 @@ pub struct Config {
     // misc
     pub channel: String,
     pub musl_root: Option<PathBuf>,
+    pub prefix: Option<String>,
 }
 
 /// Per-target configuration stored in the global configuration structure.
@@ -246,6 +247,111 @@ impl Config {
 
         return config
     }
+
+    pub fn update_with_config_mk(&mut self) {
+        let mut config = String::new();
+        File::open("config.mk").unwrap().read_to_string(&mut config).unwrap();
+        for line in config.lines() {
+            let mut parts = line.splitn(2, ":=").map(|s| s.trim());
+            let key = parts.next().unwrap();
+            let value = match parts.next() {
+                Some(n) if n.starts_with('\"') => &n[1..n.len() - 1],
+                Some(n) => n,
+                None => continue
+            };
+
+            macro_rules! check {
+                ($(($name:expr, $val:expr),)*) => {
+                    if value == "1" {
+                        $(
+                            if key == concat!("CFG_ENABLE_", $name) {
+                                $val = true;
+                                continue
+                            }
+                            if key == concat!("CFG_DISABLE_", $name) {
+                                $val = false;
+                                continue
+                            }
+                        )*
+                    }
+                }
+            }
+
+            check! {
+                ("CCACHE", self.ccache),
+                ("MANAGE_SUBMODULES", self.submodules),
+                ("COMPILER_DOCS", self.compiler_docs),
+                ("DOCS", self.docs),
+                ("LLVM_ASSERTIONS", self.llvm_assertions),
+                ("OPTIMIZE_LLVM", self.llvm_optimize),
+                ("LLVM_VERSION_CHECK", self.llvm_version_check),
+                ("LLVM_STATIC_STDCPP", self.llvm_static_stdcpp),
+                ("OPTIMIZE", self.rust_optimize),
+                ("DEBUG_ASSERTIONS", self.rust_debug_assertions),
+                ("DEBUGINFO", self.rust_debuginfo),
+                ("JEMALLOC", self.use_jemalloc),
+                ("DEBUG_JEMALLOC", self.debug_jemalloc),
+                ("RPATH", self.rust_rpath),
+            }
+
+            match key {
+                "CFG_BUILD" => self.build = value.to_string(),
+                "CFG_HOST" => {
+                    self.host = value.split(" ").map(|s| s.to_string())
+                                     .collect();
+                }
+                "CFG_TARGET" => {
+                    self.target = value.split(" ").map(|s| s.to_string())
+                                       .collect();
+                }
+                "CFG_MUSL_ROOT" if value.len() > 0 => {
+                    self.musl_root = Some(PathBuf::from(value));
+                }
+                "CFG_DEFAULT_AR" if value.len() > 0 => {
+                    self.rustc_default_ar = Some(value.to_string());
+                }
+                "CFG_DEFAULT_LINKER" if value.len() > 0 => {
+                    self.rustc_default_linker = Some(value.to_string());
+                }
+                "CFG_RELEASE_CHANNEL" => {
+                    self.channel = value.to_string();
+                }
+                "CFG_PREFIX" => {
+                    self.prefix = Some(value.to_string());
+                }
+                "CFG_LLVM_ROOT" if value.len() > 0 => {
+                    let target = self.target_config.entry(self.build.clone())
+                                     .or_insert(Target::default());
+                    let root = PathBuf::from(value);
+                    target.llvm_config = Some(root.join("bin/llvm-config"));
+                }
+                "CFG_JEMALLOC_ROOT" if value.len() > 0 => {
+                    let target = self.target_config.entry(self.build.clone())
+                                     .or_insert(Target::default());
+                    target.jemalloc = Some(PathBuf::from(value));
+                }
+                "CFG_ARM_LINUX_ANDROIDEABI_NDK" if value.len() > 0 => {
+                    let target = "arm-linux-androideabi".to_string();
+                    let target = self.target_config.entry(target)
+                                     .or_insert(Target::default());
+                    target.ndk = Some(PathBuf::from(value));
+                }
+                "CFG_I686_LINUX_ANDROID_NDK" if value.len() > 0 => {
+                    let target = "i686-linux-androideabi".to_string();
+                    let target = self.target_config.entry(target)
+                                     .or_insert(Target::default());
+                    target.ndk = Some(PathBuf::from(value));
+                }
+                "CFG_AARCH64_LINUX_ANDROID_NDK" if value.len() > 0 => {
+                    let target = "aarch64-linux-androideabi".to_string();
+                    let target = self.target_config.entry(target)
+                                     .or_insert(Target::default());
+                    target.ndk = Some(PathBuf::from(value));
+                }
+                _ => {}
+            }
+        }
+    }
 }
 
 fn set<T>(field: &mut T, val: Option<T>) {