Skip to content

Commit

Permalink
Merged latest main branch
Browse files Browse the repository at this point in the history
  • Loading branch information
olomix committed Feb 18, 2025
2 parents 96f912f + 315a7d1 commit 52384e5
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 93 deletions.
116 changes: 58 additions & 58 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ on:

jobs:

build-linux:
runs-on: ubuntu-22.04
build-linux-x86_64:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -21,38 +21,15 @@ jobs:
uses: awalsh128/cache-apt-pkgs-action@v1
with:
packages: build-essential cmake m4 nasm
version: 1.0

- name: Setup QEMU to build ARM64 variant
uses: docker/setup-qemu-action@v3

- name: Setup buildx for ARM64 platform
uses: docker/setup-buildx-action@v3
with:
platforms: linux/amd64,linux/arm64

- name: Prepare Docker image builder for ARM64
uses: docker/build-push-action@v6
env:
DOCKER_BUILD_SUMMARY: false
DOCKER_BUILD_RECORD_UPLOAD: false
with:
push: false
outputs: type=docker
platforms: linux/arm64
file: .github/images/Dockerfile.build
context: ./.github/images/context.build
cache-from: type=gha,scope=buildkit-arm64
cache-to: type=gha,mode=max,scope=buildkit-arm64
tags: builder:arm64
version: x86_64-1.0

- name: Cache gmp build
uses: actions/cache@v4
with:
path: |
depends/gmp
depends/gmp-6.2.1.tar.xz
key: ${{ runner.os }}-gmp-${{ hashFiles('build_gmp.sh') }}-4
key: ${{ runner.os }}-${{ runner.arch }}-gmp-${{ hashFiles('build_gmp.sh') }}

- name: Build gmp for Android arm64
run: if [[ ! -d "depends/gmp/package_android_arm64" ]]; then ./build_gmp.sh android; fi
Expand All @@ -63,12 +40,6 @@ jobs:
- name: Build gmp for Linux x86_64
run: if [[ ! -d "depends/gmp/package" ]]; then ./build_gmp.sh host; fi

- name: Build gmp for Linux arm64
run: |
if [[ ! -d "depends/gmp/package_aarch64" ]]; then
docker run --rm --platform=linux/arm64 -i -v $PWD:/work --workdir=/work builder:arm64 ./build_gmp.sh aarch64
fi
- name: Build prover Android ARM64
run: |
make android
Expand All @@ -95,16 +66,6 @@ jobs:
make host_noasm
ctest --rerun-failed --output-on-failure
- name: Build prover Linux arm64
run: |
docker run --rm --platform=linux/arm64 -i -v $PWD:/work --workdir=/work builder:arm64 bash -c "$(cat << 'EOF'
set -x
set -e
make arm64
ctest --rerun-failed --output-on-failure
EOF
)"
- name: Test rapidsnark
run: |
set -x
Expand Down Expand Up @@ -137,15 +98,6 @@ jobs:
package_noasm
if-no-files-found: error

- name: Upload Linux arm64 dev artifacts
if: github.event_name != 'release'
uses: actions/upload-artifact@v4
with:
name: rapidsnark-linux-arm64
path: |
package_arm64
if-no-files-found: error

- name: Upload Android dev artifacts
if: github.event_name != 'release'
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -226,6 +178,58 @@ jobs:
zip -r rapidsnark-linux-x86_64-noasm-${{ github.ref_name }}.zip rapidsnark-linux-x86_64-noasm-${{ github.ref_name }}
gh release upload ${{ github.event.release.tag_name }} rapidsnark-linux-x86_64-noasm-${{ github.ref_name }}.zip
build-linux-arm64:
runs-on: ubuntu-24.04-arm
steps:
- uses: actions/checkout@v4
with:
submodules: "recursive"

- name: install requirements
uses: awalsh128/cache-apt-pkgs-action@v1
with:
packages: build-essential cmake m4 nasm
version: arm64-1.0

