Skip to content

Commit 7ee4078

Browse files
committed
Don't add build/ to non-FIPS pre-built path
1 parent f19374d commit 7ee4078

File tree

1 file changed

+27
-34
lines changed

1 file changed

+27
-34
lines changed

boring-sys/build/main.rs

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ fn get_boringssl_source_path(config: &Config) -> &Path {
161161
/// MSVC generator on Windows place static libs in a target sub-folder,
162162
/// so adjust library location based on platform and build target.
163163
/// See issue: <https://github.com/alexcrichton/cmake-rs/issues/18>
164-
fn get_boringssl_platform_output_path(config: &Config) -> String {
164+
fn msvc_lib_subdir(config: &Config) -> Option<&'static str> {
165165
if config.target.ends_with("-msvc") {
166166
// Code under this branch should match the logic in cmake-rs
167167
let debug_env_var = config
@@ -195,9 +195,9 @@ fn get_boringssl_platform_output_path(config: &Config) -> String {
195195
_ => panic!("Unknown OPT_LEVEL={opt_env_var:?} env var."),
196196
};
197197

198-
subdir.to_string()
198+
Some(subdir)
199199
} else {
200-
String::new()
200+
None
201201
}
202202
}
203203

@@ -532,7 +532,7 @@ fn run_command(command: &mut Command) -> io::Result<Output> {
532532
Ok(out)
533533
}
534534

535-
fn built_boring_source_path(config: &Config) -> &PathBuf {
535+
fn build_boringssl_or_get_prebuilt(config: &Config) -> &Path {
536536
static BUILD_SOURCE_PATH: OnceLock<PathBuf> = OnceLock::new();
537537

538538
BUILD_SOURCE_PATH.get_or_init(|| {
@@ -562,7 +562,13 @@ fn built_boring_source_path(config: &Config) -> &PathBuf {
562562
}
563563

564564
cfg.build_target("ssl").build();
565-
cfg.build_target("crypto").build()
565+
let path = cfg.build_target("crypto").build();
566+
let build_dir = path.join("build");
567+
if build_dir.exists() {
568+
build_dir
569+
} else {
570+
path
571+
}
566572
})
567573
}
568574

@@ -589,36 +595,23 @@ fn main() {
589595
}
590596

591597
fn emit_link_directives(config: &Config) {
592-
let bssl_dir = built_boring_source_path(config);
593-
let build_path = get_boringssl_platform_output_path(config);
598+
let bssl_dir = build_boringssl_or_get_prebuilt(config);
599+
let msvc_lib_subdir = msvc_lib_subdir(config);
594600

595-
if config.is_bazel || (config.features.is_fips_like() && config.env.path.is_some()) {
596-
println!(
597-
"cargo:rustc-link-search=native={}/lib/{}",
598-
bssl_dir.display(),
599-
build_path
600-
);
601-
} else {
602-
// todo(rmehra): clean this up, I think these are pretty redundant
603-
println!(
604-
"cargo:rustc-link-search=native={}/build/crypto/{}",
605-
bssl_dir.display(),
606-
build_path
607-
);
608-
println!(
609-
"cargo:rustc-link-search=native={}/build/ssl/{}",
610-
bssl_dir.display(),
611-
build_path
612-
);
613-
println!(
614-
"cargo:rustc-link-search=native={}/build/{}",
615-
bssl_dir.display(),
616-
build_path
617-
);
618-
println!(
619-
"cargo:rustc-link-search=native={}/build",
620-
bssl_dir.display(),
621-
);
601+
let subdirs =
602+
if config.is_bazel || (config.features.is_fips_like() && config.env.path.is_some()) {
603+
&["lib"][..]
604+
} else {
605+
&["lib", "crypto", "ssl", ""][..]
606+
};
607+
608+
for subdir in subdirs {
609+
let dir = bssl_dir.join(subdir);
610+
let dir = msvc_lib_subdir
611+
.map(|s| dir.join(s))
612+
.filter(|d| d.exists())
613+
.unwrap_or(dir);
614+
println!("cargo:rustc-link-search=native={}", dir.display());
622615
}
623616

624617
if let Some(cpp_lib) = get_cpp_runtime_lib(config) {

0 commit comments

Comments
 (0)