Skip to content

Commit d14cc18

Browse files
committed
refactor: derive rustc commit from toolchain, inline format args
Drop the [metadata] section from rust-toolchain.toml; the UI test scripts now derive the rustc commit hash directly from the nightly date via the Rust manifest. Also fixes clippy uninlined_format_args warnings.
1 parent 102122a commit d14cc18

5 files changed

Lines changed: 93 additions & 40 deletions

File tree

.github/workflows/test.yml

Lines changed: 63 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,31 @@ jobs:
2222
ref: ${{ github.event.pull_request.head.sha }}
2323
submodules: recursive
2424

25+
- name: Install yq
26+
run: |
27+
set -euo pipefail
28+
YQ_VERSION="v4.52.4"
29+
mkdir -p "$HOME/.local/bin"
30+
wget -qO "$HOME/.local/bin/yq" \
31+
"https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64"
32+
chmod +x "$HOME/.local/bin/yq"
33+
echo "$HOME/.local/bin" >> $GITHUB_PATH
34+
35+
- name: 'Read nightly channel from rust-toolchain.toml'
36+
id: toolchain-meta
37+
run: |
38+
set -euo pipefail
39+
CHANNEL=$(yq -r '.toolchain.channel' rust-toolchain.toml)
40+
if [ -z "$CHANNEL" ] || [ "$CHANNEL" = "null" ]; then
41+
echo "::error::Could not read toolchain.channel from rust-toolchain.toml"
42+
exit 1
43+
fi
44+
echo "channel=$CHANNEL" >> "$GITHUB_OUTPUT"
45+
2546
- name: "Set up nightly Rust" # https://github.com/rust-lang/rustup/issues/3409
2647
uses: dtolnay/rust-toolchain@master
2748
with:
28-
toolchain: nightly-2024-11-29 # Hardcoded version, same as is in the build.rs
49+
toolchain: ${{ steps.toolchain-meta.outputs.channel }}
2950

3051
- name: 'Build stable-mir-json' # rustfmt documentation claims it is unstable on code that doesn't build
3152
run: |
@@ -66,10 +87,31 @@ jobs:
6687
ref: ${{ github.event.pull_request.head.sha }}
6788
submodules: recursive
6889

90+
- name: Install yq
91+
run: |
92+
set -euo pipefail
93+
YQ_VERSION="v4.52.4"
94+
mkdir -p "$HOME/.local/bin"
95+
wget -qO "$HOME/.local/bin/yq" \
96+
"https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64"
97+
chmod +x "$HOME/.local/bin/yq"
98+
echo "$HOME/.local/bin" >> $GITHUB_PATH
99+
100+
- name: 'Read nightly channel from rust-toolchain.toml'
101+
id: toolchain-meta
102+
run: |
103+
set -euo pipefail
104+
CHANNEL=$(yq -r '.toolchain.channel' rust-toolchain.toml)
105+
if [ -z "$CHANNEL" ] || [ "$CHANNEL" = "null" ]; then
106+
echo "::error::Could not read toolchain.channel from rust-toolchain.toml"
107+
exit 1
108+
fi
109+
echo "channel=$CHANNEL" >> "$GITHUB_OUTPUT"
110+
69111
- name: "Set up nightly Rust" # https://github.com/rust-lang/rustup/issues/3409
70112
uses: dtolnay/rust-toolchain@master
71113
with:
72-
toolchain: nightly-2024-11-29 # Hardcoded version, same as is in the build.rs
114+
toolchain: ${{ steps.toolchain-meta.outputs.channel }}
73115

74116
- name: 'Build stable-mir-json'
75117
run: | # Warning check should be redundant since code-quality runs first
@@ -108,16 +150,30 @@ jobs:
108150
"https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64"
109151
chmod +x "$HOME/.local/bin/yq"
110152
echo "$HOME/.local/bin" >> $GITHUB_PATH
111-
yq --version
112153
154+
- name: 'Read nightly channel from rust-toolchain.toml'
155+
id: toolchain-meta
156+
run: |
157+
set -euo pipefail
158+
CHANNEL=$(yq -r '.toolchain.channel' rust-toolchain.toml)
159+
if [ -z "$CHANNEL" ] || [ "$CHANNEL" = "null" ]; then
160+
echo "::error::Could not read toolchain.channel from rust-toolchain.toml"
161+
exit 1
162+
fi
163+
echo "channel=$CHANNEL" >> "$GITHUB_OUTPUT"
164+
165+
- name: "Set up nightly Rust" # https://github.com/rust-lang/rustup/issues/3409
166+
uses: dtolnay/rust-toolchain@master
167+
with:
168+
toolchain: ${{ steps.toolchain-meta.outputs.channel }}
113169

