From 37ce2ab1b8c77debb71d35df4d10ca36191ff5bd Mon Sep 17 00:00:00 2001 From: Rigidity Date: Wed, 18 Sep 2024 09:52:28 -0400 Subject: [PATCH 01/36] Run tests on multiple platforms --- .github/workflows/rust.yml | 70 ++++++++++++++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 7 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index a10e861c..e7ebaf2f 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -32,16 +32,11 @@ jobs: cd rust_bindings cargo fuzz list | xargs -I "%" sh -c "cargo +nightly fuzz run % -- -max_total_time=600 || exit 255" - build_crate: - name: Build crate + lint: + name: Lint runs-on: ubuntu-latest - strategy: - fail-fast: false - steps: - uses: actions/checkout@v4 - with: - fetch-depth: 0 - name: Set up Rust uses: dtolnay/rust-toolchain@stable @@ -54,9 +49,70 @@ jobs: - name: Clippy run: cargo clippy + test: + name: Test (${{ matrix.os.name }} ${{ matrix.arch.name }}) + runs-on: ${{ matrix.os.runs-on[matrix.arch.matrix] }} + + strategy: + fail-fast: false + matrix: + os: + - name: macOS + matrix: macos + runs-on: + arm: [macos-13-arm64] + intel: [macos-13] + cibw-archs-macos: + arm: arm64 + intel: x86_64 + - name: Ubuntu + matrix: ubuntu + runs-on: + arm: [Linux, ARM64] + intel: [ubuntu-latest] + - name: Windows + matrix: windows + runs-on: + intel: [windows-latest] + + arch: + - name: ARM + matrix: arm + - name: Intel + matrix: intel + + exclude: + - os: + name: Windows + matrix: windows + runs-on: + intel: [windows-latest] + arch: + name: ARM + matrix: arm + + steps: + - uses: actions/checkout@v4 + + - name: Set up Rust + uses: dtolnay/rust-toolchain@stable + - name: Tests run: cargo test && cargo test --release + build_crate: + name: Build crate + needs: [lint, test] + runs-on: ubuntu-latest + strategy: + fail-fast: false + + steps: + - uses: actions/checkout@v4 + + - name: Set up Rust + uses: dtolnay/rust-toolchain@stable + - name: Build run: cargo build --release From 1f5407d1bdad354178ecc83bf943d2b2808907b7 Mon Sep 17 00:00:00 2001 From: Rigidity Date: Wed, 18 Sep 2024 09:55:38 -0400 Subject: [PATCH 02/36] Library path on MacOS --- .github/workflows/rust.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index e7ebaf2f..489c39f4 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -94,6 +94,11 @@ jobs: steps: - uses: actions/checkout@v4 + - name: MacOS GMP library path + if: matrix.os.name == 'macOS' + run: | + export LIBRARY_PATH=/opt/homebrew/lib:$LIBRARY_PATH + - name: Set up Rust uses: dtolnay/rust-toolchain@stable From 3dfdfe12d31e73ed2c15ccf4c2fc66eaf955ddca Mon Sep 17 00:00:00 2001 From: Rigidity Date: Wed, 18 Sep 2024 10:01:57 -0400 Subject: [PATCH 03/36] Fix --- .github/workflows/rust.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 489c39f4..d49ec397 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -96,8 +96,7 @@ jobs: - name: MacOS GMP library path if: matrix.os.name == 'macOS' - run: | - export LIBRARY_PATH=/opt/homebrew/lib:$LIBRARY_PATH + run: echo "LIBRARY_PATH=/opt/homebrew/lib:$LIBRARY_PATH" >> $GITHUB_ENV - name: Set up Rust uses: dtolnay/rust-toolchain@stable From f80d4fa3e26ef6dd76e2a36fd58a0c7d90097f4e Mon Sep 17 00:00:00 2001 From: Rigidity Date: Wed, 18 Sep 2024 10:04:36 -0400 Subject: [PATCH 04/36] Add MPIR support to build script --- rust_bindings/build.rs | 56 +++++++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/rust_bindings/build.rs b/rust_bindings/build.rs index 6e8d5b1c..e996f1d2 100644 --- a/rust_bindings/build.rs +++ b/rust_bindings/build.rs @@ -27,18 +27,52 @@ fn main() { .define("BUILD_PYTHON", "OFF") .build(); - println!( - "cargo:rustc-link-search=native={}", - PathBuf::from_str(dst.display().to_string().as_str()) - .unwrap() - .join("build") - .join("lib") - .join("static") - .to_str() - .unwrap() - ); + if cfg!(target_os = "windows") { + let build_type = if cfg!(debug_assertions) { + "Debug" + } else { + "Release" + }; + + println!( + "cargo:rustc-link-search=native={}", + PathBuf::from_str(dst.display().to_string().as_str()) + .unwrap() + .join("build") + .join("lib") + .join("static") + .join(build_type) + .to_str() + .unwrap() + ); + + println!( + "cargo:rustc-link-search=native={}", + src_dir + .parent() + .unwrap() + .join("mpir_gc_x64") + .to_str() + .unwrap() + ); + + println!("cargo:rustc-link-lib=mpir"); + } else { + println!( + "cargo:rustc-link-search=native={}", + PathBuf::from_str(dst.display().to_string().as_str()) + .unwrap() + .join("build") + .join("lib") + .join("static") + .to_str() + .unwrap() + ); + + println!("cargo:rustc-link-lib=gmp"); + } + println!("cargo:rustc-link-lib=static=chiavdfc"); - println!("cargo:rustc-link-lib=gmp"); let bindings = bindgen::Builder::default() .header(manifest_dir.join("wrapper.h").to_str().unwrap()) From 37b5cbcacd937d173670bf5dcbc6252e843992e1 Mon Sep 17 00:00:00 2001 From: Rigidity Date: Wed, 18 Sep 2024 10:05:02 -0400 Subject: [PATCH 05/36] Include MPIR in the crate --- .github/workflows/rust.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index d49ec397..6fcaadc2 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -121,7 +121,10 @@ jobs: run: cargo build --release - name: Prepare for publish - run: cp -r src rust_bindings/cpp + run: | + cd rust_bindings + cp -r ../src cpp + git clone https://github.com/Chia-Network/mpir_gc_x64.git - name: Publish to crates.io (dry run) # We use `--allow-dirty` because the `cpp` folder is copied into the working directory. From 8a0e464bc7c59da158d10e82b2b9e37d592dc024 Mon Sep 17 00:00:00 2001 From: Rigidity Date: Wed, 18 Sep 2024 10:06:36 -0400 Subject: [PATCH 06/36] CI support for MPIR --- .github/workflows/rust.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 6fcaadc2..e08b0f42 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -94,10 +94,14 @@ jobs: steps: - uses: actions/checkout@v4 - - name: MacOS GMP library path + - name: MacOS - GMP library path if: matrix.os.name == 'macOS' run: echo "LIBRARY_PATH=/opt/homebrew/lib:$LIBRARY_PATH" >> $GITHUB_ENV + - name: Windows - Download MPIR + if: matrix.os.name == 'Windows' + run: git clone https://github.com/Chia-Network/mpir_gc_x64.git + - name: Set up Rust uses: dtolnay/rust-toolchain@stable From eef4055449f2bff605878c6ffdd8cd46b0c80d66 Mon Sep 17 00:00:00 2001 From: Rigidity Date: Wed, 18 Sep 2024 10:14:17 -0400 Subject: [PATCH 07/36] Reorder --- rust_bindings/build.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/rust_bindings/build.rs b/rust_bindings/build.rs index e996f1d2..4c924602 100644 --- a/rust_bindings/build.rs +++ b/rust_bindings/build.rs @@ -1,6 +1,5 @@ use std::env; use std::path::PathBuf; -use std::str::FromStr; use cmake::Config; @@ -27,6 +26,8 @@ fn main() { .define("BUILD_PYTHON", "OFF") .build(); + println!("cargo:rustc-link-lib=static=chiavdfc"); + if cfg!(target_os = "windows") { let build_type = if cfg!(debug_assertions) { "Debug" @@ -36,9 +37,7 @@ fn main() { println!( "cargo:rustc-link-search=native={}", - PathBuf::from_str(dst.display().to_string().as_str()) - .unwrap() - .join("build") + dst.join("build") .join("lib") .join("static") .join(build_type) @@ -60,9 +59,7 @@ fn main() { } else { println!( "cargo:rustc-link-search=native={}", - PathBuf::from_str(dst.display().to_string().as_str()) - .unwrap() - .join("build") + dst.join("build") .join("lib") .join("static") .to_str() @@ -72,8 +69,6 @@ fn main() { println!("cargo:rustc-link-lib=gmp"); } - println!("cargo:rustc-link-lib=static=chiavdfc"); - let bindings = bindgen::Builder::default() .header(manifest_dir.join("wrapper.h").to_str().unwrap()) .clang_arg("-x") From 4de90bbe289bcbfe79b13317491ebba04cb8806a Mon Sep 17 00:00:00 2001 From: Rigidity Date: Wed, 18 Sep 2024 10:18:59 -0400 Subject: [PATCH 08/36] Attempt to add static --- rust_bindings/build.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rust_bindings/build.rs b/rust_bindings/build.rs index 4c924602..e757e444 100644 --- a/rust_bindings/build.rs +++ b/rust_bindings/build.rs @@ -55,7 +55,7 @@ fn main() { .unwrap() ); - println!("cargo:rustc-link-lib=mpir"); + println!("cargo:rustc-link-lib=static=mpir"); } else { println!( "cargo:rustc-link-search=native={}", @@ -66,7 +66,7 @@ fn main() { .unwrap() ); - println!("cargo:rustc-link-lib=gmp"); + println!("cargo:rustc-link-lib=static=gmp"); } let bindings = bindgen::Builder::default() From e3f2d56841c35368905d77f9f35e653432eca9af Mon Sep 17 00:00:00 2001 From: Rigidity Date: Wed, 18 Sep 2024 10:31:35 -0400 Subject: [PATCH 09/36] Remove build script MPIR linkage --- rust_bindings/build.rs | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/rust_bindings/build.rs b/rust_bindings/build.rs index e757e444..d07e612c 100644 --- a/rust_bindings/build.rs +++ b/rust_bindings/build.rs @@ -44,18 +44,6 @@ fn main() { .to_str() .unwrap() ); - - println!( - "cargo:rustc-link-search=native={}", - src_dir - .parent() - .unwrap() - .join("mpir_gc_x64") - .to_str() - .unwrap() - ); - - println!("cargo:rustc-link-lib=static=mpir"); } else { println!( "cargo:rustc-link-search=native={}", @@ -66,7 +54,7 @@ fn main() { .unwrap() ); - println!("cargo:rustc-link-lib=static=gmp"); + println!("cargo:rustc-link-lib=gmp"); } let bindings = bindgen::Builder::default() From 2afad11a0772566fcd2633a9c72656d353bfbce0 Mon Sep 17 00:00:00 2001 From: Rigidity Date: Wed, 18 Sep 2024 10:36:13 -0400 Subject: [PATCH 10/36] Statically link mpir? --- rust_bindings/build.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/rust_bindings/build.rs b/rust_bindings/build.rs index d07e612c..4c4643b4 100644 --- a/rust_bindings/build.rs +++ b/rust_bindings/build.rs @@ -44,6 +44,18 @@ fn main() { .to_str() .unwrap() ); + + println!( + "cargo:rustc-link-search=native={}", + src_dir + .parent() + .unwrap() + .join("mpir_gc_x64") + .to_str() + .unwrap() + ); + + println!("cargo:rustc-link-lib=static=mpir"); } else { println!( "cargo:rustc-link-search=native={}", From 56e2f89d10f06645c3e6030c6e7b82504b2bbf17 Mon Sep 17 00:00:00 2001 From: Starttoaster Date: Sat, 21 Sep 2024 12:58:39 -0700 Subject: [PATCH 11/36] Use Glue Action for requests (#203) * Use Glue Action for requests * Change hw-build workflow to use glue trigger --- .github/workflows/build-c-libraries.yml | 8 ++++++-- .github/workflows/hw-build.yml | 9 ++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build-c-libraries.yml b/.github/workflows/build-c-libraries.yml index d0767b34..015ed253 100644 --- a/.github/workflows/build-c-libraries.yml +++ b/.github/workflows/build-c-libraries.yml @@ -139,5 +139,9 @@ jobs: - name: Notify new build if: env.RELEASE == 'true' - run: | - curl -s -XPOST -H "Authorization: Bearer ${{ env.JWT_TOKEN }}" --data '{"release_version":"${{ env.RELEASE_TAG }}"}' ${{ secrets.GLUE_API_URL }}/api/v1/chiavdfc/trigger + uses: Chia-Network/actions/github/glue@main + with: + json_data: '{"release_version":"${{ env.RELEASE_TAG }}"}' + glue_url: ${{ secrets.GLUE_API_URL }} + glue_project: "chiavdfc" + glue_path: "trigger" diff --git a/.github/workflows/hw-build.yml b/.github/workflows/hw-build.yml index d3799afb..59588bab 100644 --- a/.github/workflows/hw-build.yml +++ b/.github/workflows/hw-build.yml @@ -108,6 +108,9 @@ jobs: - name: Trigger repo update if: env.RELEASE == 'true' - run: | - curl -s -XPOST -H "Authorization: Bearer ${{ env.JWT_TOKEN }}" --data '{"release_version":"${{ env.RELEASE_TAG }}"}' ${{ secrets.GLUE_API_URL }}/api/v1/chiavdf-hw/${{ env.RELEASE_TAG }}/start - curl -s -XPOST -H "Authorization: Bearer ${{ env.JWT_TOKEN }}" --data '{"release_version":"${{ env.RELEASE_TAG }}"}' ${{ secrets.GLUE_API_URL }}/api/v1/chiavdf-hw/${{ env.RELEASE_TAG }}/success/release_hw + uses: Chia-Network/actions/github/glue@main + with: + json_data: '{"release_version":"${{ env.RELEASE_TAG }}"}' + glue_url: ${{ secrets.GLUE_API_URL }} + glue_project: "chiavdf-hw" + glue_path: "trigger" From ed9461b52cd3ef3547cb2ad514c44d562b4b057a Mon Sep 17 00:00:00 2001 From: Rigidity Date: Sun, 22 Sep 2024 13:59:30 -0400 Subject: [PATCH 12/36] vcpkg? --- .github/workflows/rust.yml | 6 +++--- rust_bindings/build.rs | 10 ---------- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index e08b0f42..9237a5c0 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -94,13 +94,13 @@ jobs: steps: - uses: actions/checkout@v4 - - name: MacOS - GMP library path + - name: GMP library path on MacOS if: matrix.os.name == 'macOS' run: echo "LIBRARY_PATH=/opt/homebrew/lib:$LIBRARY_PATH" >> $GITHUB_ENV - - name: Windows - Download MPIR + - name: Install MPIR on Windows if: matrix.os.name == 'Windows' - run: git clone https://github.com/Chia-Network/mpir_gc_x64.git + run: vcpkg install mpir - name: Set up Rust uses: dtolnay/rust-toolchain@stable diff --git a/rust_bindings/build.rs b/rust_bindings/build.rs index 4c4643b4..d23e51d7 100644 --- a/rust_bindings/build.rs +++ b/rust_bindings/build.rs @@ -45,16 +45,6 @@ fn main() { .unwrap() ); - println!( - "cargo:rustc-link-search=native={}", - src_dir - .parent() - .unwrap() - .join("mpir_gc_x64") - .to_str() - .unwrap() - ); - println!("cargo:rustc-link-lib=static=mpir"); } else { println!( From 4e50a36680340c84404b58b6e8b774c9ad3e6d40 Mon Sep 17 00:00:00 2001 From: Rigidity Date: Sun, 22 Sep 2024 14:06:34 -0400 Subject: [PATCH 13/36] vcpkg and mpir fix --- .github/workflows/rust.yml | 3 +-- Cargo.lock | 7 +++++++ rust_bindings/Cargo.toml | 1 + rust_bindings/build.rs | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 9237a5c0..4caeba69 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -100,7 +100,7 @@ jobs: - name: Install MPIR on Windows if: matrix.os.name == 'Windows' - run: vcpkg install mpir + run: vcpkg install mpir:x64-windows-static - name: Set up Rust uses: dtolnay/rust-toolchain@stable @@ -128,7 +128,6 @@ jobs: run: | cd rust_bindings cp -r ../src cpp - git clone https://github.com/Chia-Network/mpir_gc_x64.git - name: Publish to crates.io (dry run) # We use `--allow-dirty` because the `cpp` folder is copied into the working directory. diff --git a/Cargo.lock b/Cargo.lock index 259f7936..42f5945f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -81,6 +81,7 @@ dependencies = [ "hex", "hex-literal", "link-cplusplus", + "vcpkg", ] [[package]] @@ -359,6 +360,12 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + [[package]] name = "which" version = "4.4.2" diff --git a/rust_bindings/Cargo.toml b/rust_bindings/Cargo.toml index 88adc02e..280b0080 100644 --- a/rust_bindings/Cargo.toml +++ b/rust_bindings/Cargo.toml @@ -14,6 +14,7 @@ link-cplusplus = "1.0.9" [build-dependencies] bindgen = "0.69.4" cmake = "0.1.50" +vcpkg = "0.2.15" [dev-dependencies] hex = "0.4.3" diff --git a/rust_bindings/build.rs b/rust_bindings/build.rs index d23e51d7..2ef14dc8 100644 --- a/rust_bindings/build.rs +++ b/rust_bindings/build.rs @@ -45,7 +45,7 @@ fn main() { .unwrap() ); - println!("cargo:rustc-link-lib=static=mpir"); + vcpkg::find_package("mpir").unwrap(); } else { println!( "cargo:rustc-link-search=native={}", From 496189d225474168571994bf83893da2a70a330c Mon Sep 17 00:00:00 2001 From: Rigidity Date: Sun, 22 Sep 2024 14:19:31 -0400 Subject: [PATCH 14/36] Skip MPIR link --- rust_bindings/build.rs | 1 + src/CMakeLists.txt | 3 +++ 2 files changed, 4 insertions(+) diff --git a/rust_bindings/build.rs b/rust_bindings/build.rs index 2ef14dc8..2ec58723 100644 --- a/rust_bindings/build.rs +++ b/rust_bindings/build.rs @@ -24,6 +24,7 @@ fn main() { .define("BUILD_CHIAVDFC", "ON") .env("BUILD_VDF_CLIENT", "N") .define("BUILD_PYTHON", "OFF") + .define("SKIP_MPIR_LINK", "ON") .build(); println!("cargo:rustc-link-lib=static=chiavdfc"); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9e7b94e0..651e17cf 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.14 FATAL_ERROR) option(BUILD_CHIAVDFC "Build the chiavdfc shared library" OFF) option(BUILD_PYTHON "Build the python bindings for chiavdf" ON) +option(SKIP_MPIR_LINK "Skip linking MPIR" OFF) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -33,6 +34,8 @@ if(WIN32) if(MPIR_LIBRARY) message(STATUS "MPIR library found at ${MPIR_LIBRARY}") link_libraries(${MPIR_LIBRARY}) + elseif(SKIP_MPIR_LINK) + message(STATUS "MPIR library not found, skipping linking") else() message(FATAL_ERROR "MPIR library not found") endif() From 0f654d7d18ad5cd8d4998dce48af0a666cf29e2f Mon Sep 17 00:00:00 2001 From: Rigidity Date: Sun, 22 Sep 2024 14:26:49 -0400 Subject: [PATCH 15/36] Test thing --- .github/workflows/rust.yml | 4 +++- src/CMakeLists.txt | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 4caeba69..3f267b64 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -100,7 +100,9 @@ jobs: - name: Install MPIR on Windows if: matrix.os.name == 'Windows' - run: vcpkg install mpir:x64-windows-static + run: | + vcpkg install mpir:x64-windows-static + git clone https://github.com/Chia-Network/mpir_gc_x64.git - name: Set up Rust uses: dtolnay/rust-toolchain@stable diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 651e17cf..22cb6624 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -31,11 +31,11 @@ if(WIN32) ${MPIR_INCLUDE_DIR} ) find_library(MPIR_LIBRARY NAMES mpir PATHS ${MPIR_LIBRARY_DIR} NO_DEFAULT_PATH) - if(MPIR_LIBRARY) + if(SKIP_MPIR_LINK) + message(STATUS "MPIR library found, skipping linking") + elseif(MPIR_LIBRARY) message(STATUS "MPIR library found at ${MPIR_LIBRARY}") link_libraries(${MPIR_LIBRARY}) - elseif(SKIP_MPIR_LINK) - message(STATUS "MPIR library not found, skipping linking") else() message(FATAL_ERROR "MPIR library not found") endif() From 0db14ee02ae4b72ad0b18997a8060f88dbf52378 Mon Sep 17 00:00:00 2001 From: Rigidity Date: Sun, 22 Sep 2024 14:32:25 -0400 Subject: [PATCH 16/36] vcpkg integrate install --- .github/workflows/rust.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 3f267b64..cdb90798 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -102,6 +102,7 @@ jobs: if: matrix.os.name == 'Windows' run: | vcpkg install mpir:x64-windows-static + vcpkg integrate install git clone https://github.com/Chia-Network/mpir_gc_x64.git - name: Set up Rust From f05ec00a7230ecc1d8b424c53b31e620cd58ad52 Mon Sep 17 00:00:00 2001 From: Rigidity Date: Sun, 22 Sep 2024 14:39:17 -0400 Subject: [PATCH 17/36] md --- .github/workflows/rust.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index cdb90798..888e54c5 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -101,7 +101,7 @@ jobs: - name: Install MPIR on Windows if: matrix.os.name == 'Windows' run: | - vcpkg install mpir:x64-windows-static + vcpkg install mpir:x64-windows-static-md vcpkg integrate install git clone https://github.com/Chia-Network/mpir_gc_x64.git From ebc202fde2aa9f0f5cf256a813982b34e160d58d Mon Sep 17 00:00:00 2001 From: Rigidity Date: Sun, 22 Sep 2024 22:48:30 -0400 Subject: [PATCH 18/36] Add mpir to crate --- .github/workflows/rust.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 888e54c5..6fc872a7 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -131,6 +131,7 @@ jobs: run: | cd rust_bindings cp -r ../src cpp + git clone https://github.com/Chia-Network/mpir_gc_x64.git - name: Publish to crates.io (dry run) # We use `--allow-dirty` because the `cpp` folder is copied into the working directory. From 22c7dfbac3f359bf6345679095a5109e821735bc Mon Sep 17 00:00:00 2001 From: Rigidity Date: Wed, 25 Sep 2024 13:26:15 -0400 Subject: [PATCH 19/36] Shot in the dark --- .github/workflows/rust.yml | 2 +- rust_bindings/build.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 6fc872a7..e4ed6e7e 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -101,7 +101,7 @@ jobs: - name: Install MPIR on Windows if: matrix.os.name == 'Windows' run: | - vcpkg install mpir:x64-windows-static-md + vcpkg install gmp:x64-windows-static-md vcpkg integrate install git clone https://github.com/Chia-Network/mpir_gc_x64.git diff --git a/rust_bindings/build.rs b/rust_bindings/build.rs index 2ec58723..0da92aa6 100644 --- a/rust_bindings/build.rs +++ b/rust_bindings/build.rs @@ -46,7 +46,7 @@ fn main() { .unwrap() ); - vcpkg::find_package("mpir").unwrap(); + vcpkg::find_package("gmp").unwrap(); } else { println!( "cargo:rustc-link-search=native={}", From e4638e6515399a12e3ce19542c5799cf09e369be Mon Sep 17 00:00:00 2001 From: Rigidity Date: Sun, 29 Sep 2024 22:26:41 -0400 Subject: [PATCH 20/36] Dynamic linking --- .github/workflows/rust.yml | 5 +---- Cargo.lock | 7 ------- rust_bindings/Cargo.toml | 1 - rust_bindings/build.rs | 2 -- src/CMakeLists.txt | 5 +---- 5 files changed, 2 insertions(+), 18 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index e4ed6e7e..695c453d 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -100,10 +100,7 @@ jobs: - name: Install MPIR on Windows if: matrix.os.name == 'Windows' - run: | - vcpkg install gmp:x64-windows-static-md - vcpkg integrate install - git clone https://github.com/Chia-Network/mpir_gc_x64.git + run: git clone https://github.com/Chia-Network/mpir_gc_x64.git - name: Set up Rust uses: dtolnay/rust-toolchain@stable diff --git a/Cargo.lock b/Cargo.lock index 42f5945f..259f7936 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -81,7 +81,6 @@ dependencies = [ "hex", "hex-literal", "link-cplusplus", - "vcpkg", ] [[package]] @@ -360,12 +359,6 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "which" version = "4.4.2" diff --git a/rust_bindings/Cargo.toml b/rust_bindings/Cargo.toml index 280b0080..88adc02e 100644 --- a/rust_bindings/Cargo.toml +++ b/rust_bindings/Cargo.toml @@ -14,7 +14,6 @@ link-cplusplus = "1.0.9" [build-dependencies] bindgen = "0.69.4" cmake = "0.1.50" -vcpkg = "0.2.15" [dev-dependencies] hex = "0.4.3" diff --git a/rust_bindings/build.rs b/rust_bindings/build.rs index 0da92aa6..79ddb2e3 100644 --- a/rust_bindings/build.rs +++ b/rust_bindings/build.rs @@ -45,8 +45,6 @@ fn main() { .to_str() .unwrap() ); - - vcpkg::find_package("gmp").unwrap(); } else { println!( "cargo:rustc-link-search=native={}", diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 22cb6624..9e7b94e0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,7 +1,6 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.14 FATAL_ERROR) option(BUILD_CHIAVDFC "Build the chiavdfc shared library" OFF) option(BUILD_PYTHON "Build the python bindings for chiavdf" ON) -option(SKIP_MPIR_LINK "Skip linking MPIR" OFF) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -31,9 +30,7 @@ if(WIN32) ${MPIR_INCLUDE_DIR} ) find_library(MPIR_LIBRARY NAMES mpir PATHS ${MPIR_LIBRARY_DIR} NO_DEFAULT_PATH) - if(SKIP_MPIR_LINK) - message(STATUS "MPIR library found, skipping linking") - elseif(MPIR_LIBRARY) + if(MPIR_LIBRARY) message(STATUS "MPIR library found at ${MPIR_LIBRARY}") link_libraries(${MPIR_LIBRARY}) else() From 07d7ff87847e81c8ed2a5ee2378377e883a8a215 Mon Sep 17 00:00:00 2001 From: Rigidity Date: Sun, 29 Sep 2024 22:29:59 -0400 Subject: [PATCH 21/36] libclang-dev --- .github/workflows/rust.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 695c453d..bf0aa59e 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -94,7 +94,7 @@ jobs: steps: - uses: actions/checkout@v4 - - name: GMP library path on MacOS + - name: Setup library path on MacOS if: matrix.os.name == 'macOS' run: echo "LIBRARY_PATH=/opt/homebrew/lib:$LIBRARY_PATH" >> $GITHUB_ENV @@ -102,6 +102,10 @@ jobs: if: matrix.os.name == 'Windows' run: git clone https://github.com/Chia-Network/mpir_gc_x64.git + - name: Install libclang-dev on Linux + if: matrix.os.name == 'Ubuntu' + run: sudo apt-get install libclang-dev + - name: Set up Rust uses: dtolnay/rust-toolchain@stable From 4d917a8e22a257a8187729e3756cfb3ddfc6760b Mon Sep 17 00:00:00 2001 From: Rigidity Date: Sun, 29 Sep 2024 22:34:17 -0400 Subject: [PATCH 22/36] Add link path --- .github/workflows/rust.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index bf0aa59e..c4c0f43f 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -100,7 +100,9 @@ jobs: - name: Install MPIR on Windows if: matrix.os.name == 'Windows' - run: git clone https://github.com/Chia-Network/mpir_gc_x64.git + run: | + git clone https://github.com/Chia-Network/mpir_gc_x64.git + echo "RUSTFLAGS='-C link-args=-Wl,-rpath,${{ github.workspace }}/mpir_gc_x64'" | Out-File -FilePath $env:GITHUB_ENV -Append - name: Install libclang-dev on Linux if: matrix.os.name == 'Ubuntu' From 90466ef0a28477d6689a46ee674b377a521c89fb Mon Sep 17 00:00:00 2001 From: Rigidity Date: Sun, 29 Sep 2024 22:40:24 -0400 Subject: [PATCH 23/36] GITHUB_PATH --- .github/workflows/rust.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index c4c0f43f..7737c395 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -102,11 +102,11 @@ jobs: if: matrix.os.name == 'Windows' run: | git clone https://github.com/Chia-Network/mpir_gc_x64.git - echo "RUSTFLAGS='-C link-args=-Wl,-rpath,${{ github.workspace }}/mpir_gc_x64'" | Out-File -FilePath $env:GITHUB_ENV -Append + echo "$(Get-Location)\mpir_gc_x64" >> $GITHUB_PATH - name: Install libclang-dev on Linux if: matrix.os.name == 'Ubuntu' - run: sudo apt-get install libclang-dev + run: sudo apt-get install libclang-dev -y - name: Set up Rust uses: dtolnay/rust-toolchain@stable From 0f6e14623b13ffab40b4f9c16305fcaef041f15f Mon Sep 17 00:00:00 2001 From: Rigidity Date: Sun, 29 Sep 2024 22:48:27 -0400 Subject: [PATCH 24/36] Link mpir? --- rust_bindings/build.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/rust_bindings/build.rs b/rust_bindings/build.rs index 79ddb2e3..58c531e2 100644 --- a/rust_bindings/build.rs +++ b/rust_bindings/build.rs @@ -45,6 +45,17 @@ fn main() { .to_str() .unwrap() ); + + println!("cargo:rustc-link-lib=static=mpir"); + println!( + "cargo:rustc-link-search=native={}", + src_dir + .parent() + .unwrap() + .join("mpir_gc_x64") + .to_str() + .unwrap() + ); } else { println!( "cargo:rustc-link-search=native={}", From 06f8da9ddd955014c7f03a4d9f480060f273a005 Mon Sep 17 00:00:00 2001 From: Rigidity Date: Sun, 29 Sep 2024 22:56:12 -0400 Subject: [PATCH 25/36] Add check --- .github/workflows/rust.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 7737c395..2865d1e0 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -152,6 +152,16 @@ jobs: env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Check if MPIR DLL is on the PATH + run: | + $pathList = $Env:PATH -split ";" + foreach ($path in $pathList) { + if (Test-Path "$path\mpir.dll") { + Write-Output "Found mpir.dll in $path" + } + } + shell: powershell + - name: Publish to crates.io if: env.RELEASE == 'true' env: From 407ccc223f9bb6ce2a68ceecba8cf24905f368b6 Mon Sep 17 00:00:00 2001 From: Rigidity Date: Sun, 29 Sep 2024 23:25:45 -0400 Subject: [PATCH 26/36] fix --- .github/workflows/rust.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 2865d1e0..0f4c0abd 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -104,6 +104,16 @@ jobs: git clone https://github.com/Chia-Network/mpir_gc_x64.git echo "$(Get-Location)\mpir_gc_x64" >> $GITHUB_PATH + - name: Check if MPIR DLL is on the PATH + if: matrix.os.name == 'Windows' + run: | + $pathList = $Env:PATH -split ";" + foreach ($path in $pathList) { + if (Test-Path "$path\mpir.dll") { + Write-Output "Found mpir.dll in $path" + } + } + - name: Install libclang-dev on Linux if: matrix.os.name == 'Ubuntu' run: sudo apt-get install libclang-dev -y @@ -152,16 +162,6 @@ jobs: env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Check if MPIR DLL is on the PATH - run: | - $pathList = $Env:PATH -split ";" - foreach ($path in $pathList) { - if (Test-Path "$path\mpir.dll") { - Write-Output "Found mpir.dll in $path" - } - } - shell: powershell - - name: Publish to crates.io if: env.RELEASE == 'true' env: From 13954667285a01cfdada683a107d77ed59a76767 Mon Sep 17 00:00:00 2001 From: Rigidity Date: Mon, 30 Sep 2024 09:10:44 -0400 Subject: [PATCH 27/36] Debug --- .github/workflows/rust.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 0f4c0abd..897f4224 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -102,7 +102,16 @@ jobs: if: matrix.os.name == 'Windows' run: | git clone https://github.com/Chia-Network/mpir_gc_x64.git + echo 0 echo "$(Get-Location)\mpir_gc_x64" >> $GITHUB_PATH + echo X + echo $GITHUB_PATH + echo Y + echo $Env:PATH + echo Z + echo $Env:GITHUB_PATH + echo A + echo $Env:GITHUB_ENV - name: Check if MPIR DLL is on the PATH if: matrix.os.name == 'Windows' From b28ef6cd134e566e5425ccc92b6a78ba0caab378 Mon Sep 17 00:00:00 2001 From: Rigidity Date: Mon, 30 Sep 2024 09:15:32 -0400 Subject: [PATCH 28/36] Test --- .github/workflows/rust.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 897f4224..b26203fb 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -103,7 +103,7 @@ jobs: run: | git clone https://github.com/Chia-Network/mpir_gc_x64.git echo 0 - echo "$(Get-Location)\mpir_gc_x64" >> $GITHUB_PATH + "$((Get-Location)\mpir_gc_x64)" | Out-File -Append -FilePath $env:GITHUB_PATH echo X echo $GITHUB_PATH echo Y From f6ec69e185fc156b1d3686099491ba2f319f7f6e Mon Sep 17 00:00:00 2001 From: Rigidity Date: Mon, 30 Sep 2024 09:22:56 -0400 Subject: [PATCH 29/36] 2 --- .github/workflows/rust.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index b26203fb..851a4ba9 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -103,7 +103,7 @@ jobs: run: | git clone https://github.com/Chia-Network/mpir_gc_x64.git echo 0 - "$((Get-Location)\mpir_gc_x64)" | Out-File -Append -FilePath $env:GITHUB_PATH + "$(Get-Location)/mpir_gc_x64" | Out-File -Append -FilePath $env:GITHUB_PATH echo X echo $GITHUB_PATH echo Y From 843565a309ff821aed7dad89cbc83e7aa3cea2e6 Mon Sep 17 00:00:00 2001 From: Rigidity Date: Mon, 30 Sep 2024 09:27:02 -0400 Subject: [PATCH 30/36] Cleanup cruft --- .github/workflows/rust.yml | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 851a4ba9..51bfe149 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -102,26 +102,7 @@ jobs: if: matrix.os.name == 'Windows' run: | git clone https://github.com/Chia-Network/mpir_gc_x64.git - echo 0 "$(Get-Location)/mpir_gc_x64" | Out-File -Append -FilePath $env:GITHUB_PATH - echo X - echo $GITHUB_PATH - echo Y - echo $Env:PATH - echo Z - echo $Env:GITHUB_PATH - echo A - echo $Env:GITHUB_ENV - - - name: Check if MPIR DLL is on the PATH - if: matrix.os.name == 'Windows' - run: | - $pathList = $Env:PATH -split ";" - foreach ($path in $pathList) { - if (Test-Path "$path\mpir.dll") { - Write-Output "Found mpir.dll in $path" - } - } - name: Install libclang-dev on Linux if: matrix.os.name == 'Ubuntu' From bb6a35afb1aed533d52f3715d091a1fb1d5e0784 Mon Sep 17 00:00:00 2001 From: Rigidity Date: Mon, 30 Sep 2024 09:27:31 -0400 Subject: [PATCH 31/36] Remove old flag --- rust_bindings/build.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/rust_bindings/build.rs b/rust_bindings/build.rs index 58c531e2..5e5ba211 100644 --- a/rust_bindings/build.rs +++ b/rust_bindings/build.rs @@ -24,7 +24,6 @@ fn main() { .define("BUILD_CHIAVDFC", "ON") .env("BUILD_VDF_CLIENT", "N") .define("BUILD_PYTHON", "OFF") - .define("SKIP_MPIR_LINK", "ON") .build(); println!("cargo:rustc-link-lib=static=chiavdfc"); From 93166a0112d157cf9704e71e02fb38fa839a32b6 Mon Sep 17 00:00:00 2001 From: Rigidity Date: Mon, 30 Sep 2024 09:28:57 -0400 Subject: [PATCH 32/36] Add concurrency --- .github/workflows/rust.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 51bfe149..603a805a 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -10,6 +10,10 @@ on: branches: - "**" +concurrency: + group: ${{ github.event_name == 'pull_request' && format('{0}-{1}', github.workflow_ref, github.event.pull_request.number) || github.run_id }} + cancel-in-progress: true + permissions: id-token: write contents: read From d9c035245c640a0682def464ed6cc643a342a9a2 Mon Sep 17 00:00:00 2001 From: Rigidity Date: Mon, 30 Sep 2024 10:43:38 -0400 Subject: [PATCH 33/36] Bump Rust crate to 1.1.6 --- Cargo.lock | 2 +- rust_bindings/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 259f7936..fba1d24a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -74,7 +74,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chiavdf" -version = "1.1.5" +version = "1.1.6" dependencies = [ "bindgen", "cmake", diff --git a/rust_bindings/Cargo.toml b/rust_bindings/Cargo.toml index 88adc02e..48edaafe 100644 --- a/rust_bindings/Cargo.toml +++ b/rust_bindings/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "chiavdf" -version = "1.1.5" +version = "1.1.6" edition = "2021" license = "Apache-2.0" description = "Bindings to the chiavdf C++ library." From bde9725ea512d503d7ea3e6b47731dcbadc1b615 Mon Sep 17 00:00:00 2001 From: Rigidity Date: Wed, 2 Oct 2024 11:15:27 -0400 Subject: [PATCH 34/36] Bump to 1.1.8 --- Cargo.lock | 2 +- rust_bindings/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fba1d24a..445d06f1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -74,7 +74,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chiavdf" -version = "1.1.6" +version = "1.1.8" dependencies = [ "bindgen", "cmake", diff --git a/rust_bindings/Cargo.toml b/rust_bindings/Cargo.toml index 48edaafe..17a84bcf 100644 --- a/rust_bindings/Cargo.toml +++ b/rust_bindings/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "chiavdf" -version = "1.1.6" +version = "1.1.8" edition = "2021" license = "Apache-2.0" description = "Bindings to the chiavdf C++ library." From c89d0803130e2f5a1c64d23805d1cb2deaea094f Mon Sep 17 00:00:00 2001 From: wjblanke Date: Tue, 8 Oct 2024 11:26:23 -0700 Subject: [PATCH 35/36] xearl4's ApproximateParameter fix and GIL related parameter copies (#215) * duplicating xearl4 pr to test ci more * copy * more copies to appease the gil --- src/callback.h | 2 +- src/provers.h | 2 +- src/python_bindings/fastvdf.cpp | 45 ++++++++++++++++++++------------- 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/callback.h b/src/callback.h index a6a0b14f..92207d1b 100644 --- a/src/callback.h +++ b/src/callback.h @@ -76,7 +76,7 @@ class OneWesolowskiCallback: public WesolowskiCallback { uint32_t k, l; this->wanted_iter = wanted_iter; if (wanted_iter >= (1 << 16)) { - ApproximateParameters(wanted_iter, k, l); + ApproximateParameters(wanted_iter, l, k); } else { k = 10; l = 1; diff --git a/src/provers.h b/src/provers.h index c10a7ca4..11209345 100644 --- a/src/provers.h +++ b/src/provers.h @@ -11,7 +11,7 @@ class OneWesolowskiProver : public Prover { { this->intermediates = intermediates; if (num_iterations >= (1 << 16)) { - ApproximateParameters(num_iterations, k, l); + ApproximateParameters(num_iterations, l, k); } else { k = 10; l = 1; diff --git a/src/python_bindings/fastvdf.cpp b/src/python_bindings/fastvdf.cpp index a52c36ca..50404e29 100644 --- a/src/python_bindings/fastvdf.cpp +++ b/src/python_bindings/fastvdf.cpp @@ -25,11 +25,14 @@ PYBIND11_MODULE(chiavdf, m) { const string& x_s, const string& y_s, const string& proof_s, uint64_t num_iterations) { - py::gil_scoped_release release; integer D(discriminant); - form x = DeserializeForm(D, (const uint8_t *)x_s.data(), x_s.size()); - form y = DeserializeForm(D, (const uint8_t *)y_s.data(), y_s.size()); - form proof = DeserializeForm(D, (const uint8_t *)proof_s.data(), proof_s.size()); + std::string x_s_copy(x_s); + std::string y_s_copy(y_s); + std::string proof_s_copy(proof_s); + py::gil_scoped_release release; + form x = DeserializeForm(D, (const uint8_t *)x_s_copy.data(), x_s_copy.size()); + form y = DeserializeForm(D, (const uint8_t *)y_s_copy.data(), y_s_copy.size()); + form proof = DeserializeForm(D, (const uint8_t *)proof_s_copy.data(), proof_s_copy.size()); bool is_valid = false; VerifyWesolowskiProof(D, x, y, proof, num_iterations, is_valid); @@ -41,16 +44,19 @@ PYBIND11_MODULE(chiavdf, m) { const string& x_s, const string& proof_blob, const uint64_t num_iterations, const uint64_t disc_size_bits, const uint64_t recursion) { + std::string discriminant_copy(discriminant); + std::string x_s_copy(x_s); + std::string proof_blob_copy(proof_blob); py::gil_scoped_release release; - std::string proof_blob_str(proof_blob); - uint8_t *proof_blob_ptr = reinterpret_cast(proof_blob_str.data()); - int proof_blob_size = proof_blob.size(); + uint8_t *proof_blob_ptr = reinterpret_cast(proof_blob_copy.data()); + int proof_blob_size = proof_blob_copy.size(); - return CheckProofOfTimeNWesolowski(integer(discriminant), (const uint8_t *)x_s.data(), proof_blob_ptr, proof_blob_size, num_iterations, disc_size_bits, recursion); + return CheckProofOfTimeNWesolowski(integer(discriminant_copy), (const uint8_t *)x_s_copy.data(), proof_blob_ptr, proof_blob_size, num_iterations, disc_size_bits, recursion); }); m.def("prove", [] (const py::bytes& challenge_hash, const string& x_s, int discriminant_size_bits, uint64_t num_iterations) { std::string challenge_hash_str(challenge_hash); + std::string x_s_copy(x_s); std::vector result; { py::gil_scoped_release release; @@ -59,7 +65,7 @@ PYBIND11_MODULE(chiavdf, m) { challenge_hash_bytes, discriminant_size_bits ); - form x = DeserializeForm(D, (const uint8_t *) x_s.data(), x_s.size()); + form x = DeserializeForm(D, (const uint8_t *) x_s_copy.data(), x_s_copy.size()); result = ProveSlow(D, x, num_iterations); } py::bytes ret = py::bytes(reinterpret_cast(result.data()), result.size()); @@ -74,11 +80,14 @@ PYBIND11_MODULE(chiavdf, m) { const uint64_t num_iterations, const uint64_t recursion) { std::pair> result; { + std::string discriminant_copy(discriminant); + std::string B_copy(B); + std::string x_s_copy(x_s); + std::string proof_blob_copy(proof_blob); py::gil_scoped_release release; - std::string proof_blob_str(proof_blob); - uint8_t *proof_blob_ptr = reinterpret_cast(proof_blob_str.data()); - int proof_blob_size = proof_blob.size(); - result = CheckProofOfTimeNWesolowskiWithB(integer(discriminant), integer(B), (const uint8_t *)x_s.data(), proof_blob_ptr, proof_blob_size, num_iterations, recursion); + uint8_t *proof_blob_ptr = reinterpret_cast(proof_blob_copy.data()); + int proof_blob_size = proof_blob_copy.size(); + result = CheckProofOfTimeNWesolowskiWithB(integer(discriminant_copy), integer(B_copy), (const uint8_t *)x_s_copy.data(), proof_blob_ptr, proof_blob_size, num_iterations, recursion); } py::bytes res_bytes = py::bytes(reinterpret_cast(result.second.data()), result.second.size()); py::tuple res_tuple = py::make_tuple(result.first, res_bytes); @@ -89,11 +98,13 @@ PYBIND11_MODULE(chiavdf, m) { const string& x_s, const string& proof_blob, const uint64_t num_iterations, const uint64_t recursion) { + std::string discriminant_copy(discriminant); + std::string x_s_copy(x_s); + std::string proof_blob_copy(proof_blob); py::gil_scoped_release release; - std::string proof_blob_str(proof_blob); - uint8_t *proof_blob_ptr = reinterpret_cast(proof_blob_str.data()); - int proof_blob_size = proof_blob.size(); - integer B = GetBFromProof(integer(discriminant), (const uint8_t *)x_s.data(), proof_blob_ptr, proof_blob_size, num_iterations, recursion); + uint8_t *proof_blob_ptr = reinterpret_cast(proof_blob_copy.data()); + int proof_blob_size = proof_blob_copy.size(); + integer B = GetBFromProof(integer(discriminant_copy), (const uint8_t *)x_s_copy.data(), proof_blob_ptr, proof_blob_size, num_iterations, recursion); return B.to_string(); }); } From 5349251ae67e8f685aacd843e515bd24521fc112 Mon Sep 17 00:00:00 2001 From: Earle Lowe <30607889+emlowe@users.noreply.github.com> Date: Tue, 8 Oct 2024 11:27:42 -0700 Subject: [PATCH 36/36] Add _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR when building wheel on windows (#208) --- src/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9e7b94e0..2beca13f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -70,6 +70,11 @@ if(BUILD_PYTHON) if(UNIX) target_link_libraries(chiavdf PRIVATE -pthread) endif() + if (WIN32) + # workaround for constexpr mutex constructor change in MSVC 2022 + # https://stackoverflow.com/questions/78598141/first-stdmutexlock-crashes-in-application-built-with-latest-visual-studio + target_compile_definitions(chiavdf PUBLIC _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR) + endif() endif() add_executable(verifier_test