@@ -696,6 +696,36 @@ If you encounter an error missing from this list, please file an issue or a PR!"
696696 // depfiles need to include the explicitly listed headers too
697697 let deps = options. input_headers . iter ( ) . map ( SourceFile :: new) . collect ( ) ;
698698
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+
699729 BindgenContext {
700730 items : vec ! [ Some ( root_module) ] ,
701731 includes : Default :: default ( ) ,
@@ -708,7 +738,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
708738 semantic_parents : Default :: default ( ) ,
709739 currently_parsed_types : vec ! [ ] ,
710740 parsed_macros : Default :: default ( ) ,
711- macro_set : Default :: default ( ) ,
741+ macro_set,
712742 function_names : Default :: default ( ) ,
713743 type_names : Default :: default ( ) ,
714744 replacements : Default :: default ( ) ,
0 commit comments