@@ -696,6 +696,36 @@ If you encounter an error missing from this list, please file an issue or a PR!"
696
696
// depfiles need to include the explicitly listed headers too
697
697
let deps = options. input_headers . iter ( ) . map ( SourceFile :: new) . collect ( ) ;
698
698
699
+ // Define macros added via command-line arguments so that
700
+ // dependent macros are generated correctly.
701
+ let mut macro_set = cmacro:: MacroSet :: new ( ) ;
702
+ let mut next_is_define = false ;
703
+ for arg in & options. clang_args {
704
+ let arg = if next_is_define {
705
+ next_is_define = false ;
706
+ arg. as_ref ( )
707
+ } else if let Some ( arg) = arg. strip_prefix ( "-D" ) {
708
+ if arg. is_empty ( ) {
709
+ next_is_define = true ;
710
+ continue ;
711
+ }
712
+
713
+ arg
714
+ } else {
715
+ continue ;
716
+ } ;
717
+
718
+ let ( name, value) = if let Some ( ( name, value) ) = arg. split_once ( '=' )
719
+ {
720
+ // FIXME: Value should be tokenized instead of taken verbatim.
721
+ ( name, vec ! [ value] )
722
+ } else {
723
+ ( arg, vec ! [ ] )
724
+ } ;
725
+
726
+ macro_set. define_var_macro ( name, value) ;
727
+ }
728
+
699
729
BindgenContext {
700
730
items : vec ! [ Some ( root_module) ] ,
701
731
includes : Default :: default ( ) ,
@@ -708,7 +738,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
708
738
semantic_parents : Default :: default ( ) ,
709
739
currently_parsed_types : vec ! [ ] ,
710
740
parsed_macros : Default :: default ( ) ,
711
- macro_set : Default :: default ( ) ,
741
+ macro_set,
712
742
function_names : Default :: default ( ) ,
713
743
type_names : Default :: default ( ) ,
714
744
replacements : Default :: default ( ) ,
0 commit comments