Skip to content

Commit 974c3d2

Browse files
committed
Ensure that ERR_LIB type can be named
1 parent b4bf601 commit 974c3d2

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
@@ -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\npub use {enum_type} as ErrLib;\n")
831+
.as_bytes(),
832+
);
816833
}

0 commit comments

Comments
 (0)