@@ -9,6 +9,8 @@ const ONNXRUNTIME_VERSION: &str = "1.19.2";
9
9
const ORT_ENV_SYSTEM_LIB_LOCATION : & str = "ORT_LIB_LOCATION" ;
10
10
const ORT_ENV_SYSTEM_LIB_PROFILE : & str = "ORT_LIB_PROFILE" ;
11
11
const ORT_ENV_PREFER_DYNAMIC_LINK : & str = "ORT_PREFER_DYNAMIC_LINK" ;
12
+ const ORT_ENV_CXX_STDLIB : & str = "ORT_CXX_STDLIB" ;
13
+ const ENV_CXXSTDLIB : & str = "CXXSTDLIB" ; // Used by the `cc` crate - we should mirror if this is set for other C++ crates
12
14
#[ cfg( feature = "download-binaries" ) ]
13
15
const ORT_EXTRACT_DIR : & str = "onnxruntime" ;
14
16
@@ -133,13 +135,26 @@ fn add_search_dir<P: AsRef<Path>>(base: P) {
133
135
}
134
136
135
137
fn static_link_prerequisites ( using_pyke_libs : bool ) {
136
- let target_os = env:: var ( "CARGO_CFG_TARGET_OS" ) . unwrap ( ) ;
137
- if target_os == "macos" || target_os == "ios" {
138
- println ! ( "cargo:rustc-link-lib=c++" ) ;
138
+ let target_triple = env:: var ( "TARGET" ) . unwrap ( ) ;
139
+
140
+ let cpp_link_stdlib = if let Ok ( stdlib) = env:: var ( ORT_ENV_CXX_STDLIB ) . or_else ( |_| env:: var ( ENV_CXXSTDLIB ) ) {
141
+ if stdlib. is_empty ( ) { None } else { Some ( stdlib) }
142
+ } else if target_triple. contains ( "msvc" ) {
143
+ None
144
+ } else if target_triple. contains ( "apple" ) {
145
+ Some ( "c++" . to_string ( ) )
146
+ } else if target_triple. contains ( "android" ) {
147
+ Some ( "c++_shared" . to_string ( ) )
148
+ } else {
149
+ Some ( "stdc++" . to_string ( ) )
150
+ } ;
151
+ if let Some ( cpp_link_stdlib) = cpp_link_stdlib {
152
+ println ! ( "cargo:rustc-link-lib={cpp_link_stdlib}" ) ;
153
+ }
154
+
155
+ if target_triple. contains ( "apple" ) {
139
156
println ! ( "cargo:rustc-link-lib=framework=Foundation" ) ;
140
- } else if target_os == "linux" || target_os == "android" {
141
- println ! ( "cargo:rustc-link-lib=stdc++" ) ;
142
- } else if target_os == "windows" && ( using_pyke_libs || cfg ! ( feature = "directml" ) ) {
157
+ } else if target_triple. contains ( "windows" ) && ( using_pyke_libs || cfg ! ( feature = "directml" ) ) {
143
158
println ! ( "cargo:rustc-link-lib=dxguid" ) ;
144
159
println ! ( "cargo:rustc-link-lib=DXCORE" ) ;
145
160
println ! ( "cargo:rustc-link-lib=DXGI" ) ;
@@ -437,6 +452,8 @@ fn real_main(link: bool) {
437
452
println ! ( "cargo:rerun-if-env-changed={}" , ORT_ENV_SYSTEM_LIB_LOCATION ) ;
438
453
println ! ( "cargo:rerun-if-env-changed={}" , ORT_ENV_SYSTEM_LIB_PROFILE ) ;
439
454
println ! ( "cargo:rerun-if-env-changed={}" , ORT_ENV_PREFER_DYNAMIC_LINK ) ;
455
+ println ! ( "cargo:rerun-if-env-changed={}" , ORT_ENV_CXX_STDLIB ) ;
456
+ println ! ( "cargo:rerun-if-env-changed={}" , ENV_CXXSTDLIB ) ;
440
457
441
458
let ( install_dir, needs_link) = prepare_libort_dir ( ) ;
442
459
0 commit comments