Skip to content

Commit fd58786

Browse files
committed
Merge main and update scip version in from-source feature
2 parents 0adbe10 + 90200a5 commit fd58786

File tree

8 files changed

+333
-88
lines changed

8 files changed

+333
-88
lines changed

.github/workflows/build_and_test.yml

Lines changed: 64 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ jobs:
1414
matrix:
1515
os: [
1616
ubuntu-latest,
17-
macos-latest,
17+
macos-13,
1818
macos-14, # macOS arm runner
1919
windows-latest,
20+
ubuntu-24.04-arm
2021
]
2122
runs-on: ${{ matrix.os }}
2223
steps:
@@ -30,6 +31,27 @@ jobs:
3031
- name: Install requirements on macos
3132
if: matrix.os == 'macos-latest' || matrix.os == 'macos-14'
3233
run: |
34+
cargo b --features bundled --release
35+
cargo t --features bundled --release create
36+
cargo t --features bundled --release --examples
37+
38+
# bundled-debug-test:
39+
# strategy:
40+
# matrix:
41+
# os: [
42+
# ubuntu-latest,
43+
# macos-13,
44+
# macos-14, # macOS arm runner
45+
# windows-latest,
46+
# ]
47+
# runs-on: ${{ matrix.os }}
48+
# steps:
49+
# - uses: actions/checkout@v3
50+
# - name: Test bundled
51+
# run: |
52+
# cargo b --features bundled
53+
# cargo t --features bundled create
54+
# cargo t --features bundled --examples
3355
brew install gcc
3456
brew info gcc
3557

@@ -53,32 +75,62 @@ jobs:
5375
strategy:
5476
matrix:
5577
os: [
56-
macos-latest,
78+
macos-13,
5779
macos-14,
5880
ubuntu-latest,
81+
windows-latest,
5982
]
6083
runs-on: ${{ matrix.os }}
6184
steps:
6285
- uses: actions/checkout@v3
6386
- name: Install bison
64-
if: ${{ matrix.os == 'macos-latest' || matrix.os == 'macos-14' }}
87+
if: ${{ matrix.os == 'macos-13' || matrix.os == 'macos-14' }}
6588
run: |
66-
brew install bison
89+
brew install bison gcc
6790
- name: Test from-source
6891
run: |
6992
cargo b --features from-source -vv
7093
cargo t --features from-source create
7194
cargo t --features from-source --examples
7295
73-
# TODO: fix this, needs tbb
74-
# windows-from-source:
75-
# runs-on: windows-latest
96+
linux-conda-test:
97+
runs-on: ubuntu-latest
98+
steps:
99+
- uses: actions/checkout@v3
100+
- uses: conda-incubator/setup-miniconda@v2
101+
with:
102+
activate-environment: test
103+
allow-softlinks: true
104+
105+
- name: Install dependencies (SCIPOptSuite)
106+
run: |
107+
conda install -y --prefix $CONDA/envs/test --channel conda-forge scip
108+
echo "LD_LIBRARY_PATH=$CONDA/envs/test/lib" >> "${GITHUB_ENV}"
109+
echo "CONDA_PREFIX=$CONDA/envs/test" >> "${GITHUB_ENV}"
110+
111+
- name: Test
112+
run: |
113+
cargo b -vv
114+
cargo t create
115+
cargo t --examples
116+
117+
# from-source-linux-arm-test:
118+
# runs-on: ubuntu-latest
76119
# steps:
77120
# - uses: actions/checkout@v3
78121
#
79-
# - name: Test from-source
122+
# - name: Set up QEMU for ARM64 emulation
123+
# uses: docker/setup-qemu-action@v2
124+
# with:
125+
# platforms: arm64
126+
#
127+
# - name: Run test in ARM64 environment
80128
# run: |
81-
# echo "${{ runner.workspace }}/vcpkg" >> $GITHUB_PATH
82-
# cargo b --features from-source -vv
83-
# cargo t --features from-source create
84-
# cargo t --features from-source --examples
129+
# docker run --rm --platform linux/arm64 \
130+
# -v ${{ github.workspace }}:/workspace \
131+
# -w /workspace \
132+
# rust:latest /bin/bash -c "
133+
# cargo build --features from-source -vv
134+
# cargo test --features from-source create
135+
# cargo test --features from-source --examples
136+
# "

Cargo.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "scip-sys"
3-
version = "0.1.14"
3+
version = "0.1.22"
44
edition = "2021"
55
description = "Bindings for the C SCIP solver."
66
repository = "https://github.com/scipopt/scip-sys"
@@ -9,18 +9,19 @@ links = "scip"
99

