From c61845ed45b7e90de637debf96c3e86a8180c504 Mon Sep 17 00:00:00 2001 From: Giles Cope Date: Thu, 21 May 2026 09:29:23 +0100 Subject: [PATCH] valgrind example --- docs/examples/examples.md | 2 +- examples/README.md | 2 +- examples/c/Earthfile | 42 ++++++++++++++++++++++++++++++++++++--- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/docs/examples/examples.md b/docs/examples/examples.md index 8e0da04700..a14e595ad5 100644 --- a/docs/examples/examples.md +++ b/docs/examples/examples.md @@ -42,7 +42,7 @@ Please note that these examples, although similar, are distinct from the ones us -- [c](https://github.com/earthbuild/earthbuild/tree/main/examples/c) +- [c](https://github.com/earthbuild/earthbuild/tree/main/examples/c) - also demonstrates running `valgrind` inside earthbuild, useful on macOS / Windows where valgrind isn't available natively. - [clojure](https://github.com/earthbuild/earthbuild/tree/main/examples/clojure) - [cobol](https://github.com/earthbuild/earthbuild/tree/main/examples/cobol) - [cpp](https://github.com/earthbuild/earthbuild/tree/main/examples/cpp) diff --git a/examples/README.md b/examples/README.md index a53c50cc1d..6501b951ba 100644 --- a/examples/README.md +++ b/examples/README.md @@ -23,7 +23,7 @@ Please note that these examples, although similar, are distinct from the ones us - [clojure](./clojure) - [cobol](./cobol) -- [c](./c) +- [c](./c) - also demonstrates running `valgrind` inside earthbuild, useful on macOS / Windows where valgrind isn't available natively. - [cpp](./cpp) - [dotnet](./dotnet) - [elixir](./elixir) diff --git a/examples/c/Earthfile b/examples/c/Earthfile index 6f1d841076..97e54e0547 100644 --- a/examples/c/Earthfile +++ b/examples/c/Earthfile @@ -1,9 +1,18 @@ VERSION 0.8 -FROM alpine:3.23.3 + +# renovate: datasource=docker packageName=alpine +ARG --global alpine_version=3.23.3 +FROM alpine:$alpine_version WORKDIR /c-example deps: - RUN apk --update add build-base cmake + # renovate: datasource=repology depName=alpine_3_23/build-base versioning=loose + ARG build_base_version=0.5-r3 + # renovate: datasource=repology depName=alpine_3_23/cmake versioning=loose + ARG cmake_version=4.1.3-r0 + RUN apk --update add \ + build-base=$build_base_version \ + cmake=$cmake_version build: FROM +deps @@ -19,14 +28,41 @@ docker: unit-test: FROM +deps - RUN apk add cunit-dev + # renovate: datasource=repology depName=alpine_3_23/cunit-dev versioning=loose + ARG cunit_dev_version=2.1.3-r7 + RUN apk add cunit-dev=$cunit_dev_version COPY src src COPY test test RUN cmake test RUN make RUN ./unit-test +# memcheck runs the unit-test binary under valgrind's memcheck tool to detect +# leaks, invalid reads/writes, and uninitialised reads. Built with -g -O0 so +# stack traces resolve to source lines. +memcheck: + FROM +deps + # renovate: datasource=repology depName=alpine_3_23/cunit-dev versioning=loose + ARG cunit_dev_version=2.1.3-r7 + # renovate: datasource=repology depName=alpine_3_23/valgrind versioning=loose + ARG valgrind_version=3.25.1-r2 + RUN apk add \ + cunit-dev=$cunit_dev_version \ + valgrind=$valgrind_version + COPY src src + COPY test test + RUN cmake -DCMAKE_C_FLAGS="-g -O0" test + RUN make + RUN valgrind \ + --error-exitcode=1 \ + --leak-check=full \ + --show-leak-kinds=all \ + --errors-for-leak-kinds=definite \ + --track-origins=yes \ + ./unit-test + all: BUILD +build BUILD +unit-test + BUILD +memcheck BUILD +docker