Skip to content

Commit bfed6ba

Browse files
authored
Merge pull request #10 from vaaaaanquish/make_osx
Support osx
2 parents 03ebd7b + 270ed47 commit bfed6ba

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ readme = "README.md"
99
exclude = [".gitignore", ".gitmodules", "examples", "lightgbm-sys"]
1010

1111
[dependencies]
12-
lightgbm-sys = "0.1.0"
12+
lightgbm-sys = "0.2.0"
1313
libc = "0.2.81"
1414
derive_builder = "0.5.1"
1515
serde_json = "1.0.59"

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ You need an environment that can build LightGBM.
99
```
1010
# linux
1111
apt install -y cmake libclang-dev libc++-dev gcc-multilib
12+
13+
# OS X
14+
brew install cmake libomp
1215
```
1316

1417
Please see below for details.

lightgbm-sys/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "lightgbm-sys"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
authors = ["vaaaaanquish <[email protected]>"]
55
build = "build.rs"
66
license = "MIT"

lightgbm-sys/build.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::path::{Path, PathBuf};
88

99

1010
fn main() {
11+
let target = env::var("TARGET").unwrap();
1112
let out_dir = env::var("OUT_DIR").unwrap();
1213
let lgbm_root = Path::new(&out_dir).join("lightgbm");
1314

@@ -23,10 +24,10 @@ fn main() {
2324

2425
// CMake
2526
let dst = Config::new(&lgbm_root)
26-
.profile("Release")
27-
.uses_cxx11()
28-
.define("BUILD_STATIC_LIB", "ON")
29-
.build();
27+
.profile("Release")
28+
.uses_cxx11()
29+
.define("BUILD_STATIC_LIB", "ON")
30+
.build();
3031

3132
// bindgen build
3233
let bindings = bindgen::Builder::default()
@@ -40,9 +41,16 @@ fn main() {
4041
.write_to_file(out_path.join("bindings.rs"))
4142
.expect("Couldn't write bindings.");
4243

44+
// link to appropriate C++ lib
45+
if target.contains("apple") {
46+
println!("cargo:rustc-link-lib=c++");
47+
println!("cargo:rustc-link-lib=dylib=omp");
48+
} else {
49+
println!("cargo:rustc-link-lib=stdc++");
50+
println!("cargo:rustc-link-lib=dylib=gomp");
51+
}
52+
4353
println!("cargo:rustc-link-search={}", out_path.join("lib").display());
44-
println!("cargo:rustc-link-lib=dylib=gomp");
45-
println!("cargo:rustc-link-lib=stdc++");
4654
println!("cargo:rustc-link-search=native={}", dst.display());
4755
println!("cargo:rustc-link-lib=static=_lightgbm");
4856
}

0 commit comments

Comments
 (0)