1
1
extern crate bindgen;
2
+ extern crate cmake;
2
3
4
+ use cmake:: Config ;
3
5
use std:: process:: Command ;
4
6
use std:: env;
5
7
use std:: path:: { Path , PathBuf } ;
@@ -19,23 +21,20 @@ fn main() {
19
21
} ) ;
20
22
}
21
23
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 ( ) ;
32
29
33
30
let xgb_root = xgb_root. canonicalize ( ) . unwrap ( ) ;
34
31
35
32
let bindings = bindgen:: Builder :: default ( )
36
33
. header ( "wrapper.h" )
34
+ . clang_args ( & [ "-x" , "c++" , "-std=c++11" ] )
37
35
. clang_arg ( format ! ( "-I{}" , xgb_root. join( "include" ) . display( ) ) )
38
36
. clang_arg ( format ! ( "-I{}" , xgb_root. join( "rabit/include" ) . display( ) ) )
37
+ . clang_arg ( format ! ( "-I{}" , xgb_root. join( "dmlc-core/include" ) . display( ) ) )
39
38
. generate ( )
40
39
. expect ( "Unable to generate bindings." ) ;
41
40
@@ -48,21 +47,17 @@ fn main() {
48
47
println ! ( "cargo:rustc-link-search={}" , xgb_root. join( "rabit/lib" ) . display( ) ) ;
49
48
println ! ( "cargo:rustc-link-search={}" , xgb_root. join( "dmlc-core" ) . display( ) ) ;
50
49
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
-
59
50
// link to appropriate C++ lib
60
51
if target. contains ( "apple" ) {
61
52
println ! ( "cargo:rustc-link-lib=c++" ) ;
53
+ println ! ( "cargo:rustc-link-lib=dylib=omp" ) ;
62
54
} else {
63
55
println ! ( "cargo:rustc-link-lib=stdc++" ) ;
56
+ println ! ( "cargo:rustc-link-lib=dylib=gomp" ) ;
64
57
}
65
58
59
+ println ! ( "cargo:rustc-link-search=native={}" , dst. display( ) ) ;
60
+ println ! ( "cargo:rustc-link-search=native={}" , dst. join( "lib" ) . display( ) ) ;
66
61
println ! ( "cargo:rustc-link-lib=static=dmlc" ) ;
67
62
println ! ( "cargo:rustc-link-lib=static=xgboost" ) ;
68
63
}
0 commit comments