docker: Share the target deps and build caches globally.

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk
2025-05-30 17:02:02 +00:00
parent c1c4ce9679
commit 3c02faa532
6 changed files with 26 additions and 10 deletions

View File

@@ -7,6 +7,7 @@ ARG RUSTUP_HOME
ARG CARGO_HOME
ARG CARGO_TARGET
ARG CARGO_TARGET_DIR
ARG CARGO_TARGET_CACHE
ARG cargo_profile
ARG cargo_features
ARG cargo_spec_features
@@ -24,8 +25,10 @@ RUN \
--mount=type=cache,dst=${RUSTUP_HOME},sharing=locked \
--mount=type=cache,dst=${CARGO_HOME},sharing=locked \
--mount=type=cache,dst=${CARGO_TARGET_DIR},sharing=locked \
--mount=type=cache,dst=${CARGO_TARGET_DIR}/deps,sharing=shared \
--mount=type=cache,dst=${CARGO_TARGET_DIR}/build,sharing=shared \
--mount=type=cache,dst=${CARGO_TARGET_DIR}/deps,id=${CARGO_TARGET_CACHE}/deps,sharing=shared \
--mount=type=cache,dst=${CARGO_TARGET_DIR}/build,id=${CARGO_TARGET_CACHE}/build,sharing=shared \
--mount=type=cache,dst=${CARGO_TARGET_DIR}/incremental,id=${CARGO_TARGET_CACHE}/incremental,sharing=shared \
--mount=type=cache,dst=${CARGO_TARGET_DIR}/.fingerprint,id=${CARGO_TARGET_CACHE}/fingerprint,sharing=shared \
<<EOF
set -eux
rustup run ${rust_toolchain} \

View File

@@ -7,6 +7,7 @@ ARG RUSTUP_HOME
ARG CARGO_HOME
ARG CARGO_TARGET
ARG CARGO_TARGET_DIR
ARG CARGO_TARGET_CACHE
ARG cargo_profile
ARG cargo_features
ARG cargo_spec_features
@@ -21,8 +22,10 @@ RUN \
--mount=type=cache,dst=${RUSTUP_HOME},sharing=locked \
--mount=type=cache,dst=${CARGO_HOME},sharing=locked \
--mount=type=cache,dst=${CARGO_TARGET_DIR},sharing=locked \
--mount=type=cache,dst=${CARGO_TARGET_DIR}/deps,sharing=shared \
--mount=type=cache,dst=${CARGO_TARGET_DIR}/build,sharing=shared \
--mount=type=cache,dst=${CARGO_TARGET_DIR}/deps,id=${CARGO_TARGET_CACHE}/deps,sharing=shared \
--mount=type=cache,dst=${CARGO_TARGET_DIR}/build,id=${CARGO_TARGET_CACHE}/build,sharing=shared \
--mount=type=cache,dst=${CARGO_TARGET_DIR}/incremental,id=${CARGO_TARGET_CACHE}/incremental,sharing=shared \
--mount=type=cache,dst=${CARGO_TARGET_DIR}/.fingerprint,id=${CARGO_TARGET_CACHE}/fingerprint,sharing=shared \
<<EOF
set -eux
mkdir -p "${pkg_dir}"

View File

@@ -7,6 +7,7 @@ ARG RUSTUP_HOME
ARG CARGO_HOME
ARG CARGO_TARGET
ARG CARGO_TARGET_DIR
ARG CARGO_TARGET_CACHE
ARG CARGO_BUILD_RUSTFLAGS
ARG CARGO_PROFILE_test_DEBUG
ARG CARGO_PROFILE_bench_DEBUG
@@ -34,8 +35,10 @@ RUN \
--mount=type=cache,dst=${RUSTUP_HOME},sharing=locked \
--mount=type=cache,dst=${CARGO_HOME},sharing=locked \
--mount=type=cache,dst=${CARGO_TARGET_DIR},sharing=locked \
--mount=type=cache,dst=${CARGO_TARGET_DIR}/deps,sharing=shared \
--mount=type=cache,dst=${CARGO_TARGET_DIR}/build,sharing=shared \
--mount=type=cache,dst=${CARGO_TARGET_DIR}/deps,id=${CARGO_TARGET_CACHE}/deps,sharing=shared \
--mount=type=cache,dst=${CARGO_TARGET_DIR}/build,id=${CARGO_TARGET_CACHE}/build,sharing=shared \
--mount=type=cache,dst=${CARGO_TARGET_DIR}/incremental,id=${CARGO_TARGET_CACHE}/incremental,sharing=shared \
--mount=type=cache,dst=${CARGO_TARGET_DIR}/.fingerprint,id=${CARGO_TARGET_CACHE}/fingerprint,sharing=shared \
<<EOF
set -eux
rustup run ${rust_toolchain} \

