@@ -489,7 +489,7 @@ def bin_root(self):
489
489
"""
490
490
return os .path .join (self .build_dir , self .build , "stage0" )
491
491
492
- def get_toml (self , key ):
492
+ def get_toml (self , key , section = None ):
493
493
"""Returns the value of the given key in config.toml, otherwise returns None
494
494
495
495
>>> rb = RustBuild()
@@ -501,12 +501,29 @@ def get_toml(self, key):
501
501
502
502
>>> rb.get_toml("key3") is None
503
503
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
504
514
"""
515
+
516
+ cur_section = None
505
517
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
+
506
522
match = re .match (r'^{}\s*=(.*)$' .format (key ), line )
507
523
if match is not None :
508
524
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 ()
510
527
return None
511
528
512
529
def cargo (self ):
@@ -589,7 +606,17 @@ def build_bootstrap(self):
589
606
env ["LIBRARY_PATH" ] = os .path .join (self .bin_root (), "lib" ) + \
590
607
(os .pathsep + env ["LIBRARY_PATH" ]) \
591
608
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
+
593
620
env ["PATH" ] = os .path .join (self .bin_root (), "bin" ) + \
594
621
os .pathsep + env ["PATH" ]
595
622
if not os .path .isfile (self .cargo ()):
0 commit comments