diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 4d9fc1f..14b2a7e 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -7,10 +7,8 @@ on: branches: [ master ] jobs: - build: - + linux: runs-on: ubuntu-latest - steps: - uses: actions/checkout@v2 - name: Prepare dependencies @@ -21,9 +19,7 @@ jobs: run: cargo test --verbose --all windows: - runs-on: windows-latest - steps: - uses: actions/checkout@v2 - name: Prepare dependencies @@ -33,11 +29,12 @@ jobs: mkdir C:\Cbc Invoke-WebRequest "https://bintray.com/coin-or/download/download_file?file_path=Cbc-2.9-win32-msvc14.zip" -OutFile "C:\Cbc\Cbc-2.9.zip" 7z x C:\Cbc\Cbc-2.9.zip -o"C:\Cbc\" + Get-ChildItem -Path "C:\Cbc" + Get-ChildItem -Path "C:\Cbc\lib" + echo "C:\Cbc\lib" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + echo $env:GITHUB_PATH + type $env:GITHUB_PATH - name: Build - run: | - echo "C:\Cbc\lib" >> $GITHUB_PATH - cargo build --verbose --all + run: cargo build --verbose --all - name: Run tests - run: | - echo "C:\Cbc\lib" >> $GITHUB_PATH - cargo test --verbose --all + run: cargo test --verbose --all diff --git a/coin_cbc_sys/Cargo.toml b/coin_cbc_sys/Cargo.toml index 3a37f52..39b560a 100644 --- a/coin_cbc_sys/Cargo.toml +++ b/coin_cbc_sys/Cargo.toml @@ -9,3 +9,5 @@ repository = "https://github.com/KardinalAI/coin_cbc" keywords = ["MILP", "MIP", "linear programming"] categories = ["external-ffi-bindings", "mathematics", "science"] license = "MIT " +build = "build.rs" +links = "CbcSolver" diff --git a/coin_cbc_sys/build.rs b/coin_cbc_sys/build.rs new file mode 100644 index 0000000..f474d9f --- /dev/null +++ b/coin_cbc_sys/build.rs @@ -0,0 +1,22 @@ +fn main() { + use std::env; + + let is_linux = env::var("CARGO_CFG_UNIX"); + if is_linux.is_ok() { + println!("cargo:rustc-link-lib=CbcSolver"); + return; + } + + let is_win = env::var("CARGO_CFG_WINDOWS"); + if is_win.is_ok() { + println!("cargo:rustc-link-lib=libCbcSolver"); + let path = env::var("PATH"); + if let Ok(ok_path) = path { + let cbc_path = ok_path.split(";").find(|&s| s.contains("Cbc")); + if let Some(final_path) = cbc_path { + println!("cargo:rustc-link-search={}", final_path); + } + } + return; + } +} diff --git a/coin_cbc_sys/src/lib.rs b/coin_cbc_sys/src/lib.rs index 5246d01..807b96b 100644 --- a/coin_cbc_sys/src/lib.rs +++ b/coin_cbc_sys/src/lib.rs @@ -22,8 +22,6 @@ pub type cbc_callback = Option< ), >; -#[cfg_attr(unix, link(name = "CbcSolver"))] -#[cfg_attr(windows, link(name = "libCbcSolver"))] extern "C" { pub fn Cbc_newModel() -> *mut Cbc_Model; pub fn Cbc_deleteModel(model: *mut Cbc_Model);