Skip to content

Support constrained LLVM selectors with shared version expressions - #909

Closed
helly25 wants to merge 12 commits into
masterfrom
feat/version-selector-projections
Closed

helly25 wants to merge 12 commits into
masterfrom
feat/version-selector-projections

Conversation

@helly25

@helly25 helly25 commented Oct 17, 2026 •

Copy link
Copy Markdown
Collaborator

Support release-series policies such as latest:major==23, so updating the pinned toolchain catalogue can adopt LLVM 23 fixes without another exact-version edit. Keep major compiler and clang-tidy upgrades explicit, with the same requirement syntax for LLVM and linker catalogues.

AG;DR

Dependency: mboworks_bzl 0.7.0 is published in the official Bazel Central Registry; BCR #11158 is merged. The registry source metadata and MODULE.bazel are reachable and identify version 0.7.0. Its archive integrity matches the published release (sha256-sS12HYg9SX7MP15MAFoCsZtCVgax6t1RXRWD2KvpyhQ=).

Implementation:

  • Update the root bazel_dep to bzl 0.7.0 and resolve it normally through BCR. Remove the temporary bzl archive overrides and publication-pending comments from all four module roots: the repository root, tests, tests/feature_overrides, and tests/mold_module. The integration roots retain their existing local overrides of toolchains_llvm so they test this checkout. Merged Update dependency mboworks_bzl to v0.7.0 #910 already supplies the 0.7.0 WORKSPACE/archive dependency declarations; those files are outside this PR's diff.
  • Bind selector, LLVM and linker version handling with versions.with_mode("semver"). Parsing, ordering, supplied constants and nested expression calls consistently inherit SemVer mode. The macOS LLVM linker guard uses the same mode. Numeric releases compare with zero padding; prerelease identifiers retain their spelling and boundaries (rc1 differs from rc.1, and rc10 precedes rc2 lexically).
  • Export one immutable version_selectors namespace. LLVM prerelease call sites invoke its method directly. Export the bound library parser directly too: no local comma splitting or second expression parser. This preserves quoted commas while the shared parser rejects genuinely empty clauses.
  • Delegate requirement operators to bzl: ordered/exact comparisons, compatible (~=), negated compatible (!~=), trailing-prefix matching/exclusion (==23.1.* / !=23.1.*), extended compatible (~~=), and its negation (!~~=).
  • Supply per-candidate major, minor and patch constants. latest:major==23 and latest:major()==23 both work; constants and functions have independent namespaces. Support the library's allowlisted nested component/introspection calls, implied or explicit versions, literal/keyword arguments, and typed integer/boolean/text results. Expression calls cannot switch mode or evaluate arbitrary Starlark; Python-only helpers fail in SemVer mode.
  • Keep first/latest strategy separate from ANDed constraints. Selection uses the pinned checksummed catalogue, configured additions and execution-host archive availability. A toolchains_llvm upgrade that adds LLVM identifiers can therefore upgrade LLVM in the same dependency change; latest:major==23 confines this to LLVM 23. Fixed inputs and host produce a fixed selection; builds do not discover new upstream releases.
  • Preserve explicit prerelease admission for LLVM and linker catalogues: a positive, unprojected requirement must name a prerelease with the same numeric release core. Exclusions, wildcard-only bounds and introspection predicates do not themselves opt in. Exact version attributes may select named prereleases. Build metadata such as +-.rc1 does not classify a stable version as a prerelease. Fix the no-match diagnostic's sorting call.
  • Cover selectors with deterministic unit/analysis tests and synthetic Linux/macOS catalogues, including all operators, named constants/functions, invalid inputs, host-specific fallback, first/latest ordering, prerelease filtering and quoted-comma regressions. The README focuses on toolchain upgrade policy, basic selectors and prerelease admission, with links to the published bzl 0.7.0 SemVer, operator and expression/constant reference headings.