- name: Cache gmp build
uses: actions/cache@v4
with:
path: |
depends/gmp
depends/gmp-6.2.1.tar.xz
key: ${{ runner.os }}-${{ runner.arch }}-gmp-${{ hashFiles('build_gmp.sh') }}

- name: Build gmp for Linux arm64
run: if [[ ! -d "depends/gmp/package_aarch64" ]]; then ./build_gmp.sh aarch64; fi

- name: Build prover Linux arm64
run: |
make host_arm64
ctest --rerun-failed --output-on-failure
- name: Test rapidsnark
run: |
set -x
set -e
time package_arm64/bin/prover testdata/circuit_final.zkey testdata/witness.wtns proof.json public.json
time package_arm64/bin/verifier testdata/verification_key.json public.json proof.json
# make a wrong public.json by decrementing the first element by 1
(value_0=$(jq '.[0]' public.json | tr -d '"') && value_0=$(echo "$value_0 - 1" | BC_LINE_LENGTH=100 bc) && jq --arg value_0 "$value_0" '.[0] = $value_0' public.json) > public_bad.json
set +e
time package_arm64/bin/verifier testdata/verification_key.json public_bad.json proof.json
exit_code=$?
set -e
[ $exit_code -ne 0 ]
- name: Upload Linux arm64 dev artifacts
if: github.event_name != 'release'
uses: actions/upload-artifact@v4
with:
name: rapidsnark-linux-arm64
path: |
package_arm64
if-no-files-found: error

- name: Upload Linux ARM64 release artifacts
if: github.event_name == 'release'
env:
Expand All @@ -250,18 +254,15 @@ jobs:
path: |
depends/gmp
depends/gmp-6.2.1.tar.xz
key: ${{ runner.os }}-gmp-arm64-${{ hashFiles('build_gmp.sh') }}
key: ${{ runner.os }}-${{ runner.arch }}-gmp-${{ hashFiles('build_gmp.sh') }}

- name: build
run: |
if [[ ! -d "depends/gmp/package_ios_arm64" ]]; then ./build_gmp.sh ios; fi
if [[ ! -d "depends/gmp/package_iphone_simulator" ]]; then ./build_gmp.sh ios_simulator; fi
if [[ ! -d "depends/gmp/package_macos_arm64" ]]; then ./build_gmp.sh macos_arm64; fi
make ios
make ios_simulator
make macos_arm64
ctest --rerun-failed --output-on-failure
Expand Down Expand Up @@ -352,7 +353,7 @@ jobs:
path: |
depends/gmp
depends/gmp-6.2.1.tar.xz
key: ${{ runner.os }}-gmp-x86_64-${{ hashFiles('build_gmp.sh') }}-2
key: ${{ runner.os }}-${{ runner.arch }}-gmp-${{ hashFiles('build_gmp.sh') }}

- name: install dependencies
run: |
Expand All @@ -361,7 +362,6 @@ jobs:
- name: build
run: |
if [[ ! -d "depends/gmp/package_macos_x86_64" ]]; then ./build_gmp.sh macos_x86_64; fi
make macos_x86_64
ctest --rerun-failed --output-on-failure
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.10)

include(cmake/platform.cmake)

Expand Down
65 changes: 41 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,10 @@ host:

host_noasm:
rm -rf build_prover_noasm && mkdir build_prover_noasm && cd build_prover_noasm && \
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package_noasm -DUSE_ASM=NO && \
make -j$(nproc) -vvv && make install
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package_noasm -DUSE_ASM=NO && \
make -j$(nproc) -vvv && make install

host_arm64:
rm -rf build_prover && mkdir build_prover && cd build_prover && \
cmake .. -DTARGET_PLATFORM=arm64_host -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package && \
make -j$(nproc) -vvv && make install

arm64:
rm -rf build_prover_arm64 && mkdir build_prover_arm64 && cd build_prover_arm64 && \
cmake .. -DTARGET_PLATFORM=aarch64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package_arm64 && \
make -j$(nproc) -vvv && make install
Expand All @@ -42,32 +37,54 @@ android_openmp_x86_64:
make -j$(nproc) -vvv && make install

