This page will help you use Earthly if you are using Rust.
Step 1: Import the Rust library
To get started, import the rust library as shown below. Note that the --global-cache flag is currently required to allow for adequate caching of the Rust toolchain. This flag will be implied in a future release.
VERSION --global-cache 0.7IMPORT github.com/earthly/lib/rust:2.2.11 AS rust
Step 2: Initialize the Rust toolchain
Next, initialize the Rust toolchain via rust+INIT. This will install any necessary dependencies that rust+CARGO needs underneath.
install:FROM rust:1.73.0-bookwormRUN apt-get update -qqRUN apt-get install --no-install-recommends -qq autoconf autotools-dev libtool-bin clang cmake bsdmainutilsRUN rustup component add clippyRUN rustup component add rustfmt # Call +INIT before copying the source file to avoid installing depencies every time source code changes. # This parametrization will be used in future calls to functions of the library DO rust+INIT --keep_fingerprints=true
Step 3: Build your Rust project
Now you can build your Rust project. Collect the necessary sources and call rust+CARGO to build your project.
Notice the need for the --keep-ts flag when copying the source files. This is necessary to ensure that the timestamps of the source files are preserved such that Rust's incremental compilation works correctly.
Additionally, because cargo does not make a good distinction between intermediate and final artifacts, we use the --output flag to specify which files should be extracted from the cache at the end of the operation.