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

Commit

Permalink
Merge pull request #521 from netlify/fix_rust_cache
Browse files Browse the repository at this point in the history
Fix Rust caching issues
  • Loading branch information
calavera authored Jan 14, 2021
2 parents e1ca735 + 4d33fdd commit d84c794
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions run-build-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,11 @@ cache_artifacts() {
cache_cwd_directory ".venv" "python virtualenv"
cache_cwd_directory ".build" "swift build"
cache_cwd_directory ".netlify/plugins" "build plugins"
cache_cwd_directory "target" "rust compile output"

if [ -f Cargo.toml ] || [ -f Cargo.lock ]
then
cache_cwd_directory_fast_copy "target" "rust compile output"
fi

cache_home_directory ".yarn_cache" "yarn cache"
cache_home_directory ".cache/pip" "pip cache"
Expand All @@ -686,8 +690,12 @@ cache_artifacts() {
cache_home_directory ".composer" "composer dependencies"
cache_home_directory ".homebrew-cache", "homebrew cache"
cache_home_directory ".rustup" "rust rustup cache"
cache_home_directory ".cargo/registry" "rust cargo registry cache"
cache_home_directory ".cargo/bin" "rust cargo bin cache"

if [ -f Cargo.toml ] || [ -f Cargo.lock ]
then
cache_home_directory ".cargo/registry" "rust cargo registry cache"
cache_home_directory ".cargo/bin" "rust cargo bin cache"
fi

# Don't follow the Go import path or we'll store
# the origin repo twice.
Expand Down Expand Up @@ -748,6 +756,17 @@ move_cache() {
fi
}

fast_copy_cache() {
local src=$1
local dst=$2
if [ -d $src ]
then
echo "Started $3"
cp --reflink=always $src $dst
echo "Finished $3"
fi
}

restore_home_cache() {
move_cache "$NETLIFY_CACHE_DIR/$1" "$HOME/$1" "restoring cached $2"
}
Expand All @@ -764,6 +783,10 @@ cache_cwd_directory() {
move_cache "$PWD/$1" "$NETLIFY_CACHE_DIR/$1" "saving $2"
}

cache_cwd_directory_fast_copy() {
fast_copy_cache "$PWD/$1" "$NETLIFY_CACHE_DIR/$1" "saving $2"
}

install_missing_commands() {
if [[ $BUILD_COMMAND_PARSER == *"grunt"* ]]
then
Expand Down

0 comments on commit d84c794

Please sign in to comment.