From 755af938dde4be3a24deb8e2ffb5ba675bb7d8d0 Mon Sep 17 00:00:00 2001 From: arvidn Date: Tue, 23 Nov 2021 14:44:17 +0100 Subject: [PATCH] use features to control what we link against --- .github/workflows/build-arm64-wheels.yml | 2 +- .github/workflows/build-test.yml | 12 ++++++------ Cargo.toml | 6 +++++- build.rs | 14 ++++++++++---- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build-arm64-wheels.yml b/.github/workflows/build-arm64-wheels.yml index 05bcac0d..2433844c 100644 --- a/.github/workflows/build-arm64-wheels.yml +++ b/.github/workflows/build-arm64-wheels.yml @@ -54,7 +54,7 @@ jobs: if [ ! -f "activate" ]; then ln -s venv/bin/activate; fi && \ . ./activate && \ pip install maturin && \ - CC=gcc maturin build --no-sdist --release --strip --manylinux 2014 --cargo-extra-args="--features=openssl" \ + CC=gcc maturin build --no-sdist --release --strip --manylinux 2014 --cargo-extra-args="--features=openssl,libgmp10" \ ' - name: Upload artifacts diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 9529dee8..87bdd3dd 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -89,7 +89,7 @@ jobs: . ./activate && \ pip install --upgrade pip && \ pip install maturin && \ - CC=gcc maturin build --no-sdist --release --strip --manylinux 2010 --cargo-extra-args="--features=openssl" \ + CC=gcc maturin build --no-sdist --release --strip --manylinux 2010 --cargo-extra-args="--features=openssl,libgmp3" \ ' - name: Build Windows with maturin on Python ${{ matrix.python }} @@ -99,12 +99,12 @@ jobs: . .\venv\Scripts\Activate.ps1 ln -s venv\Scripts\Activate.ps1 activate git clone https://github.com/Chia-Network/mpir_gc_x64.git --depth 1 - maturin build --no-sdist -i python --release --strip + maturin build --no-sdist -i python --release --strip --cargo-extra-args="--features=mpir" # this will install into the venv # it'd be better to use the wheel, but I can't figure out how to do that # TODO: figure this out # this does NOT work: pip install target/wheels/clvm_rs-*.whl - maturin develop --release + maturin develop --release --cargo-extra-args="--features=mpir" # the line above also doesn't seem to work - name: Install clvm_rs wheel @@ -232,11 +232,11 @@ jobs: with: toolchain: nightly - name: install GMP - run: sudo apt install libgmp3-dev + run: sudo apt install libgmp-dev - name: cargo-fuzz run: cargo +nightly install cargo-fuzz - name: build - run: cargo +nightly fuzz build + run: cargo +nightly fuzz build --cargo-extra-args="--features=openssl" unit_tests: runs-on: ubuntu-20.04 @@ -251,6 +251,6 @@ jobs: toolchain: stable components: rustfmt, clippy - name: install GMP - run: sudo apt install libgmp3-dev + run: sudo apt install libgmp-dev - name: cargo test run: cargo test diff --git a/Cargo.toml b/Cargo.toml index ff8756d2..137c4204 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,11 @@ lto = true [features] extension-module = ["pyo3/extension-module"] -default = ["extension-module"] +libgmp = [] +libgmp3 = [] +libgmp10 = [] +mpir = [] +default = ["extension-module", "libgmp"] [dependencies] hex = "=0.4.3" diff --git a/build.rs b/build.rs index 8e500fb5..0d9ee860 100644 --- a/build.rs +++ b/build.rs @@ -1,18 +1,24 @@ +use std::env; + fn main() { - #[cfg(target_os = "windows")] - { + if env::var_os("CARGO_FEATURE_MPIR").is_some() { println!("cargo:rustc-link-lib=mpir"); println!("cargo:rustc-link-search=mpir_gc_x64"); + } else if env::var_os("CARGO_FEATURE_LIBGMP3").is_some() { + println!("cargo:rustc-link-lib=libgmp.so.3"); + } else if env::var_os("CARGO_FEATURE_LIBGMP10").is_some() { + println!("cargo:rustc-link-lib=libgmp.so.10"); + } else if env::var_os("CARGO_FEATURE_LIBGMP").is_some() { + println!("cargo:rustc-link-lib=gmp"); } + #[cfg(target_os = "linux")] { - println!("cargo:rustc-link-lib=gmp"); println!("cargo:rustc-link-search=/usr/lib64"); println!("cargo:rustc-link-search=/usr/lib"); } #[cfg(target_os = "macos")] { - println!("cargo:rustc-link-lib=gmp"); println!("cargo:rustc-link-search=/opt/homebrew/lib"); } }