|
1 | 1 | use std::{
|
2 | 2 | env, fs,
|
3 |
| - path::{Path, PathBuf}, |
4 |
| - process::Command |
| 3 | + path::{Path, PathBuf} |
5 | 4 | };
|
6 | 5 |
|
7 | 6 | #[allow(unused)]
|
@@ -165,11 +164,19 @@ fn prepare_libort_dir() -> (PathBuf, bool) {
|
165 | 164 | if let Ok(lib_dir) = env::var(ORT_ENV_SYSTEM_LIB_LOCATION) {
|
166 | 165 | let lib_dir = PathBuf::from(lib_dir);
|
167 | 166 |
|
168 |
| - let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap().to_lowercase(); |
169 | 167 | let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap().to_lowercase();
|
170 | 168 | let platform_format_lib = |a: &str| {
|
171 | 169 | if target_os.contains("windows") { format!("{}.lib", a) } else { format!("lib{}.a", a) }
|
172 | 170 | };
|
| 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 | + }; |
173 | 180 |
|
174 | 181 | let mut profile = env::var(ORT_ENV_SYSTEM_LIB_PROFILE).unwrap_or_default();
|
175 | 182 | if profile.is_empty() {
|
@@ -234,22 +241,16 @@ fn prepare_libort_dir() -> (PathBuf, bool) {
|
234 | 241 | println!("cargo:rustc-link-lib=static=onnx");
|
235 | 242 | println!("cargo:rustc-link-lib=static=onnx_proto");
|
236 | 243 |
|
237 |
| - let nsync_path = transform_dep(external_lib_dir.join("google_nsync-build"), &profile); |
238 | 244 | // 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"); |
243 | 246 |
|
244 | 247 | add_search_dir(transform_dep(external_lib_dir.join("pytorch_cpuinfo-build"), &profile));
|
245 | 248 | // clog isn't built when not building unit tests, or when compiling for android
|
246 | 249 | for potential_clog_path in [
|
247 | 250 | transform_dep(external_lib_dir.join("pytorch_cpuinfo-build").join("deps").join("clog"), &profile),
|
248 | 251 | transform_dep(external_lib_dir.join("pytorch_clog-build"), &profile)
|
249 | 252 | ] {
|
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") { |
253 | 254 | break;
|
254 | 255 | }
|
255 | 256 | }
|
@@ -301,9 +302,7 @@ fn prepare_libort_dir() -> (PathBuf, bool) {
|
301 | 302 | println!("cargo:rustc-link-lib=static=absl_log_internal_format");
|
302 | 303 | println!("cargo:rustc-link-lib=static=absl_log_internal_proto");
|
303 | 304 | 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"); |
307 | 306 | println!("cargo:rustc-link-lib=static=absl_log_internal_log_sink_set");
|
308 | 307 | println!("cargo:rustc-link-lib=static=absl_log_sink");
|
309 | 308 | println!("cargo:rustc-link-lib=static=absl_log_internal_message");
|
|
0 commit comments