Skip to content

Commit

Permalink
[rust] Tell Cargo to link cpp runtime library
Browse files Browse the repository at this point in the history
https://boringssl-review.googlesource.com/c/boringssl/+/66288
allowed C++ runtime in libssl. The build script of bssl-sys crate
should indicate that the crate requires a C++ runtime. Use
libc++ on MacOS and libstdc++ on other unix like systems by
default. Introduce a new environment variable to configure C++
runtime to use.

Change-Id: Ib445955012126080dd03ad7b650287ea9dde10b0
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/67147
Commit-Queue: David Benjamin <[email protected]>
Reviewed-by: David Benjamin <[email protected]>
Reviewed-by: Adam Langley <[email protected]>
  • Loading branch information
bashi authored and Boringssl LUCI CQ committed Mar 27, 2024
1 parent ee4c2a3 commit 54c956b
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions rust/bssl-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,23 @@ fn get_bssl_build_dir() -> PathBuf {
return Path::new(&crate_dir).join("../../build");
}

fn get_cpp_runtime_lib() -> Option<String> {
println!("cargo:rerun-if-env-changed=BORINGSSL_RUST_CPPLIB");

if let Ok(cpp_lib) = env::var("BORINGSSL_RUST_CPPLIB") {
return Some(cpp_lib);
}

if env::var_os("CARGO_CFG_UNIX").is_some() {
match env::var("CARGO_CFG_TARGET_OS").unwrap().as_ref() {
"macos" => Some("c++".into()),
_ => Some("stdc++".into()),
}
} else {
None
}
}

fn main() {
let bssl_build_dir = get_bssl_build_dir();
let bssl_sys_build_dir = bssl_build_dir.join("rust/bssl-sys");
Expand Down Expand Up @@ -106,5 +123,9 @@ fn main() {
);
println!("cargo:rustc-link-lib=static=rust_wrapper");

if let Some(cpp_lib) = get_cpp_runtime_lib() {
println!("cargo:rustc-link-lib={}", cpp_lib);
}

println!("cargo:conf={}", OSSL_CONF_DEFINES.join(","));
}

0 comments on commit 54c956b

Please sign in to comment.