Skip to content

Commit bd2fb7d

Browse files
committed
Copy src to OUT_DIR before compiling.
1 parent dc4fa96 commit bd2fb7d

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

xgboost-sys/build.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,22 @@ extern crate bindgen;
22

33
use std::process::Command;
44
use std::env;
5-
use std::path::PathBuf;
5+
use std::path::{Path, PathBuf};
66

77
fn main() {
8-
let xgb_root = std::fs::canonicalize("xgboost").unwrap();
98
let target = env::var("TARGET").unwrap();
9+
let out_dir = env::var("OUT_DIR").unwrap();
10+
let xgb_root = Path::new(&out_dir).join("xgboost");
11+
12+
// copy source code into OUT_DIR for compilation if it doesn't exist
13+
if !xgb_root.exists() {
14+
Command::new("cp")
15+
.args(&["-r", "xgboost", xgb_root.to_str().unwrap()])
16+
.status()
17+
.unwrap_or_else(|e| {
18+
panic!("Failed to copy ./xgboost to {}: {}", xgb_root.display(), e);
19+
});
20+
}
1021

1122
// TODO: allow for dynamic/static linking
1223
// TODO: check whether rabit should be built/linked
@@ -19,6 +30,8 @@ fn main() {
1930
.expect("Failed to execute XGBoost build.sh script.");
2031
}
2132

33+
let xgb_root = xgb_root.canonicalize().unwrap();
34+
2235
let bindings = bindgen::Builder::default()
2336
.header("wrapper.h")
2437
.clang_arg(format!("-I{}", xgb_root.join("include").display()))

0 commit comments

Comments
 (0)