feat: upload to server

This commit is contained in:
Ya-wen, Jeng 2025-02-05 19:00:49 +08:00
parent e2a33dc2bd
commit d01f81e550
6 changed files with 86 additions and 13 deletions

View File

@ -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

View File

@ -15,4 +15,4 @@ num-bigint = "0.4.6"
num-traits = "0.2.19"
[build-dependencies]
cc = "1.0"
cc = "1.0"

View File

@ -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)

View File

@ -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++"

52
crates/download_rapidsnark.sh Executable file
View File

@ -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

View File

@ -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.