[CI] Preserve Rust Docker cache across commits (#53290)

Signed-off-by: mgoin <mgoin64@gmail.com>
Co-authored-by: OpenAI Codex <codex@openai.com>
This commit is contained in:
Misha Goin
2026-08-25 11:13:36 -07:00
committed by GitHub
co-authored by OpenAI Codex
parent 299ebd094a
commit c9331d8064
5 changed files with 50 additions and 25 deletions
+12 -10
View File
@@ -253,7 +253,7 @@ ENV TORCH_CUDA_ARCH_LIST=${torch_cuda_arch_list}
# build stage doesn't need the rust toolchain or the rust source.
# This stage reuses the Python environment from base and runs in parallel with
# csrc-build/extensions-build.
FROM base AS rust-build
FROM base AS rust-build-cache
ARG USE_SCCACHE
ARG SCCACHE_ENDPOINT
@@ -283,26 +283,28 @@ ENV CARGO_BUILD_JOBS=4
# separate local sccache daemon while sharing the same remote cache backend.
ENV SCCACHE_SERVER_PORT=4227
# Only Rust inputs are present, so suppress the artificial dirty state caused
# by other tracked files being absent from this build stage.
ENV SETUPTOOLS_SCM_PRETEND_METADATA={dirty=false}
# Build the release artifacts. Cache cargo registry/git, but not target/,
# because stale target metadata can outlive source updates across BuildKit
# cache reuse.
# Build with a stable version so this target snapshot is keyed only by Rust
# inputs. The child stage below relinks the crates that embed the exact version.
RUN --mount=type=cache,target=/root/.cargo/registry,sharing=locked \
--mount=type=cache,target=/root/.cargo/git,sharing=locked \
--mount=type=bind,source=.git,target=.git \
--mount=type=secret,id=aws-credentials,target=/root/.aws/credentials,required=false \
if [ "$USE_SCCACHE" = "1" ]; then \
if [ -n "${SCCACHE_ENDPOINT}" ]; then export SCCACHE_ENDPOINT="${SCCACHE_ENDPOINT}"; fi; \
export RUSTC_WRAPPER=sccache; \
sccache --show-stats; \
fi \
&& bash build_rust.sh \
&& SETUPTOOLS_SCM_PRETEND_VERSION="0.0.0+docker.cache" bash build_rust.sh \
&& if [ "$USE_SCCACHE" = "1" ]; then \
sccache --show-stats; \
fi
# Relink with the exact Git-derived package version.
FROM rust-build-cache AS rust-build
RUN --mount=type=cache,target=/root/.cargo/registry,sharing=locked \
--mount=type=cache,target=/root/.cargo/git,sharing=locked \
--mount=type=bind,source=.git,target=.git \
SETUPTOOLS_SCM_PRETEND_METADATA="{dirty=false}" bash build_rust.sh
#################### RUST BUILD IMAGE ####################
#################### CSRC BUILD IMAGE ####################