Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust: Allow running non-cargo commands with caches mounted #19

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions rust/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@ CARGO:
IF [ "$keep_fingerprints" = "false" ]
DO +REMOVE_SOURCE_FINGERPRINTS
END
RUN --mount=type=cache,mode=0777,sharing=shared,target=$CARGO_HOME/registry \
--mount=type=cache,mode=0777,sharing=shared,target=$CARGO_HOME/git \
--mount=type=cache,mode=0777,target=target \
cargo $args; \
if [ -n "$output" ]; then \
mkdir /earthly_lib_rust_temp; \
cd target; \
find . -type f -regextype posix-egrep -regex "./$output" -exec cp --parents \{\} /earthly_lib_rust_temp \; ; \
fi
DO +RUN_WITH_CACHE --command="cargo $args;
if [ -n \"$output\" ]; then
mkdir /earthly_lib_rust_temp;
cd target;
find . -type f -regextype posix-egrep -regex \"./$output\" -exec cp --parents \{\} /earthly_lib_rust_temp \; ;
fi"
IF [ "$output" != "" ]
RUN mkdir -p target; \
mv /earthly_lib_rust_temp/* target 2>/dev/null || echo "no files found within ./target matching the provided output regexp" ;
Expand Down Expand Up @@ -50,3 +47,19 @@ get-stoml:
RUN wget -O stoml https://github.com/freshautomations/stoml/releases/download/v0.7.1/stoml_linux_amd64; \
chmod +x stoml
SAVE ARTIFACT ./stoml stoml

# RUN_WITH_CACHE runs the passed command with the CARGO caches mounted.
# Arguments:
# - command (required): Command to run, can be any expression.
#
# This implementation is not expected to significantly change. Prefer using the
# `CARGO` UDC if you can, so you can get future improvements transparently.
RUN_WITH_CACHE:
COMMAND
ARG command
RUN --mount=type=cache,mode=0777,sharing=shared,target=$CARGO_HOME/registry \
--mount=type=cache,mode=0777,sharing=shared,target=$CARGO_HOME/git \
--mount=type=cache,mode=0777,target=target \
set -e; \
printf "Running:\n $command\n"; \
eval $command