diff --git a/crates/build.rs b/crates/build.rs index 308640c..95c7789 100644 --- a/crates/build.rs +++ b/crates/build.rs @@ -18,12 +18,18 @@ fn main() { 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"); - Command::new("sh") + let child_process = Command::new("sh") .arg(rapidsnark_script_path.to_str().unwrap()) - .spawn() - .expect("Failed to spawn rapidsnark download") - .wait() - .expect("rapidsnark download errored"); + .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) diff --git a/crates/download_rapidsnark.sh b/crates/download_rapidsnark.sh index 3b17f4d..c492a7b 100755 --- a/crates/download_rapidsnark.sh +++ b/crates/download_rapidsnark.sh @@ -19,13 +19,34 @@ mkdir -p $BUILD_DIR download_and_unzip() { local target="$1" local zip_file="$BUILD_DIR/$target.zip" - curl -L -o $zip_file https://rapidsnark.zkmopro.org/$target.zip - unzip $zip_file -d $BUILD_DIR + + 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" } -download_and_unzip $TARGET -# Check if curl was successful -if [ $? -ne 0 ]; then - arch=$(echo "$TARGET" | cut -d'-' -f1) - download_and_unzip $arch +# 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