Skip to content

Commit

Permalink
add Prepare base builder and Running checks sections
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Leshiy committed Nov 24, 2023
1 parent d2439f8 commit 77691b4
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 3 deletions.
71 changes: 70 additions & 1 deletion docs/src/guides/languages/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,73 @@ Also we will take a look how we are setup Rust projects and what configuration i
[example](https://github.com/input-output-hk/catalyst-ci/blob/master/examples/rust/Earthfile).
<!-- markdownlint-enable max-one-sentence-per-line -->

### Prepare base builder
### Prepare base builder


```Earthfile
VERSION 0.7
# Set up our target toolchains, and copy our files.
builder:
FROM ./../../earthly/rust+rust-base
COPY --dir "*" .
DO ./../../earthly/rust+SETUP
```

The first target `builder` is responsible for preparing an already configured Rust environment,
instal all needed tools and dependencies.

The fist step of the `builder` target is to prepare a Rust environment via `+rust-base` target.
Next step is to copy source code of the project and finally finalize the build
which is done with `+SETUP` UDC target.
The `+SETUP` UDC target requires to have a `rust-toolchain.toml` file,
with the specified `channel` option in it.

### Running checks

```Earthfile
# Test rust build container - Use best architecture host tools.
check-hosted:
FROM +builder
DO ./../../earthly/rust+CHECK
# Test which runs check with all supported host tooling. Needs qemu or rosetta to run.
# Only used to validate tooling is working across host toolsets.
check-all-hosts:
BUILD --platform=linux/amd64 --platform=linux/arm64 +check-hosted
## Standard CI targets.
##
## These targets are discovered and executed automatically by CI.
# Run check using the most efficient host tooling
# CI Automated Entry point.
check:
FROM busybox
# This is necessary to pick the correct architecture build to suit the native machine.
# It primarily ensures that Darwin/Arm builds work as expected without needing x86 emulation.
# All target implementation of this should follow this pattern.
ARG USERARCH
IF [ "$USERARCH" == "arm64" ]
BUILD --platform=linux/arm64 +check-hosted
ELSE
BUILD --platform=linux/amd64 +check-hosted
END
```

With prepared environment and all data, we're now ready to start operating with the source code and configuration files.
The `check-hosted` target which actually performs all checks and validation
with the help of `+CHECK` UDC target.
The `+CHECK` UDC target performs static checks of the Rust project as `cargo fmt`, `cargo machete`, `cargo deny` which will validate formatting, find unused dependencies and any supply chain issues with dependencies.
Also during it validates configuration files as `.cargo/config.toml`, `rustfmt.toml`, `.config/nextest.toml`, `clippy.toml`, `deny.toml`
to be the same as defined in `earthly/rust/stdcfgs` directory of the `catalyst-ci` repo.

Another targets as `check-all-hosts` and `check` (running on CI) just invoke `check-hosted`
with the specified `--platform`.
It is important to define a `linux` target platform with a proper cpu architecture
for the Rust project when you are building it inside Docker
and check the build process with different scenarios.
The same approach we will see for the another targets of this guide.
1 change: 1 addition & 0 deletions earthly/rust/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ rust-base-all-hosts:
SETUP:
COMMAND

COPY ./rust-toolchain.toml .
ENV default_rust_channel=$(rg -oP 'channel\s*=\s*"\K[^"]+' rust-toolchain.toml)

# Check that `default_rust_channel` and $RUST_VERSION from the rust-base container are exactly the same.
Expand Down
3 changes: 1 addition & 2 deletions examples/rust/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ VERSION 0.7
# Set up our target toolchains, and copy our files.
builder:
FROM ./../../earthly/rust+rust-base

COPY --dir "*" .

COPY --dir "*" .
DO ./../../earthly/rust+SETUP

# Test rust build container - Use best architecture host tools.
Expand Down

0 comments on commit 77691b4

Please sign in to comment.