Skip to content

Commit 083179e

Browse files
committed
add rust cfg file to kbuild
Signed-off-by: Finn Behrens <[email protected]>
1 parent f60edb2 commit 083179e

File tree

1 file changed

+67
-1
lines changed

1 file changed

+67
-1
lines changed

scripts/kconfig/confdata.c

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,55 @@ static struct conf_printer kconfig_printer_cb =
636636
.print_comment = kconfig_print_comment,
637637
};
638638

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+
639688
/*
640689
* Header printer
641690
*
@@ -1043,7 +1092,7 @@ int conf_write_autoconf(int overwrite)
10431092
struct symbol *sym;
10441093
const char *name;
10451094
const char *autoconf_name = conf_get_autoconfig_name();
1046-
FILE *out, *out_h;
1095+
FILE *out, *out_h, *out_r;
10471096
int i;
10481097

10491098
if (!overwrite && is_present(autoconf_name))
@@ -1064,6 +1113,13 @@ int conf_write_autoconf(int overwrite)
10641113
return 1;
10651114
}
10661115

1116+
out_r = fopen(".tmprconfig", "w");
1117+
if (!out_r) {
1118+
fclose(out);
1119+
fclose(out_h);
1120+
return 1;
1121+
}
1122+
10671123
conf_write_heading(out, &kconfig_printer_cb, NULL);
10681124
conf_write_heading(out_h, &header_printer_cb, NULL);
10691125

@@ -1075,9 +1131,11 @@ int conf_write_autoconf(int overwrite)
10751131
/* write symbols to auto.conf and autoconf.h */
10761132
conf_write_symbol(out, sym, &kconfig_printer_cb, (void *)1);
10771133
conf_write_symbol(out_h, sym, &header_printer_cb, NULL);
1134+
conf_write_symbol(out_r, sym, &rconfig_printer_cb, NULL);
10781135
}
10791136
fclose(out);
10801137
fclose(out_h);
1138+
fclose(out_r);
10811139

10821140
name = getenv("KCONFIG_AUTOHEADER");
10831141
if (!name)
@@ -1087,6 +1145,14 @@ int conf_write_autoconf(int overwrite)
10871145
if (rename(".tmpconfig.h", name))
10881146
return 1;
10891147

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+
10901156
if (make_parent_dir(autoconf_name))
10911157
return 1;
10921158
/*

0 commit comments

Comments
 (0)