From a5f4e967b21028ae8d32793a5e0199fe7cb8f333 Mon Sep 17 00:00:00 2001 From: Dirk Leifeld Date: Sat, 24 Oct 2020 18:26:34 +0200 Subject: [PATCH] fixing windows path --- .github/workflows/rust.yml | 13 +++++++------ coin_cbc_sys/Cargo.toml | 1 + coin_cbc_sys/build.rs | 19 +++++++++++++++++++ coin_cbc_sys/src/lib.rs | 2 -- 4 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 coin_cbc_sys/build.rs diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 4d9fc1f..8cb1d2f 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -33,11 +33,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..aa345fb 100644 --- a/coin_cbc_sys/Cargo.toml +++ b/coin_cbc_sys/Cargo.toml @@ -9,3 +9,4 @@ repository = "https://github.com/KardinalAI/coin_cbc" keywords = ["MILP", "MIP", "linear programming"] categories = ["external-ffi-bindings", "mathematics", "science"] license = "MIT " +build = "build.rs" diff --git a/coin_cbc_sys/build.rs b/coin_cbc_sys/build.rs new file mode 100644 index 0000000..d2fcb57 --- /dev/null +++ b/coin_cbc_sys/build.rs @@ -0,0 +1,19 @@ +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 { + println!("cargo:rustc-link-search={}", ok_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);