From 09fdf61c6660353fb49bcc7ecec500f4e1c9c436 Mon Sep 17 00:00:00 2001 From: frozenlib Date: Mon, 20 May 2024 11:24:06 +0900 Subject: [PATCH] Add support for macos-14-arm64 --- .github/workflows/ci.yml | 12 ++++++++++-- README.md | 4 +++- lgbm-sys/build.rs | 9 ++++++++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 019a07e..6dfc00c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,11 +10,13 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest, windows-latest, macos-13] + os: [ubuntu-latest, windows-latest, macos-13, macos-latest] link: [static, dynamic] exclude: - os: macos-13 link: static + - os: macos-latest + link: static steps: - uses: actions/checkout@v4 @@ -57,11 +59,17 @@ jobs: cmake .. make -j4 - - name: Install LightGBM (macos - dynamic) + - name: Install LightGBM (macos-13 - dynamic) if: matrix.os == 'macos-13' && matrix.link == 'dynamic' run: | brew install lightgbm + - name: Install LightGBM (macos - dynamic) + if: matrix.os == 'macos-latest' && matrix.link == 'dynamic' + run: | + brew install lightgbm + echo "LIGHTGBM_LIB_DIR=/opt/homebrew/Cellar/lightgbm/4.3.0/lib/" >> $GITHUB_ENV + - name: Rustup update stable run: rustup update stable - name: Show cargo version diff --git a/README.md b/README.md index 587868a..235b881 100644 --- a/README.md +++ b/README.md @@ -15,10 +15,12 @@ Unofficial Rust bindings for [LightGBM](https://lightgbm.readthedocs.io/en/lates ### MacOS -Run the following command to install LightGBM on your system. +1. Run `brew install lightgbm` and install LightGBM on your system. +2. Set the environment variable `LIGHTGBM_LIB_PATH` to the directory containing `lib_lightgbm.dylib`. ```sh brew install lightgbm +export LIGHTGBM_LIB_PATH=/opt/homebrew/Cellar/lightgbm/4.3.0/lib/ ``` ## Example diff --git a/lgbm-sys/build.rs b/lgbm-sys/build.rs index fe0a9f6..66b08de 100644 --- a/lgbm-sys/build.rs +++ b/lgbm-sys/build.rs @@ -50,13 +50,20 @@ fn build_linux() { } } fn build_macos() { + if let Some(dir) = try_env_var("LIGHTGBM_LIB_DIR") { + println!("cargo:rustc-link-search={dir}"); + } println!("cargo:rustc-link-lib=dylib=_lightgbm"); } fn env_var(key: &str) -> String { + try_env_var(key).unwrap_or_else(|| panic!("environment variable `{key}` is not set")) +} +fn try_env_var(key: &str) -> Option { println!("cargo:rerun-if-env-changed={key}"); - env::var(key).unwrap_or_else(|_| panic!("environment variable `{key}` is not set")) + env::var(key).ok() } + fn rerun_if_changed(path: &Path) { println!("cargo:rerun-if-changed={}", path.display()); }