11
11
// This builds a program that is run on the compilation host before the code is compiled. It can
12
12
// output configuration settings that affect the compilation.
13
13
14
+ use std:: collections:: BTreeMap ;
14
15
use std:: env;
15
16
use std:: fs:: File ;
16
17
use std:: io:: { BufRead , BufReader , Write } ;
@@ -27,19 +28,26 @@ mod devicetree;
27
28
/// Export boolean Kconfig entries. This must happen in any crate that wishes to access the
28
29
/// configuration settings.
29
30
pub fn export_bool_kconfig ( ) {
30
- let dotconfig = env:: var ( "DOTCONFIG " ) . expect ( "DOTCONFIG must be set by wrapper" ) ;
31
+ let build_dir = env:: var ( "BUILD_DIR " ) . expect ( "BUILD_DIR must be set by wrapper" ) ;
31
32
32
- // Ensure the build script is rerun when the dotconfig changes.
33
- println ! ( "cargo:rerun-if-env-changed=DOTCONFIG" ) ;
34
- println ! ( "cargo-rerun-if-changed={}" , dotconfig) ;
33
+ let bool_options_path = Path :: new ( & build_dir)
34
+ . join ( "rust-kconfig-bool-options.json" )
35
+ . to_str ( )
36
+ . unwrap ( )
37
+ . to_string ( ) ;
35
38
36
- let config_y = Regex :: new ( r"^(CONFIG_.*)=y$" ) . unwrap ( ) ;
39
+ // Ensure the build script is rerun when kconfig bool options change.
40
+ println ! ( "cargo:rerun-if-changed={}" , bool_options_path) ;
37
41
38
- let file = File :: open ( & dotconfig) . expect ( "Unable to open dotconfig" ) ;
39
- for line in BufReader :: new ( file) . lines ( ) {
40
- let line = line. expect ( "reading line from dotconfig" ) ;
41
- if let Some ( caps) = config_y. captures ( & line) {
42
- println ! ( "cargo:rustc-cfg={}" , & caps[ 1 ] ) ;
42
+ let bool_options = File :: open ( & bool_options_path) . expect ( "Unable to open bool options" ) ;
43
+ let bool_options: BTreeMap < String , String > =
44
+ serde_yaml_ng:: from_reader ( bool_options) . expect ( "Unable to parse bool options" ) ;
45
+
46
+ for ( key, value) in bool_options. iter ( ) {
47
+ println ! ( "cargo:rustc-check-cfg=cfg({})" , key) ;
48
+
49
+ if value == "y" {
50
+ println ! ( "cargo:rustc-cfg={}" , key) ;
43
51
}
44
52
}
45
53
}
0 commit comments