Skip to content

Commit c05a339

Browse files
rushilmehrakornelski
authored andcommitted
Support linking with a runtime cpp library
As of https://boringssl-review.googlesource.com/c/boringssl/+/66288, libssl allows a C++ runtime dependency. As such, we need to link with a cpp runtime library. Implementation is inspired heavily from google/boringssl@54c956b. Before releasing this change, we'll need to figure out a way to support this for windows.
1 parent 49d5a61 commit c05a339

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

boring-sys/build/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub(crate) struct Env {
3434
pub(crate) opt_level: Option<OsString>,
3535
pub(crate) android_ndk_home: Option<PathBuf>,
3636
pub(crate) cmake_toolchain_file: Option<PathBuf>,
37+
pub(crate) cpp_runtime_lib: Option<OsString>,
3738
}
3839

3940
impl Config {
@@ -164,6 +165,7 @@ impl Env {
164165
opt_level: target_var("OPT_LEVEL"),
165166
android_ndk_home: target_var("ANDROID_NDK_HOME").map(Into::into),
166167
cmake_toolchain_file: target_var("CMAKE_TOOLCHAIN_FILE").map(Into::into),
168+
cpp_runtime_lib: target_var("BORING_BSSL_RUST_CPPLIB").map(Into::into),
167169
}
168170
}
169171
}

boring-sys/build/main.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use fslock::LockFile;
2+
use std::env;
23
use std::ffi::OsString;
34
use std::fs;
45
use std::io;
@@ -636,6 +637,22 @@ fn link_in_precompiled_bcm_o(config: &Config) {
636637
.unwrap();
637638
}
638639

640+
fn get_cpp_runtime_lib(config: &Config) -> Option<String> {
641+
if let Some(ref cpp_lib) = config.env.cpp_runtime_lib {
642+
return cpp_lib.clone().into_string().ok();
643+
}
644+
645+
// TODO(rmehra): figure out how to do this for windows
646+
if env::var_os("CARGO_CFG_UNIX").is_some() {
647+
match env::var("CARGO_CFG_TARGET_OS").unwrap().as_ref() {
648+
"macos" | "ios" => Some("c++".into()),
649+
_ => Some("stdc++".into()),
650+
}
651+
} else {
652+
None
653+
}
654+
}
655+
639656
fn main() {
640657
let config = Config::from_env();
641658
let bssl_dir = built_boring_source_path(&config);
@@ -673,6 +690,9 @@ fn main() {
673690
link_in_precompiled_bcm_o(&config);
674691
}
675692

693+
if let Some(cpp_lib) = get_cpp_runtime_lib(&config) {
694+
println!("cargo:rustc-link-lib={}", cpp_lib);
695+
}
676696
println!("cargo:rustc-link-lib=static=crypto");
677697
println!("cargo:rustc-link-lib=static=ssl");
678698

0 commit comments

Comments
 (0)