diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 8400cf63..fdf6b999 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -73,7 +73,7 @@ jobs: git clone https://github.com/Chia-Network/clvm_tools.git --branch=main --single-branch python -m pip install ./clvm_tools python -m pip install colorama - maturin develop --release + maturin develop --release --cargo-extra-args="--features=openssl" - name: Run benchmarks if: ${{ !startsWith(matrix.os, 'windows') }} @@ -119,7 +119,7 @@ jobs: git clone https://github.com/Chia-Network/clvm_tools.git --branch=main --single-branch python -m pip install ./clvm_tools python -m pip install colorama - maturin develop --release + maturin develop --release --cargo-extra-args="--features=openssl" - name: Run cost checks run: | diff --git a/.github/workflows/build-arm64-wheels.yml b/.github/workflows/build-arm64-wheels.yml index 0e8a3587..cb40a22f 100644 --- a/.github/workflows/build-arm64-wheels.yml +++ b/.github/workflows/build-arm64-wheels.yml @@ -52,7 +52,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 \ + CC=gcc maturin build --no-sdist --release --strip --manylinux 2014 --cargo-extra-args="--features=openssl" \ ' - name: Upload artifacts diff --git a/.github/workflows/build-m1-wheel.yml b/.github/workflows/build-m1-wheel.yml index d338a6a3..941d538e 100644 --- a/.github/workflows/build-m1-wheel.yml +++ b/.github/workflows/build-m1-wheel.yml @@ -43,7 +43,7 @@ jobs: . ./venv/bin/activate export PATH=~/.cargo/bin:$PATH arch -arm64 pip install maturin - arch -arm64 maturin build --no-sdist -i python --release --strip + arch -arm64 maturin build --no-sdist -i python --release --strip --cargo-extra-args="--features=openssl" - name: Install clvm_rs wheel run: | diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 45598e30..fbb7cedc 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -50,7 +50,7 @@ jobs: python -m venv venv ln -s venv/bin/activate . ./activate - maturin build --no-sdist -i python --release --strip + maturin build --no-sdist -i python --release --strip --cargo-extra-args="--features=openssl" # - name: Build Linux with maturin on Python ${{ matrix.python }} # if: startsWith(matrix.os, 'ubuntu') @@ -86,7 +86,7 @@ jobs: . ./activate && \ pip install --upgrade pip && \ pip install maturin && \ - CC=gcc maturin build --no-sdist --release --strip --manylinux 2010 \ + CC=gcc maturin build --no-sdist --release --strip --manylinux 2010 --cargo-extra-args="--features=openssl" \ ' - name: Build Windows with maturin on Python ${{ matrix.python }} diff --git a/Cargo.toml b/Cargo.toml index e781c50c..24d25a14 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,11 +27,8 @@ num-bigint = "=0.4.0" num-traits = "=0.2.14" num-integer = "=0.1.44" bls12_381 = "=0.5.0" - sha2 = "=0.9.5" - -[target.'cfg(unix)'.dependencies] -openssl = { version = "0.10.35", features = ["vendored"] } +openssl = { version = "0.10.35", features = ["vendored"], optional = true } [target.'cfg(target_family="wasm")'.dependencies] wasm-bindgen = "=0.2.75" diff --git a/README.md b/README.md index 8c1ea919..5c79363e 100644 --- a/README.md +++ b/README.md @@ -15,12 +15,26 @@ Build `clvm_rs` directly into the current virtualenv with $ maturin develop --release ``` +On UNIX-based platforms, you may get a speed boost on `sha256` operations by building +with OpenSSL. + +``` +$ maturin develop --release --cargo-extra-args="--features=openssl" +``` + + To build the wheel, do ``` $ maturin build --release --no-sdist ```` +or + +``` +$ maturin build --release --no-sdist --cargo-extra-args="--features=openssl" +``` + WASM ---- @@ -34,7 +48,7 @@ $ cargo install wasm-pack Then build with ``` -$ wasm-pack build --release +$ wasm-pack build --release ``` diff --git a/src/sha2.rs b/src/sha2.rs index a3966ee9..bf45d393 100644 --- a/src/sha2.rs +++ b/src/sha2.rs @@ -1,18 +1,18 @@ -#[cfg(not(unix))] +#[cfg(not(openssl))] use sha2::{Digest, Sha256 as Ctx}; -#[cfg(unix)] +#[cfg(openssl)] use openssl::sha; // WINDOWS PART -#[cfg(not(unix))] +#[cfg(not(openssl))] #[derive(Clone)] pub struct Sha256 { ctx: Ctx, } -#[cfg(not(unix))] +#[cfg(not(openssl))] impl Sha256 { pub fn new() -> Sha256 { Sha256 { ctx: Ctx::new() } @@ -25,15 +25,15 @@ impl Sha256 { } } -// UNIX PART +// OPENSSL PART -#[cfg(unix)] +#[cfg(openssl)] #[derive(Clone)] pub struct Sha256 { ctx: sha::Sha256, } -#[cfg(unix)] +#[cfg(openssl)] impl Sha256 { pub fn new() -> Sha256 { Sha256 {