@@ -763,6 +763,9 @@ static void print_symbol_for_c(FILE *fp, struct symbol *sym)
763763static void print_symbol_for_rustccfg (FILE * fp , struct symbol * sym )
764764{
765765 const char * val ;
766+ const char * val_prefix = "" ;
767+ char * val_prefixed = NULL ;
768+ size_t val_prefixed_len ;
766769 char * escaped = NULL ;
767770
768771 if (sym -> type == S_UNKNOWN )
@@ -771,12 +774,10 @@ static void print_symbol_for_rustccfg(FILE *fp, struct symbol *sym)
771774 val = sym_get_string_value (sym );
772775
773776 switch (sym -> type ) {
774- case S_INT :
775- case S_HEX :
776777 case S_BOOLEAN :
777778 case S_TRISTATE :
778779 /*
779- * We don't care about disabled ones, i.e. no need for
780+ * We do not care about disabled ones, i.e. no need for
780781 * what otherwise are "comments" in other printers.
781782 */
782783 if (* val == 'n' )
@@ -791,23 +792,31 @@ static void print_symbol_for_rustccfg(FILE *fp, struct symbol *sym)
791792 * a `--cfg CONFIG_X="y"` or `--cfg CONFIG_X="m"`, which can
792793 * be used as the equivalent of `IS_BUILTIN()`/`IS_MODULE()`.
793794 */
794- if (* val == 'y' || * val == 'm' )
795- fprintf (fp , "--cfg=%s%s\n" , CONFIG_ , sym -> name );
796-
797- escaped = escape_string_value (val );
798- val = escaped ;
795+ fprintf (fp , "--cfg=%s%s\n" , CONFIG_ , sym -> name );
799796 break ;
800- case S_STRING :
801- escaped = escape_string_value (val );
802- val = escaped ;
797+ case S_HEX :
798+ if ( val [ 0 ] != '0' || (val [ 1 ] != 'x' && val [ 1 ] != 'X' ))
799+ val_prefix = "0x" ;
803800 break ;
804801 default :
805802 break ;
806803 }
807804
805+ if (strlen (val_prefix ) > 0 ) {
806+ val_prefixed_len = strlen (val ) + strlen (val_prefix ) + 1 ;
807+ val_prefixed = xmalloc (val_prefixed_len );
808+ snprintf (val_prefixed , val_prefixed_len , "%s%s" , val_prefix , val );
809+ val = val_prefixed ;
810+ }
811+
812+ /* All values get escaped: the `--cfg` option only takes strings */
813+ escaped = escape_string_value (val );
814+ val = escaped ;
815+
808816 fprintf (fp , "--cfg=%s%s=%s\n" , CONFIG_ , sym -> name , val );
809817
810818 free (escaped );
819+ free (val_prefixed );
811820}
812821
813822/*
0 commit comments