From 0df054bbcbf9cfc615b383426a4bf5c30d69245b Mon Sep 17 00:00:00 2001 From: Sami Ahmed Date: Thu, 23 Apr 2026 13:28:02 -0700 Subject: [PATCH] Build acceleration: ccache, unity build, precompiled headers - Auto-detect and use ccache as compiler launcher when available - Add ENABLE_UNITY_BUILD option for jumbo builds (batch size 8) - Precompile heavy STL/Boost/OpenSSL headers for C++ targets - Exclude hash9 crypto from unity builds (colliding static symbols) - Fix RAND_screen() compile error on OpenSSL 3.x (removed API) Co-Authored-By: Claude Opus 4.6 --- CMakeLists.txt | 21 +++++++++++++++++++++ src/CMakeLists.txt | 28 ++++++++++++++++++++++++++++ src/util.cpp | 3 ++- 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 11c3189..31213c6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,24 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_C_STANDARD 11) +# ── Build acceleration ── +# ccache: auto-detect and use if available +find_program(CCACHE_PROGRAM ccache) +if(CCACHE_PROGRAM) + set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}") + set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}") + message(STATUS "ccache found: ${CCACHE_PROGRAM}") +else() + message(STATUS "ccache not found — install it for faster rebuilds") +endif() + +# Unity (jumbo) build: batch source files to reduce header parsing overhead +option(ENABLE_UNITY_BUILD "Enable CMake unity (jumbo) builds" OFF) +if(ENABLE_UNITY_BUILD) + set(CMAKE_UNITY_BUILD ON) + set(CMAKE_UNITY_BUILD_BATCH_SIZE 8) +endif() + # ── Output directories ── set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") @@ -113,4 +131,7 @@ message(STATUS " D-Bus: ${USE_DBUS}") message(STATUS " ZMQ: ${USE_ZMQ}") message(STATUS " Embedded Tor: ${USE_TOR_EMBEDDED}") message(STATUS " Static linking: ${ENABLE_STATIC}") +message(STATUS " ccache: ${CCACHE_PROGRAM}") +message(STATUS " Unity build: ${ENABLE_UNITY_BUILD}") +message(STATUS " Precompiled header: ON") message(STATUS "") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8425535..27cd6f3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -23,6 +23,8 @@ add_library(hash9_crypto STATIC ) target_include_directories(hash9_crypto PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") set_target_properties(hash9_crypto PROPERTIES LINKER_LANGUAGE C) +# Hash9 C files have colliding static symbols (IV512, DECL_STATE, etc.) — skip unity +set_target_properties(hash9_crypto PROPERTIES UNITY_BUILD OFF) # ═══════════════════════════════════════════════════════════════════════════════ # 2. JSON library (header-only nlohmann/json via json_compat.h shim) @@ -185,6 +187,31 @@ endif() add_dependencies(triangles_common generate_build_info build_leveldb) +# ── Precompiled header (heavy STL + Boost + OpenSSL includes, C++ only) ── +target_precompile_headers(triangles_common PRIVATE + "$<$:>" + "$<$:>" + "$<$:>" + "$<$:>" + "$<$:>" + "$<$:>" + "$<$:>" + "$<$:>" + "$<$:>" + "$<$:>" + "$<$:>" + "$<$:>" + "$<$:>" + "$<$:>" + "$<$:>" + "$<$:>" + "$<$:>" + "$<$:>" + "$<$:>" + "$<$:>" + "$<$:>" +) + # ═══════════════════════════════════════════════════════════════════════════════ # 4. Headless daemon (trianglesd) # ═══════════════════════════════════════════════════════════════════════════════ @@ -196,6 +223,7 @@ if(BUILD_DAEMON) ) # No QT_GUI define — daemon gets the #if !defined(QT_GUI) code paths target_link_libraries(trianglesd PRIVATE triangles_common) + target_precompile_headers(trianglesd REUSE_FROM triangles_common) if(WIN32) set_target_properties(trianglesd PROPERTIES SUFFIX ".exe") diff --git a/src/util.cpp b/src/util.cpp index ff89147..221fb3b 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -111,8 +111,9 @@ public: CRYPTO_set_locking_callback(locking_callback); #endif -#ifdef WIN32 +#if defined(WIN32) && OPENSSL_VERSION_NUMBER < 0x30000000L // Seed random number generator with screen scrape and other hardware sources + // (removed in OpenSSL 3.x — auto-seeded via BCryptGenRandom) RAND_screen(); #endif