Skip to content

Commit d16e2e2

Browse files
committed
use cmake
1 parent 0680234 commit d16e2e2

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

src/booster.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ impl Booster {
361361
dmat.handle,
362362
option_mask,
363363
ntree_limit,
364+
0,
364365
&mut out_len,
365366
&mut out_result))?;
366367

@@ -381,10 +382,10 @@ impl Booster {
381382
dmat.handle,
382383
option_mask,
383384
ntree_limit,
385+
1,
384386
&mut out_len,
385387
&mut out_result))?;
386388
assert!(!out_result.is_null());
387-
388389
let data = unsafe { slice::from_raw_parts(out_result, out_len as usize).to_vec() };
389390
Ok(data)
390391
}
@@ -403,6 +404,7 @@ impl Booster {
403404
dmat.handle,
404405
option_mask,
405406
ntree_limit,
407+
0,
406408
&mut out_len,
407409
&mut out_result))?;
408410
assert!(!out_result.is_null());
@@ -429,6 +431,7 @@ impl Booster {
429431
dmat.handle,
430432
option_mask,
431433
ntree_limit,
434+
0,
432435
&mut out_len,
433436
&mut out_result))?;
434437
assert!(!out_result.is_null());
@@ -456,6 +459,7 @@ impl Booster {
456459
dmat.handle,
457460
option_mask,
458461
ntree_limit,
462+
0,
459463
&mut out_len,
460464
&mut out_result))?;
461465
assert!(!out_result.is_null());

xgboost-sys/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ libc = "0.2"
1414

1515
[build-dependencies]
1616
bindgen = "0.59"
17+
cmake = "0.1"

xgboost-sys/build.rs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
extern crate bindgen;
2+
extern crate cmake;
23

4+
use cmake::Config;
35
use std::process::Command;
46
use std::env;
57
use 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
}

xgboost-sys/xgboost

Submodule xgboost updated 489 files

0 commit comments

Comments
 (0)