View File

@@ -7,6 +7,7 @@ ARG RUSTUP_HOME
ARG CARGO_HOME
ARG CARGO_TARGET
ARG CARGO_TARGET_DIR
ARG CARGO_TARGET_CACHE
ARG cargo_profile
ARG cargo_features
ARG cargo_spec_features
@@ -26,8 +27,10 @@ RUN \
--mount=type=cache,dst=${RUSTUP_HOME},sharing=locked \
--mount=type=cache,dst=${CARGO_HOME},sharing=locked \
--mount=type=cache,dst=${CARGO_TARGET_DIR},sharing=locked \
--mount=type=cache,dst=${CARGO_TARGET_DIR}/deps,sharing=shared \
--mount=type=cache,dst=${CARGO_TARGET_DIR}/build,sharing=shared \
--mount=type=cache,dst=${CARGO_TARGET_DIR}/deps,id=${CARGO_TARGET_CACHE}/deps,sharing=shared \
--mount=type=cache,dst=${CARGO_TARGET_DIR}/build,id=${CARGO_TARGET_CACHE}/build,sharing=shared \
--mount=type=cache,dst=${CARGO_TARGET_DIR}/incremental,id=${CARGO_TARGET_CACHE}/incremental,sharing=shared \
--mount=type=cache,dst=${CARGO_TARGET_DIR}/.fingerprint,id=${CARGO_TARGET_CACHE}/fingerprint,sharing=shared \
<<EOF
set -eux
case "$cargo_profile" in

View File

@@ -7,6 +7,7 @@ ARG RUSTUP_HOME
ARG CARGO_HOME
ARG CARGO_TARGET
ARG CARGO_TARGET_DIR
ARG CARGO_TARGET_CACHE
ARG cargo_profile
ARG cargo_features
ARG cargo_spec_features
@@ -21,8 +22,10 @@ RUN \
--mount=type=cache,dst=${RUSTUP_HOME},sharing=locked \
--mount=type=cache,dst=${CARGO_HOME},sharing=locked \
--mount=type=cache,dst=${CARGO_TARGET_DIR},sharing=locked \
--mount=type=cache,dst=${CARGO_TARGET_DIR}/deps,sharing=shared \
--mount=type=cache,dst=${CARGO_TARGET_DIR}/build,sharing=shared \
--mount=type=cache,dst=${CARGO_TARGET_DIR}/deps,id=${CARGO_TARGET_CACHE}/deps,sharing=shared \
--mount=type=cache,dst=${CARGO_TARGET_DIR}/build,id=${CARGO_TARGET_CACHE}/build,sharing=shared \
--mount=type=cache,dst=${CARGO_TARGET_DIR}/incremental,id=${CARGO_TARGET_CACHE}/incremental,sharing=shared \
--mount=type=cache,dst=${CARGO_TARGET_DIR}/.fingerprint,id=${CARGO_TARGET_CACHE}/fingerprint,sharing=shared \
<<EOF
set -eux
mkdir -p "${pkg_dir}"

View File

@@ -1072,6 +1072,7 @@ target "deps-base" {
cargo_profile = cargo_profile
cook_args = "--all-targets --no-build"
CARGO_TARGET_DIR = "/usr/src/tuwunel/target/${sys_name}/${sys_version}/${rust_toolchain}/${cargo_profile}/${feat_set}"
CARGO_TARGET_CACHE = "/usr/src/tuwunel/target/${sys_name}/${sys_version}/_shared_cache"
CARGO_PROFILE_test_DEBUG = "0"
CARGO_PROFILE_bench_DEBUG = "0"
CARGO_PROFILE_bench_LTO = "0"