Skip to content

fix: validate stage0 version matches release version - #12700

Merged
kim-em merged 6 commits into
masterfrom
kimmo/check-stage0-version
Mar 4, 2026
Merged

kim-em merged 6 commits into
masterfrom
kimmo/check-stage0-version

Conversation

@kim-em

@kim-em kim-em commented Feb 26, 2026 •

Copy link
Copy Markdown
Collaborator

This PR fixes a CMake scoping bug that made -DLEAN_VERSION_* overrides ineffective.

The version variables (LEAN_VERSION_MAJOR, MINOR, PATCH, IS_RELEASE) were declared with plain set(), which creates normal variables that shadow cache variables set by -D on the command line. The fix changes them to CACHE STRING "" to match the existing LEAN_SPECIAL_VERSION_DESC pattern.

However, CACHE STRING "" alone isn't sufficient because project(LEAN CXX C) implicitly creates empty LEAN_VERSION_{MAJOR,MINOR,PATCH} normal variables (CMake sets <PROJECT>_VERSION_* for the project name). These shadow the cache values, so we unset() them after the cache declarations to let ${VAR} fall through to the cache.

Closes #12681

🤖 Prepared with Claude Code

This PR adds a check to both `release_checklist.py` and CI to verify that
`stage0/src/CMakeLists.txt` has the same LEAN_VERSION_MAJOR and
LEAN_VERSION_MINOR as the release tag. The stage0 pre-built compiler stamps
.olean headers with its baked-in version, so a mismatch causes the release
tarball to contain .olean files with the wrong version. This happened in
v4.29.0-rc2 (#12681) because the
'begin development cycle for v4.30.0' commit bumped stage0 to 4.30.0 before
the release was cut.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@github-actions github-actions Bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Feb 26, 2026
@mathlib-lean-pr-testing

mathlib-lean-pr-testing Bot commented Feb 26, 2026 •

Copy link
Copy Markdown

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 65a0c618068bd01a933596cdb6dd3b9b482d24a8 --onto c595413fccaa47ebdc399d9b817c17425687fc26. You can force Mathlib CI using the force-mathlib-ci label. (2026-02-26 09:34:10)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 65a0c618068bd01a933596cdb6dd3b9b482d24a8 --onto 87ec768a509c45987a7d73258da0cc1ef047925c. You can force Mathlib CI using the force-mathlib-ci label. (2026-03-01 13:43:04)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase ec565f3bf7a3985b6b8592f5cb5fa063b86a0ecf --onto 87ec768a509c45987a7d73258da0cc1ef047925c. You can force Mathlib CI using the force-mathlib-ci label. (2026-03-02 03:53:25)

@leanprover-bot

leanprover-bot commented Feb 26, 2026 •

Copy link
Copy Markdown
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase 65a0c618068bd01a933596cdb6dd3b9b482d24a8 --onto 8038a8b8904f89ad9542c8eda11379f8f006eab1. You can force reference manual CI using the force-manual-ci label. (2026-02-26 09:34:12)
  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase ec565f3bf7a3985b6b8592f5cb5fa063b86a0ecf --onto 8038a8b8904f89ad9542c8eda11379f8f006eab1. You can force reference manual CI using the force-manual-ci label. (2026-03-02 03:53:26)

@Kha

Kha commented Feb 26, 2026

Copy link
Copy Markdown
Member

I don't think this is the right fix. We already set -DLEAN_VERSION_* in ci.yml which CMakeLists.txt should forward to stage 0 as well, why isn't this working?

@kim-em

kim-em commented Feb 27, 2026

Copy link
Copy Markdown
Collaborator Author

I don't think this is the right fix. We already set -DLEAN_VERSION_* in ci.yml which CMakeLists.txt should forward to stage 0 as well, why isn't this working?

@Kha, the problem was that I unwittingly pulled in a stage0 update from master (which was using MINOR=30) to the releases/v4.29.0 branch. Our existing validation doesn't guard against this.

@Kha

Kha commented Feb 27, 2026

Copy link
Copy Markdown
Member

I understand the repo state that led to this but I don't understand why the logic I described above did not lead to the stage0/ content being irrelevant here

The version variables (LEAN_VERSION_MAJOR, MINOR, PATCH, IS_RELEASE) were
declared with plain `set()`, which creates normal variables that shadow
cache variables set by `-D` flags on the command line. This made the
`-DLEAN_VERSION_*` flags passed by CI (and forwarded to stage0 via
STAGE0_ARGS) completely ineffective — the `set()` always won.

Change them to `set(... CACHE STRING "")` to match the existing pattern
used by LEAN_SPECIAL_VERSION_DESC. With CACHE STRING (no FORCE), the
value in CMakeLists.txt is the default, but `-D` flags take precedence.

Also update release_checklist.py parsing to handle the new format.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@kim-em

kim-em commented Mar 1, 2026

Copy link
Copy Markdown
Collaborator Author

You're right — the -DLEAN_VERSION_* flags are forwarded to stage0 via STAGE0_ARGS, so they should override the hardcoded values. The reason they don't is a CMake scoping issue: the version variables were declared with plain set() (no CACHE), which creates normal variables that shadow cache variables set by -D on the command line. So the forwarded flags were dead code.

Contrast with LEAN_SPECIAL_VERSION_DESC which uses CACHE STRING — that's why the -rc2 suffix was applied correctly while the major/minor/patch numbers weren't (the .olean files were stamped 4.30.0-rc2).

I've pushed a fix that changes the version set() calls to use CACHE STRING "" to match LEAN_SPECIAL_VERSION_DESC. The CI validation is kept as belt-and-suspenders.

@kim-em
kim-em enabled auto-merge March 1, 2026 21:13
@kim-em
kim-em added this pull request to the merge queue Mar 1, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Mar 1, 2026
@Kha

Kha commented Mar 2, 2026

Copy link
Copy Markdown
Member

Thanks!

project(LEAN CXX C) implicitly creates empty LEAN_VERSION_{MAJOR,MINOR,PATCH}
normal variables (CMake sets <PROJECT>_VERSION_* for the project name). These
shadow the CACHE STRING values, making ${VAR} resolve to empty instead of
falling through to the cache. unset() them after the cache declarations.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

@Kha Kha left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Wait, why does the unnecessary validation code still exist then?

@kim-em

kim-em commented Mar 2, 2026 •

Copy link
Copy Markdown
Collaborator Author

Wait, why does the unnecessary validation code still exist then?

Belt and suspenders? I like defense in depth for CI/release stuff, having been burnt so many times. Happy to remove if you prefer.

The CACHE STRING fix (with unset workaround) makes -DLEAN_VERSION_*
overrides work correctly, so stage0's hardcoded version is always
overridden by CI. The validation is no longer needed.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@kim-em

kim-em commented Mar 4, 2026

Copy link
Copy Markdown
Collaborator Author

Wait, why does the unnecessary validation code still exist then?

Belt and suspenders? I like defense in depth for CI/release stuff, having been burnt so many times. Happy to remove if you prefer.

I've now removed the extra validation, and will merge.

@kim-em
kim-em enabled auto-merge March 4, 2026 01:17
@kim-em
kim-em added this pull request to the merge queue Mar 4, 2026
Merged via the queue into master with commit f375286 Mar 4, 2026
15 checks passed
github-merge-queue Bot pushed a commit that referenced this pull request Mar 4, 2026
This PR fixes a parsing bug in \`release_checklist.py\` introduced by
#12700, which reformatted
\`src/CMakeLists.txt\` to use \`CACHE STRING \"\"\`:

\`\`\`cmake
set(LEAN_VERSION_MINOR 30 CACHE STRING "")
\`\`\`

The old code used \`split()[-1].rstrip(")")\` to extract the version
number, which now yields \`""\` (the empty string argument) instead of
the minor version. Use a regex to extract the digit directly.

🤖 Prepared with Claude Code

Co-authored-by: Claude Sonnet 4.6 <[email protected]>
stepbrobd pushed a commit to stepbrobd/lean4 that referenced this pull request Oct 13, 2026
This PR switches normal and nightly releases to use stage2 binaries
instead of stage1, meaning that we no longer ship oleans built by
stage0. Because of this, we no longer need to override stage0's version
number and special description since they no longer end up in the
resulting binaries, effectively reverting leanprover#12700 and simplifying our
build setup. Non-release builds continue to use the original stage1
setup for resource/performance reasons.

This change may also help with caching around stage0, and during
development since the version numbers are no longer "sticky" (i.e. stuck
to the values that the build directory was originally created with).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog-other toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v4.29.0-rc2: all .olean files in release tarball are stamped with version 4.30.0-rc2 instead of 4.29.0-rc2

3 participants