From 879d012275aea45aec255066e6787edae3686ef0 Mon Sep 17 00:00:00 2001 From: Alejandro Cabeza Romero Date: Fri, 4 Jul 2025 21:52:03 +0200 Subject: [PATCH] Add README to detail building for linux and windows (with xcompilation). --- circom_circuits/Mantle/README.md | 108 +++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 circom_circuits/Mantle/README.md diff --git a/circom_circuits/Mantle/README.md b/circom_circuits/Mantle/README.md new file mode 100644 index 0000000..a26e258 --- /dev/null +++ b/circom_circuits/Mantle/README.md @@ -0,0 +1,108 @@ +# 🛠️ Building + +## 🐧 Linux (Fedora) +1. Generate the C++ code + ```bash + circom --c --r1cs --no_asm pol.circom + ``` +2. Compile + ```bash + make pol + ``` + +## 🪟 Windows (Cross-compile from Linux) +1. Generate the C++ code + ```bash + circom --c --r1cs --no_asm pol.circom + ``` +2. Enter working directory + ```bash + cd pol_cpp + ``` +3. Replace the Makefile + The autogenerated `Makefile` does not support cross-compilation. Replace the `Makefile` contents with the following: + ```make + # ========== General ========== + + DEPS_HPP = circom.hpp calcwit.hpp fr.hpp + + # ========== Native Linux build ========== + CXX = g++ + CXXFLAGS = -std=c++11 -O3 -I. + LDFLAGS = -lgmp + + OBJS = main.o calcwit.o fr.o pol.o + + all: pol + + %.o: %.cpp $(DEPS_HPP) + $(CXX) -Wno-address-of-packed-member -c $< $(CXXFLAGS) + + pol: $(OBJS) + $(CXX) -o $@ $^ $(LDFLAGS) + + # ========== Windows cross-compilation ========== + + CXX_WIN = x86_64-w64-mingw32-g++ + CC_WIN = x86_64-w64-mingw32-gcc + CXXFLAGS_WIN = -std=c++11 -O3 -I. -Iinclude -Duint="unsigned int" -Ideps/mman-win32 + LDFLAGS_WIN = -L/usr/x86_64-w64-mingw32/sys-root/mingw/lib -lgmp + + WIN_OBJS = main.win.o calcwit.win.o fr.win.o pol.win.o mman.win.o + + %.win.o: %.cpp $(DEPS_HPP) + $(CXX_WIN) -Wno-address-of-packed-member -c $< -o $@ $(CXXFLAGS_WIN) + + mman.win.o: deps/mman-win32/mman.c + $(CC_WIN) -c $< -o $@ + + pol.exe: $(WIN_OBJS) + $(CXX_WIN) -o $@ $^ $(LDFLAGS_WIN) + + # ========== Cleanup ========== + + clean: + $(RM) *.o *.win.o pol pol.exe + ``` +4. Install Dependencies + 1. Cross-Compiler + ```bash + sudo dnf install mingw64-gcc mingw64-gcc-c++ # Compiler + ``` + 2. `sys/mman.h` + ```bash + mkdir -p include/sys + mkdir -p deps + git clone https://github.com/alitrack/mman-win32.git deps/mman-win32 + cp deps/mman-win32/mman.h ./sys/ + ``` + 3. `nlohmann/json` + ```bash + mkdir -p include/nlohmann + wget https://raw.githubusercontent.com/nlohmann/json/develop/single_include/nlohmann/json.hpp -O include/nlohmann/json.hpp + ``` + 4. `gmp` + ``` + sudo dnf install mingw64-gmp + ``` +5. Compile + ```bash + make pol.exe + ``` +6. Bundle + 1. Copy `.dll`s + ```bash + cp /usr/x86_64-w64-mingw32/sys-root/mingw/bin/libgcc_s_seh-1.dll \ + /usr/x86_64-w64-mingw32/sys-root/mingw/bin/libgmp-10.dll \ + /usr/x86_64-w64-mingw32/sys-root/mingw/bin/libwinpthread-1.dll \ + /usr/x86_64-w64-mingw32/sys-root/mingw/bin/libstdc++-6.dll \ + . + ``` + 2. Copy `.dat` + ``` + cp pol.dat pol.exe.dat + ``` + 3. Bundle + ```bash + tar -czf pol-windows-bundle.tar.gz pol.exe pol.exe.dat *.dll + ```