File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed
Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -810,7 +810,24 @@ fn generate_bindings(config: &Config) {
810810 }
811811
812812 let bindings = builder. generate ( ) . expect ( "Unable to generate bindings" ) ;
813+ let mut source_code = Vec :: new ( ) ;
813814 bindings
814- . write_to_file ( config. out_dir . join ( "bindings.rs" ) )
815- . expect ( "Couldn't write bindings!" ) ;
815+ . write ( Box :: new ( & mut source_code) )
816+ . expect ( "Couldn't serialize bindings!" ) ;
817+ ensure_err_lib_enum_is_named ( & mut source_code) ;
818+ fs:: write ( config. out_dir . join ( "bindings.rs" ) , source_code) . expect ( "Couldn't write bindings!" ) ;
819+ }
820+
821+ /// err.h has anonymous `enum { ERR_LIB_NONE = 1 }`, which makes a dodgy `_bindgen_ty_1` name
822+ fn ensure_err_lib_enum_is_named ( source_code : & mut Vec < u8 > ) {
823+ let src = String :: from_utf8_lossy ( source_code) ;
824+ let enum_type = src
825+ . split_once ( "ERR_LIB_SSL:" )
826+ . and_then ( |( _, def) | Some ( def. split_once ( "=" ) ?. 0 ) )
827+ . unwrap_or ( "_bindgen_ty_1" ) ;
828+
829+ source_code. extend_from_slice (
830+ format ! ( "\n /// Newtype for [`ERR_LIB_SSL`] constants\n pub use {enum_type} as ErrLib;\n " )
831+ . as_bytes ( ) ,
832+ ) ;
816833}
You can’t perform that action at this time.
0 commit comments