Skip to content

build(tests): respect CMAKE_BUILD_TYPE flags, expand format PCHs, and clean unity builds - #261

Open
clockblocker wants to merge 1 commit into
mainfrom
queue/build-test-opt-pch-unity
Open

clockblocker wants to merge 1 commit into
mainfrom
queue/build-test-opt-pch-unity

Conversation

@clockblocker

@clockblocker clockblocker commented Dec 6, 2026 •

Copy link
Copy Markdown
Owner

AI-authored below this line.

Problem

tests/CMakeLists.txt hardcodes -O3 -ggdb into CMAKE_CXX_FLAGS for GCC and Clang regardless of CMAKE_BUILD_TYPE. Release test builds emit full DWARF debug info (788 MiB across 340 objects for the default JSON suites alone), while Debug test builds silently compile at -O3.

Meanwhile, tests/generic has no precompiled header at all, the other test targets only precompile rfl.hpp rather than their format headers, and standard CMake unity builds (-DCMAKE_UNITY_BUILD=ON) fail on macro-redefining enum-range tests and global test types.

# Standard CMake flags now work as expected (zero new project options):
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DREFLECTCPP_BUILD_TESTS=ON
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug   -DREFLECTCPP_BUILD_TESTS=ON
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DREFLECTCPP_BUILD_TESTS=ON \
  -DCMAKE_UNITY_BUILD=ON -DCMAKE_UNITY_BUILD_BATCH_SIZE=16
  • Measured impact (reflect-cpp-self JSON-5, 607/607 CTests, Apple M1 arm64, Apple Clang 17.0.0, -j4, Release, paired vs. 290bdb24):
    • Default Release (zero extra flags): wall 176.9 → 129.0 s (-27.1%), CPU 695.5 → 491.4 s (-29.3%), peak RSS 809 → 576 MiB (-28.8%), total .o 788 → 46 MiB (-94.2%, 17.1x smaller).
    • Standard -DCMAKE_UNITY_BUILD=ON -DCMAKE_UNITY_BUILD_BATCH_SIZE=16: wall 176.9 → 67.7 s (-61.7%, 2.61x faster), CPU 695.5 → 245.3 s (-64.7%), peak RSS 809 → 709 MiB (-12.4%), total .o 788 → 27 MiB (-96.6%, 29.2x smaller; 340 → 28 objects).

Summary

  • Drops hardcoded -O3 -ggdb from tests/CMakeLists.txt (keeping -Wall -Werror -ftemplate-backtrace-limit=0) so CMAKE_BUILD_TYPE and CMAKE_CXX_FLAGS_<CONFIG> control optimization and debug info, and adds /bigobj (MSVC) / -Wa,-mbig-obj (MinGW) under CMAKE_UNITY_BUILD. All 12 upstream GitHub Actions cmake -S jobs already pass -DCMAKE_BUILD_TYPE=Release.
  • Adds PCH to tests/generic (excluding test_enum_range*.cpp from PCH and unity via SKIP_PRECOMPILE_HEADERS / SKIP_UNITY_BUILD_INCLUSION since they redefine RFL_ENUM_RANGE_MIN/MAX before <rfl.hpp>) and upgrades the 7 verified test targets (generic, json, json_c_arrays_and_inheritance, cli, env, xml, boost_serialization) to public format headers only (no local write_and_read.hpp, preserving REFLECTCPP_JSON=OFF; remaining 13 format suites stay untouched for a CI-verified follow-up).
  • Keeps -DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON, GCC 16 -O2, and -DCMAKE_UNITY_BUILD=ON (BATCH_SIZE=16 and 0) -Wall -Werror-clean across all 7 verified suites with zero include/ or src/ edits (target_compile_definitions + non-MSVC -Wno-missing-braces in json_c_arrays_and_inheritance for C-array brace elision when PCH is disabled, reserve(4 + N) in tests/check_bitset.hpp check_native/check_size to prevent GCC 16 -O2 -Werror=array-bounds, and file-scoped namespaces in 4 test files).
For Agents
  • Queue placement: Rank 57 in upstream-queue (283ad7d7) · Score 69/100 (S=27, M=18, D=12, R=12) · +57/-17 (13f)
  • Verification (Apple M1 arm64, Apple Clang 17.0.0 & Homebrew GCC 16.2.0): All 7 touched suites (generic, json, json_c_arrays_and_inheritance, cli, env, xml, boost_serialization) 721/721 PASS across 4 modes — Release default (UNITY=OFF), Release CMAKE_UNITY_BUILD=ON (BATCH_SIZE=16 and BATCH_SIZE=0 single-TU), CMAKE_BUILD_TYPE=Debug (-O0 -g, __DWARF verified), and CMAKE_DISABLE_PRECOMPILE_HEADERS=ON; GCC 16.2.0 41/41 compile units across 5 GCC-buildable suites + -O2 -Wall -Werror on check_size & check_native 0 warnings; upstream-queue REFLECTCPP_JSON=OFF (xml+boost_serialization) 114/114 PASS and REFLECTCPP_JSON=ON (#258 yyjson.c isolated outside unity) 147/147 PASS.
  • Paired A/B (reflect-cpp-self JSON-5, -j4, Release, Apple Clang 17 vs. 290bdb24): Default Release wall 176.9 → 129.0 s (-27.1%), CPU 695.5 → 491.4 s (-29.3%), RSS 809 → 576 MiB (-28.8%), .o 788 → 46 MiB (-94.2%); with -DCMAKE_UNITY_BUILD=ON -DCMAKE_UNITY_BUILD_BATCH_SIZE=16 wall 67.7 s (-61.7%), CPU 245.3 s (-64.7%), RSS 709 MiB (-12.4%), .o 27 MiB (-96.6%, 340 → 28 objs).
  • Maintainer review & upstream prep: Passed 3 adversarial review cycles against maintainer-review-guide.md (dropped all 5 bespoke REFLECTCPP_TEST_* options in favor of standard CMake, dropped write_and_read.hpp from PCHs, fixed both check_bitset.hpp GCC -O2 paths, reverted 13 unbuilt format suites). Applies with 0 conflicts to origin/main (aaa991b5) and fork/upstream-queue (3d33e721); all 12 .github/workflows/ cmake -S jobs already pass -DCMAKE_BUILD_TYPE=Release. Optional: land after #258 when using -DCMAKE_UNITY_BUILD=ON with extra formats (isolates src/yyjson.c from unity batches); remaining 13 format suites are a CI-verified follow-up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant