Skip to content

Commit d1f3463

Browse files
committed
use libgmp for bignum instead of num-bigint
1 parent 3e9afdd commit d1f3463

File tree

15 files changed

+678
-103
lines changed

15 files changed

+678
-103
lines changed

.github/workflows/benchmark.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ jobs:
5454
git clone https://github.com/Chia-Network/clvm_tools.git --branch=main --single-branch
5555
python -m pip install ./clvm_tools
5656
python -m pip install colorama
57+
git clone https://github.com/Chia-Network/mpir_gc_x64.git --depth 1
5758
maturin develop --release
5859
5960
- name: Run benchmarks (Windows)
@@ -62,6 +63,13 @@ jobs:
6263
. .\venv\Scripts\Activate.ps1
6364
python benchmark/run-benchmark.py
6465
66+
- name: Install GMP
67+
if: ${{ startsWith(matrix.os, 'ubuntu') }}
68+
run: |
69+
sudo apt install libgmp3-dev
70+
ls -la /usr/lib64
71+
ls -la /usr/lib
72+
6573
- name: Build
6674
if: ${{ !startsWith(matrix.os, 'windows') }}
6775
env:
@@ -108,6 +116,9 @@ jobs:
108116
run: |
109117
python -m pip install maturin
110118
rustup target add x86_64-unknown-linux-musl
119+
sudo apt install libgmp3-dev
120+
ls -la /usr/lib64
121+
ls -la /usr/lib
111122
112123
- name: Build
113124
env:

.github/workflows/build-arm64-wheels.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ jobs:
4242
curl -L https://sh.rustup.rs > rustup-init.sh && \
4343
sh rustup-init.sh -y && \
4444
yum -y install openssl-devel && \
45+
yum -y install gmp && \
46+
ls -la /usr/lib64/ && \
4547
source $HOME/.cargo/env && \
4648
rustup target add aarch64-unknown-linux-musl && \
4749
rm -rf venv && \

.github/workflows/build-crate-and-npm.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ jobs:
3939
run: cargo +stable fmt -- --files-with-diff --check
4040
- name: clippy (stable)
4141
run: cargo +stable clippy
42+
- name: install GMP
43+
run: sudo apt install libgmp3-dev
4244
- name: tests
4345
run: cargo test && cargo test --release
4446
- name: build

.github/workflows/build-m1-wheel.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ jobs:
3737
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rust.sh
3838
arch -arm64 sh rust.sh -y
3939
40+
- name: install GMP
41+
run: |
42+
curl -L https://gmplib.org/download/gmp/gmp-6.2.1.tar.lz | tar x
43+
cd gmp-6.2.1
44+
./configure --enable-fat --with-pic
45+
make -j 6
46+
sudo make install
47+
cd ..
48+
rm -rf gmp-6.2.1
49+
4050
- name: Build m1 wheels
4151
run: |
4252
arch -arm64 python3 -m venv venv

.github/workflows/build-test.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ jobs:
4747
- name: Build MacOs with maturin on Python ${{ matrix.python }}
4848
if: startsWith(matrix.os, 'macos')
4949
run: |
50+
brew install gmp
5051
python -m venv venv
5152
ln -s venv/bin/activate
5253
. ./activate
@@ -70,6 +71,8 @@ jobs:
7071
curl -L https://sh.rustup.rs > rustup-init.sh && \
7172
sh rustup-init.sh -y && \
7273
yum -y install openssl-devel && \
74+
yum -y install gmp && \
75+
ls -la /usr/lib64 && \
7376
source $HOME/.cargo/env && \
7477
rustup target add x86_64-unknown-linux-musl && \
7578
rm -rf venv && \
@@ -95,6 +98,7 @@ jobs:
9598
python -m venv venv
9699
. .\venv\Scripts\Activate.ps1
97100
ln -s venv\Scripts\Activate.ps1 activate
101+
git clone https://github.com/Chia-Network/mpir_gc_x64.git --depth 1
98102
maturin build --no-sdist -i python --release --strip
99103
# this will install into the venv
100104
# it'd be better to use the wheel, but I can't figure out how to do that
@@ -227,6 +231,8 @@ jobs:
227231
uses: actions-rs/toolchain@v1
228232
with:
229233
toolchain: nightly
234+
- name: install GMP
235+
run: sudo apt install libgmp3-dev
230236
- name: cargo-fuzz
231237
run: cargo +nightly install cargo-fuzz
232238
- name: build
@@ -244,5 +250,7 @@ jobs:
244250
with:
245251
toolchain: stable
246252
components: rustfmt, clippy
253+
- name: install GMP
254+
run: sudo apt install libgmp3-dev
247255
- name: cargo test
248256
run: cargo test

Cargo.lock

Lines changed: 0 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ default = ["extension-module"]
2323
[dependencies]
2424
hex = "=0.4.3"
2525
lazy_static = "=1.4.0"
26-
num-bigint = "=0.4.0"
27-
num-traits = "=0.2.14"
28-
num-integer = "=0.1.44"
2926
bls12_381 = "=0.5.0"
3027
sha2 = "=0.9.5"
3128
openssl = { version = "0.10.35", features = ["vendored"], optional = true }

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ Use `maturin` to build the python interface. First, install into current virtual
99
$ pip install maturin
1010
```
1111

12+
As we need `MPIR` for MSVC builds, prepare this dependency with
13+
14+
```
15+
$ git clone https://github.com/Chia-Network/mpir_gc_x64.git --depth 1
16+
```
17+
1218
Build `clvm_rs` directly into the current virtualenv with
1319

1420
```

build.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
fn main() {
2+
#[cfg(target_os = "windows")]
3+
{
4+
println!("cargo:rustc-link-lib=mpir");
5+
println!("cargo:rustc-link-search=mpir_gc_x64");
6+
}
7+
#[cfg(target_os = "linux")]
8+
{
9+
println!("cargo:rustc-link-lib=gmp");
10+
println!("cargo:rustc-link-search=/usr/lib64");
11+
println!("cargo:rustc-link-search=/usr/lib");
12+
}
13+
#[cfg(target_os = "macos")]
14+
{
15+
println!("cargo:rustc-link-lib=gmp");
16+
println!("cargo:rustc-link-search=/opt/homebrew/lib");
17+
}
18+
}

src/gen/conditions.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,6 @@ use crate::serialize::node_to_bytes;
555555
#[cfg(test)]
556556
use hex::FromHex;
557557
#[cfg(test)]
558-
use num_traits::Num;
559-
#[cfg(test)]
560558
use std::collections::HashMap;
561559

562560
#[cfg(test)]
@@ -689,7 +687,7 @@ fn parse_list_impl(
689687
(a.new_atom(&buf).unwrap(), v.len() + 1)
690688
} else if input.starts_with("-") || "0123456789".contains(input.get(0..1).unwrap()) {
691689
let v = input.split_once(" ").unwrap().0;
692-
let num = Number::from_str_radix(v, 10).unwrap();
690+
let num = Number::from_str_radix(v, 10);
693691
(ptr_from_number(a, &num).unwrap(), v.len() + 1)
694692
} else {
695693
panic!("atom not supported \"{}\"", input);

0 commit comments

Comments
 (0)