From 5612b2dfd4c7ec17835a7294ab8891dbf4bdcbc0 Mon Sep 17 00:00:00 2001 From: aiongg Date: Fri, 20 Nov 2026 04:14:10 +0000 Subject: [PATCH] ci: pin the toolchain in rust-toolchain.toml The file is the one source: the jobs install what it names through craft-common-actions' rust-channel action, and the nightly run opens a pull request that changes only the file when a newer stable exists. Part of #15711 --- .github/workflows/ci.yml | 114 +++++++++++++++++++++++------ .github/workflows/perf-nightly.yml | 9 ++- docs/development.md | 2 +- rust-toolchain.toml | 8 ++ scripts/ci-toolchain-bump.py | 65 ++++++++++++++++ scripts/test-ci-toolchain-bump.py | 29 ++++++++ scripts/test-ci-toolchain-pin.py | 32 -------- 7 files changed, 201 insertions(+), 58 deletions(-) create mode 100644 rust-toolchain.toml create mode 100644 scripts/ci-toolchain-bump.py create mode 100644 scripts/test-ci-toolchain-bump.py delete mode 100644 scripts/test-ci-toolchain-pin.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 561c75e875..ea8e7a9a9b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,12 +57,6 @@ permissions: env: CARGO_TERM_COLOR: always - # The Rust release every job builds with. A release that came out overnight must not start a cold - # build in every cache key (the key holds `rustc -vV`); a change to this value is the one cold - # day, reviewed as any change. The gate calls below carry the same value (their `env` is not this - # one), and scripts/test-ci-toolchain-pin.py checks that they agree. The name stays outside the - # prefixes rust-cache hashes into its keys. - TOOLCHAIN_PIN: "1.100.0" RUST_BACKTRACE: 1 PHOTOCRAFT_FULL_SWEEP: ${{ inputs.full_sweep && '1' || '0' }} # No test or fuzz run may print a page: the engine refuses to spool, and if something ever @@ -173,8 +167,6 @@ jobs: # Tracks @main so suite-wide CI fixes reach every app without a PR in each repository. uses: storytold/craft-common-actions/.github/workflows/gate.yml@main with: - # TOOLCHAIN_PIN (the called workflow does not see this file's `env`). - toolchain: "1.100.0" # egui/winit/rfd. packages: >- libxkbcommon-dev libwayland-dev libx11-dev libxrandr-dev libxi-dev libgl1-mesa-dev @@ -199,7 +191,7 @@ jobs: # fmt, egui-fork, clippy, layers, panel-commands, scorecard, the wasm32 check and the # missing-translations report (`cargo xtask ci lint`, xtask/src/main.rs), and the CI scripts' # own tests. - lint-command: python3 scripts/test-ci-gpu-lavapipe.py && python3 scripts/test-ci-windows-gpu-tests.py && python3 scripts/test-ci-test-times.py && python3 scripts/test-ci-toolchain-pin.py && cargo xtask ci lint + lint-command: python3 scripts/test-ci-gpu-lavapipe.py && python3 scripts/test-ci-windows-gpu-tests.py && python3 scripts/test-ci-test-times.py && python3 scripts/test-ci-toolchain-bump.py && cargo xtask ci lint archive-command: cargo xtask ci archive --gpu-shard after-archive-command: cargo xtask ci doctest test-shards: 4 @@ -224,8 +216,6 @@ jobs: uses: storytold/craft-common-actions/.github/workflows/gate.yml@main with: os: '["windows-latest"]' - # TOOLCHAIN_PIN. - toolchain: "1.100.0" lint-cache: false # The all-language UI tests shape real Japanese, Chinese, Korean and Devanagari labels with # kittest's strict `MissingGlyphPolicy::Panic`, and a hosted Windows image has no guaranteed @@ -333,9 +323,13 @@ jobs: libxkbcommon-dev libwayland-dev libx11-dev libxrandr-dev libxi-dev libgl1-mesa-dev libgtk-3-dev + - id: rust + uses: storytold/craft-common-actions/actions/rust-channel@main - uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0 with: - toolchain: ${{ env.TOOLCHAIN_PIN }} + toolchain: ${{ steps.rust.outputs.toolchain }} + targets: ${{ steps.rust.outputs.targets }} + components: ${{ steps.rust.outputs.components }} # The gate's own key (the shared action computes it), restore only. The toolchain action # exports CARGO_HOME, which the gate's legs do not have; align-environment leaves it out of @@ -378,9 +372,13 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false + - id: rust + uses: storytold/craft-common-actions/actions/rust-channel@main - uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0 with: - toolchain: ${{ env.TOOLCHAIN_PIN }} + toolchain: ${{ steps.rust.outputs.toolchain }} + targets: ${{ steps.rust.outputs.targets }} + components: ${{ steps.rust.outputs.components }} - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 with: prefix-key: v1-rust @@ -421,10 +419,13 @@ jobs: - name: Check out craft-i18n uses: storytold/craft-common-actions/actions/checkout-craft-i18n@main + - id: rust + uses: storytold/craft-common-actions/actions/rust-channel@main - uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0 with: - toolchain: ${{ env.TOOLCHAIN_PIN }} - targets: wasm32-unknown-unknown + toolchain: ${{ steps.rust.outputs.toolchain }} + targets: ${{ steps.rust.outputs.targets }} + components: ${{ steps.rust.outputs.components }} - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 with: prefix-key: v1-rust @@ -469,6 +470,9 @@ jobs: # Placeholder: manual trigger only until a nightly schedule is enabled. if: github.event_name == 'workflow_dispatch' && inputs.fuzz runs-on: ubuntu-latest + env: + # cargo-fuzz needs nightly; the checkout's rust-toolchain.toml would pick the pinned release. + RUSTUP_TOOLCHAIN: nightly strategy: fail-fast: false matrix: @@ -540,9 +544,13 @@ jobs: packages: >- libxkbcommon-dev libwayland-dev libx11-dev libxrandr-dev libxi-dev libgl1-mesa-dev libgtk-3-dev + - id: rust + uses: storytold/craft-common-actions/actions/rust-channel@main - uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0 with: - toolchain: ${{ env.TOOLCHAIN_PIN }} + toolchain: ${{ steps.rust.outputs.toolchain }} + targets: ${{ steps.rust.outputs.targets }} + components: ${{ steps.rust.outputs.components }} - name: Compare exact outputs and release timings on 24 MP run: | set -o pipefail @@ -573,9 +581,13 @@ jobs: packages: >- libxkbcommon-dev libwayland-dev libx11-dev libxrandr-dev libxi-dev libgl1-mesa-dev libgtk-3-dev + - id: rust + uses: storytold/craft-common-actions/actions/rust-channel@main - uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0 with: - toolchain: ${{ env.TOOLCHAIN_PIN }} + toolchain: ${{ steps.rust.outputs.toolchain }} + targets: ${{ steps.rust.outputs.targets }} + components: ${{ steps.rust.outputs.components }} - name: Compare exact outputs and release timings on 36 MP run: | set -o pipefail @@ -605,9 +617,13 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false + - id: rust + uses: storytold/craft-common-actions/actions/rust-channel@main - uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0 with: - toolchain: ${{ env.TOOLCHAIN_PIN }} + toolchain: ${{ steps.rust.outputs.toolchain }} + targets: ${{ steps.rust.outputs.targets }} + components: ${{ steps.rust.outputs.components }} # perf-nightly.yml's entry (same key and runner); only that job saves it. - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 with: @@ -638,9 +654,13 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false + - id: rust + uses: storytold/craft-common-actions/actions/rust-channel@main - uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0 with: - toolchain: ${{ env.TOOLCHAIN_PIN }} + toolchain: ${{ steps.rust.outputs.toolchain }} + targets: ${{ steps.rust.outputs.targets }} + components: ${{ steps.rust.outputs.components }} - name: Compare exact outputs and release timings on 36 MP run: | set -o pipefail @@ -671,9 +691,13 @@ jobs: persist-credentials: false ref: ${{ inputs.brush_tip_base }} path: before + - id: rust + uses: storytold/craft-common-actions/actions/rust-channel@main - uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0 with: - toolchain: ${{ env.TOOLCHAIN_PIN }} + toolchain: ${{ steps.rust.outputs.toolchain }} + targets: ${{ steps.rust.outputs.targets }} + components: ${{ steps.rust.outputs.components }} - name: Build the same benchmark against both versions run: | cp after/crates/paint/examples/big_dab_bench.rs before/crates/paint/examples/big_dab_bench.rs @@ -722,9 +746,13 @@ jobs: git worktree add --detach "$RUNNER_TEMP/photocraft-baseline" "$base" mkdir -p "$RUNNER_TEMP/photocraft-baseline/crates/engine/examples" cp crates/engine/examples/bench_dry_mixer.rs "$RUNNER_TEMP/photocraft-baseline/crates/engine/examples/bench_dry_mixer.rs" + - id: rust + uses: storytold/craft-common-actions/actions/rust-channel@main - uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0 with: - toolchain: ${{ env.TOOLCHAIN_PIN }} + toolchain: ${{ steps.rust.outputs.toolchain }} + targets: ${{ steps.rust.outputs.targets }} + components: ${{ steps.rust.outputs.components }} - name: Install Linux build dependencies uses: storytold/craft-common-actions/actions/install-apt-packages@main with: @@ -757,3 +785,47 @@ jobs: with: name: dry-mixer-performance path: dry-mixer-perf.txt + + # After the nightly cold run passes, a newer stable Rust release gets a pull request that changes + # only rust-toolchain.toml (a file the workflow token may change; it may not change workflow + # files). Pull requests the token opens start no checks, so the branch also gets a dispatched run + # of this workflow, which runs the whole gate on it. A failed step warns: tomorrow's run tries again. + toolchain-bump: + name: toolchain bump + needs: gate + if: github.event_name == 'schedule' && needs.gate.result == 'success' + runs-on: ubuntu-24.04 + timeout-minutes: 10 + continue-on-error: true + permissions: + contents: write + pull-requests: write + actions: write + steps: + - name: Harden runner + uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 + with: + egress-policy: audit + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - name: Open the bump pull request + env: + GH_TOKEN: ${{ github.token }} + run: | + set -euo pipefail + version=$(python3 scripts/ci-toolchain-bump.py) + if [ -z "$version" ]; then + echo "rust-toolchain.toml is current" + exit 0 + fi + branch="toolchain-$version" + if [ -n "$(gh pr list --head "$branch" --state all --json number --jq '.[].number')" ]; then + echo "$branch already has a pull request" + exit 0 + fi + python3 scripts/ci-toolchain-bump.py --write "$version" + git -c user.name=github-actions -c user.email=41898282+github-actions[bot]@users.noreply.github.com \ + commit -q -m "Build with Rust $version" rust-toolchain.toml + git push origin "HEAD:refs/heads/$branch" + gh pr create --head "$branch" --base main --title "Build with Rust $version" \ + --body "Moves rust-toolchain.toml to Rust $version, the newest stable release. A pull request opened with the workflow token starts no checks; the run dispatched on this branch is its check. The first main run after the merge builds cold once." + gh workflow run ci.yml --ref "$branch" diff --git a/.github/workflows/perf-nightly.yml b/.github/workflows/perf-nightly.yml index 314589c417..50db0066d7 100644 --- a/.github/workflows/perf-nightly.yml +++ b/.github/workflows/perf-nightly.yml @@ -35,9 +35,6 @@ concurrency: env: CARGO_TERM_COLOR: always - # ci.yml's TOOLCHAIN_PIN: the quick performance suite there restores this workflow's cache entry, whose key - # holds the Rust release. - TOOLCHAIN_PIN: "1.100.0" jobs: perf: @@ -54,9 +51,13 @@ jobs: with: persist-credentials: false + - id: rust + uses: storytold/craft-common-actions/actions/rust-channel@main - uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0 with: - toolchain: ${{ env.TOOLCHAIN_PIN }} + toolchain: ${{ steps.rust.outputs.toolchain }} + targets: ${{ steps.rust.outputs.targets }} + components: ${{ steps.rust.outputs.components }} - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 with: diff --git a/docs/development.md b/docs/development.md index bd62ca10e1..796e58f6ee 100644 --- a/docs/development.md +++ b/docs/development.md @@ -2,7 +2,7 @@ ## Prerequisites -- Rust stable (1.95+). Add the web target with `rustup target add wasm32-unknown-unknown`. +- Rust: `rust-toolchain.toml` names the release CI builds with, and rustup installs it with the web target on first use (`rust-version` in Cargo.toml is the oldest release the sources support, 1.95). - macOS, Windows or Linux. On Linux, install the windowing, GL and GTK development packages: - Debian/Ubuntu: `sudo apt install libxkbcommon-dev libwayland-dev libx11-dev libxrandr-dev libxi-dev libgl1-mesa-dev libgtk-3-dev` - Fedora/RHEL: `sudo dnf install libxkbcommon-devel wayland-devel libX11-devel libXrandr-devel libXi-devel mesa-libGL-devel gtk3-devel` diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000000..0e0c1ccbf1 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,8 @@ +# The Rust release CI and contributors build with. One release means a new Rust release does not +# start a cold build in every cache key (they hold `rustc -vV`). The nightly CI run opens a pull +# request that changes only `channel` when a newer stable exists (scripts/ci-toolchain-bump.py). +# `rust-version` in Cargo.toml is the oldest release the sources support. +[toolchain] +channel = "1.100.0" +components = ["clippy", "rustfmt"] +targets = ["wasm32-unknown-unknown"] diff --git a/scripts/ci-toolchain-bump.py b/scripts/ci-toolchain-bump.py new file mode 100644 index 0000000000..41bbca05ce --- /dev/null +++ b/scripts/ci-toolchain-bump.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python3 +"""Moves rust-toolchain.toml to the newest stable Rust release. + + python3 scripts/ci-toolchain-bump.py prints the newest stable release when it is newer than the file's + python3 scripts/ci-toolchain-bump.py --write V sets the file's channel to V + +CI's nightly run (ci.yml `toolchain-bump`) runs both and opens a pull request that changes only +rust-toolchain.toml. Prints nothing when the file is current. +""" + +import re +import sys +import tomllib +import urllib.request +from pathlib import Path + +FILE = Path(__file__).resolve().parent.parent / 'rust-toolchain.toml' +MANIFEST = 'https://static.rust-lang.org/dist/channel-rust-stable.toml' +CHANNEL = re.compile(r'^(channel\s*=\s*")([^"]*)(")', re.M) +RELEASE = re.compile(r'^\d+\.\d+\.\d+$') + + +def numbers(version): + return tuple(int(part) for part in version.split('.')) + + +def current(text): + return tomllib.loads(text)['toolchain']['channel'] + + +def latest(manifest_text): + """`1.101.0` from the stable manifest's `[pkg.rust] version = "1.101.0 ( )"`.""" + version = tomllib.loads(manifest_text)['pkg']['rust']['version'].split()[0] + if not RELEASE.match(version): + raise ValueError(f'unexpected stable version {version!r}') + return version + + +def newer(file_text, manifest_text): + """The stable release when it is newer than the file's channel (a `1.x.y` release), else None.""" + pinned = current(file_text) + stable = latest(manifest_text) + if RELEASE.match(pinned) and numbers(stable) <= numbers(pinned): + return None + return stable + + +def with_channel(file_text, version): + if not RELEASE.match(version): + raise ValueError(f'not a release: {version!r}') + return CHANNEL.sub(lambda m: m.group(1) + version + m.group(3), file_text, count=1) + + +def main(argv): + if argv[:1] == ['--write']: + FILE.write_text(with_channel(FILE.read_text(), argv[1])) + return + with urllib.request.urlopen(MANIFEST, timeout=30) as response: + stable = newer(FILE.read_text(), response.read().decode()) + if stable: + print(stable) + + +if __name__ == '__main__': + main(sys.argv[1:]) diff --git a/scripts/test-ci-toolchain-bump.py b/scripts/test-ci-toolchain-bump.py new file mode 100644 index 0000000000..3c467c5f57 --- /dev/null +++ b/scripts/test-ci-toolchain-bump.py @@ -0,0 +1,29 @@ +from importlib.machinery import SourceFileLoader +from pathlib import Path +import unittest + +bump = SourceFileLoader('bump', str(Path(__file__).with_name('ci-toolchain-bump.py'))).load_module() + +FILE = '# note\n[toolchain]\nchannel = "1.100.0"\ncomponents = ["clippy"]\n' + + +def manifest(version): + return f'[pkg.rust]\nversion = "{version} (0ef1bc386 2026-11-09)"\n' + + +class TestBump(unittest.TestCase): + def test_a_newer_stable_is_reported_and_the_same_or_older_is_not(self): + self.assertEqual(bump.newer(FILE, manifest('1.101.0')), '1.101.0') + self.assertEqual(bump.newer(FILE, manifest('1.110.0')), '1.110.0') + self.assertIsNone(bump.newer(FILE, manifest('1.100.0'))) + self.assertIsNone(bump.newer(FILE, manifest('1.99.2'))) + + def test_a_pin_that_is_not_a_release_moves_to_stable(self): + self.assertEqual(bump.newer(FILE.replace('1.100.0', 'stable'), manifest('1.100.0')), '1.100.0') + + def test_writing_changes_only_the_channel(self): + self.assertEqual(bump.with_channel(FILE, '1.101.0'), FILE.replace('1.100.0', '1.101.0')) + + +if __name__ == '__main__': + unittest.main() diff --git a/scripts/test-ci-toolchain-pin.py b/scripts/test-ci-toolchain-pin.py deleted file mode 100644 index 46978c2779..0000000000 --- a/scripts/test-ci-toolchain-pin.py +++ /dev/null @@ -1,32 +0,0 @@ -"""ci.yml and perf-nightly.yml build every job with one Rust release: TOOLCHAIN_PIN, and the gate calls' `toolchain`.""" -from pathlib import Path -import re -import unittest - -WORKFLOWS = Path(__file__).resolve().parent.parent / '.github' / 'workflows' -CI = WORKFLOWS / 'ci.yml' -PERF = WORKFLOWS / 'perf-nightly.yml' - - -class TestToolchainPin(unittest.TestCase): - def setUp(self): - self.text = CI.read_text() - - def test_the_gate_calls_use_the_pinned_release(self): - pin = re.search(r'^ TOOLCHAIN_PIN: "([^"]+)"$', self.text, re.M) - self.assertIsNotNone(pin, 'ci.yml sets no TOOLCHAIN_PIN') - calls = re.findall(r'^ toolchain: "([^"]+)"$', self.text, re.M) - self.assertEqual(calls, [pin.group(1)] * 2, 'the Linux and Windows gate calls must name the pin') - - def test_perf_nightly_uses_the_same_release(self): - pins = [re.search(r'^ TOOLCHAIN_PIN: "([^"]+)"$', t, re.M) for t in (self.text, PERF.read_text())] - self.assertTrue(all(pins), 'a workflow sets no TOOLCHAIN_PIN') - self.assertEqual(pins[0].group(1), pins[1].group(1)) - - def test_no_job_installs_a_floating_stable(self): - self.assertNotIn('toolchain: stable', self.text) - self.assertNotIn('toolchain: stable', PERF.read_text()) - - -if __name__ == '__main__': - unittest.main()