ios:
@if [ ! -d "./depends/gmp/package_ios_arm64" ]; then echo "Looks like gmp lib is not built. Run './build_gmp.sh ios' first." && exit 1; fi
rm -rf build_prover_ios && mkdir build_prover_ios && cd build_prover_ios && \
cmake .. -GXcode -DTARGET_PLATFORM=IOS -DCMAKE_INSTALL_PREFIX=../package_ios -DBUILD_TESTS=OFF && \
xcodebuild -destination 'generic/platform=iOS' -scheme rapidsnarkStatic -project rapidsnark.xcodeproj -configuration Release && \
xcodebuild -destination 'generic/platform=iOS' -scheme rapidsnark -project rapidsnark.xcodeproj -configuration Release CODE_SIGNING_ALLOWED=NO && \
cp ../depends/gmp/package_ios_arm64/lib/libgmp.a src/Release-iphoneos && \
echo "" && echo "Now open Xcode and compile the generated project" && echo ""
cmake .. -GXcode -DTARGET_PLATFORM=IOS -DCMAKE_INSTALL_PREFIX=../package_ios && \
xcodebuild -destination 'generic/platform=iOS' -scheme rapidsnarkStatic -project rapidsnark.xcodeproj -configuration Release && \
xcodebuild -destination 'generic/platform=iOS' -scheme rapidsnark -project rapidsnark.xcodeproj -configuration Release CODE_SIGNING_ALLOWED=NO && \
cp ../depends/gmp/package_ios_arm64/lib/libgmp.a src/Release-iphoneos && \
echo "" && echo "iOS Simulator artifacts built in build_prover_ios/src/Release-iphoneos" && echo ""

ios_simulator:
@if [ ! -d "./depends/gmp/package_iphone_simulator" ]; then echo "Looks like gmp lib is not built. Run './build_gmp.sh ios_simulator' first." && exit 1; fi
rm -rf build_prover_ios_simulator && mkdir build_prover_ios_simulator && cd build_prover_ios_simulator && \
cmake .. -GXcode -DTARGET_PLATFORM=IOS_SIMULATOR -DCMAKE_INSTALL_PREFIX=../package_ios_simulator -DUSE_ASM=NO -DBUILD_TESTS=OFF && \
xcodebuild -destination 'generic/platform=iOS Simulator' -scheme rapidsnarkStatic -project rapidsnark.xcodeproj && \
xcodebuild -destination 'generic/platform=iOS Simulator' -scheme rapidsnark -project rapidsnark.xcodeproj CODE_SIGNING_ALLOWED=NO ARCHS=arm64 && \
cp ../depends/gmp/package_iphone_simulator/lib/libgmp.a src/Debug-iphonesimulator && \
echo "" && echo "Now open Xcode and compile the generated project" && echo ""
cmake .. -GXcode -DTARGET_PLATFORM=IOS_SIMULATOR -DCMAKE_INSTALL_PREFIX=../package_ios_simulator -DUSE_ASM=NO && \
xcodebuild -destination 'generic/platform=iOS Simulator' -scheme rapidsnarkStatic -project rapidsnark.xcodeproj && \
xcodebuild -destination 'generic/platform=iOS Simulator' -scheme rapidsnark -project rapidsnark.xcodeproj CODE_SIGNING_ALLOWED=NO ARCHS=arm64 && \
cp ../depends/gmp/package_iphone_simulator/lib/libgmp.a src/Debug-iphonesimulator && \
echo "" && echo "iOS Simulator artifacts built in build_prover_ios_simulator/src/Debug-iphonesimulator" && echo ""

macos_arm64:
@if [ ! -d "./depends/gmp/package_macos_arm64" ]; then echo "Looks like gmp lib is not built. Run './build_gmp.sh macos_arm64' first." && exit 1; fi
rm -rf build_prover_macos_arm64 && mkdir build_prover_macos_arm64 && cd build_prover_macos_arm64 && \
cmake .. -DTARGET_PLATFORM=macos_arm64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package_macos_arm64 && \
make -j$(nproc) -vvv && make install
cmake .. -DTARGET_PLATFORM=macos_arm64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package_macos_arm64 && \
make -j$(nproc) -vvv && make install

