Skip to content

Commit 0a54e4d

Browse files
committed
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.
1 parent 046e687 commit 0a54e4d

File tree

3 files changed

+123
-0
lines changed

3 files changed

+123
-0
lines changed

src/bootstrap/bootstrap.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ def get_toml(self, key):
135135
return self.get_string(line)
136136
return None
137137

138+
def get_mk(self, key):
139+
for line in iter(self.config_mk.splitlines()):
140+
if line.startswith(key):
141+
return line[line.find(':=') + 2:].strip()
142+
return None
143+
138144
def cargo(self):
139145
config = self.get_toml('cargo')
140146
if config:
@@ -145,6 +151,9 @@ def rustc(self):
145151
config = self.get_toml('rustc')
146152
if config:
147153
return config
154+
config = self.get_mk('CFG_LOCAL_RUST')
155+
if config:
156+
return config + '/bin/rustc' + self.exe_suffix()
148157
return os.path.join(self.bin_root(), "bin/rustc" + self.exe_suffix())
149158

150159
def get_string(self, line):
@@ -187,6 +196,9 @@ def run(self, args, env):
187196

188197
def build_triple(self):
189198
config = self.get_toml('build')
199+
if config:
200+
return config
201+
config = self.get_mk('CFG_BUILD')
190202
if config:
191203
return config
192204
try:
@@ -279,6 +291,10 @@ def build_triple(self):
279291
rb.config_toml = config.read()
280292
except:
281293
pass
294+
try:
295+
rb.config_mk = open('config.mk').read()
296+
except:
297+
pass
282298

283299
# Fetch/build the bootstrap
284300
rb.build = rb.build_triple()

src/bootstrap/build/compile.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ pub fn rustc<'a>(build: &'a Build, stage: u32, target: &str,
118118
.env("CFG_RELEASE_CHANNEL", &build.config.channel)
119119
.env("CFG_VERSION", &build.version)
120120
.env("CFG_BOOTSTRAP_KEY", &build.bootstrap_key)
121+
.env("CFG_PREFIX", build.config.prefix.clone().unwrap_or(String::new()))
121122
.env("RUSTC_BOOTSTRAP_KEY", &build.bootstrap_key)
122123
.env("CFG_LIBDIR_RELATIVE", "lib");
123124

src/bootstrap/build/config.rs

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ pub struct Config {
6565
// misc
6666
pub channel: String,
6767
pub musl_root: Option<PathBuf>,
68+
pub prefix: Option<String>,
6869
}
6970

7071
/// Per-target configuration stored in the global configuration structure.
@@ -246,6 +247,111 @@ impl Config {
246247

247248
return config
248249
}
250+
251+
pub fn update_with_config_mk(&mut self) {
252+
let mut config = String::new();
253+
File::open("config.mk").unwrap().read_to_string(&mut config).unwrap();
254+
for line in config.lines() {
255+
let mut parts = line.splitn(2, ":=").map(|s| s.trim());
256+
let key = parts.next().unwrap();
257+
let value = match parts.next() {
258+
Some(n) if n.starts_with('\"') => &n[1..n.len() - 1],
259+
Some(n) => n,
260+
None => continue
261+
};
262+
263+
macro_rules! check {
264+
($(($name:expr, $val:expr),)*) => {
265+
if value == "1" {
266+
$(
267+
if key == concat!("CFG_ENABLE_", $name) {
268+
$val = true;
269+
continue
270+
}
271+
if key == concat!("CFG_DISABLE_", $name) {
272+
$val = false;
273+
continue
274+
}
275+
)*
276+
}
277+
}
278+
}
279+
280+
check! {
281+
("CCACHE", self.ccache),
282+
("MANAGE_SUBMODULES", self.submodules),
283+
("COMPILER_DOCS", self.compiler_docs),
284+
("DOCS", self.docs),
285+
("LLVM_ASSERTIONS", self.llvm_assertions),
286+
("OPTIMIZE_LLVM", self.llvm_optimize),
287+
("LLVM_VERSION_CHECK", self.llvm_version_check),
288+
("LLVM_STATIC_STDCPP", self.llvm_static_stdcpp),
289+
("OPTIMIZE", self.rust_optimize),
290+
("DEBUG_ASSERTIONS", self.rust_debug_assertions),
291+
("DEBUGINFO", self.rust_debuginfo),
292+
("JEMALLOC", self.use_jemalloc),
293+
("DEBUG_JEMALLOC", self.debug_jemalloc),
294+
("RPATH", self.rust_rpath),
295+
}
296+
297+
match key {
298+
"CFG_BUILD" => self.build = value.to_string(),
299+
"CFG_HOST" => {
300+
self.host = value.split(" ").map(|s| s.to_string())
301+
.collect();
302+
}
303+
"CFG_TARGET" => {
304+
self.target = value.split(" ").map(|s| s.to_string())
305+
.collect();
306+
}
307+
"CFG_MUSL_ROOT" if value.len() > 0 => {
308+
self.musl_root = Some(PathBuf::from(value));
309+
}
310+
"CFG_DEFAULT_AR" if value.len() > 0 => {
311+
self.rustc_default_ar = Some(value.to_string());
312+
}
313+
"CFG_DEFAULT_LINKER" if value.len() > 0 => {
314+
self.rustc_default_linker = Some(value.to_string());
315+
}
316+
"CFG_RELEASE_CHANNEL" => {
317+
self.channel = value.to_string();
318+
}
319+
"CFG_PREFIX" => {
320+
self.prefix = Some(value.to_string());
321+
}
322+
"CFG_LLVM_ROOT" if value.len() > 0 => {
323+
let target = self.target_config.entry(self.build.clone())
324+
.or_insert(Target::default());
325+
let root = PathBuf::from(value);
326+
target.llvm_config = Some(root.join("bin/llvm-config"));
327+
}
328+
"CFG_JEMALLOC_ROOT" if value.len() > 0 => {
329+
let target = self.target_config.entry(self.build.clone())
330+
.or_insert(Target::default());
331+
target.jemalloc = Some(PathBuf::from(value));
332+
}
333+
"CFG_ARM_LINUX_ANDROIDEABI_NDK" if value.len() > 0 => {
334+
let target = "arm-linux-androideabi".to_string();
335+
let target = self.target_config.entry(target)
336+
.or_insert(Target::default());
337+
target.ndk = Some(PathBuf::from(value));
338+
}
339+
"CFG_I686_LINUX_ANDROID_NDK" if value.len() > 0 => {
340+
let target = "i686-linux-androideabi".to_string();
341+
let target = self.target_config.entry(target)
342+
.or_insert(Target::default());
343+
target.ndk = Some(PathBuf::from(value));
344+
}
345+
"CFG_AARCH64_LINUX_ANDROID_NDK" if value.len() > 0 => {
346+
let target = "aarch64-linux-androideabi".to_string();
347+
let target = self.target_config.entry(target)
348+
.or_insert(Target::default());
349+
target.ndk = Some(PathBuf::from(value));
350+
}
351+
_ => {}
352+
}
353+
}
354+
}
249355
}
250356

251357
fn set<T>(field: &mut T, val: Option<T>) {

0 commit comments

Comments
 (0)