@@ -8,6 +8,7 @@ use std::path::{Path, PathBuf};
88
99
1010fn main ( ) {
11+ let target = env:: var ( "TARGET" ) . unwrap ( ) ;
1112 let out_dir = env:: var ( "OUT_DIR" ) . unwrap ( ) ;
1213 let lgbm_root = Path :: new ( & out_dir) . join ( "lightgbm" ) ;
1314
@@ -23,10 +24,10 @@ fn main() {
2324
2425 // CMake
2526 let dst = Config :: new ( & lgbm_root)
26- . profile ( "Release" )
27- . uses_cxx11 ( )
28- . define ( "BUILD_STATIC_LIB" , "ON" )
29- . build ( ) ;
27+ . profile ( "Release" )
28+ . uses_cxx11 ( )
29+ . define ( "BUILD_STATIC_LIB" , "ON" )
30+ . build ( ) ;
3031
3132 // bindgen build
3233 let bindings = bindgen:: Builder :: default ( )
@@ -40,9 +41,16 @@ fn main() {
4041 . write_to_file ( out_path. join ( "bindings.rs" ) )
4142 . expect ( "Couldn't write bindings." ) ;
4243
44+ // link to appropriate C++ lib
45+ if target. contains ( "apple" ) {
46+ println ! ( "cargo:rustc-link-lib=c++" ) ;
47+ println ! ( "cargo:rustc-link-lib=dylib=omp" ) ;
48+ } else {
49+ println ! ( "cargo:rustc-link-lib=stdc++" ) ;
50+ println ! ( "cargo:rustc-link-lib=dylib=gomp" ) ;
51+ }
52+
4353 println ! ( "cargo:rustc-link-search={}" , out_path. join( "lib" ) . display( ) ) ;
44- println ! ( "cargo:rustc-link-lib=dylib=gomp" ) ;
45- println ! ( "cargo:rustc-link-lib=stdc++" ) ;
4654 println ! ( "cargo:rustc-link-search=native={}" , dst. display( ) ) ;
4755 println ! ( "cargo:rustc-link-lib=static=_lightgbm" ) ;
4856}
0 commit comments