From 7806db98146a18360a36a0229cac583bd433a8a9 Mon Sep 17 00:00:00 2001 From: Alejandro Cabeza Romero Date: Fri, 29 Aug 2025 18:16:59 +0200 Subject: [PATCH] Simplify witness generator makefile. --- .github/resources/witness-generator/Makefile | 43 ++++++++++++++++++++ .github/workflows/build-circuits.yml | 12 +++--- 2 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 .github/resources/witness-generator/Makefile 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/workflows/build-circuits.yml b/.github/workflows/build-circuits.yml index 7bedc16..7ae311b 100644 --- a/.github/workflows/build-circuits.yml +++ b/.github/workflows/build-circuits.yml @@ -104,11 +104,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 @@ -270,12 +270,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 +394,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 +402,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