Skip to content

Commit

Permalink
Support linking with a runtime cpp library
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rushilmehra authored and kornelski committed Jan 6, 2025
1 parent 49d5a61 commit c05a339
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions boring-sys/build/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub(crate) struct Env {
pub(crate) opt_level: Option<OsString>,
pub(crate) android_ndk_home: Option<PathBuf>,
pub(crate) cmake_toolchain_file: Option<PathBuf>,
pub(crate) cpp_runtime_lib: Option<OsString>,
}

impl Config {
Expand Down Expand Up @@ -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),
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions boring-sys/build/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use fslock::LockFile;
use std::env;
use std::ffi::OsString;
use std::fs;
use std::io;
Expand Down Expand Up @@ -636,6 +637,22 @@ fn link_in_precompiled_bcm_o(config: &Config) {
.unwrap();
}

fn get_cpp_runtime_lib(config: &Config) -> Option<String> {
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);
Expand Down Expand Up @@ -673,6 +690,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");

Expand Down

0 comments on commit c05a339

Please sign in to comment.