Skip to content

Commit

Permalink
Make openssl a feature rather than a platform choice. (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardkiss authored Nov 12, 2021
1 parent ab57404 commit 2441c43
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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') }}
Expand Down Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-arm64-wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-m1-wheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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 }}
Expand Down
5 changes: 1 addition & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
----
Expand All @@ -34,7 +48,7 @@ $ cargo install wasm-pack
Then build with
```
$ wasm-pack build --release
$ wasm-pack build --release
```
Expand Down
14 changes: 7 additions & 7 deletions src/sha2.rs
Original file line number Diff line number Diff line change
@@ -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() }
Expand All @@ -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 {
Expand Down

0 comments on commit 2441c43

Please sign in to comment.