diff --git a/boring-sys/build/config.rs b/boring-sys/build/config.rs index 7af00f4b..1671981f 100644 --- a/boring-sys/build/config.rs +++ b/boring-sys/build/config.rs @@ -34,6 +34,7 @@ pub(crate) struct Env { pub(crate) opt_level: Option, pub(crate) android_ndk_home: Option, pub(crate) cmake_toolchain_file: Option, + pub(crate) cpp_runtime_lib: Option, } impl Config { @@ -164,6 +165,7 @@ impl Env { opt_level: target_var("OPT_LEVEL"), android_ndk_home: target_var("ANDROID_NDK_HOME").map(Into::into), cmake_toolchain_file: target_var("CMAKE_TOOLCHAIN_FILE").map(Into::into), + cpp_runtime_lib: target_var("BORING_BSSL_RUST_CPPLIB").map(Into::into), } } } diff --git a/boring-sys/build/main.rs b/boring-sys/build/main.rs index 05242028..95993b6a 100644 --- a/boring-sys/build/main.rs +++ b/boring-sys/build/main.rs @@ -1,4 +1,5 @@ use fslock::LockFile; +use std::env; use std::ffi::OsString; use std::fs; use std::io; @@ -636,6 +637,22 @@ fn link_in_precompiled_bcm_o(config: &Config) { .unwrap(); } +fn get_cpp_runtime_lib(config: &Config) -> Option { + if let Some(ref cpp_lib) = config.env.cpp_runtime_lib { + return cpp_lib.clone().into_string().ok(); + } + + // TODO(rmehra): figure out how to do this for windows + if env::var_os("CARGO_CFG_UNIX").is_some() { + match env::var("CARGO_CFG_TARGET_OS").unwrap().as_ref() { + "macos" | "ios" => Some("c++".into()), + _ => Some("stdc++".into()), + } + } else { + None + } +} + fn main() { let config = Config::from_env(); let bssl_dir = built_boring_source_path(&config); @@ -669,6 +686,9 @@ fn main() { link_in_precompiled_bcm_o(&config); } + if let Some(cpp_lib) = get_cpp_runtime_lib(&config) { + println!("cargo:rustc-link-lib={}", cpp_lib); + } println!("cargo:rustc-link-lib=static=crypto"); println!("cargo:rustc-link-lib=static=ssl"); diff --git a/boring/src/x509/tests/trusted_first.rs b/boring/src/x509/tests/trusted_first.rs index 951d1da5..adddb877 100644 --- a/boring/src/x509/tests/trusted_first.rs +++ b/boring/src/x509/tests/trusted_first.rs @@ -93,12 +93,12 @@ fn verify( let mut store_ctx = X509StoreContext::new().unwrap(); - let _ = store_ctx.init(&trusted, cert, &untrusted, |ctx| { - configure(ctx.verify_param_mut()); - ctx.verify_cert().unwrap(); - - Ok(()) - }); - - store_ctx.verify_result() + store_ctx + .init(&trusted, cert, &untrusted, |ctx| { + configure(ctx.verify_param_mut()); + ctx.verify_cert().unwrap(); + + Ok(ctx.verify_result()) + }) + .expect("failed to obtain X509VerifyResult") }