Skip to content

Commit 5ecf29d

Browse files
committed
bootstrap.py: respect crt-static
Bootstrap requires serde_derive, which needs proc-macro crate types, so it won't work with crt-static.
1 parent a5a875d commit 5ecf29d

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

src/bootstrap/bootstrap.py

+30-3
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ def bin_root(self):
489489
"""
490490
return os.path.join(self.build_dir, self.build, "stage0")
491491

492-
def get_toml(self, key):
492+
def get_toml(self, key, section=None):
493493
"""Returns the value of the given key in config.toml, otherwise returns None
494494
495495
>>> rb = RustBuild()
@@ -501,12 +501,29 @@ def get_toml(self, key):
501501
502502
>>> rb.get_toml("key3") is None
503503
True
504+
505+
Optionally also matches the section the key appears in
506+
507+
>>> rb.config_toml = '[a]\\nkey = "value1"\\n[b]\\nkey = "value2"'
508+
>>> rb.get_toml('key', 'a')
509+
'value1'
510+
>>> rb.get_toml('key', 'b')
511+
'value2'
512+
>>> rb.get_toml('key', 'c') is None
513+
True
504514
"""
515+
516+
cur_section = None
505517
for line in self.config_toml.splitlines():
518+
section_match = re.match(r'^\s*\[(.*)\]\s*$', line)
519+
if section_match is not None:
520+
cur_section = section_match.group(1)
521+
506522
match = re.match(r'^{}\s*=(.*)$'.format(key), line)
507523
if match is not None:
508524
value = match.group(1)
509-
return self.get_string(value) or value.strip()
525+
if section is None or section == cur_section:
526+
return self.get_string(value) or value.strip()
510527
return None
511528

512529
def cargo(self):
@@ -589,7 +606,17 @@ def build_bootstrap(self):
589606
env["LIBRARY_PATH"] = os.path.join(self.bin_root(), "lib") + \
590607
(os.pathsep + env["LIBRARY_PATH"]) \
591608
if "LIBRARY_PATH" in env else ""
592-
env["RUSTFLAGS"] = "-Cdebuginfo=2"
609+
env["RUSTFLAGS"] = "-Cdebuginfo=2 "
610+
611+
build_section = "target.{}".format(self.build_triple())
612+
target_features = []
613+
if self.get_toml("crt-static", build_section) == "true":
614+
target_features += ["+crt-static"]
615+
elif self.get_toml("crt-static", build_section) == "false":
616+
target_features += ["-crt-static"]
617+
if target_features:
618+
env["RUSTFLAGS"] += "-C target-feature=" + (",".join(target_features)) + " "
619+
593620
env["PATH"] = os.path.join(self.bin_root(), "bin") + \
594621
os.pathsep + env["PATH"]
595622
if not os.path.isfile(self.cargo()):

0 commit comments

Comments
 (0)