114-
- name: 'Read rustc commit from rust-toolchain.toml'
170+
- name: 'Derive rustc commit and check out Rust repo'
115171
id: rustc-meta
116172
run: |
117173
set -euo pipefail
118-
COMMIT=$(yq '.metadata.rustc-commit' rust-toolchain.toml)
119-
if [ -z "$COMMIT" ] || [ "$COMMIT" = "null" ]; then
120-
echo "::error::metadata.rustc-commit not found in rust-toolchain.toml"
174+
COMMIT=$(rustc -vV | grep 'commit-hash' | cut -d' ' -f2)
175+
if [ -z "$COMMIT" ]; then
176+
echo "::error::Could not determine rustc commit-hash from 'rustc -vV'"
121177
exit 1
122178
fi
123179
echo "rustc-commit=$COMMIT" >> "$GITHUB_OUTPUT"
@@ -130,11 +186,6 @@ jobs:
130186
path: rust
131187
fetch-depth: 1
132188

133-
- name: "Set up nightly Rust" # https://github.com/rust-lang/rustup/issues/3409
134-
uses: dtolnay/rust-toolchain@master
135-
with:
136-
toolchain: nightly-2024-11-29 # Hardcoded version, same as is in the build.rs
137-
138189
- name: 'Build stable-mir-json'
139190
run: | # Warning check should be redundant since code-quality runs first
140191
RUSTFLAGS='--deny warnings' cargo build -vv

rust-toolchain.toml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
11
[toolchain]
22
channel = "nightly-2024-11-29"
33
components = ["llvm-tools", "rustc-dev", "rust-src", "rust-analyzer"]
4-
5-
# Ignored by rustup; used by our test scripts.
6-
# This is the rustc commit that backs the nightly above.
7-
# UI test scripts automatically checkout this commit in RUST_DIR_ROOT.
8-
[metadata]
9-
rustc-commit = "a2545fd6fc66b4323f555223a860c451885d1d2b"

