Skip to content

Build contracts with -Os whatever CMAKE_BUILD_TYPE the environment sets - #668

Merged
heifner merged 1 commit into
masterfrom
fix/pin-contracts-build-type
Oct 7, 2026
Merged

heifner merged 1 commit into
masterfrom
fix/pin-contracts-build-type

Conversation

@heifner

@heifner heifner commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

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 empty CMAKE_BUILD_TYPE.

Why

The contract projects are ExternalProjects and never received a build type, so a plain cmake -DCMAKE_BUILD_TYPE=Release top-level build, and CI's release build, already produced -Os contracts. But CMake 3.22+ uses a CMAKE_BUILD_TYPE environment variable as the default for a new cache, and the Bazel platform wrapper (wire-platform-build-system build_defs.bzl) exports it from WIRE_BUILD_TYPE. A Release type appends -O3 -DNDEBUG after 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. With CMAKE_BUILD_TYPE=Release exported, 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.

…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.
@heifner
heifner requested review from a team and huangminghuang October 7, 2026 13:04

@huangminghuang huangminghuang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@heifner
heifner merged commit fa3a3fb into master Oct 7, 2026
13 checks passed
@heifner
heifner deleted the fix/pin-contracts-build-type branch October 7, 2026 14:34
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.

2 participants