Skip to content

Commit

Permalink
prepare examples/rust Earthfile
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Leshiy committed Nov 23, 2023
1 parent fdf54d4 commit 0235708
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 129 deletions.
126 changes: 1 addition & 125 deletions earthly/rust/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,10 @@ rust-base:
rust-base-all-hosts:
BUILD --platform=linux/amd64 --platform=linux/arm64 +rust-base

# Common Rust setup
# Parameters:
# * toolchain : The `rust-toolchain` toml file.
# Common Rust setup.
SETUP:
COMMAND
ARG toolchain=./rust-toolchain.toml

# Poetry Installation directory.
# Gives poetry and our poetry project a reliable location.
WORKDIR /build

# Copy our toolchain dependency.
COPY $toolchain ./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 All @@ -110,22 +101,6 @@ SETUP:
cargo --version && \
cargo +nightly --version


CP_SRC:
# Copy the build src using this.
COMMAND
# This can be one directory like `"src/*"` or multiple src separated by `","`:
# eg, "example/Cargo.toml, example/Cargo.lock, example/src"
ARG src=""

# ONLY copy whats needed to build. Not everything.
# Note: rust-toolchain.toml was already copied when rust was setup.
# Minimizing whats copied reduces needless cache misses.
FOR --sep=", " file IN $src
COPY --dir $file .
END


# Steps we do during the `check` CI phase for all Rust programs
CHECK:
COMMAND
Expand All @@ -147,102 +122,3 @@ SMOKE_TEST:

# ALL executables MUST have `--help` as an option.
RUN target/$TARGETARCH/release/$bin --help


# Set up our target toolchains, and copy our files.
builder:
FROM +rust-base

DO +SETUP --toolchain=example/rust-toolchain.toml

DO +CP_SRC --src="example/*"

# Test rust build container - Use best architecture host tools.
check-hosted:
FROM +builder

DO +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

build-hosted:
ARG TARGETPLATFORM

# Build the service
FROM +builder

RUN /scripts/std_build.sh

DO +SMOKE_TEST --bin=hello_world

SAVE ARTIFACT target/$TARGETARCH/doc doc
SAVE ARTIFACT target/$TARGETARCH/release/hello_world hello_world

# 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 --platform=linux/amd64 --platform=linux/arm64 +build-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

# Run build using the most efficient host tooling
# CI Automated Entry point.
build:
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 +build-hosted
ELSE
BUILD --platform=linux/amd64 +build-hosted
END


# This step will build any packages we would intend to publish or integration test.
#package:
# FROM scratch

# Run integration tests on all packages built during the `package` step.
#test:
# FROM scratch

# Publish packages if all integration tests have passed.
# (Failure to pass tests will prevent packages being published.)
# Don't have a `publish` target if nothing to actually publish.
#publish:
# FROM scratch

## -----------------------------------------------------------------------------

# This step simulates the full CI run for local purposes only.
local-ci-run:
BUILD +check
BUILD +build
# BUILD +package
# BUILD +test
# BUILD +publish
79 changes: 79 additions & 0 deletions examples/rust/Earthfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
VERSION 0.7

# Set up our target toolchains, and copy our files.
builder:
FROM ./../../earthly/rust+rust-base

COPY --dir "*" .

DO ./../../earthly/rust+SETUP

# 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

build-hosted:
ARG TARGETPLATFORM

# Build the service
FROM +builder

RUN /scripts/std_build.sh

DO +SMOKE_TEST --bin=hello_world

SAVE ARTIFACT target/$TARGETARCH/doc doc
SAVE ARTIFACT target/$TARGETARCH/release/hello_world hello_world

# 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 --platform=linux/amd64 --platform=linux/arm64 +build-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

# Run build using the most efficient host tooling
# CI Automated Entry point.
build:
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 +build-hosted
ELSE
BUILD --platform=linux/amd64 +build-hosted
END

# This step simulates the full CI run for local purposes only.
local-ci-run:
BUILD +check
BUILD +build
4 changes: 0 additions & 4 deletions examples/rust/README.md

This file was deleted.

0 comments on commit 0235708

Please sign in to comment.