@@ -636,6 +636,55 @@ static struct conf_printer kconfig_printer_cb =
636
636
.print_comment = kconfig_print_comment ,
637
637
};
638
638
639
+ /*
640
+ * Rust configuration printer
641
+ *
642
+ * This printer is used when generating the resulting rustc configuration
643
+ * after kconfig invocation and `defconfig` files.
644
+ *
645
+ */
646
+ static void
647
+ rconfig_print_symbol (FILE * fp , struct symbol * sym , const char * value , void * arg )
648
+ {
649
+ const char * str ;
650
+
651
+ switch (sym -> type ) {
652
+ case S_INT :
653
+ case S_HEX :
654
+ case S_BOOLEAN :
655
+ case S_TRISTATE :
656
+ str = sym_escape_string_value (value );
657
+ if (* value == 'n' ) {
658
+ /* rust cfg does not support comments
659
+ bool skip_unset = (arg != NULL);
660
+
661
+ if (!skip_unset)
662
+ fprintf(fp, "# %s%s is not set\n",
663
+ CONFIG_, sym->name);*/
664
+ return ;
665
+ }
666
+ break ;
667
+ default :
668
+ str = value ;
669
+ break ;
670
+ }
671
+
672
+ fprintf (fp , "--cfg=%s%s=%s\n" , CONFIG_ , sym -> name , str );
673
+ }
674
+
675
+ static void
676
+ rconfig_print_comment (FILE * fp , const char * value , void * arg )
677
+ {
678
+ fprintf (stderr , "could not print commend\n" );
679
+ return ;
680
+ }
681
+
682
+ static struct conf_printer rconfig_printer_cb =
683
+ {
684
+ .print_symbol = rconfig_print_symbol ,
685
+ .print_comment = rconfig_print_comment ,
686
+ };
687
+
639
688
/*
640
689
* Header printer
641
690
*
@@ -1043,7 +1092,7 @@ int conf_write_autoconf(int overwrite)
1043
1092
struct symbol * sym ;
1044
1093
const char * name ;
1045
1094
const char * autoconf_name = conf_get_autoconfig_name ();
1046
- FILE * out , * out_h ;
1095
+ FILE * out , * out_h , * out_r ;
1047
1096
int i ;
1048
1097
1049
1098
if (!overwrite && is_present (autoconf_name ))
@@ -1064,6 +1113,13 @@ int conf_write_autoconf(int overwrite)
1064
1113
return 1 ;
1065
1114
}
1066
1115
1116
+ out_r = fopen (".tmprconfig" , "w" );
1117
+ if (!out_r ) {
1118
+ fclose (out );
1119
+ fclose (out_h );
1120
+ return 1 ;
1121
+ }
1122
+
1067
1123
conf_write_heading (out , & kconfig_printer_cb , NULL );
1068
1124
conf_write_heading (out_h , & header_printer_cb , NULL );
1069
1125
@@ -1075,9 +1131,11 @@ int conf_write_autoconf(int overwrite)
1075
1131
/* write symbols to auto.conf and autoconf.h */
1076
1132
conf_write_symbol (out , sym , & kconfig_printer_cb , (void * )1 );
1077
1133
conf_write_symbol (out_h , sym , & header_printer_cb , NULL );
1134
+ conf_write_symbol (out_r , sym , & rconfig_printer_cb , NULL );
1078
1135
}
1079
1136
fclose (out );
1080
1137
fclose (out_h );
1138
+ fclose (out_r );
1081
1139
1082
1140
name = getenv ("KCONFIG_AUTOHEADER" );
1083
1141
if (!name )
@@ -1087,6 +1145,14 @@ int conf_write_autoconf(int overwrite)
1087
1145
if (rename (".tmpconfig.h" , name ))
1088
1146
return 1 ;
1089
1147
1148
+ name = getenv ("KCONFIG_RUSTCONFIG" );
1149
+ if (!name )
1150
+ name = "include/generated/rust_cfg" ;
1151
+ if (make_parent_dir (name ))
1152
+ return 1 ;
1153
+ if (rename (".tmprconfig" , name ))
1154
+ return 1 ;
1155
+
1090
1156
if (make_parent_dir (autoconf_name ))
1091
1157
return 1 ;
1092
1158
/*
0 commit comments