Skip to content

Commit 4c9f324

Browse files
committed
chore(sys): cleanup
1 parent 6dd3c06 commit 4c9f324

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

ort-sys/build.rs

+13-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::{
22
env, fs,
3-
path::{Path, PathBuf},
4-
process::Command
3+
path::{Path, PathBuf}
54
};
65

76
#[allow(unused)]
@@ -165,11 +164,19 @@ fn prepare_libort_dir() -> (PathBuf, bool) {
165164
if let Ok(lib_dir) = env::var(ORT_ENV_SYSTEM_LIB_LOCATION) {
166165
let lib_dir = PathBuf::from(lib_dir);
167166

168-
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap().to_lowercase();
169167
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap().to_lowercase();
170168
let platform_format_lib = |a: &str| {
171169
if target_os.contains("windows") { format!("{}.lib", a) } else { format!("lib{}.a", a) }
172170
};
171+
let optional_link_lib = |dir: &Path, lib: &str| {
172+
if dir.exists() && dir.join(platform_format_lib(lib)).exists() {
173+
add_search_dir(dir);
174+
println!("cargo:rustc-link-lib=static={lib}");
175+
true
176+
} else {
177+
false
178+
}
179+
};
173180

174181
let mut profile = env::var(ORT_ENV_SYSTEM_LIB_PROFILE).unwrap_or_default();
175182
if profile.is_empty() {
@@ -234,22 +241,16 @@ fn prepare_libort_dir() -> (PathBuf, bool) {
234241
println!("cargo:rustc-link-lib=static=onnx");
235242
println!("cargo:rustc-link-lib=static=onnx_proto");
236243

237-
let nsync_path = transform_dep(external_lib_dir.join("google_nsync-build"), &profile);
238244
// some builds of ONNX Runtime, particularly the default no-EP windows build, don't require nsync
239-
if nsync_path.exists() {
240-
add_search_dir(nsync_path);
241-
println!("cargo:rustc-link-lib=static=nsync_cpp");
242-
}
245+
optional_link_lib(&transform_dep(external_lib_dir.join("google_nsync-build"), &profile), "nsync_cpp");
243246

244247
add_search_dir(transform_dep(external_lib_dir.join("pytorch_cpuinfo-build"), &profile));
245248
// clog isn't built when not building unit tests, or when compiling for android
246249
for potential_clog_path in [
247250
transform_dep(external_lib_dir.join("pytorch_cpuinfo-build").join("deps").join("clog"), &profile),
248251
transform_dep(external_lib_dir.join("pytorch_clog-build"), &profile)
249252
] {
250-
if potential_clog_path.exists() && potential_clog_path.join(platform_format_lib("clog")).exists() {
251-
add_search_dir(potential_clog_path);
252-
println!("cargo:rustc-link-lib=static=clog");
253+
if optional_link_lib(&potential_clog_path, "clog") {
253254
break;
254255
}
255256
}
@@ -301,9 +302,7 @@ fn prepare_libort_dir() -> (PathBuf, bool) {
301302
println!("cargo:rustc-link-lib=static=absl_log_internal_format");
302303
println!("cargo:rustc-link-lib=static=absl_log_internal_proto");
303304
println!("cargo:rustc-link-lib=static=absl_log_internal_globals");
304-
if abseil_lib_log_dir.join(platform_format_lib("absl_log_internal_check_op")).exists() {
305-
println!("cargo:rustc-link-lib=static=absl_log_internal_check_op");
306-
}
305+
optional_link_lib(&abseil_lib_log_dir, "absl_log_internal_check_op");
307306
println!("cargo:rustc-link-lib=static=absl_log_internal_log_sink_set");
308307
println!("cargo:rustc-link-lib=static=absl_log_sink");
309308
println!("cargo:rustc-link-lib=static=absl_log_internal_message");

0 commit comments

Comments
 (0)