diff --git a/.forgejo/workflows/test.yml b/.forgejo/workflows/test.yml new file mode 100644 index 0000000..327c473 --- /dev/null +++ b/.forgejo/workflows/test.yml @@ -0,0 +1,8 @@ +on: [push] +jobs: + test: + runs-on: docker + steps: + - uses: https://git.kemitix.net/kemitix/rust@main + with: + args: test diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..966a772 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +FROM docker.io/rust:1.78.0-slim-bookworm + +# nodejs - runtime used by forgejo/github actions +# curl - to download cargo-binstall +# clang-16 & mold - faster linkers for rust +RUN apt-get update && \ + apt-get install -y \ + --no-install-recommends \ + nodejs=18.19.0+dfsg-6~deb12u1 \ + curl=7.88.1-10+deb12u5 \ + clang-16=1:16.0.6-15~deb12u1 \ + mold=1.10.1+dfsg-1 && \ + rm -r /var/lib/apt/lists/* + +RUN curl -L https://github.com/cargo-bins/cargo-binstall/releases/latest/download/cargo-binstall-x86_64-unknown-linux-musl.tgz -o cargo-binstall.tgz && \ + tar -xzf cargo-binstall.tgz && \ + rm cargo-binstall.tgz && \ + mv cargo-binstall /usr/local/bin/ + +RUN cargo binstall -y cargo-chef + +RUN rustup component add rustfmt clippy + +COPY entrypoint.sh / + +ENTRYPOINT [ "/entrypoint.sh" ] diff --git a/README.md b/README.md index 620e0c3..6055f11 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,51 @@ -# docker-builders +# docker-builder-rust -Builder images for use by forgejo actions. \ No newline at end of file +Docker image for building Rust projects with Cargo. + +## Usage + +In a Forgejo action file, e.g. `.forgejo/workflows/test.yml`: + +```yml +on: [push] +jobs: + test: + runs-on: docker + steps: + - uses: https://git.kemitix.net/kemitix/rust@main + with: + args: test + - uses: https://git.kemitix.net/kemitix/rust@main + with: + args: build + +``` + +## Contents + +- nodejs +- clang-16 +- mold +- rust +- cargo +- cargo-binstall + +## Linking + +To take advantage of the clang and mold packages, add the following to the `.cargo/config.toml` file in your project. + +```toml +[target.x86_64-unknown-linux-gnu] +linker = "/usr/bin/clang-16" +rustflags = ["-C", "link-arg=--ld-path=/usr/bin/mold"] +``` + +## Binary size + +To reduce the size of the debug binary, add the following to the `.cargo/config.toml` file in you project. + +```toml +[profile.dev] +debug = 0 +strip = "debuginfo" +``` diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..badef71 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +set -e + +echo cargo $* +ls -l