Skip to content

Commit a22cbe6

Browse files
committed
Download xgboost from github at build time, instead of including as submodule.
XGBoost's source contains symlinks, which made packaging using cargo problematic.
1 parent 037ef54 commit a22cbe6

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
lines changed

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
[submodule "xgboost-sys/xgboost"]
2-
path = xgboost-sys/xgboost
3-
url = https://github.com/dmlc/xgboost.git

xgboost-sys/Cargo.toml

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

1414
[build-dependencies]
1515
bindgen = "0.36"
16+
git2 = "0.7"

xgboost-sys/build.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,37 @@
11
extern crate bindgen;
2+
extern crate git2;
23

34
use std::process::Command;
45
use std::env;
56
use std::path::PathBuf;
6-
use std::fs::canonicalize;
7+
8+
// Contains symlinks, so cannot be included as a git submodule and packaged with cargo. Downloaded
9+
// at build time instead.
10+
static XGBOOST_SRC: &str = "https://github.com/dmlc/xgboost.git";
11+
static XGBOOST_SPEC: &str = "refs/tags/v0.80";
712

813
fn main() {
9-
let target = env::var("TARGET").unwrap();
10-
let xgb_root = canonicalize("xgboost").unwrap();
14+
let target = env::var("TARGET").expect("Failed to read TARGET environment variable");
15+
16+
let xgb_root = std::path::Path::new("xgboost");
17+
18+
let repo = {
19+
if !xgb_root.exists() {
20+
match git2::Repository::clone_recurse(XGBOOST_SRC, "xgboost") {
21+
Ok(repo) => repo,
22+
Err(e) => panic!("failed to clone: {}", e),
23+
}
24+
} else {
25+
match git2::Repository::open("xgboost") {
26+
Ok(repo) => repo,
27+
Err(e) => panic!("failed to open: {}", e),
28+
}
29+
}
30+
};
31+
32+
repo.set_head(XGBOOST_SPEC).expect("failed to set head");
33+
34+
let xgb_root = xgb_root.canonicalize().unwrap();
1135

1236
// TODO: allow for dynamic/static linking
1337
// TODO: check whether rabit should be built/linked

xgboost-sys/xgboost

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)