From 2e494c0cf6debe612c6179610932130146833d24 Mon Sep 17 00:00:00 2001 From: everoddandeven Date: Sun, 29 Nov 2026 03:26:13 +0100 Subject: [PATCH 1/4] build: build only the static monero-cpp and compile in parallel --- .github/workflows/build-linux.yml | 9 +++++---- .github/workflows/build-macos.yml | 6 ++++-- .github/workflows/build-windows.yml | 3 ++- .vscode/tasks.json | 4 ++-- bin/build_libmonero_python.sh | 4 ++-- bin/build_monero_cpp.sh | 5 +++-- debian/rules | 2 +- 7 files changed, 19 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build-linux.yml b/.github/workflows/build-linux.yml index a82452ec..6faf2ff3 100644 --- a/.github/workflows/build-linux.yml +++ b/.github/workflows/build-linux.yml @@ -42,7 +42,7 @@ jobs: tar -xf expat-2.7.1.tar.bz2 cd expat-2.7.1 ./configure --enable-static --disable-shared --with-pic - make + make -j"$(nproc)" sudo make install cd ../ @@ -84,15 +84,16 @@ jobs: mkdir -p build cd build cmake .. -DENABLE_COVERAGE=ON -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache - cmake --build . - make -j3 + # the static library only, which is the one that the module links + cmake --build . --target monero-cpp-static --parallel 3 cd ../../../ - name: Build the monero-python module (with coverage) run: | mkdir -p build cmake -B build -DENABLE_COVERAGE=ON -Dpybind11_DIR="$(python3 -m pybind11 --cmakedir)" - cmake --build build + # a compiler of the module takes more than 2 GB of memory: the runner has enough for 3 at once + cmake --build build --parallel 3 # stubgen, pinned because a new version can report more, reads the signatures that pybind11 writes in # the docstrings and fails on what is wrong with the bindings: a C++ type that leaked into one, a default diff --git a/.github/workflows/build-macos.yml b/.github/workflows/build-macos.yml index b50425d1..dd5635db 100644 --- a/.github/workflows/build-macos.yml +++ b/.github/workflows/build-macos.yml @@ -101,13 +101,15 @@ jobs: mkdir -p build cd build cmake .. -DOPENSSL_ROOT_DIR="$OPENSSL_ROOT_DIR" -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache - cmake --build . - make -j3 + # the static library only, which is the one that the module links + cmake --build . --target monero-cpp-static --parallel 3 cd ../../../ - name: Build the monero-python wheel run: | mkdir -p build + # the compilers of the module at once: each one takes much memory, which the arm runner has little of + export CMAKE_BUILD_PARALLEL_LEVEL=3 python3 -m pip wheel . -w dist --no-build-isolation - name: Show ccache statistics diff --git a/.github/workflows/build-windows.yml b/.github/workflows/build-windows.yml index 02388c87..48f4ce2f 100644 --- a/.github/workflows/build-windows.yml +++ b/.github/workflows/build-windows.yml @@ -130,7 +130,8 @@ jobs: mkdir -p build cd build cmake .. -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache - cmake --build . --parallel $(nproc) + # the static library only, which is the one that the module links + cmake --build . --target monero-cpp-static --parallel $(nproc) - name: Build the monero-python wheel run: | diff --git a/.vscode/tasks.json b/.vscode/tasks.json index af81a1b6..014b2247 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -49,8 +49,8 @@ // build. The type stays in the cache of that build, also for bin/build_monero_cpp.sh: -DCMAKE_BUILD_TYPE= goes back "label": "build: monero-cpp with debug info", "type": "shell", - "command": "cmake -S external/monero-cpp -B external/monero-cpp/build -DCMAKE_BUILD_TYPE=RelWithDebInfo && nice -n 19 cmake --build external/monero-cpp/build -j\"$(printenv MONERO_JOBS | grep . || echo 3)\"", - "windows": { "command": "cmake -S external/monero-cpp -B external/monero-cpp/build -DCMAKE_BUILD_TYPE=RelWithDebInfo && cmake --build external/monero-cpp/build -j3" }, + "command": "cmake -S external/monero-cpp -B external/monero-cpp/build -DCMAKE_BUILD_TYPE=RelWithDebInfo && nice -n 19 cmake --build external/monero-cpp/build --target monero-cpp-static -j\"$(printenv MONERO_JOBS | grep . || echo 3)\"", + "windows": { "command": "cmake -S external/monero-cpp -B external/monero-cpp/build -DCMAKE_BUILD_TYPE=RelWithDebInfo && cmake --build external/monero-cpp/build --target monero-cpp-static -j3" }, "problemMatcher": ["$gcc"] }, { diff --git a/bin/build_libmonero_python.sh b/bin/build_libmonero_python.sh index 9b83cd83..232d27b3 100755 --- a/bin/build_libmonero_python.sh +++ b/bin/build_libmonero_python.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# Builds monero-project, monero-cpp and the module. JOBS is the number of compilers at once for the module, and for monero-project -# on Linux and macOS, 3 by default +# Builds monero-project, monero-cpp and the module. JOBS is the number of compilers at once for the module, and for +# monero-project and monero-cpp on Linux and macOS, 3 by default set -euo pipefail root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) diff --git a/bin/build_monero_cpp.sh b/bin/build_monero_cpp.sh index cc76bf93..22714b67 100755 --- a/bin/build_monero_cpp.sh +++ b/bin/build_monero_cpp.sh @@ -3,7 +3,7 @@ # CI and the deb package use it on Linux and macOS. Windows has its own toolchain, # see .github/workflows/build-windows.yml. # -# JOBS parallel jobs for monero-project, 3 by default +# JOBS parallel jobs for monero-project and monero-cpp, 3 by default # COVERAGE ON builds monero-cpp with coverage # OPENSSL_ROOT_DIR the openssl both projects are built with, they look for brew's otherwise on macOS set -euo pipefail @@ -52,4 +52,5 @@ if [ "${COVERAGE:-OFF}" = ON ]; then cmake_args+=(-DENABLE_COVERAGE=ON) fi cmake .. ${cmake_args[@]+"${cmake_args[@]}"} -cmake --build . +# the static library only, which is the one that the module links +cmake --build . --target monero-cpp-static --parallel "$jobs" diff --git a/debian/rules b/debian/rules index bfec531f..a3cd958d 100755 --- a/debian/rules +++ b/debian/rules @@ -31,7 +31,7 @@ override_dh_auto_build: # the module is built here by scikit-build-core, which finds what the step above built override_dh_auto_install: - $(LINUX32) pip3 install -vvv . --no-build-isolation --target $(SITE_PACKAGES) + $(LINUX32) env CMAKE_BUILD_PARALLEL_LEVEL=$(JOBS) pip3 install -vvv . --no-build-isolation --target $(SITE_PACKAGES) rm -rf $(SITE_PACKAGES)/pybind11* $(SITE_PACKAGES)/bin -ccache --show-stats From ceb04c89b71e6036eb6d3bb254153c7ddbd04c68 Mon Sep 17 00:00:00 2001 From: everoddandeven Date: Sun, 29 Nov 2026 03:26:29 +0100 Subject: [PATCH 2/4] build: turn lto off in the coverage build and in the static unbound --- .github/workflows/build-linux.yml | 3 ++- CMakeLists.txt | 2 ++ bin/install_unbound_macos.sh | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-linux.yml b/.github/workflows/build-linux.yml index 6faf2ff3..90eae3d9 100644 --- a/.github/workflows/build-linux.yml +++ b/.github/workflows/build-linux.yml @@ -52,7 +52,8 @@ jobs: echo "c5dd1bdef5d5685b2cedb749158dd152c52d44f65529a34ac15cd88d4b1b3d43 unbound-1.22.0.tar.gz" | sha256sum -c tar xzf unbound-1.22.0.tar.gz cd unbound-1.22.0 - ./configure --with-libexpat=/usr/local --with-ssl=/usr --enable-static --disable-shared --with-pic + # no LTO, which configure turns on when CFLAGS is empty: it makes the links of what takes the library in slow + ./configure --with-libexpat=/usr/local --with-ssl=/usr --enable-static --disable-shared --disable-flto --with-pic # monero only needs libunbound, skip the daemon and the tools make -j"$(nproc)" lib sudo make install-lib diff --git a/CMakeLists.txt b/CMakeLists.txt index cfb39b0b..f74214af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,6 +47,8 @@ if(ENABLE_COVERAGE) message(STATUS "Coverage enabled") add_compile_options(--coverage -O0 -g -fprofile-update=atomic) add_link_options(--coverage) + # pybind11 leaves LTO off when this is defined: with -O0 it only makes the link slow + set(CMAKE_INTERPROCEDURAL_OPTIMIZATION OFF) endif() # The flags of the hardening for the sources of the module. The libraries it links get theirs from diff --git a/bin/install_unbound_macos.sh b/bin/install_unbound_macos.sh index 6982e5c3..8df5b715 100755 --- a/bin/install_unbound_macos.sh +++ b/bin/install_unbound_macos.sh @@ -23,6 +23,7 @@ curl --retry 5 --retry-delay 5 -fsSLO "https://www.nlnetlabs.nl/downloads/unboun echo "${sha256} unbound-${version}.tar.gz" | shasum -a 256 -c - tar xzf "unbound-${version}.tar.gz" cd "unbound-${version}" -./configure --with-libexpat="$(brew --prefix expat)" --with-ssl="$(brew --prefix openssl@3)" --with-libunbound-only --with-libevent=no --enable-static --disable-shared --with-pic +# no LTO, which configure turns on when CFLAGS is empty: it makes the link of the module slow +./configure --with-libexpat="$(brew --prefix expat)" --with-ssl="$(brew --prefix openssl@3)" --with-libunbound-only --with-libevent=no --enable-static --disable-shared --disable-flto --with-pic make -j3 sudo make install From 2b81624227f40da3d4f5f2e8bf1614522a4d666e Mon Sep 17 00:00:00 2001 From: everoddandeven Date: Sun, 29 Nov 2026 03:27:34 +0100 Subject: [PATCH 3/4] build: let ccache cache the coverage build of the module --- CMakeLists.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f74214af..3f6c18a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,8 +45,15 @@ endif() if(ENABLE_COVERAGE) message(STATUS "Coverage enabled") - add_compile_options(--coverage -O0 -g -fprofile-update=atomic) + add_compile_options(--coverage -O0 -g) add_link_options(--coverage) + # ccache 4.9 does not know -fprofile-update and does not cache a file compiled with it, unless it is told to pass it on as it is. + # Only ccache itself has the option, not a launcher such as sccache + if(CMAKE_CXX_COMPILER_LAUNCHER MATCHES "(^|/)ccache(\\.exe)?$") + add_compile_options("SHELL:--ccache-skip -fprofile-update=atomic") + else() + add_compile_options(-fprofile-update=atomic) + endif() # pybind11 leaves LTO off when this is defined: with -O0 it only makes the link slow set(CMAKE_INTERPROCEDURAL_OPTIMIZATION OFF) endif() From 9633a252ff263c0ec2540a0c9d2e881c4b8f5af5 Mon Sep 17 00:00:00 2001 From: everoddandeven Date: Sun, 29 Nov 2026 03:36:03 +0100 Subject: [PATCH 4/4] build: run lto in parallel when the deb packages build with more than one job --- debian/rules | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/debian/rules b/debian/rules index a3cd958d..dc12da89 100755 --- a/debian/rules +++ b/debian/rules @@ -4,6 +4,9 @@ include /usr/share/dpkg/buildopts.mk # the jobs given with dpkg-buildpackage -j, one by default JOBS := $(or $(DEB_BUILD_OPTION_PARALLEL),1) +# with more than one, cmake sets the flags of LTO instead of pybind11: from cmake 3.24 the link of the module then runs LTO in parallel, on +# all the cpus, where older ones, as the one of jammy, still run it one part at a time. With one job it stays that way, which needs less memory +MODULE_LTO := $(if $(filter-out 1,$(JOBS)),CMAKE_ARGS=-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON) SITE_PACKAGES := debian/python3-monero/usr/lib/python3/dist-packages # a 32 bit arm container on a 64 bit arm runner still reports aarch64 and configure scripts and @@ -31,7 +34,7 @@ override_dh_auto_build: # the module is built here by scikit-build-core, which finds what the step above built override_dh_auto_install: - $(LINUX32) env CMAKE_BUILD_PARALLEL_LEVEL=$(JOBS) pip3 install -vvv . --no-build-isolation --target $(SITE_PACKAGES) + $(LINUX32) env CMAKE_BUILD_PARALLEL_LEVEL=$(JOBS) $(MODULE_LTO) pip3 install -vvv . --no-build-isolation --target $(SITE_PACKAGES) rm -rf $(SITE_PACKAGES)/pybind11* $(SITE_PACKAGES)/bin -ccache --show-stats