1010
[features]
1111
bundled = ["ureq", "zip", "tempfile", "zip-extract"]
12-
from-source = ["ureq", "zip", "tempfile", "zip-extract", "cmake"]
12+
from-source = ["ureq", "zip", "tempfile", "zip-extract", "cmake", "flate2", "tar"]
1313
static = ["libz-sys/static"]
1414

1515
[build-dependencies]
16-
bindgen = "0.64"
17-
cc = "1.0.73"
16+
bindgen = "0.72.0"
1817
glob = "0.3.1"
1918
ureq = { version = "2.9.6", optional = true }
2019
zip = { version = "0.5", optional = true }
2120
tempfile = { version = "3.2", optional = true }
2221
zip-extract = { version = "0.1.3", optional = true }
2322
cmake = { version = "0.1.50", optional = true }
23+
flate2 = { version = "1.0", optional = true }
24+
tar = { version = "0.4", optional = true }
2425

2526
[dependencies]
2627
libz-sys = { version="1.1.16", features = ["static"], optional = true }

build.rs

Lines changed: 72 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use std::env;
1111
use std::error::Error;
1212
use std::path::PathBuf;
1313

14+
use crate::from_source::{compile_scip, download_scip_source, is_from_source_feature_enabled};
1415
use bundled::*;
15-
use crate::from_source::{download_scip_source, is_from_source_feature_enabled, compile_scip};
1616

