Skip to content

Commit 3d4bd10

Browse files
committed
XGBoost Mac compile
1 parent 9370bf8 commit 3d4bd10

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

xgboost-sys/build.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,23 @@ fn main() {
2828
.define("BUILD_STATIC_LIB", "ON")
2929
.define("USE_CUDA", "ON")
3030
.define("BUILD_WITH_CUDA", "ON")
31-
.define("BUILD_WITH_CUDA_CUB", "ON")
32-
.build();
31+
.define("BUILD_WITH_CUDA_CUB", "ON");
3332

3433
#[cfg(not(feature = "cuda"))]
35-
let dst = Config::new(&xgb_root)
36-
.uses_cxx11()
37-
.define("BUILD_STATIC_LIB", "ON")
38-
.build();
34+
let mut dst = Config::new(&xgb_root);
35+
36+
let dst = dst.uses_cxx11()
37+
.define("BUILD_STATIC_LIB", "ON");
38+
39+
#[cfg(target_os = "macos")]
40+
let dst =
41+
dst
42+
.define("CMAKE_C_COMPILER", "/opt/homebrew/opt/llvm/bin/clang")
43+
.define("CMAKE_CXX_COMPILER", "/opt/homebrew/opt/llvm/bin/clang++")
44+
.define("OPENMP_LIBRARIES", "/opt/homebrew/opt/llvm/lib")
45+
.define("OPENMP_INCLUDES", "/opt/homebrew/opt/llvm/include");
46+
47+
let dst = dst.build();
3948

4049
let xgb_root = xgb_root.canonicalize().unwrap();
4150

@@ -57,6 +66,10 @@ fn main() {
5766
.generate()
5867
.expect("Unable to generate bindings.");
5968

69+
#[cfg(targe_os = "darwin")]
70+
let bindings = bindings
71+
.clang_arg("-L/opt/homebrew/Cellar/libomp/16.0.6/lib/");
72+
6073
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
6174
bindings
6275
.write_to_file(out_path.join("bindings.rs"))

0 commit comments

Comments
 (0)