Skip to content

Commit

Permalink
feat: UNIT_TEST UDC (#138)
Browse files Browse the repository at this point in the history
* feat: UNIT_TEST UDC target

* fix: add llvm-tools to stable rust

* fix: add cspell words

* feat: add test target to rust example

* fix: artifact path
  • Loading branch information
kukkok3 authored Dec 27, 2023
1 parent 55f95da commit 2cd566a
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 20 deletions.
24 changes: 19 additions & 5 deletions earthly/rust/Earthfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Common Rust UDCs and Builders.
VERSION 0.7

# cspell: words rustup miri nextest ripgrep colordiff rustfmt stdcfgs toolset readelf depgraph
# cspell: words rustup miri nextest ripgrep colordiff rustfmt stdcfgs toolset readelf depgraph lcov
# cspell: words TARGETPLATFORM TARGETOS TARGETARCH TARGETVARIANT USERPLATFORM USEROS USERARCH USERVARIANT

# Base Rustup build container.
Expand All @@ -28,11 +28,11 @@ rust-base:
echo "USERPLATFORM = $USERPLATFORM"; \
echo "USEROS = $USEROS"; \
echo "USERARCH = $USERARCH"; \
echo "USERVARIANT = $USERVARIANT";
echo "USERVARIANT = $USERVARIANT";

WORKDIR /root

# Install necessary packages
# Install necessary packages
# Expand this list as needed, rather than adding more tools in later containers.
RUN apk add --no-cache \
musl-dev \
Expand All @@ -46,6 +46,9 @@ rust-base:
# Make sure we have the clippy linter.
RUN rustup component add clippy

# Needed to generate code coverage.
RUN rustup component add llvm-tools-preview

# Install a nightly toolchain which matches.
RUN rustup toolchain install nightly --component miri --component rust-src --component rustfmt --component clippy

Expand All @@ -61,7 +64,8 @@ rust-base:
cargo install refinery_cli --version=0.8.11 && \
cargo install cargo-deny --version=0.14.3 && \
cargo install cargo-modules --version=0.10.2 && \
cargo install cargo-depgraph --version=1.5.0
cargo install cargo-depgraph --version=1.5.0 && \
cargo install cargo-llvm-cov --version=0.5.39

SAVE ARTIFACT $CARGO_HOME/bin/refinery refinery

Expand All @@ -75,7 +79,7 @@ rust-base:

# Builds all the rust-base targets for each supported DOCKER architecture.
# Currently only used for multi-platform cross build testing.
# This will ONLY work if you have `qemu` properly setup on linux and `rosetta` for
# This will ONLY work if you have `qemu` properly setup on linux and `rosetta` for
# docker enabled on Mac.
# Again, this is just a test target, and not for general use.
rust-base-all-hosts:
Expand Down Expand Up @@ -123,6 +127,16 @@ BUILD:

RUN /scripts/std_build.sh "$libs" "$bins"

# Run unit tests and generates test and coverage report artifacts
UNIT_TEST:
COMMAND
# remove artifacts that may affect the coverage results
RUN cargo llvm-cov clean --workspace
# run unit tests and display test result and test coverage
RUN cargo llvm-cov nextest --release --bins --lib --workspace --locked -P ci
# generate lcov report
RUN cargo llvm-cov report --release --output-path coverage-report.info

# Check if the build executable, isn't a busted mess.
SMOKE_TEST:
COMMAND
Expand Down
4 changes: 0 additions & 4 deletions earthly/rust/scripts/std_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ status $rc "Checking all Clippy Lints in the workspace" \
status $rc "Checking Documentation can be generated OK" \
cargo +nightly docs; rc=$?

## Check if all Self contained tests pass (Test that need no external resources).
status $rc "Checking Self contained Unit tests all pass" \
cargo testunit; rc=$?

## Check if all documentation tests pass.
status $rc "Checking Documentation tests all pass" \
cargo +nightly testdocs; rc=$?
Expand Down
4 changes: 1 addition & 3 deletions earthly/rust/stdcfgs/cargo_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ lint-vscode = "clippy --workspace --message-format=json-diagnostic-rendered-ansi

docs = "doc --workspace -r --all-features --no-deps --bins --document-private-items --examples --locked"
# nightly docs build broken... when they are'nt we can enable these docs... --unit-graph --timings=html,json -Z unstable-options"
testfast = "nextest run --release --workspace --locked"
testunit = "nextest run --release --bins --lib --workspace --locked -P ci"
testci = "nextest run --release --workspace --locked -P ci"
testfast = "nextest --release --workspace --locked"
testdocs = "test --doc --release --workspace --locked"

# Rust formatting, MUST be run with +nightly
Expand Down
4 changes: 1 addition & 3 deletions examples/rust/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ lint-vscode = "clippy --workspace --message-format=json-diagnostic-rendered-ansi

docs = "doc --workspace -r --all-features --no-deps --bins --document-private-items --examples --locked"
# nightly docs build broken... when they are'nt we can enable these docs... --unit-graph --timings=html,json -Z unstable-options"
testfast = "nextest run --release --workspace --locked"
testunit = "nextest run --release --bins --lib --workspace --locked -P ci"
testci = "nextest run --release --workspace --locked -P ci"
testfast = "nextest --release --workspace --locked"
testdocs = "test --doc --release --workspace --locked"

# Rust formatting, MUST be run with +nightly
Expand Down
32 changes: 27 additions & 5 deletions examples/rust/Earthfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
VERSION 0.7

# cspell: words TARGETARCH USERARCH toolsets rustfmt
# cspell: words TARGETARCH USERARCH toolsets rustfmt nextest

# Set up our target toolchains, and copy our files.
builder:
Expand All @@ -20,14 +20,14 @@ check-hosted:

# 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:
check-all-hosts:
BUILD --platform=linux/amd64 --platform=linux/arm64 +check-hosted


# Build the service.
build-hosted:
FROM +builder

DO ./../../earthly/rust+BUILD --libs="bar" --bins="foo/foo"

DO ./../../earthly/rust+SMOKE_TEST --bin="foo"
Expand All @@ -37,9 +37,17 @@ build-hosted:

# 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.
build-all-hosts:
build-all-hosts:
BUILD --platform=linux/amd64 --platform=linux/arm64 +build-hosted

test-hosted:
FROM +builder

DO ./../../earthly/rust+UNIT_TEST

SAVE ARTIFACT target/nextest/ci/junit.xml junit-report.xml
SAVE ARTIFACT coverage-report.info coverage-report.info

## -----------------------------------------------------------------------------
##
## Standard CI targets.
Expand Down Expand Up @@ -76,7 +84,21 @@ build:
BUILD --platform=linux/amd64 +build-hosted
END

test:
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 +test-hosted
ELSE
BUILD --platform=linux/amd64 +test-hosted
END

# This step simulates the full CI run for local purposes only.
local-ci-run:
BUILD +check
BUILD +build
BUILD +build
BUILD +test

0 comments on commit 2cd566a

Please sign in to comment.