src/printer/items.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ pub(super) fn mk_item(tcx: TyCtxt<'_>, item: MonoItem, sym_name: String) -> (Mon
101101
Ok(alloc) => Some(alloc),
102102
err => {
103103
eprintln!(
104-
"StaticDef({:#?}).eval_initializer() failed with: {:#?}",
105-
static_def, err
104+
"StaticDef({static_def:#?}).eval_initializer() failed with: {err:#?}"
106105
);
107106
None
108107
}
@@ -125,7 +124,7 @@ pub(super) fn mk_item(tcx: TyCtxt<'_>, item: MonoItem, sym_name: String) -> (Mon
125124
)
126125
}
127126
MonoItem::GlobalAsm(ref asm) => {
128-
let asm_str = format!("{:#?}", asm);
127+
let asm_str = format!("{asm:#?}");
129128
(
130129
item,
131130
Item::new(

src/printer/schema.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,10 @@ impl AllocMap {
118118

119119
assert!(
120120
missing_from_map.is_empty(),
121-
"Alloc-id coherence violation: AllocIds {:?} are referenced in \
121+
"Alloc-id coherence violation: AllocIds {missing_from_map:?} are referenced in \
122122
stored Item bodies but missing from the alloc map. This means \
123123
the analysis phase collected allocations from a different body \
124-
than what is stored in the Items.",
125-
missing_from_map
124+
than what is stored in the Items."
126125
);
127126

128127
assert!(

tests/ui/ensure_rustc_commit.sh

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22
#
33
# Ensures a rust checkout (regular or bare+worktree) is at the commit
4-
# specified in rust-toolchain.toml's [metadata] rustc-commit field.
4+
# that backs the active nightly toolchain (derived from `rustc -vV`).
55
#
66
# Usage: source this script after setting RUST_DIR to the repo root.
77
# It sets RUST_SRC_DIR to the directory containing the source files
@@ -11,21 +11,11 @@ set -u
1111

1212
: "${RUST_DIR:?RUST_DIR must be set before sourcing ensure_rustc_commit.sh}"
1313

14-
# Require yq (mikefarah/yq) for TOML parsing
15-
if ! command -v yq &> /dev/null; then
16-
echo "Error: yq is required but not installed."
17-
echo "Install via: brew install yq | apt install yq | nix shell nixpkgs#yq-go"
18-
echo "See: https://github.com/mikefarah/yq#install"
19-
exit 1
20-
fi
21-
22-
_SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
23-
_REPO_ROOT=$( cd -- "$_SCRIPT_DIR/../.." &> /dev/null && pwd )
24-
25-
# Read the expected rustc commit from rust-toolchain.toml
26-
RUSTC_COMMIT=$(yq -r '.metadata.rustc-commit' "$_REPO_ROOT/rust-toolchain.toml")
27-
if [ -z "$RUSTC_COMMIT" ] || [ "$RUSTC_COMMIT" = "null" ]; then
28-
echo "Error: Could not read metadata.rustc-commit from $_REPO_ROOT/rust-toolchain.toml"
14+
# Derive the rustc commit from the active toolchain; rust-toolchain.toml
15+
# selects the nightly, so this stays in sync automatically.
16+
RUSTC_COMMIT=$(rustc -vV | grep 'commit-hash' | cut -d' ' -f2)
17+
if [ -z "$RUSTC_COMMIT" ]; then
18+
echo "Error: Could not determine rustc commit-hash from 'rustc -vV'"
2919
exit 1
3020
fi
3121

@@ -48,6 +38,16 @@ if [ "$IS_BARE" = "true" ]; then
4838
exit 1
4939
fi
5040
else
41+
# Ensure the commit is available locally; fetch if needed.
42+
if ! git -C "$RUST_DIR" cat-file -e "$RUSTC_COMMIT" 2>/dev/null; then
43+
echo "Commit ${SHORT_COMMIT} not found locally; fetching..."
44+
git -C "$RUST_DIR" fetch origin "$RUSTC_COMMIT" --quiet 2>/dev/null || \
45+
git -C "$RUST_DIR" fetch origin --quiet || {
46+
echo "Error: Could not fetch commit ${RUSTC_COMMIT}."
47+
echo "Ensure ${RUST_DIR} is a clone of https://github.com/rust-lang/rust"
48+
exit 1
49+
}
50+
fi
5151
echo "Creating worktree at ${WORKTREE_DIR} for commit ${SHORT_COMMIT}..."
5252
git -C "$RUST_DIR" worktree add "$WORKTREE_DIR" "$RUSTC_COMMIT" --detach --quiet || {
5353
echo "Error: Failed to create worktree for commit ${RUSTC_COMMIT} in ${RUST_DIR}"
@@ -59,6 +59,16 @@ else
5959
# Regular repo: checkout the commit directly
6060
CURRENT_COMMIT=$(git -C "$RUST_DIR" rev-parse HEAD 2>/dev/null)
6161
if [ "${CURRENT_COMMIT}" != "${RUSTC_COMMIT}" ]; then
62+
# Ensure the commit is available locally; fetch if needed.
63+
if ! git -C "$RUST_DIR" cat-file -e "$RUSTC_COMMIT" 2>/dev/null; then
64+
echo "Commit ${SHORT_COMMIT} not found locally; fetching..."
65+
git -C "$RUST_DIR" fetch origin "$RUSTC_COMMIT" --quiet 2>/dev/null || \
66+
git -C "$RUST_DIR" fetch origin --quiet || {
67+
echo "Error: Could not fetch commit ${RUSTC_COMMIT}."
68+
echo "Ensure ${RUST_DIR} is a clone of https://github.com/rust-lang/rust"
69+
exit 1
70+
}
71+
fi
6272
echo "Checking out rustc commit ${SHORT_COMMIT} in ${RUST_DIR}..."
6373
git -C "$RUST_DIR" checkout "$RUSTC_COMMIT" --quiet || {
6474
echo "Error: Failed to checkout commit ${RUSTC_COMMIT} in ${RUST_DIR}"

0 commit comments

Comments
 (0)