Skip to content

Commit 6e16f39

Browse files
committed
Ensure that ERR_LIB type can be named
1 parent 43ccedd commit 6e16f39

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

boring-sys/build/main.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff 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\npub use {enum_type} as ErrLib;\n")
835+
.as_bytes(),
836+
);
820837
}

0 commit comments

Comments
 (0)