bootstrap: Read configuration from config.mk

During the transition period where we're still using ./configure and makefiles,
read some extra configuration from `config.mk` if it's present. This means that
the bootstrap build should be configured the same as the original ./configure
invocation.

Eventually this will all be removed in favor of only storing information in
`config.toml` (e.g. the configure script will generate config.toml), but for now
this should suffice.
This commit is contained in:
Alex Crichton 2015-11-19 16:55:21 -08:00
parent 046e6874c4
commit 0a54e4dd87
3 changed files with 123 additions and 0 deletions

View File

@ -135,6 +135,12 @@ class RustBuild:
return self.get_string(line) return self.get_string(line)
return None 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): def cargo(self):
config = self.get_toml('cargo') config = self.get_toml('cargo')
if config: if config:
@ -145,6 +151,9 @@ class RustBuild:
config = self.get_toml('rustc') config = self.get_toml('rustc')
if config: if config:
return 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()) return os.path.join(self.bin_root(), "bin/rustc" + self.exe_suffix())
def get_string(self, line): def get_string(self, line):
@ -187,6 +196,9 @@ class RustBuild:
def build_triple(self): def build_triple(self):
config = self.get_toml('build') config = self.get_toml('build')
if config:
return config
config = self.get_mk('CFG_BUILD')
if config: if config:
return config return config
try: try:
@ -279,6 +291,10 @@ try:
rb.config_toml = config.read() rb.config_toml = config.read()
except: except:
pass pass
try:
rb.config_mk = open('config.mk').read()
except:
pass
# Fetch/build the bootstrap # Fetch/build the bootstrap
rb.build = rb.build_triple() rb.build = rb.build_triple()

View File

@ -118,6 +118,7 @@ pub fn rustc<'a>(build: &'a Build, stage: u32, target: &str,
.env("CFG_RELEASE_CHANNEL", &build.config.channel) .env("CFG_RELEASE_CHANNEL", &build.config.channel)
.env("CFG_VERSION", &build.version) .env("CFG_VERSION", &build.version)
.env("CFG_BOOTSTRAP_KEY", &build.bootstrap_key) .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("RUSTC_BOOTSTRAP_KEY", &build.bootstrap_key)
.env("CFG_LIBDIR_RELATIVE", "lib"); .env("CFG_LIBDIR_RELATIVE", "lib");

View File

@ -65,6 +65,7 @@ pub struct Config {
// misc // misc
pub channel: String, pub channel: String,
pub musl_root: Option<PathBuf>, pub musl_root: Option<PathBuf>,
pub prefix: Option<String>,
} }
/// Per-target configuration stored in the global configuration structure. /// Per-target configuration stored in the global configuration structure.
@ -246,6 +247,111 @@ impl Config {
return 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>) { fn set<T>(field: &mut T, val: Option<T>) {