11extern crate bindgen;
2+ extern crate cmake;
23
4+ use cmake:: Config ;
35use std:: process:: Command ;
46use std:: env;
57use std:: path:: { Path , PathBuf } ;
@@ -19,23 +21,20 @@ fn main() {
1921 } ) ;
2022 }
2123
22- // TODO: allow for dynamic/static linking
23- // TODO: check whether rabit should be built/linked
24- if !xgb_root. join ( "lib" ) . exists ( ) {
25- // TODO: better checks for build completion, currently xgboost's build script can run
26- // `make clean_all` if openmp build fails
27- Command :: new ( xgb_root. join ( "build.sh" ) )
28- . current_dir ( & xgb_root)
29- . status ( )
30- . expect ( "Failed to execute XGBoost build.sh script." ) ;
31- }
24+ // CMake
25+ let dst = Config :: new ( & xgb_root)
26+ . uses_cxx11 ( )
27+ . define ( "BUILD_STATIC_LIB" , "ON" )
28+ . build ( ) ;
3229
3330 let xgb_root = xgb_root. canonicalize ( ) . unwrap ( ) ;
3431
3532 let bindings = bindgen:: Builder :: default ( )
3633 . header ( "wrapper.h" )
34+ . clang_args ( & [ "-x" , "c++" , "-std=c++11" ] )
3735 . clang_arg ( format ! ( "-I{}" , xgb_root. join( "include" ) . display( ) ) )
3836 . clang_arg ( format ! ( "-I{}" , xgb_root. join( "rabit/include" ) . display( ) ) )
37+ . clang_arg ( format ! ( "-I{}" , xgb_root. join( "dmlc-core/include" ) . display( ) ) )
3938 . generate ( )
4039 . expect ( "Unable to generate bindings." ) ;
4140
@@ -48,21 +47,17 @@ fn main() {
4847 println ! ( "cargo:rustc-link-search={}" , xgb_root. join( "rabit/lib" ) . display( ) ) ;
4948 println ! ( "cargo:rustc-link-search={}" , xgb_root. join( "dmlc-core" ) . display( ) ) ;
5049
51- // check if built with multithreading support, otherwise link to dummy lib
52- if xgb_root. join ( "rabit/lib/librabit.a" ) . exists ( ) {
53- println ! ( "cargo:rustc-link-lib=static=rabit" ) ;
54- println ! ( "cargo:rustc-link-lib=dylib=gomp" ) ;
55- } else {
56- println ! ( "cargo:rustc-link-lib=static=rabit_empty" ) ;
57- }
58-
5950 // link to appropriate C++ lib
6051 if target. contains ( "apple" ) {
6152 println ! ( "cargo:rustc-link-lib=c++" ) ;
53+ println ! ( "cargo:rustc-link-lib=dylib=omp" ) ;
6254 } else {
6355 println ! ( "cargo:rustc-link-lib=stdc++" ) ;
56+ println ! ( "cargo:rustc-link-lib=dylib=gomp" ) ;
6457 }
6558
59+ println ! ( "cargo:rustc-link-search=native={}" , dst. display( ) ) ;
60+ println ! ( "cargo:rustc-link-search=native={}" , dst. join( "lib" ) . display( ) ) ;
6661 println ! ( "cargo:rustc-link-lib=static=dmlc" ) ;
6762 println ! ( "cargo:rustc-link-lib=static=xgboost" ) ;
6863}
0 commit comments