Validation of the override removal:

  • Official BCR source.json and MODULE.bazel both resolve; version and archive integrity match the released 0.7.0 artifact.
  • Bazel 9.0.0: all 39 //toolchain/... tests pass using the normal registry, with no temporary bzl override, command-line module override or additional registry URL. Valid cached test results are reused after fresh analysis.
  • Bazel 9.0.0: bazel mod graph succeeds independently in all three integration roots and each resolves mboworks_bzl@0.7.0 through the normal registry.
  • trunk fmt, trunk check --ci and git diff --check pass.
  • Current registry-based head ac4055749414b749173bdfa820f5276d4c5714c8 passes all 100 GitHub checks, including the Linux/macOS and Bazel/WORKSPACE matrices. The temporary bzl overrides are removed, and official-registry resolution is validated in CI. The branch is up to date with master and conflict-free.
  • Earlier downstream validation passes all 296 core/extra-module xff tests in one Bazel invocation using latest:major==23, selecting LLVM 23.1.3. That local check tested the current selector implementation with the published bzl archive; valid build/test cache results were reused. The host's uutils printf also fails a baseline child-argument assertion, so the passing local run puts the installed GNU printf first on the test PATH without changing source or tests. xff draft #1011 still needs the released toolchains_llvm version containing this integration and validation of that final dependency pin before merge.

Runtime remains pure Starlark; this updates an existing dependency. Catalogue availability remains host-dependent. The exact LLVM 22.1.8/compiler-runtime pairing used by the existing MSan configuration is preserved.

@helly25

helly25 commented Oct 18, 2026

Copy link
Copy Markdown
Collaborator Author

Superseded by #911, which reimplements version selection using mboworks/bzl and includes the subsequent selector and prerelease-policy improvements. Please continue review there.

@helly25 helly25 closed this Oct 18, 2026
helly25 added a commit that referenced this pull request Oct 20, 2026
…e control (#911)

Cleanup of expression-based LLVM and linker version selectors using bzl
0.8.0, with independent `llvm_version_allow_prereleases` and
`linker_version_allow_prereleases` controls. This clean redo supersedes
the closed #909.

Mainly we are using the advanced/generalized bzl 0.8.0 functionality.

NOTE: The two `*_allow_prereleases` are incompatible changes. They
replace the old magic allowance by referencing in requirements.

## AG;DR

- Share requirement parsing, SemVer comparisons, projection constants,
filtering, and first/latest selection through bzl. Restrict candidates
to compatible artifacts before selecting and preserve the chosen
artifact alongside its version.
- Both public prerelease flags default to false. Requirements always
apply; exact pins remain authoritative. The generic `allow_prereleases`
parameter exists only in internal resolver code and tests.
- Use the same environment selector expansion for LLVM and catalogued
linkers, including mold. Feature overrides inherit the flags
independently; linker-only changes preserve LLVM archive sharing.
- Replace `_version_string` with bzl `normalize_string`; existing
distribution goldens remain unchanged.
- Resolve bzl 0.8.0 directly from BCR in all four module roots, with no
temporary overrides. Both WORKSPACE declarations use the published
release archive. bazelbuild/bazel-central-registry#11173 is merged; the
release dependency is satisfied.
- Validation at synchronized head `c71ba5c`: all 45 toolchain tests
passed in Bzlmod (Bazel 9.3.0) and all 45 passed in WORKSPACE mode
(Bazel 8.8.1). All 14 Python wrapper tests and 11 distribution-script
tests passed; Trunk buildifier/prettier checks passed. The three
integration module graphs were previously validated at `1e1ea62` and
were not rerun for this sync.
- Remove the redundant distribution-version wrapper; both production
callers use the existing parser directly.
- Move all three LLVM distribution golden-output writers and their
fixtures into `llvm_distributions_test.bzl`. Production code exposes one
internal-only `testing` struct with eight helper references; existing
test targets and golden files are unchanged.
- Tests cover selector parity, prerelease pins, platform compatibility,
environment fallbacks and errors, and independent feature-override
policies. The complete bzl 0.8.0 dependency upgrade merged into master
via #912 (including #913). This branch is synchronized with upstream
master `6ceed3a`, including the dylib-linked tool wrapper fix (#914) and
LLVM 23.1.4 catalogue update (#915). The prerelease golden conflict was
resolved by preserving all expanded selector cases and updating only the
catalogue-driven expectations to 23.1.4; synthetic fixtures are
unchanged. Its diff against master contains only the selector
functionality, tests, and documentation, plus removal of an obsolete
dependency comment.

---------

Signed-off-by: helly25 <6420169+helly25@users.noreply.github.com>
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