Skip to content

Commit f5c85ce

Browse files
committed
fix(configs): sync devcontainer.json RUST_VERSION in
sync-rustc-version.sh
1 parent 1a685b5 commit f5c85ce

2 files changed

Lines changed: 52 additions & 6 deletions

File tree

.devcontainer/devcontainer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
"hostRequirements": {
44
"cpus": 4,
55
"memory": "16gb",
6-
"storage": "32gb"
6+
"storage": "64gb"
77
},
88
"build": {
99
"dockerfile": "Dockerfile",
10-
"context": "..",
10+
"context": ".."
1111
},
1212
"features": {
1313
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {

scripts/ci/sync-rustc-version.sh

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,61 @@ for dockerfile in $DOCKERFILES; do
182182
fi
183183
done
184184

185+
# ── devcontainer.json ──────────────────────────────────────────────
186+
#
187+
# devcontainer.json's `build.args` key is passed by VS Code as
188+
# `docker build --build-arg` and overrides the default value of
189+
# `ARG RUST_VERSION=1.96` in `.devcontainer/Dockerfile`. When the key
190+
# is absent the Dockerfile's ARG default wins and no sync is needed.
191+
# When present it must match rust-toolchain.toml, otherwise the
192+
# devcontainer image can silently drift from the pinned toolchain.
193+
DEVCONTAINER_JSON=".devcontainer/devcontainer.json"
194+
195+
check_devcontainer_json() {
196+
if [ ! -f "$DEVCONTAINER_JSON" ]; then
197+
return 0
198+
fi
199+
200+
local current_version
201+
current_version=$(jq -r '(.build.args.RUST_VERSION // .build.args.rust_version // "")' "$DEVCONTAINER_JSON" 2>/dev/null || true)
202+
if [ -z "$current_version" ] || [ "$current_version" = "null" ]; then
203+
return 0
204+
fi
205+
206+
TOTAL_FILES=$((TOTAL_FILES + 1))
207+
208+
if [ "$MODE" = "check" ]; then
209+
if [ "$current_version" != "$RUST_VERSION_SHORT" ]; then
210+
MISALIGNED_FILES+=("$DEVCONTAINER_JSON")
211+
echo -e "${RED}${NC} $DEVCONTAINER_JSON: build.args.RUST_VERSION ${RED}$current_version${NC} (expected: ${GREEN}$RUST_VERSION_SHORT${NC})"
212+
else
213+
echo -e "${GREEN}${NC} $DEVCONTAINER_JSON: build.args.RUST_VERSION ${GREEN}$RUST_VERSION_SHORT${NC}"
214+
fi
215+
elif [ "$MODE" = "fix" ]; then
216+
if [ "$current_version" != "$RUST_VERSION_SHORT" ]; then
217+
local tmp_file
218+
tmp_file=$(mktemp)
219+
jq --arg v "$RUST_VERSION_SHORT" '.build.args.RUST_VERSION = $v' "$DEVCONTAINER_JSON" > "$tmp_file"
220+
mv "$tmp_file" "$DEVCONTAINER_JSON"
221+
FIXED_FILES=$((FIXED_FILES + 1))
222+
echo -e "${GREEN}Fixed${NC} $DEVCONTAINER_JSON: build.args.RUST_VERSION ${RED}$current_version${NC} -> ${GREEN}$RUST_VERSION_SHORT${NC}"
223+
else
224+
echo -e "${GREEN}${NC} $DEVCONTAINER_JSON: build.args.RUST_VERSION already correct (${GREEN}$RUST_VERSION_SHORT${NC})"
225+
fi
226+
fi
227+
}
228+
229+
check_devcontainer_json
230+
185231
echo ""
186232
echo "────────────────────────────────────────────────"
187233

188234
if [ "$MODE" = "check" ]; then
189235
if [ ${#MISALIGNED_FILES[@]} -eq 0 ]; then
190-
echo -e "${GREEN}✓ All $TOTAL_FILES Dockerfiles are aligned with Rust version $RUST_VERSION_SHORT${NC}"
236+
echo -e "${GREEN}✓ All $TOTAL_FILES files are aligned with Rust version $RUST_VERSION_SHORT${NC}"
191237
exit 0
192238
else
193-
echo -e "${RED}✗ Found ${#MISALIGNED_FILES[@]} misaligned Dockerfile(s) out of $TOTAL_FILES:${NC}"
239+
echo -e "${RED}✗ Found ${#MISALIGNED_FILES[@]} misaligned file(s) out of $TOTAL_FILES:${NC}"
194240
for file in "${MISALIGNED_FILES[@]}"; do
195241
echo -e " ${RED}$file${NC}"
196242
done
@@ -200,9 +246,9 @@ if [ "$MODE" = "check" ]; then
200246
fi
201247
elif [ "$MODE" = "fix" ]; then
202248
if [ $FIXED_FILES -eq 0 ]; then
203-
echo -e "${GREEN}✓ All $TOTAL_FILES Dockerfiles were already aligned with Rust version $RUST_VERSION_SHORT${NC}"
249+
echo -e "${GREEN}✓ All $TOTAL_FILES files were already aligned with Rust version $RUST_VERSION_SHORT${NC}"
204250
else
205-
echo -e "${GREEN}✓ Fixed $FIXED_FILES out of $TOTAL_FILES Dockerfiles to use Rust version $RUST_VERSION_SHORT${NC}"
251+
echo -e "${GREEN}✓ Fixed $FIXED_FILES out of $TOTAL_FILES files to use Rust version $RUST_VERSION_SHORT${NC}"
206252
fi
207253
exit 0
208254
fi

0 commit comments

Comments
 (0)