Skip to content

Commit

Permalink
fix(rust): Bring upstream rust earthly changes into the rust builders (
Browse files Browse the repository at this point in the history
…#321)

* fix(rust): Bring upstream rust earthly changes into the rust builders

* fix(rust): Add arguments to tune the rust builder to +SETUP

* fix(rust): Add --keep-ts to rust example projects

* refactor(rust): Move the FINGERPRINT_SRC function from cat-libs to cat-ci
  • Loading branch information
stevenj authored Oct 1, 2024
1 parent 6ed2066 commit 60da1e7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
37 changes: 25 additions & 12 deletions earthly/rust/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ VERSION 0.8
# the Rust library from Earthly can only be imported in this Earthfile.
# FUNCTIONs or targets in that Earthfile MUST be shimmed here.
# No other earthfile should reference the rust library in the earthly/lib repo.
IMPORT github.com/earthly/lib/rust:3.0.2 AS rust
IMPORT github.com/earthly/lib/rust:3.0.3 AS rust

# Local Earthfile reference imports
IMPORT ./tools AS rust-tools
Expand Down Expand Up @@ -139,7 +139,9 @@ installer:
# Call `+INIT` before copying the source file to avoid installing dependencies every time source code changes.
# This parametrization will be used in future calls to functions of the library
# Init using the common cat-ci cache prefix.
DO rust+INIT --keep_fingerprints=true
ARG keep_fingerprints=true
ARG sweep_days=4
DO rust+INIT --keep_fingerprints=$keep_fingerprints --sweep_days=$sweep_days

# Set the mount cache env vars
DO rust+SET_CACHE_MOUNTS_ENV
Expand Down Expand Up @@ -213,9 +215,11 @@ EXECUTE:
RUN --mount=$EARTHLY_RUST_CARGO_HOME_CACHE --mount=$EARTHLY_RUST_TARGET_CACHE \
set -e; \
rm -f fail; \
$cmd $args1 $args2 $args3 $args4 $args5 $args6 || touch fail; \
$cmd $args1 $args2 $args3 $args4 $args5 $args6; \
cargo sweep -r -t $EARTHLY_SWEEP_DAYS; \
cargo sweep -r -i
cargo sweep -r -i; \
$EARTHLY_FUNCTIONS_HOME/copy-output.sh "$output";
RUN $EARTHLY_FUNCTIONS_HOME/rename-output.sh


# We always want to save these (if requested) even if the command fails.
Expand Down Expand Up @@ -246,11 +250,6 @@ EXECUTE:
SAVE ARTIFACT target/doc doc
END

# This output is ONLY saved on successful command execution.
IF [ "$output" != "" ]
DO rust+COPY_OUTPUT --output=$output
END

# CARGO : Shim so we use the correct upstream RUST library consistently
# without having to import it into consuming Earthfiles.
# By default this will NOT expose docs built during the execution of cargo
Expand Down Expand Up @@ -289,14 +288,15 @@ CARGO:
COPY_OUTPUT:
FUNCTION
ARG --required output
ARG TMP_FOLDER="/tmp/earthly/lib/rust"

DO rust+COPY_OUTPUT --output=$output --TMP_FOLDER=$TMP_FOLDER
DO rust+COPY_OUTPUT --output=$output

# SETUP : Common Rust setup.
SETUP:
FUNCTION
FROM +installer
ARG keep_fingerprints=true
ARG sweep_days=4
FROM +installer --keep_fingerprints=$keep_fingerprints --sweep_days=$sweep_days

# The ONLY toolchain we support is the one in the installer.
# DO NOT copy the `rust-toolchain.toml` file into CI as it breaks
Expand All @@ -314,3 +314,16 @@ SYNC_STD_CFG:
SAVE ARTIFACT /stdcfgs/deny.toml AS LOCAL deny.toml
SAVE ARTIFACT /stdcfgs/rustfmt.toml AS LOCAL rustfmt.toml
SAVE ARTIFACT /stdcfgs/rust-toolchain.toml AS LOCAL rust-toolchain.toml

# FINGERPRINT_SRC : Generates a fingerprint of the source.
FINGERPRINT_SRC:
FUNCTION

ARG WHENCE=..
ARG DIR=build
ARG FINGERPRINT=src_fingerprint.txt

RUN cd $WHENCE; \
tar -C ./ -cf - --sort=name --mtime='UTC 2019-01-01' --group=0 --owner=0 --numeric-owner $DIR \
| sha256sum > $FINGERPRINT
RUN cat $WHENCE/$FINGERPRINT
7 changes: 4 additions & 3 deletions examples/rust/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ IMPORT ./../../earthly/rust AS rust-ci
builder:
DO rust-ci+SETUP

COPY --dir .cargo .config crates .
COPY Cargo.toml .
COPY clippy.toml deny.toml rustfmt.toml .
COPY --keep-ts --dir \
.cargo .config Cargo.toml clippy.toml deny.toml rustfmt.toml \
crates \
.

## -----------------------------------------------------------------------------
##
Expand Down
7 changes: 4 additions & 3 deletions utilities/dbviz/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ IMPORT ./../../earthly/rust AS rust-ci
builder:
DO rust-ci+SETUP

COPY --dir .cargo .config src .
COPY Cargo.toml .
COPY clippy.toml deny.toml rustfmt.toml .
COPY --keep-ts --dir \
.cargo .config Cargo.toml clippy.toml deny.toml rustfmt.toml \
src \
.

## -----------------------------------------------------------------------------
##
Expand Down

0 comments on commit 60da1e7

Please sign in to comment.