-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
33 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,9 @@ INIT: | |
# ($CARGO_HOME/.package-cache has to be in the cache so Cargo can properly synchronize parallel access to $CARGO_HOME resources). | ||
ENV CARGO_HOME="/tmp/earthly/.cargo" | ||
|
||
DO +INSTALL_EARTHLY_FUNCTIONS | ||
|
||
|
||
# CARGO runs the cargo command "cargo $args". | ||
# This function is thread safe. Parallel builds of targets calling this function should be free of race conditions. | ||
# Notice that in order to run this function, +INIT must be called first. | ||
|
@@ -60,10 +63,9 @@ CARGO: | |
set -e; \ | ||
cargo $args; \ | ||
cargo sweep -r -t $EARTHLY_SWEEP_DAYS; \ | ||
cargo sweep -r -i; | ||
IF [ "$output" != "" ] | ||
DO +COPY_OUTPUT --output=$output | ||
END | ||
cargo sweep -r -i; \ | ||
$EARTHLY_FUNCTIONS_HOME/copy-output.sh "$output"; | ||
RUN $EARTHLY_FUNCTIONS_HOME/rename-output.sh | ||
|
||
# SET_CACHE_MOUNTS_ENV sets the following entries in the environment, to be used to mount the cargo caches. | ||
# - EARTHLY_RUST_CARGO_HOME_CACHE: Code of the mount cache for the cargo home. | ||
|
@@ -95,26 +97,13 @@ SET_CACHE_MOUNTS_ENV: | |
COPY_OUTPUT: | ||
FUNCTION | ||
ARG --required output | ||
ARG TMP_FOLDER="/tmp/earthly/lib/rust" | ||
DO +CHECK_INITED | ||
RUN if [ ! -n "$EARTHLY_RUST_TARGET_CACHE" ]; then \ | ||
echo "+SET_CACHE_MOUNTS_ENV has not been called yet in this build environment" ; \ | ||
exit 1; \ | ||
fi; | ||
RUN --mount=$EARTHLY_RUST_TARGET_CACHE \ | ||
if [ -n "$output" ]; then \ | ||
echo "Copying output files" ; \ | ||
mkdir -p $TMP_FOLDER; \ | ||
cd target; \ | ||
find . -type f -regextype posix-egrep -regex "./$output" -exec cp --parents {} $TMP_FOLDER \; ; \ | ||
cd ..; \ | ||
fi; | ||
RUN mkdir -p target; \ | ||
if [ "$(find "$TMP_FOLDER" -type f -printf . | wc -c)" -eq 0 ]; then \ | ||
echo "no files found within ./target matching the provided output regexp"; \ | ||
else \ | ||
cp -ruT "$TMP_FOLDER" target; \ | ||
rm -rf "$TMP_FOLDER"; \ | ||
fi; | ||
RUN --mount=$EARTHLY_RUST_TARGET_CACHE $EARTHLY_FUNCTIONS_HOME/copy-output.sh "$output" | ||
RUN $EARTHLY_FUNCTIONS_HOME/rename-output.sh | ||
|
||
# CROSS runs the [cross](https://github.com/cross-rs/cross) command "cross $args --target $target". | ||
# Notice that in order to run this function, +INIT must be called first. | ||
|
@@ -170,6 +159,30 @@ INSTALL_CARGO_SWEEP: | |
cargo install [email protected] --locked --root $CARGO_HOME; \ | ||
fi; | ||
|
||
INSTALL_EARTHLY_FUNCTIONS: | ||
FUNCTION | ||
ENV EARTHLY_FUNCTIONS_HOME="/tmp/earthly/functions" | ||
RUN mkdir -p $EARTHLY_FUNCTIONS_HOME | ||
RUN if [ ! -f $EARTHLY_FUNCTIONS_HOME/copy-output.sh ]; then \ | ||
OUTPUT_TMP_FOLDER="/tmp/earthly/lib/rust"; \ | ||
echo "if [ -n \"\$1\" ]; then | ||
echo \"Copying output files\" ; | ||
mkdir -p $OUTPUT_TMP_FOLDER; | ||
cd target; | ||
find . -type f -regextype posix-egrep -regex \"./\$1\" -exec cp --parents {} $OUTPUT_TMP_FOLDER \; ; | ||
cd ..; | ||
fi;" > $EARTHLY_FUNCTIONS_HOME/copy-output.sh; \ | ||
chmod +x $EARTHLY_FUNCTIONS_HOME/copy-output.sh; \ | ||
echo "mkdir -p target; | ||
if [ \"\$(find \"$OUTPUT_TMP_FOLDER\" -type f -printf . | wc -c)\" -eq 0 ]; then | ||
echo \"no files found within ./target matching the provided output regexp\"; | ||
else | ||
cp -ruT \"$OUTPUT_TMP_FOLDER\" target; | ||
rm -rf \"$OUTPUT_TMP_FOLDER\"; | ||
fi;" > $EARTHLY_FUNCTIONS_HOME/rename-output.sh; \ | ||
chmod +x $EARTHLY_FUNCTIONS_HOME/rename-output.sh; \ | ||
fi; | ||
|
||
REMOVE_SOURCE_FINGERPRINTS: | ||
FUNCTION | ||
DO +CHECK_INITED | ||
|