From f332df9cf5019b0ceac2cb6d45d246241c52e619 Mon Sep 17 00:00:00 2001 From: Ryan Butler Date: Wed, 29 Jan 2025 11:29:47 +0100 Subject: [PATCH] build: add docker runner for mac users to run tests --- .cargo/config.toml | 4 ++++ docker/cargo-runner.sh | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100755 docker/cargo-runner.sh diff --git a/.cargo/config.toml b/.cargo/config.toml index 77aa9eb8..9f4a1a17 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -5,3 +5,7 @@ [net] # libgit2 doesn't handle git credentials well git-fetch-with-cli = true + +# Run cargo with `RUSTFLAGS='--cfg docker_runner'` +[target.'cfg(docker_runner)'] +runner = "docker/cargo-runner.sh" diff --git a/docker/cargo-runner.sh b/docker/cargo-runner.sh new file mode 100755 index 00000000..5fcf1807 --- /dev/null +++ b/docker/cargo-runner.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +# Allows running tests inside docker. Takes care of linux-only dependencies and avoids +# the need to emulate the architecture. + +set -o pipefail -eu + +PROGRAM=$1; shift + +main() { + local -r absolute_path="$(realpath ${PROGRAM})" + + docker run \ + --rm \ + -v "${absolute_path}:/mnt/program" \ + -w /mnt \ + -e RUST_BACKTRACE \ + -it debian:latest \ + /mnt/program $@ +} + +main $@