Skip to content

Commit

Permalink
Use static linking for the from-source feature (#22)
Browse files Browse the repository at this point in the history
* Use static build when compiling scip

* CI: just macos for now

* Install gcc too on macos

* Static linking for the from-source feature

* Reenable ubuntu in CI for from-source feature

* Try out windows and linux arm

* Remove libz requirement

* Add ubuntu arm docker container test to CI

* Update scip source to 9.1.1

* Use another link for scip source

* Fix scip version number

* Use mac arm runner for linux arm emulation

* Test another way of using arm linux

* Rollback to qemu

* Try out statically linking stdc++ in windows

* Avoid linking to stdc++ on windows

* Link correct soplex library on windows

* Add back other runners

* And also bundled runners
  • Loading branch information
mmghannam authored Oct 30, 2024
1 parent 4c74b6e commit 90f6fc4
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 18 deletions.
27 changes: 18 additions & 9 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,38 @@ jobs:
macos-latest,
macos-14,
ubuntu-latest,
windows-latest,
]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Install bison
if: ${{ matrix.os == 'macos-latest' || matrix.os == 'macos-14' }}
run: |
brew install bison
brew install bison gcc
- name: Test from-source
run: |
cargo b --features from-source -vv
cargo t --features from-source create
cargo t --features from-source --examples
# TODO: fix this, needs tbb
# windows-from-source:
# runs-on: windows-latest
# from-source-linux-arm-test:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
#
# - name: Test from-source
# - name: Set up QEMU for ARM64 emulation
# uses: docker/setup-qemu-action@v2
# with:
# platforms: arm64
#
# - name: Run test in ARM64 environment
# run: |
# echo "${{ runner.workspace }}/vcpkg" >> $GITHUB_PATH
# cargo b --features from-source -vv
# cargo t --features from-source create
# cargo t --features from-source --examples
# docker run --rm --platform linux/arm64 \
# -v ${{ github.workspace }}:/workspace \
# -w /workspace \
# rust:latest /bin/bash -c "
# cargo build --features from-source -vv
# cargo test --features from-source create
# cargo test --features from-source --examples
# "
25 changes: 21 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,27 @@ fn main() -> Result<(), Box<dyn Error>> {
}
};

#[cfg(windows)]
println!("cargo:rustc-link-lib=libscip");
#[cfg(not(windows))]
println!("cargo:rustc-link-lib=scip");

#[cfg(windows)] {
println!("cargo:rustc-link-lib=libscip");
println!("cargo:rustc-link-lib=libsoplex");
}
#[cfg(not(windows))] {
println!("cargo:rustc-link-lib=scip");
println!("cargo:rustc-link-lib=soplex");
}

#[cfg(feature = "from-source")] {
let target = env::var("TARGET").unwrap();
let apple = target.contains("apple");
let linux = target.contains("linux");
let mingw = target.contains("pc-windows-gnu");
if apple {
println!("cargo:rustc-link-lib=dylib=c++");
} else if linux || mingw {
println!("cargo:rustc-link-lib=dylib=stdc++");
}
}

let builder = builder
.blocklist_item("FP_NAN")
Expand Down
22 changes: 17 additions & 5 deletions from_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@ pub fn download_scip_source() -> PathBuf {

#[cfg(feature = "from-source")]
pub fn download_scip_source() -> PathBuf {
let url = "https://github.com/scipopt/scip-sys/releases/download/v0.1.9/scipoptsuite-9.0.0.zip";
let scip_version = "9.1.1";
let url = format!("https://github.com/scipopt/scip-sys/releases/download/v0.1.9/scipoptsuite-{scip_version}.zip");
let target = env::var("OUT_DIR").unwrap();
let target = std::path::Path::new(&target);
if target.join("scipoptsuite-9.0.0").exists() {
if target.join(format!("scipoptsuite-{scip_version}")).exists() {
println!("cargo:warning=SCIP was previously downloaded, skipping download");
} else {
download_and_extract_zip(url, &*target).expect("Failed to download SCIP");
download_and_extract_zip(&url, &*target).expect("Failed to download SCIP");
}
target.join("scipoptsuite-9.0.0")
target.join(format!("scipoptsuite-{scip_version}"))
}


Expand All @@ -48,7 +49,18 @@ pub fn compile_scip(source_path: PathBuf) -> PathBuf {
use cmake::Config;
let mut dst = Config::new(source_path);

dst.define("AUTOBUILD", "ON").build()
dst
.define("IPOPT", "OFF")
.define("ZIMPL", "OFF")
.define("GMP", "OFF")
.define("READLINE", "OFF")
.define("BOOST", "OFF")
.define("AUTOBUILD","OFF")
.define("PAPILO", "OFF")
.define("SYM", "snauty")
.define("ZLIB", "OFF")
.define("SHARED", "OFF")
.build()
}

#[cfg(not(feature = "from-source"))]
Expand Down

0 comments on commit 90f6fc4

Please sign in to comment.