Skip to content

Commit

Permalink
packaging lightgbm-sys
Browse files Browse the repository at this point in the history
  • Loading branch information
vaaaaanquish committed Jan 9, 2021
1 parent 0e32cc1 commit 49d5de7
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions lightgbm-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,33 @@ extern crate bindgen;
extern crate cmake;

use cmake::Config;
use std::process::Command;
use std::env;
use std::path::{Path, PathBuf};


fn main() {
let out_dir = env::var("OUT_DIR").unwrap();
let lgbm_root = Path::new(&out_dir);
let lgbm_root = Path::new(&out_dir).join("lightgbm");

// copy source code
if !lgbm_root.exists() {
Command::new("cp")
.args(&["-r", "lightgbm", lgbm_root.to_str().unwrap()])
.status()
.unwrap_or_else(|e| {
panic!("Failed to copy ./lightgbm to {}: {}", lgbm_root.display(), e);
});
}

// CMake
let dst = Config::new("lightgbm")
let dst = Config::new(&lgbm_root)
.profile("Release")
.uses_cxx11()
.define("BUILD_STATIC_LIB", "ON")
.build();

// bindgen build
let bindings = bindgen::Builder::default()
.header("wrapper.h")
.clang_args(&["-x","c++", "-std=c++11"])
Expand All @@ -27,7 +40,7 @@ fn main() {
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings.");

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

0 comments on commit 49d5de7

Please sign in to comment.