From f6defd7456c4502ce93aa6e21c1ab0923480ff1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lex?= Date: Mon, 25 May 2026 11:09:22 +0200 Subject: [PATCH] fix(build): gmp version consitency (#31) --- .github/resources/witness-generator/Makefile | 19 +++++++--- .github/workflows/ci.yml | 40 ++++++++++++++++---- 2 files changed, 45 insertions(+), 14 deletions(-) diff --git a/.github/resources/witness-generator/Makefile b/.github/resources/witness-generator/Makefile index 7d26905..2acddeb 100644 --- a/.github/resources/witness-generator/Makefile +++ b/.github/resources/witness-generator/Makefile @@ -7,6 +7,7 @@ endif # ---- Common ---- CXX := g++ +PRIORITY_FLAGS ?= CXXFLAGS_COMMON := -std=c++11 -O3 -I. -Wno-address-of-packed-member -Dmain=circom_main COMMON_SRCS := main.cpp calcwit.cpp fr.cpp $(PROJECT).cpp COMMON_OBJS := $(COMMON_SRCS:.cpp=.o) @@ -26,30 +27,36 @@ endif LIB := $(LIB_PREFIX)$(PROJECT)$(LIB_EXT) # ---- Linux (x86_64 and aarch64) ---- -linux: CXXFLAGS=$(CXXFLAGS_COMMON) +# NOTE: linux (bin) links system gmp via -lgmp. CI uses linux-lib only, which +# relies on PRIORITY_FLAGS to prefer the gmp built from source over the system one. +linux: CXXFLAGS=$(PRIORITY_FLAGS) $(CXXFLAGS_COMMON) linux: LDFLAGS=-static linux: LDLIBS=-lgmp linux: $(BIN) -linux-lib: CXXFLAGS=$(CXXFLAGS_COMMON) -fPIC +linux-lib: CXXFLAGS=$(PRIORITY_FLAGS) $(CXXFLAGS_COMMON) -fPIC linux-lib: $(LIB) # ---- macOS ---- -macos: CXXFLAGS=$(CXXFLAGS_COMMON) -I/opt/homebrew/include -include gmp_patch.hpp +# NOTE: macos (bin) hardcodes Homebrew gmp for both includes and linking. CI uses +# macos-lib only, which relies on PRIORITY_FLAGS to prefer the gmp built from source. +macos: CXXFLAGS=$(PRIORITY_FLAGS) $(CXXFLAGS_COMMON) -I/opt/homebrew/include -include gmp_patch.hpp -mmacosx-version-min=11.0 macos: LDFLAGS=-Wl,-search_paths_first -Wl,-dead_strip macos: LDLIBS=/opt/homebrew/lib/libgmp.a macos: $(BIN) -macos-lib: CXXFLAGS=$(CXXFLAGS_COMMON) -fPIC -I/opt/homebrew/include -include gmp_patch.hpp +macos-lib: CXXFLAGS=$(PRIORITY_FLAGS) $(CXXFLAGS_COMMON) -fPIC -I/opt/homebrew/include -include gmp_patch.hpp -mmacosx-version-min=11.0 macos-lib: $(LIB) # ---- Windows (MinGW) ---- -windows: CXXFLAGS=$(CXXFLAGS_COMMON) -I/include -Duint="unsigned int" +# NOTE: windows (bin) links system gmp via -lgmp. CI uses windows-lib only, which +# relies on PRIORITY_FLAGS to prefer the gmp built from source over the system one. +windows: CXXFLAGS=$(PRIORITY_FLAGS) $(CXXFLAGS_COMMON) -I/include -Duint="unsigned int" windows: LDFLAGS=-static windows: LDLIBS=-L/lib -lgmp -lmman windows: $(BIN) -windows-lib: CXXFLAGS=$(CXXFLAGS_COMMON) -fPIC -I/include -Duint="unsigned int" +windows-lib: CXXFLAGS=$(PRIORITY_FLAGS) $(CXXFLAGS_COMMON) -fPIC -I/include -Duint="unsigned int" windows-lib: $(LIB) # Localizes all circuit-specific code to prevent conflicts when multiple circuit diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e7dea46..4a62191 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -196,7 +196,7 @@ jobs: run: sudo apt update -y - name: Install Dependencies [Prover] - run: sudo apt install -y build-essential cmake libgmp-dev libsodium-dev nasm curl m4 + run: sudo apt install -y build-essential cmake libsodium-dev nasm curl m4 - name: Install Dependencies [Witness Generator] run: sudo apt install -y nlohmann-json3-dev llvm @@ -225,6 +225,12 @@ jobs: ./build_gmp.sh host make host_linux_x86_64_static + - name: Prioritize Built GMP Headers Over System GMP + run: | + # System gmp (6.2.1) is preinstalled on the runner. Prepend our built gmp headers + # so the witness generator compiles against the same gmp version as the prover. + echo "PRIORITY_FLAGS=-I${{ github.workspace }}/rapidsnark/depends/gmp/package/include" >> $GITHUB_ENV + - name: Bundle Rapidsnark Prover env: BINARY_NAME: prover @@ -441,7 +447,7 @@ jobs: run: sudo apt update -y - name: Install Dependencies [Prover] - run: sudo apt install -y build-essential cmake libgmp-dev libsodium-dev nasm curl m4 + run: sudo apt install -y build-essential cmake libsodium-dev nasm curl m4 - name: Install Dependencies [Witness Generator] run: sudo apt install -y nlohmann-json3-dev llvm @@ -472,6 +478,12 @@ jobs: ln -s package depends/gmp/package_aarch64 make host_linux_aarch64_static + - name: Prioritize Built GMP Headers Over System GMP + run: | + # System gmp (6.2.1) is preinstalled on the runner. Prepend our built gmp headers + # so the witness generator compiles against the same gmp version as the prover. + echo "PRIORITY_FLAGS=-I${{ github.workspace }}/rapidsnark/depends/gmp/package/include" >> $GITHUB_ENV + - name: Bundle Rapidsnark Prover env: BINARY_NAME: prover @@ -755,6 +767,13 @@ jobs: ./build_gmp.sh host make host_windows_x86_64_static + - name: Prioritize Built GMP Headers Over System GMP + shell: msys2 {0} + run: | + # System gmp (6.3.0) is preinstalled on the runner. Prepend our built gmp headers + # so the witness generator compiles against the same gmp version as the prover. + echo "PRIORITY_FLAGS=-I$(cygpath -u "$GITHUB_WORKSPACE")/rapidsnark/depends/gmp/package/include" >> $GITHUB_ENV + - name: Bundle Rapidsnark Prover shell: msys2 {0} env: @@ -995,9 +1014,20 @@ jobs: - name: Compile Prover and Verifier working-directory: rapidsnark run: | + # build_gmp.sh hardcodes -mmacos-version-min=14.0 in CFLAGS, ignoring + # MACOSX_DEPLOYMENT_TARGET. Patch it to 11.0 so libgmp.a matches Rust's + # aarch64-apple-darwin toolchain target (macOS 11.0+). + sed -i '' 's/-mmacos-version-min=14\.0/-mmacos-version-min=11.0/g' build_gmp.sh ./build_gmp.sh macos_arm64 make macos_arm64 + - name: Prioritize Built GMP Headers Over System GMP + run: | + # System gmp (6.3.0) is preinstalled on the runner. Prepend our built gmp headers + # so the witness generator compiles against the same gmp version as the prover, + # and the built gmp targets macOS 11.0 rather than the runner's current OS version. + echo "PRIORITY_FLAGS=-I${{ github.workspace }}/rapidsnark/depends/gmp/package_macos_arm64/include" >> $GITHUB_ENV + - name: Bundle Rapidsnark Prover env: BINARY_NAME: prover @@ -1201,9 +1231,6 @@ jobs: - name: Install Rust Toolchain uses: actions-rust-lang/setup-rust-toolchain@2b1f5e9b395427c92ee4e3331786ca3c37afe2d7 # v1.16.0 - - name: Install Dependencies - run: sudo apt install -y libgmp-dev - - name: Cache Cargo artifacts uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # Version 4.2.3 with: @@ -1257,9 +1284,6 @@ jobs: - name: Install Rust Toolchain uses: actions-rust-lang/setup-rust-toolchain@2b1f5e9b395427c92ee4e3331786ca3c37afe2d7 # v1.16.0 - - name: Install Dependencies - run: sudo apt install -y libgmp-dev - - name: Cache Cargo artifacts uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # Version 4.2.3 with: