Skip to content
This repository was archived by the owner on Jan 25, 2023. It is now read-only.

Commit d84c794

Browse files
authored
Merge pull request #521 from netlify/fix_rust_cache
Fix Rust caching issues
2 parents e1ca735 + 4d33fdd commit d84c794

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

run-build-functions.sh

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,11 @@ cache_artifacts() {
675675
cache_cwd_directory ".venv" "python virtualenv"
676676
cache_cwd_directory ".build" "swift build"
677677
cache_cwd_directory ".netlify/plugins" "build plugins"
678-
cache_cwd_directory "target" "rust compile output"
678+
679+
if [ -f Cargo.toml ] || [ -f Cargo.lock ]
680+
then
681+
cache_cwd_directory_fast_copy "target" "rust compile output"
682+
fi
679683

680684
cache_home_directory ".yarn_cache" "yarn cache"
681685
cache_home_directory ".cache/pip" "pip cache"
@@ -686,8 +690,12 @@ cache_artifacts() {
686690
cache_home_directory ".composer" "composer dependencies"
687691
cache_home_directory ".homebrew-cache", "homebrew cache"
688692
cache_home_directory ".rustup" "rust rustup cache"
689-
cache_home_directory ".cargo/registry" "rust cargo registry cache"
690-
cache_home_directory ".cargo/bin" "rust cargo bin cache"
693+
694+
if [ -f Cargo.toml ] || [ -f Cargo.lock ]
695+
then
696+
cache_home_directory ".cargo/registry" "rust cargo registry cache"
697+
cache_home_directory ".cargo/bin" "rust cargo bin cache"
698+
fi
691699

692700
# Don't follow the Go import path or we'll store
693701
# the origin repo twice.
@@ -748,6 +756,17 @@ move_cache() {
748756
fi
749757
}
750758

759+
fast_copy_cache() {
760+
local src=$1
761+
local dst=$2
762+
if [ -d $src ]
763+
then
764+
echo "Started $3"
765+
cp --reflink=always $src $dst
766+
echo "Finished $3"
767+
fi
768+
}
769+
751770
restore_home_cache() {
752771
move_cache "$NETLIFY_CACHE_DIR/$1" "$HOME/$1" "restoring cached $2"
753772
}
@@ -764,6 +783,10 @@ cache_cwd_directory() {
764783
move_cache "$PWD/$1" "$NETLIFY_CACHE_DIR/$1" "saving $2"
765784
}
766785

786+
cache_cwd_directory_fast_copy() {
787+
fast_copy_cache "$PWD/$1" "$NETLIFY_CACHE_DIR/$1" "saving $2"
788+
}
789+
767790
install_missing_commands() {
768791
if [[ $BUILD_COMMAND_PARSER == *"grunt"* ]]
769792
then

0 commit comments

Comments
 (0)