diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index e7489b9..9de54ff 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -67,7 +67,7 @@ jobs: - name: Install Android NDK run: cargo install cargo-ndk - name: Build - run: cargo ndk -t ${{ matrix.target }} build + run: cargo ndk -t ${{ matrix.target }} build -vv test-linux: runs-on: ubuntu-latest if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name @@ -79,7 +79,7 @@ jobs: toolchain: "1.81.0" override: true - name: Run tests - run: cargo test + run: cargo test -vv test-macOS: runs-on: macos-latest if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name diff --git a/crates/Cargo.toml b/crates/Cargo.toml index 96da21d..0a8bb3c 100644 --- a/crates/Cargo.toml +++ b/crates/Cargo.toml @@ -15,4 +15,4 @@ num-bigint = "0.4.6" num-traits = "0.2.19" [build-dependencies] -cc = "1.0" \ No newline at end of file +cc = "1.0" diff --git a/crates/README.md b/crates/README.md index d547453..64c9efb 100644 --- a/crates/README.md +++ b/crates/README.md @@ -77,6 +77,10 @@ let valid = rust_rapidsnark::groth16_verify_wrapper( - aarch64-linux-android - x86_64-linux-android +## Uploaded binaries + +- Rapidsnark artifacts are uploaded [here](https://github.com/vivianjeng/rapidsnark/actions/runs/13075683259) + ## Community - Website: [zkmopro.com](https://zkmopro.com) diff --git a/crates/build.rs b/crates/build.rs index 0d2730a..95c7789 100644 --- a/crates/build.rs +++ b/crates/build.rs @@ -2,20 +2,40 @@ use std::env; use std::fs; use std::path::Path; use std::path::PathBuf; +use std::process::Command; + +const RAPIDSNARK_DOWNLOAD_SCRIPT: &str = include_str!("./download_rapidsnark.sh"); fn main() { - let target = std::env::var("TARGET").unwrap(); + let target = env::var("TARGET").unwrap(); + let out_dir = env::var("OUT_DIR").expect("OUT_DIR not set"); let arch = target.split('-').next().unwrap(); // Try to list contents of the target directory - let manifest_dir = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()); - let rapidsnark_dir = manifest_dir.join("rapidsnark"); - let absolute_lib_path = if rapidsnark_dir.join(&target).exists() { - rapidsnark_dir.join(&target) + let rapidsnark_path = Path::new(&out_dir).join(Path::new("rapidsnark")); + // If the rapidsnark repo is not downloaded, download it + if !rapidsnark_path.exists() { + let rapidsnark_script_path = Path::new(&out_dir).join(Path::new("download_rapidsnark.sh")); + fs::write(&rapidsnark_script_path, RAPIDSNARK_DOWNLOAD_SCRIPT) + .expect("Failed to write build script"); + let child_process = Command::new("sh") + .arg(rapidsnark_script_path.to_str().unwrap()) + .spawn(); + if let Err(e) = child_process { + panic!("Failed to spawn rapidsnark download: {}", e); + } + let status = child_process.unwrap().wait(); + if let Err(e) = status { + panic!("Failed to wait for rapidsnark download: {}", e); + } else if !status.unwrap().success() { + panic!("Failed to wait for rapidsnark download"); + } + } + let absolute_lib_path = if rapidsnark_path.join(&target).exists() { + rapidsnark_path.join(&target) } else { - rapidsnark_dir.join(arch) + rapidsnark_path.join(arch) }; - let compiler = cc::Build::new().get_compiler(); let cpp_stdlib = if compiler.is_like_clang() { "c++" diff --git a/crates/download_rapidsnark.sh b/crates/download_rapidsnark.sh new file mode 100755 index 0000000..c492a7b --- /dev/null +++ b/crates/download_rapidsnark.sh @@ -0,0 +1,52 @@ +#!/bin/sh + +# Exit on error +set -e + +# OUT_DIR is specified by the rust build environment +if [ -z $OUT_DIR ]; then + echo "OUT_DIR not specified" + exit 1 +fi +# TARGET is specified by the rust build environment +if [ -z $TARGET ]; then + echo "TARGET not specified" + exit 1 +fi +BUILD_DIR=$OUT_DIR/rapidsnark +mkdir -p $BUILD_DIR + +download_and_unzip() { + local target="$1" + local zip_file="$BUILD_DIR/$target.zip" + + echo "Downloading $target..." + + # Download file with error handling + if ! curl -L -o "$zip_file" "https://rapidsnark.zkmopro.org/$target.zip"; then + echo "Failed to download $target.zip" + return 1 # Return failure status + fi + + echo "Unzipping $zip_file..." + + # Unzip with error handling + if ! unzip "$zip_file" -d "$BUILD_DIR"; then + echo "Failed to unzip $zip_file" + return 1 + fi + + echo "✅ Successfully downloaded and extracted $target.zip" +} + +# Try downloading the full target +if ! download_and_unzip "$TARGET"; then + echo "Retrying with local architecture..." + + local_arch=$(echo "$TARGET" | cut -d'-' -f1) + + if ! download_and_unzip "$local_arch"; then + echo "Download failed for both $TARGET and $local_arch" + exit 1 # Exit the script with failure + fi +fi diff --git a/crates/rapidsnark/README.md b/crates/rapidsnark/README.md deleted file mode 100644 index 2dee0f6..0000000 --- a/crates/rapidsnark/README.md +++ /dev/null @@ -1,3 +0,0 @@ -Built from [here](https://github.com/chancehudson/rapidsnark/tree/rust-ffi). This is built into static libraries and then linked into the rust project. Importantly we need to compile static libraries for each platform we intend to support. - -Linking static libraries instead of compiling from c++ source should make it easier to maintain the `build.rs` script.