macos_x86_64:
@if [ ! -d "./depends/gmp/package_macos_x86_64" ]; then echo "Looks like gmp lib is not built. Run './build_gmp.sh macos_x86_64' first." && exit 1; fi
rm -rf build_prover_macos_x86_64 && mkdir build_prover_macos_x86_64 && cd build_prover_macos_x86_64 && \
cmake .. -DTARGET_PLATFORM=macos_x86_64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package_macos_x86_64 && \
make -j$(nproc) -vvv && make install
cmake .. -DTARGET_PLATFORM=macos_x86_64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package_macos_x86_64 && \
make -j$(nproc) -vvv && make install

clean:
rm -rf build_prover build_prover_android build_prover_android_x86_64 build_prover_ios package package_android \
package_android_x86_64 package_ios depends/gmp/package depends/gmp/package_android_arm64 \
depends/gmp/package_android_x86_64 depends/gmp/package_ios_arm64
rm -rf build_prover \
build_prover_macos_arm64 \
build_prover_macos_x86_64 \
build_prover_android \
build_prover_android_x86_64 \
build_prover_ios \
build_prover_ios_simulator \
package \
package_macos_arm64 \
package_macos_x86_64 \
package_android \
package_android_x86_64 \
package_ios \
package_ios_simulator \
depends/gmp/package \
depends/gmp/package_macos_arm64 \
depends/gmp/package_macos_x86_64 \
depends/gmp/package_android_arm64 \
depends/gmp/package_android_x86_64 \
depends/gmp/package_ios_arm64 \
depends/gmp/package_iphone_simulator
12 changes: 10 additions & 2 deletions build_gmp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ build_android()
return 1
fi

export TOOLCHAIN=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64
if [ "$(uname)" == "Darwin" ]; then
export TOOLCHAIN=$ANDROID_NDK/toolchains/llvm/prebuilt/darwin-x86_64
else
export TOOLCHAIN=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64
fi

export TARGET=aarch64-linux-android
export API=21
Expand Down Expand Up @@ -173,7 +177,11 @@ build_android_x86_64()
return 1
fi

export TOOLCHAIN=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64
if [ "$(uname)" == "Darwin" ]; then
export TOOLCHAIN=$ANDROID_NDK/toolchains/llvm/prebuilt/darwin-x86_64
else
export TOOLCHAIN=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64
fi

export TARGET=x86_64-linux-android
export API=21
Expand Down
9 changes: 2 additions & 7 deletions cmake/platform.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.10)

string(TOLOWER "${TARGET_PLATFORM}" TARGET_PLATFORM)

Expand Down Expand Up @@ -55,11 +55,6 @@ elseif(TARGET_PLATFORM MATCHES "aarch64")
set(GMP_PREFIX ${GMP_ROOT}/package_aarch64)
set(ARCH arm64)

elseif(TARGET_PLATFORM MATCHES "arm64_host")

set(GMP_PREFIX ${GMP_ROOT}/package)
set(ARCH arm64)

elseif(TARGET_PLATFORM MATCHES "macos_x86_64")

set(CMAKE_OSX_ARCHITECTURES x86_64)
Expand All @@ -79,7 +74,7 @@ else()

endif()

if (CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin")
if (CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin" AND NOT TARGET_PLATFORM MATCHES "^android(_x86_64)?")
set(GMP_DEFINIONS -D_LONG_LONG_LIMB)
endif()

Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ endif()

if(USE_ASM AND ARCH MATCHES "x86_64")

if (CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin")
if (CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin" AND NOT TARGET_PLATFORM MATCHES "^android(_x86_64)?")
set(NASM_FLAGS -fmacho64 --prefix _)
else()
set(NASM_FLAGS -felf64 -DPIC)
Expand Down

0 comments on commit 52384e5

Please sign in to comment.