From 6f898f02b314c1572115abc7a665b19d1255f54c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lex?= Date: Mon, 1 Sep 2025 16:31:04 +0200 Subject: [PATCH] ci(circuits): Simplify makefiles (#91) * Simplify witness generator makefile. * Simplify prover makefile. --- .../prover/{windows.Makefile => Makefile} | 32 +++++-- .github/resources/prover/linux.Makefile | 94 ------------------- .github/resources/witness-generator/Makefile | 43 +++++++++ .../witness-generator/linux.Makefile | 18 ---- .../witness-generator/macos.Makefile | 19 ---- .../witness-generator/windows.Makefile | 17 ---- .github/workflows/build-circuits.yml | 24 ++--- 7 files changed, 76 insertions(+), 171 deletions(-) rename .github/resources/prover/{windows.Makefile => Makefile} (86%) delete mode 100644 .github/resources/prover/linux.Makefile create mode 100644 .github/resources/witness-generator/Makefile delete mode 100644 .github/resources/witness-generator/linux.Makefile delete mode 100644 .github/resources/witness-generator/macos.Makefile delete mode 100644 .github/resources/witness-generator/windows.Makefile diff --git a/.github/resources/prover/windows.Makefile b/.github/resources/prover/Makefile similarity index 86% rename from .github/resources/prover/windows.Makefile rename to .github/resources/prover/Makefile index 83d60e6..25f9bb7 100644 --- a/.github/resources/prover/windows.Makefile +++ b/.github/resources/prover/Makefile @@ -1,23 +1,36 @@ ### +EXTRA_CMAKE_FLAGS ?= +LIBGOMP_A := $(shell $(CXX) --print-file-name=libgomp.a) + #Build targets +# Add EXTRA_CMAKE_FLAGS host: rm -rf build_prover && mkdir build_prover && cd build_prover && \ cmake .. \ - -DCMAKE_BUILD_TYPE=Release - -DCMAKE_INSTALL_PREFIX=../package && \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=../package \ + $(EXTRA_CMAKE_FLAGS) && \ make -j$(nproc) -vvv && make install -# Copy of the original host target, with specific flags for Windows x86_64 to add patches, missing libraries and -# include paths -host_windows_x86_64: +host_linux_x86_64_static: rm -rf build_prover && mkdir build_prover && cd build_prover && \ cmake .. \ - -DUSE_ASM=OFF \ - -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=../package \ - -DCMAKE_EXE_LINKER_FLAGS="-static -static-libstdc++ -static-libgcc -L/lib -lmman" \ - -DCMAKE_CXX_FLAGS="-I/include -include mman_patch.hpp -include cstdint -Duint=unsigned\ int -Du_int32_t=uint32_t -Du_int64_t=uint64_t" && \ + -DCMAKE_EXE_LINKER_FLAGS="-static -static-libstdc++ -static-libgcc -no-pie" \ + -DOpenMP_gomp_LIBRARY=$(LIBGOMP_A) \ + -DCMAKE_PREFIX_PATH=depends/gmp/package && \ + make -j$(nproc) -vvv && make install + +host_windows_x86_64_static: + rm -rf build_prover && mkdir build_prover && cd build_prover && \ + cmake .. \ + -DUSE_ASM=OFF \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=../package \ + -DCMAKE_EXE_LINKER_FLAGS="-static -static-libstdc++ -static-libgcc -L/lib -lmman" \ + -DCMAKE_CXX_FLAGS="-I/include -include mman_patch.hpp -include cstdint -Duint=unsigned\ int -Du_int32_t=uint32_t -Du_int64_t=uint64_t" && \ make -j$(nproc) -vvv && make install host_noasm: @@ -102,3 +115,4 @@ clean: depends/gmp/package_android_x86_64 \ depends/gmp/package_ios_arm64 \ depends/gmp/package_iphone_simulator + diff --git a/.github/resources/prover/linux.Makefile b/.github/resources/prover/linux.Makefile deleted file mode 100644 index 8eacc90..0000000 --- a/.github/resources/prover/linux.Makefile +++ /dev/null @@ -1,94 +0,0 @@ -### - - -# Build targets -EXTRA_CMAKE_FLAGS ?= - -host: - rm -rf build_prover && mkdir build_prover && cd build_prover && \ - cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package $(EXTRA_CMAKE_FLAGS) && \ - make -j$$(nproc) -vvv && make install - -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 - -host_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 - -android: - rm -rf build_prover_android && mkdir build_prover_android && cd build_prover_android && \ - cmake .. -DTARGET_PLATFORM=ANDROID -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package_android -DBUILD_TESTS=OFF -DUSE_OPENMP=OFF && \ - make -j$(nproc) -vvv && make install - -android_openmp: - rm -rf build_prover_android_openmp && mkdir build_prover_android_openmp && cd build_prover_android_openmp && \ - cmake .. -DTARGET_PLATFORM=ANDROID -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package_android_openmp -DBUILD_TESTS=OFF -DUSE_OPENMP=ON && \ - make -j$(nproc) -vvv && make install - -android_x86_64: - rm -rf build_prover_android_x86_64 && mkdir build_prover_android_x86_64 && cd build_prover_android_x86_64 && \ - cmake .. -DTARGET_PLATFORM=ANDROID_x86_64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package_android_x86_64 -DBUILD_TESTS=OFF -DUSE_OPENMP=OFF && \ - make -j$(nproc) -vvv && make install - -android_openmp_x86_64: - rm -rf build_prover_android_openmp_x86_64 && mkdir build_prover_android_openmp_x86_64 && cd build_prover_android_openmp_x86_64 && \ - cmake .. -DTARGET_PLATFORM=ANDROID_x86_64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package_android_openmp_x86_64 -DBUILD_TESTS=OFF -DUSE_OPENMP=ON && \ - 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 && \ - 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 && \ - 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 - -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 - -clean: - 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 - diff --git a/.github/resources/witness-generator/Makefile b/.github/resources/witness-generator/Makefile new file mode 100644 index 0000000..1cbcecb --- /dev/null +++ b/.github/resources/witness-generator/Makefile @@ -0,0 +1,43 @@ +.PHONY: linux macos windows build clean + +# ---- Common ---- +CXX := g++ +CXXFLAGS_COMMON := -std=c++11 -O3 -I. -Wno-address-of-packed-member +SRCS := main.cpp calcwit.cpp fr.cpp pol.cpp +OBJS := $(SRCS:.cpp=.o) +DEPS_HPP := circom.hpp calcwit.hpp fr.hpp +BIN_WINDOWS := pol.exe +BIN_UNIX := pol +BINS := $(BIN_UNIX) $(BIN_WINDOWS) + +# ---- Linux ---- +linux: BIN=$(BIN_UNIX) +linux: CXXFLAGS=$(CXXFLAGS_COMMON) +linux: LDFLAGS=-static +linux: LDLIBS=-lgmp +linux: $(BIN_UNIX) + +# ---- macOS ---- +macos: BIN=$(BIN_UNIX) +macos: CXXFLAGS=$(CXXFLAGS_COMMON) -I/opt/homebrew/include -include gmp_patch.hpp +macos: LDFLAGS=-Wl,-search_paths_first -Wl,-dead_strip +macos: LDLIBS=/opt/homebrew/lib/libgmp.a +macos: $(BIN_UNIX) + +# ---- Windows (MinGW) ---- +windows: BIN=$(BIN_WINDOWS) +windows: CXXFLAGS=$(CXXFLAGS_COMMON) -I/include -Duint="unsigned int" +windows: LDFLAGS=-static +windows: LDLIBS=-L/lib -lgmp -lmman +windows: $(BIN_WINDOWS) + +# ---- Rules ---- +$(BINS): $(OBJS) + $(CXX) $(LDFLAGS) $^ $(LDLIBS) -o $@ + +%.o: %.cpp $(DEPS_HPP) + $(CXX) $(CXXFLAGS) -c $< -o $@ + +clean: + rm -f $(OBJS) $(BIN_WINDOWS) $(BIN_UNIX) + diff --git a/.github/resources/witness-generator/linux.Makefile b/.github/resources/witness-generator/linux.Makefile deleted file mode 100644 index 3c01dcc..0000000 --- a/.github/resources/witness-generator/linux.Makefile +++ /dev/null @@ -1,18 +0,0 @@ -CC=g++ -CFLAGS=-std=c++11 -O3 -I. -LDFLAGS = -lgmp -static - -DEPS_HPP = circom.hpp calcwit.hpp fr.hpp pol.cpp -DEPS_O = main.o calcwit.o fr.o pol.o - -all: pol - -%.o: %.cpp $(DEPS_HPP) - $(CC) -Wno-address-of-packed-member -c $< $(CFLAGS) -o $@ - -pol: $(DEPS_O) - $(CC) -o pol $(DEPS_O) $(LDFLAGS) - -clean: - rm -f *.o pol - diff --git a/.github/resources/witness-generator/macos.Makefile b/.github/resources/witness-generator/macos.Makefile deleted file mode 100644 index 926a92d..0000000 --- a/.github/resources/witness-generator/macos.Makefile +++ /dev/null @@ -1,19 +0,0 @@ -CC = g++ -CFLAGS = -std=c++11 -O3 -I. -I/opt/homebrew/include -include gmp_patch.hpp -Wno-address-of-packed-member -LDFLAGS = -Wl,-search_paths_first -Wl,-dead_strip -L/opt/homebrew/lib -LDLIBS = /opt/homebrew/lib/libgmp.a - -DEPS_HPP = circom.hpp calcwit.hpp fr.hpp pol.cpp -DEPS_O = main.o calcwit.o fr.o pol.o - -all: pol - -%.o: %.cpp $(DEPS_HPP) - $(CC) $(CFLAGS) -c $< -o $@ - -pol: $(DEPS_O) - $(CC) -o $@ $(DEPS_O) $(LDFLAGS) $(LDLIBS) - -clean: - rm -f *.o pol - diff --git a/.github/resources/witness-generator/windows.Makefile b/.github/resources/witness-generator/windows.Makefile deleted file mode 100644 index 2f0c7e7..0000000 --- a/.github/resources/witness-generator/windows.Makefile +++ /dev/null @@ -1,17 +0,0 @@ -CC = g++ -CFLAGS = -std=c++11 -O3 -I. -I/include -Duint="unsigned int" -LDFLAGS = -L/lib -lgmp -lmman -static - -DEPS_HPP = circom.hpp calcwit.hpp fr.hpp pol.cpp -DEPS_O = main.o calcwit.o fr.o pol.o - -all: pol.exe - -%.o: %.cpp $(DEPS_HPP) - $(CC) -Wno-address-of-packed-member -c $< $(CFLAGS) -o $@ - -pol.exe: $(DEPS_O) - $(CC) -o pol.exe $(DEPS_O) $(LDFLAGS) - -clean: - rm -f *.o pol.exe diff --git a/.github/workflows/build-circuits.yml b/.github/workflows/build-circuits.yml index 7bedc16..f28d1d5 100644 --- a/.github/workflows/build-circuits.yml +++ b/.github/workflows/build-circuits.yml @@ -86,17 +86,13 @@ jobs: - name: Replace Prover Makefile # TODO: Make a fork generate the appropriate Linux Makefile working-directory: repo - run: cp .github/resources/prover/${{ env.OS }}.Makefile circom_circuits/rapidsnark/Makefile + run: cp .github/resources/prover/Makefile circom_circuits/rapidsnark/Makefile - name: Compile Prover and Verifier working-directory: repo/circom_circuits/rapidsnark run: | ./build_gmp.sh host - GOMP_A="$(g++ --print-file-name=libgomp.a)" - - PKG_CONFIG_STATIC=1 \ - LDFLAGS= \ - make host EXTRA_CMAKE_FLAGS='-DCMAKE_EXE_LINKER_FLAGS="-static -static-libstdc++ -static-libgcc -no-pie" -DOpenMP_gomp_LIBRARY='"$GOMP_A -DCMAKE_PREFIX_PATH=depends/gmp/package" + make host_linux_x86_64_static - name: Generate Witness Generator's C++ Circuit working-directory: repo/circom_circuits/Mantle @@ -104,11 +100,11 @@ jobs: - name: Replace Witness Generator Makefile # TODO: Make a fork generate the appropriate Linux Makefile working-directory: repo - run: cp .github/resources/witness-generator/${{ env.OS }}.Makefile circom_circuits/Mantle/pol_cpp/Makefile + run: cp .github/resources/witness-generator/Makefile circom_circuits/Mantle/pol_cpp/Makefile - name: Compile Witness Generator working-directory: repo/circom_circuits/Mantle/pol_cpp - run: make pol + run: make linux - name: Bundle Rapidsnark Prover working-directory: repo @@ -234,7 +230,7 @@ jobs: - name: Replace Prover Makefile # TODO: Make a fork generate the appropriate Windows Makefile shell: msys2 {0} working-directory: repo - run: cp .github/resources/prover/${{ env.OS }}.Makefile circom_circuits/rapidsnark/Makefile + run: cp .github/resources/prover/Makefile circom_circuits/rapidsnark/Makefile - name: Replace Prover CMakeLists shell: msys2 {0} @@ -261,7 +257,7 @@ jobs: working-directory: repo/circom_circuits/rapidsnark run: | ./build_gmp.sh host - make host_windows_x86_64 + make host_windows_x86_64_static - name: Generate Witness Generator's C++ Circuit working-directory: repo/circom_circuits/Mantle @@ -270,12 +266,12 @@ jobs: - name: Replace Witness Generator Makefile # TODO: Make a fork generate the appropriate Windows Makefile shell: msys2 {0} working-directory: repo - run: cp .github/resources/witness-generator/${{ env.OS }}.Makefile circom_circuits/Mantle/pol_cpp/Makefile + run: cp .github/resources/witness-generator/Makefile circom_circuits/Mantle/pol_cpp/Makefile - name: Compile Witness Generator shell: msys2 {0} working-directory: repo/circom_circuits/Mantle/pol_cpp - run: make pol.exe + run: make windows - name: Bundle Rapidsnark Prover shell: msys2 {0} @@ -394,7 +390,7 @@ jobs: - name: Replace Witness Generator's Makefile # TODO: Make a fork generate the appropriate MacOS Makefile working-directory: repo - run: cp .github/resources/witness-generator/${{ env.OS }}.Makefile circom_circuits/Mantle/pol_cpp/Makefile + run: cp .github/resources/witness-generator/Makefile circom_circuits/Mantle/pol_cpp/Makefile - name: Patch MacOS GMP working-directory: repo @@ -402,7 +398,7 @@ jobs: - name: Compile Witness Generator working-directory: repo/circom_circuits/Mantle/pol_cpp - run: make pol + run: make macos - name: Bundle Rapidsnark Prover working-directory: repo