Loading Cargo.toml +3 −0 Original line number Diff line number Diff line Loading @@ -6,3 +6,6 @@ members = [ "openssl-sys", "systest", ] [patch.crates-io] bindgen = { git = "https://github.com/daviddrysdale/rust-bindgen", branch = "allowlist-file" } openssl-sys/build/find_normal.rs +11 −10 Original line number Diff line number Diff line Loading @@ -209,7 +209,7 @@ fn try_pkg_config() { } }; super::validate_headers(&lib.include_paths); super::postprocess(&lib.include_paths); for include in lib.include_paths.iter() { println!("cargo:include={}", include.display()); Loading @@ -227,17 +227,18 @@ fn try_vcpkg() { // vcpkg will not emit any metadata if it can not find libraries // appropriate for the target triple with the desired linkage. let lib = vcpkg::Config::new() let lib = match vcpkg::Config::new() .emit_includes(true) .find_package("openssl"); if let Err(e) = lib { .find_package("openssl") { Ok(lit) => lib, Err(e) => { println!("note: vcpkg did not find openssl: {}", e); return; } }; let lib = lib.unwrap(); super::validate_headers(&lib.include_paths); super::postprocess(&lib.include_paths); println!("cargo:rustc-link-lib=user32"); println!("cargo:rustc-link-lib=gdi32"); Loading openssl-sys/build/main.rs +9 −4 Original line number Diff line number Diff line Loading @@ -86,7 +86,7 @@ fn main() { ); println!("cargo:include={}", include_dir.to_string_lossy()); let version = validate_headers(&[include_dir.clone()]); let version = postprocess(&[include_dir.clone()]); let libs_env = env("OPENSSL_LIBS"); let libs = match libs_env.as_ref().and_then(|s| s.to_str()) { Loading Loading @@ -128,9 +128,6 @@ fn main() { println!("cargo:rustc-link-lib=dylib=ws2_32"); println!("cargo:rustc-link-lib=dylib=advapi32"); } #[cfg(feature = "bindgen")] run_bindgen::run(&include_dir); } fn check_rustc_versions() { Loading @@ -141,6 +138,14 @@ fn check_rustc_versions() { } } fn postprocess(include_dirs: &[PathBuf]) -> Version { let version = validate_headers(include_dirs); #[cfg(feature = "bindgen")] run_bindgen::run(&include_dirs); version } /// Validates the header files found in `include_dir` and then returns the /// version string of OpenSSL. #[allow(clippy::manual_strip)] // we need to support pre-1.45.0 Loading openssl-sys/build/run_bindgen.rs +24 −8 Original line number Diff line number Diff line use bindgen::callbacks::{MacroParsingBehavior, ParseCallbacks}; use bindgen::RustTarget; use std::env; use std::path::{Path, PathBuf}; use std::path::PathBuf; const INCLUDES: &str = " #include <openssl/crypto.h> #include <openssl/stack.h> "; pub fn run(include_dir: &Path) { pub fn run(include_dirs: &[PathBuf]) { let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap()); bindgen::builder() let mut builder = bindgen::builder() .parse_callbacks(Box::new(OpensslCallbacks)) .rust_target(RustTarget::Stable_1_47) .ctypes_prefix("::libc") .raw_line("use libc::*;") .blocklist_file("stdlib.h") .blocklist_file("time.h") .allowlist_file(".*/openssl/[^/]+.h") .allowlist_recursively(false) // libc is missing pthread_once_t on macOS .blocklist_type("CRYPTO_ONCE") .blocklist_function("CRYPTO_THREAD_run_once") .layout_tests(false) .header_contents("includes.h", INCLUDES); for include_dir in include_dirs { builder = builder .clang_arg("-I") .clang_arg(include_dir.display().to_string()) .header_contents("includes.h", INCLUDES) .clang_arg(include_dir.display().to_string()); } builder .generate() .unwrap() .write_to_file(out_dir.join("bindgen.rs")) Loading @@ -39,4 +45,14 @@ impl ParseCallbacks for OpensslCallbacks { fn will_parse_macro(&self, _name: &str) -> MacroParsingBehavior { MacroParsingBehavior::Ignore } // Our original definitions of these are wrong (missing the Option layer), so we need to rename to avoid breakage fn item_name(&self, original_item_name: &str) -> Option<String> { match original_item_name { "CRYPTO_EX_new" | "CRYPTO_EX_dup" | "CRYPTO_EX_free" => { Some(format!("{}2", original_item_name)) } _ => None, } } } openssl-sys/src/crypto.rs +26 −0 Original line number Diff line number Diff line use libc::*; use *; // FIXME should be options pub type CRYPTO_EX_new = unsafe extern "C" fn( parent: *mut c_void, ptr: *mut c_void, ad: *const CRYPTO_EX_DATA, idx: c_int, argl: c_long, argp: *const c_void, ) -> c_int; pub type CRYPTO_EX_dup = unsafe extern "C" fn( to: *mut CRYPTO_EX_DATA, from: *mut CRYPTO_EX_DATA, from_d: *mut c_void, idx: c_int, argl: c_long, argp: *mut c_void, ) -> c_int; pub type CRYPTO_EX_free = unsafe extern "C" fn( parent: *mut c_void, ptr: *mut c_void, ad: *mut CRYPTO_EX_DATA, idx: c_int, argl: c_long, argp: *mut c_void, ); #[cfg(ossl110)] #[inline] #[track_caller] Loading Loading
Cargo.toml +3 −0 Original line number Diff line number Diff line Loading @@ -6,3 +6,6 @@ members = [ "openssl-sys", "systest", ] [patch.crates-io] bindgen = { git = "https://github.com/daviddrysdale/rust-bindgen", branch = "allowlist-file" }
openssl-sys/build/find_normal.rs +11 −10 Original line number Diff line number Diff line Loading @@ -209,7 +209,7 @@ fn try_pkg_config() { } }; super::validate_headers(&lib.include_paths); super::postprocess(&lib.include_paths); for include in lib.include_paths.iter() { println!("cargo:include={}", include.display()); Loading @@ -227,17 +227,18 @@ fn try_vcpkg() { // vcpkg will not emit any metadata if it can not find libraries // appropriate for the target triple with the desired linkage. let lib = vcpkg::Config::new() let lib = match vcpkg::Config::new() .emit_includes(true) .find_package("openssl"); if let Err(e) = lib { .find_package("openssl") { Ok(lit) => lib, Err(e) => { println!("note: vcpkg did not find openssl: {}", e); return; } }; let lib = lib.unwrap(); super::validate_headers(&lib.include_paths); super::postprocess(&lib.include_paths); println!("cargo:rustc-link-lib=user32"); println!("cargo:rustc-link-lib=gdi32"); Loading
openssl-sys/build/main.rs +9 −4 Original line number Diff line number Diff line Loading @@ -86,7 +86,7 @@ fn main() { ); println!("cargo:include={}", include_dir.to_string_lossy()); let version = validate_headers(&[include_dir.clone()]); let version = postprocess(&[include_dir.clone()]); let libs_env = env("OPENSSL_LIBS"); let libs = match libs_env.as_ref().and_then(|s| s.to_str()) { Loading Loading @@ -128,9 +128,6 @@ fn main() { println!("cargo:rustc-link-lib=dylib=ws2_32"); println!("cargo:rustc-link-lib=dylib=advapi32"); } #[cfg(feature = "bindgen")] run_bindgen::run(&include_dir); } fn check_rustc_versions() { Loading @@ -141,6 +138,14 @@ fn check_rustc_versions() { } } fn postprocess(include_dirs: &[PathBuf]) -> Version { let version = validate_headers(include_dirs); #[cfg(feature = "bindgen")] run_bindgen::run(&include_dirs); version } /// Validates the header files found in `include_dir` and then returns the /// version string of OpenSSL. #[allow(clippy::manual_strip)] // we need to support pre-1.45.0 Loading
openssl-sys/build/run_bindgen.rs +24 −8 Original line number Diff line number Diff line use bindgen::callbacks::{MacroParsingBehavior, ParseCallbacks}; use bindgen::RustTarget; use std::env; use std::path::{Path, PathBuf}; use std::path::PathBuf; const INCLUDES: &str = " #include <openssl/crypto.h> #include <openssl/stack.h> "; pub fn run(include_dir: &Path) { pub fn run(include_dirs: &[PathBuf]) { let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap()); bindgen::builder() let mut builder = bindgen::builder() .parse_callbacks(Box::new(OpensslCallbacks)) .rust_target(RustTarget::Stable_1_47) .ctypes_prefix("::libc") .raw_line("use libc::*;") .blocklist_file("stdlib.h") .blocklist_file("time.h") .allowlist_file(".*/openssl/[^/]+.h") .allowlist_recursively(false) // libc is missing pthread_once_t on macOS .blocklist_type("CRYPTO_ONCE") .blocklist_function("CRYPTO_THREAD_run_once") .layout_tests(false) .header_contents("includes.h", INCLUDES); for include_dir in include_dirs { builder = builder .clang_arg("-I") .clang_arg(include_dir.display().to_string()) .header_contents("includes.h", INCLUDES) .clang_arg(include_dir.display().to_string()); } builder .generate() .unwrap() .write_to_file(out_dir.join("bindgen.rs")) Loading @@ -39,4 +45,14 @@ impl ParseCallbacks for OpensslCallbacks { fn will_parse_macro(&self, _name: &str) -> MacroParsingBehavior { MacroParsingBehavior::Ignore } // Our original definitions of these are wrong (missing the Option layer), so we need to rename to avoid breakage fn item_name(&self, original_item_name: &str) -> Option<String> { match original_item_name { "CRYPTO_EX_new" | "CRYPTO_EX_dup" | "CRYPTO_EX_free" => { Some(format!("{}2", original_item_name)) } _ => None, } } }
openssl-sys/src/crypto.rs +26 −0 Original line number Diff line number Diff line use libc::*; use *; // FIXME should be options pub type CRYPTO_EX_new = unsafe extern "C" fn( parent: *mut c_void, ptr: *mut c_void, ad: *const CRYPTO_EX_DATA, idx: c_int, argl: c_long, argp: *const c_void, ) -> c_int; pub type CRYPTO_EX_dup = unsafe extern "C" fn( to: *mut CRYPTO_EX_DATA, from: *mut CRYPTO_EX_DATA, from_d: *mut c_void, idx: c_int, argl: c_long, argp: *mut c_void, ) -> c_int; pub type CRYPTO_EX_free = unsafe extern "C" fn( parent: *mut c_void, ptr: *mut c_void, ad: *mut CRYPTO_EX_DATA, idx: c_int, argl: c_long, argp: *mut c_void, ); #[cfg(ossl110)] #[inline] #[track_caller] Loading