From 997c046dc5ee2d83be01bd7903b8b5e5e4615caf Mon Sep 17 00:00:00 2001 From: Alejandro Cabeza Romero Date: Mon, 14 Jul 2025 15:02:14 +0200 Subject: [PATCH] Improve README explaining crosscompilation for windows from linux. --- circom_circuits/Mantle/README.md | 84 ++++++++++++++++++-------------- 1 file changed, 48 insertions(+), 36 deletions(-) diff --git a/circom_circuits/Mantle/README.md b/circom_circuits/Mantle/README.md index a26e258..f45ca93 100644 --- a/circom_circuits/Mantle/README.md +++ b/circom_circuits/Mantle/README.md @@ -22,66 +22,81 @@ 3. Replace the Makefile The autogenerated `Makefile` does not support cross-compilation. Replace the `Makefile` contents with the following: ```make - # ========== General ========== +# ========== General ========== - DEPS_HPP = circom.hpp calcwit.hpp fr.hpp +DEPS_HPP = circom.hpp calcwit.hpp fr.hpp - # ========== Native Linux build ========== - CXX = g++ - CXXFLAGS = -std=c++11 -O3 -I. - LDFLAGS = -lgmp +# ========== Native Linux build ========== +CXX = g++ +CXXFLAGS = -std=c++11 -O3 -I. +LDFLAGS = -lgmp - OBJS = main.o calcwit.o fr.o pol.o +OBJS = main.o calcwit.o fr.o pol.o - all: pol +all: pol - %.o: %.cpp $(DEPS_HPP) - $(CXX) -Wno-address-of-packed-member -c $< $(CXXFLAGS) +%.o: %.cpp $(DEPS_HPP) + $(CXX) -Wno-address-of-packed-member -c $< $(CXXFLAGS) - pol: $(OBJS) - $(CXX) -o $@ $^ $(LDFLAGS) +pol: $(OBJS) + $(CXX) -o $@ $^ $(LDFLAGS) - # ========== Windows cross-compilation ========== +# ========== 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 +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" +LDFLAGS_WIN = -Llib -lgmp -lmman - WIN_OBJS = main.win.o calcwit.win.o fr.win.o pol.win.o mman.win.o +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) +%.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 $@ +mman.win.o: deps/mman-win32/mman.c + $(CC_WIN) -c $< -o $@ - pol.exe: $(WIN_OBJS) - $(CXX_WIN) -o $@ $^ $(LDFLAGS_WIN) +pol.exe: $(WIN_OBJS) + $(CXX_WIN) -o $@ $^ $(LDFLAGS_WIN) - # ========== Cleanup ========== +# ========== Cleanup ========== - clean: - $(RM) *.o *.win.o pol pol.exe +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` + 2. Directory structure ```bash mkdir -p include/sys mkdir -p deps + mkdir -p lib + ```mkdir -p include/sys + mkdir -p deps + mkdir -p lib + + 3. `sys/mman.h` + ```bash git clone https://github.com/alitrack/mman-win32.git deps/mman-win32 - cp deps/mman-win32/mman.h ./sys/ + + # cp deps/mman-win32/mman.h ./sys/ + #### + cd deps/mman-win32 + ./configure + make CC=x86_64-w64-mingw32-gcc + cd ../.. + cp deps/mman-win32/mman.h include/sys/ + cp deps/mman-win32/libmman.a lib ``` - 3. `nlohmann/json` + 4. `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` + 5. `gmp` ``` sudo dnf install mingw64-gmp ``` @@ -92,11 +107,8 @@ 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 \ - . + MINGW_DLL_DIR="$(x86_64-w64-mingw32-gcc -print-sysroot)/mingw/bin" + cp "$MINGW_DLL_DIR"/{libgcc_s_seh-1.dll,libgmp-10.dll,libwinpthread-1.dll,libstdc++-6.dll} . ``` 2. Copy `.dat` ```