Skip to content

Commit 49d5de7

Browse files
committed
packaging lightgbm-sys
1 parent 0e32cc1 commit 49d5de7

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

lightgbm-sys/build.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,33 @@ extern crate bindgen;
22
extern crate cmake;
33

44
use cmake::Config;
5+
use std::process::Command;
56
use std::env;
67
use std::path::{Path, PathBuf};
78

89

910
fn main() {
1011
let out_dir = env::var("OUT_DIR").unwrap();
11-
let lgbm_root = Path::new(&out_dir);
12+
let lgbm_root = Path::new(&out_dir).join("lightgbm");
13+
14+
// copy source code
15+
if !lgbm_root.exists() {
16+
Command::new("cp")
17+
.args(&["-r", "lightgbm", lgbm_root.to_str().unwrap()])
18+
.status()
19+
.unwrap_or_else(|e| {
20+
panic!("Failed to copy ./lightgbm to {}: {}", lgbm_root.display(), e);
21+
});
22+
}
1223

1324
// CMake
14-
let dst = Config::new("lightgbm")
25+
let dst = Config::new(&lgbm_root)
1526
.profile("Release")
1627
.uses_cxx11()
1728
.define("BUILD_STATIC_LIB", "ON")
1829
.build();
30+
31+
// bindgen build
1932
let bindings = bindgen::Builder::default()
2033
.header("wrapper.h")
2134
.clang_args(&["-x","c++", "-std=c++11"])
@@ -27,7 +40,7 @@ fn main() {
2740
.write_to_file(out_path.join("bindings.rs"))
2841
.expect("Couldn't write bindings.");
2942

30-
println!("cargo:rustc-link-search={}", lgbm_root.join("lib").display());
43+
println!("cargo:rustc-link-search={}", out_path.join("lib").display());
3144
println!("cargo:rustc-link-lib=dylib=gomp");
3245
println!("cargo:rustc-link-lib=stdc++");
3346
println!("cargo:rustc-link-search=native={}", dst.display());

0 commit comments

Comments
 (0)