1717
#[cfg(not(feature = "bundled"))]
1818
pub fn is_bundled_feature_enabled() -> bool {
@@ -29,7 +29,7 @@ fn _build_from_scip_dir(path: &str) -> bindgen::Builder {
2929
println!("cargo:libdir={}", lib_dir_path);
3030

3131
#[cfg(windows)]
32-
let lib_dir_path = PathBuf::from(&path).join("bin");
32+
let lib_dir_path = PathBuf::from(&path).join("bin");
3333
#[cfg(windows)]
3434
println!("cargo:rustc-link-search={}", lib_dir_path.to_str().unwrap());
3535
} else {
@@ -64,7 +64,7 @@ fn _build_from_scip_dir(path: &str) -> bindgen::Builder {
6464
bindgen::Builder::default()
6565
.header(scip_header_file)
6666
.header(scipdefplugins_header_file)
67-
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
67+
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
6868
.clang_arg(format!("-I{}", include_dir_path))
6969
}
7070

@@ -94,46 +94,76 @@ fn look_in_scipoptdir_and_conda_env() -> Option<bindgen::Builder> {
9494
}
9595

9696
fn main() -> Result<(), Box<dyn Error>> {
97-
let builder =
98-
if is_bundled_feature_enabled() {
99-
download_scip();
100-
let path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("scip_install");
101-
_build_from_scip_dir(path.to_str().unwrap())
102-
} else if is_from_source_feature_enabled() {
103-
let source_path = download_scip_source();
104-
let build_path = compile_scip(source_path);
105-
_build_from_scip_dir(build_path.to_str().unwrap())
97+
let builder = if is_bundled_feature_enabled() {
98+
download_scip();
99+
let path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("scip_install");
100+
_build_from_scip_dir(path.to_str().unwrap())
101+
} else if is_from_source_feature_enabled() {
102+
let source_path = download_scip_source();
103+
let build_path = compile_scip(source_path);
104+
_build_from_scip_dir(build_path.to_str().unwrap())
105+
} else {
106+
let builder = look_in_scipoptdir_and_conda_env();
107+
if builder.is_some() {
108+
builder.unwrap()
106109
} else {
107-
let builder = look_in_scipoptdir_and_conda_env();
108-
if builder.is_some() {
109-
builder.unwrap()
110-
} else {
111-
println!("cargo:warning=SCIP was not found in SCIPOPTDIR or in Conda environemnt");
112-
println!("cargo:warning=Looking for SCIP in system libraries");
113-
114-
let headers_dir_path = "headers/";
115-
let headers_dir = PathBuf::from(headers_dir_path);
116-
let scip_header_file = PathBuf::from(&headers_dir)
117-
.join("scip")
118-
.join("scip.h")
119-
.to_str()
120-
.unwrap()
121-
.to_owned();
122-
let scipdefplugins_header_file = PathBuf::from(&headers_dir)
123-
.join("scip")
124-
.join("scipdefplugins.h")
125-
.to_str()
126-
.unwrap()
127-
.to_owned();
128-
129-
bindgen::Builder::default()
130-
.header(scip_header_file)
131-
.header(scipdefplugins_header_file)
132-
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
133-
.clang_arg(format!("-I{}", headers_dir_path))
134-
}
135-
};
110+
println!("cargo:warning=SCIP was not found in SCIPOPTDIR or in Conda environemnt");
111+
println!("cargo:warning=Looking for SCIP in system libraries");
112+
113+
let headers_dir_path = "headers/";
114+
let headers_dir = PathBuf::from(headers_dir_path);
115+
let scip_header_file = PathBuf::from(&headers_dir)
116+
.join("scip")
117+
.join("scip.h")
118+
.to_str()
119+
.unwrap()
120+
.to_owned();
121+
let scipdefplugins_header_file = PathBuf::from(&headers_dir)
122+
.join("scip")
123+
.join("scipdefplugins.h")
124+
.to_str()
125+
.unwrap()
126+
.to_owned();
127+
128+
bindgen::Builder::default()
129+
.header(scip_header_file)
130+
.header(scipdefplugins_header_file)
131+
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
132+
.clang_arg(format!("-I{}", headers_dir_path))
133+
}
134+
};
135+
136+
#[cfg(windows)]
137+
{
138+
println!("cargo:rustc-link-lib=libscip");
139+
}
140+
#[cfg(not(windows))]
141+
{
142+
println!("cargo:rustc-link-lib=scip");
143+
}
144+
145+
#[cfg(feature = "from-source")]
146+
{
147+
let target = env::var("TARGET").unwrap();
148+
let apple = target.contains("apple");
149+
let linux = target.contains("linux");
150+
let mingw = target.contains("pc-windows-gnu");
151+
if apple {
152+
println!("cargo:rustc-link-lib=dylib=c++");
153+
} else if linux || mingw {
154+
println!("cargo:rustc-link-lib=dylib=stdc++");
155+
}
136156

157+
#[cfg(windows)]
158+
{
159+
println!("cargo:rustc-link-lib=libsoplex");
160+
}
161+
#[cfg(not(windows))]
162+
{
163+
println!("cargo:rustc-link-lib=soplex");
164+
}
165+
}
166+
137167
#[cfg(feature = "static")] {
138168
#[cfg(windows)]{
139169
println!("cargo:rustc-link-lib=static=libscip");
@@ -178,7 +208,7 @@ fn main() -> Result<(), Box<dyn Error>> {
178208
.blocklist_item("FP_ZERO")
179209
.blocklist_item("FP_SUBNORMAL")
180210
.blocklist_item("FP_NORMAL")
181-
.parse_callbacks(Box::new(bindgen::CargoCallbacks));
211+
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()));
182212

183213
let bindings = builder.generate()?;
184214
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());

bundled.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@ pub fn download_scip() {
1919
return;
2020
}
2121

22-
let os = env::consts::OS;
23-
let arch = std::env::consts::ARCH;
22+
let os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
23+
let arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap();
2424
println!("cargo:warning=Detected OS: {}", os);
2525
println!("cargo:warning=Detected arch: {}", arch);
2626

2727
let os_string = if os == "linux" && arch == "x86_64" {
2828
"linux"
29-
} else if os == "macos" && arch == "x86_64" {
30-
"macos"
29+
} else if os == "linux" && arch == "aarch64" {
30+
"linux-arm"
31+
}
32+
else if os == "macos" && arch == "x86_64" {
33+
"macos-intel"
3134
} else if os == "macos" && arch == "aarch64" {
3235
"macos-arm"
3336
} else if os == "windows" && arch == "x86_64" {
@@ -36,8 +39,18 @@ pub fn download_scip() {
3639
panic!("Unsupported OS-arch combination: {}-{}", os, arch);
3740
};
3841

42+
// if debug mode is enabled, download the debug version of SCIP
43+
#[cfg(debug_assertions)]
44+
let debug_str = "-debug";
45+
#[cfg(not(debug_assertions))]
46+
let debug_str = "";
47+
48+
// TODO: enable this when debug builds are available
49+
// let url = format!(
50+
// "https://github.com/scipopt/scipoptsuite-deploy/releases/download/v0.8.0/libscip-{os_string}{debug_str}.zip",
51+
// );
3952
let url = format!(
40-
"https://github.com/scipopt/scip-sys/releases/download/v0.1.9/libscip-{os_string}.zip"
53+
"https://github.com/scipopt/scipoptsuite-deploy/releases/download/v0.8.0/libscip-{os_string}.zip",
4154
);
4255

4356
download_and_extract_zip(&url, &extract_path)

0 commit comments

Comments
 (0)