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 @@ -814,7 +814,24 @@ fn generate_bindings(config: &Config) {
814814 }
815815
816816 let bindings = builder. generate ( ) . expect ( "Unable to generate bindings" ) ;
817+ let mut source_code = Vec :: new ( ) ;
817818 bindings
818- . write_to_file ( config. out_dir . join ( "bindings.rs" ) )
819- . expect ( "Couldn't write bindings!" ) ;
819+ . write ( Box :: new ( & mut source_code) )
820+ . expect ( "Couldn't serialize bindings!" ) ;
821+ ensure_err_lib_enum_is_named ( & mut source_code) ;
822+ fs:: write ( config. out_dir . join ( "bindings.rs" ) , source_code) . expect ( "Couldn't write bindings!" ) ;
823+ }
824+
825+ /// err.h has anonymous `enum { ERR_LIB_NONE = 1 }`, which makes a dodgy `_bindgen_ty_1` name
826+ fn ensure_err_lib_enum_is_named ( source_code : & mut Vec < u8 > ) {
827+ let src = String :: from_utf8_lossy ( source_code) ;
828+ let enum_type = src
829+ . split_once ( "ERR_LIB_SSL:" )
830+ . and_then ( |( _, def) | Some ( def. split_once ( "=" ) ?. 0 ) )
831+ . unwrap_or ( "_bindgen_ty_1" ) ;
832+
833+ source_code. extend_from_slice (
834+ format ! ( "\n /// Newtype for [`ERR_LIB_SSL`] constants\n pub use {enum_type} as ErrLib;\n " )
835+ . as_bytes ( ) ,
836+ ) ;
820837}
You can’t perform that action at this time.
0 commit comments