From 90f6fc4101b95ff78f5715068d2564ce770c57fc Mon Sep 17 00:00:00 2001 From: Mohammed Ghannam Date: Wed, 30 Oct 2024 22:11:11 +0100 Subject: [PATCH] Use static linking for the from-source feature (#22) * 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 --- .github/workflows/build_and_test.yml | 27 ++++++++++++++++++--------- build.rs | 25 +++++++++++++++++++++---- from_source.rs | 22 +++++++++++++++++----- 3 files changed, 56 insertions(+), 18 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 27f04c1..142aa6d 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -34,6 +34,7 @@ jobs: macos-latest, macos-14, ubuntu-latest, + windows-latest, ] runs-on: ${{ matrix.os }} steps: @@ -41,22 +42,30 @@ jobs: - 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 \ No newline at end of file +# 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 +# " \ No newline at end of file diff --git a/build.rs b/build.rs index b9ed33a..c320915 100644 --- a/build.rs +++ b/build.rs @@ -134,10 +134,27 @@ fn main() -> Result<(), Box> { } }; - #[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") diff --git a/from_source.rs b/from_source.rs index d6b59a4..96ef347 100644 --- a/from_source.rs +++ b/from_source.rs @@ -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}")) } @@ -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"))]