cargo
Build and test a Rust crate or workspace, with the cargo registry kept on the host.
Build and test a Rust crate or workspace, with the cargo registry kept on the host.
build compiles into target, test runs the tests after it. Both are skipped while
the .rs files and Cargo.toml/Cargo.lock are unchanged, and downloaded crates are
kept in ~/.cargo, so they are not fetched again.
includes:
cargo:
git: https://github.com/no0dles/hammerkit.git
ref: v1.19.0
path: catalog/cargo
with:
CARGO_ARGS: --locked --workspace
tasks:
check:
deps: [cargo:test]Tasks
| Task | What it does | Reads | Produces |
|---|---|---|---|
build | Build the crate into target. | every Cargo.toml, Cargo.lock, every .rs file | target |
test | Run the tests of the crate. | every Cargo.toml, Cargo.lock, every .rs file |
Inputs
| Input | Default | Meaning |
|---|---|---|
RUST_VERSION | 1.90 | Tag of the rust image the tasks run in. The image is rust:<RUST_VERSION>-slim. Quote it in with ('1.90'), or YAML reads it as a number. |
CARGO_ARGS | --locked | Arguments for cargo build and cargo test, for example --locked --workspace. |
The entry
# Builds and tests a Rust crate or workspace with the cargo registry kept on the host.
envs:
# tag of the rust image the tasks run in, quoted so 1.90 stays 1.90
RUST_VERSION: '1.90'
# arguments for cargo, for example --locked --workspace
CARGO_ARGS: --locked
tasks:
build:
description: build the crate into target
image: rust:${RUST_VERSION}-slim
src:
- Cargo.toml
- Cargo.lock
- '**/Cargo.toml'
- '**/*.rs'
generates: [target]
mounts:
- ~/.cargo/registry:/usr/local/cargo/registry
- ~/.cargo/git:/usr/local/cargo/git
cmds:
- cargo build ${CARGO_ARGS}
test:
description: run the tests of the crate
image: rust:${RUST_VERSION}-slim
deps: [build]
src:
- Cargo.toml
- Cargo.lock
- '**/Cargo.toml'
- '**/*.rs'
mounts:
- ~/.cargo/registry:/usr/local/cargo/registry
- ~/.cargo/git:/usr/local/cargo/git
cmds:
- cargo test ${CARGO_ARGS}