Repository navigation
Build contracts with -Os whatever CMAKE_BUILD_TYPE the environment sets - #668
Merged
Merged
Conversation
…ment 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.
huangminghuang
approved these changes
Oct 7, 2026
huangminghuang
left a comment
Contributor
There was a problem hiding this comment.
Reviewed bb04945. No actionable findings. Verified all four contracts_target() callers and the CDT toolchain interaction. Focused CMake/CDT checks passed with Release, Debug, and unset build-type environments, including automatic correction of an existing Release cache. PR CI passed; the full project was not rebuilt locally.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Contracts always compile with the CDT toolchain's
-Os.contracts_target()now passes every contract project (the system contracts, the testing contracts and both test-contract sets) an explicit emptyCMAKE_BUILD_TYPE.Why
The contract projects are ExternalProjects and never received a build type, so a plain
cmake -DCMAKE_BUILD_TYPE=Releasetop-level build, and CI's release build, already produced-Oscontracts. But CMake 3.22+ uses aCMAKE_BUILD_TYPEenvironment variable as the default for a new cache, and the Bazel platform wrapper (wire-platform-build-systembuild_defs.bzl) exports it fromWIRE_BUILD_TYPE. A Release type appends-O3 -DNDEBUGafter the toolchain's-Os, so those builds made contracts 17-37% larger than everyone else's, with identical ABIs. Nine of the contract binaries committed in #662 came out that way (sysio.system 277,605 bytes against 202,678), and they cannot be reproduced from the standard build.An explicit
-DCMAKE_BUILD_TYPE=overrides the environment variable. WithCMAKE_BUILD_TYPE=Releaseexported, every contract project now configures with an empty build type, the system contracts rebuild byte-identical to master's, and the test contracts come out identical to a build without the variable. An existing build tree picks this up on its next build, since the changed arguments re-run the contract projects' configure.