From bb049459fe94ce3f248dd1502663c678585c95bd Mon Sep 17 00:00:00 2001 From: kevin Heifner Date: Wed, 7 Oct 2026 08:04:49 -0500 Subject: [PATCH] cmake: build contracts with -Os whatever CMAKE_BUILD_TYPE the environment sets The CDT toolchain compiles contracts with -Os. `contracts_target()` passed the contract projects no build type, so CMake 3.22+ took a `CMAKE_BUILD_TYPE` environment variable as the default for their caches, and a Release type appended `-O3 -DNDEBUG`. The Bazel platform wrapper exports that variable, so its Release builds produced contracts 17-37% larger than every other build, with the same ABIs. Pass an explicit empty build type, which overrides the environment, so every contract build gets the toolchain's -Os. --- cmake/contract-tools.cmake | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmake/contract-tools.cmake b/cmake/contract-tools.cmake index 132dd4d866..a6e8652358 100644 --- a/cmake/contract-tools.cmake +++ b/cmake/contract-tools.cmake @@ -22,6 +22,9 @@ if(BUILD_SYSTEM_CONTRACTS AND NOT CDT_BUILD) -DBUILD_TEST_CONTRACTS=${BUILD_TEST_CONTRACTS} -DCDT_BUILD=ON -DCDT_CONTRACT_INCLUDE_PATH=${CDT_CONTRACT_INCLUDE_PATH} + # Contracts build with the CDT toolchain's -Os. The explicit empty build type also overrides a + # CMAKE_BUILD_TYPE environment variable, whose Release flags would append -O3 -DNDEBUG. + -DCMAKE_BUILD_TYPE= ) if (CDT_ROOT AND EXISTS ${CDT_ROOT}/lib/cmake/cdt/cdt-config.cmake) list(APPEND CDT_CMAKE_ARGS -DCDT_ROOT=${CDT_ROOT})