8000 cargo-mutants 27.1.0 (new): mutation testing for Rust (fv-lab) by bryan-minimal · Pull Request #1609 · gominimal/pkgs · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions packages/cargo-mutants/build.ncl
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
let { subsetOf, Attrs, BuildSpec, Local, Needs, OutputBin, Source, Test, .. } = import "minimal.ncl" in
let base = import "../base/build.ncl" in
let bash-bootstrap = import "../bash-bootstrap/build.ncl" in
let detbuild = import "../detbuild/build.ncl" in
let grep = import "../grep/build.ncl" in
let rust = import "../rust/build.ncl" in
let toolchain = import "../toolchain/build.ncl" in

let gcc = import "../gcc/build.ncl" in
let glibc = import "../glibc/build.ncl" in

let version = "27.1.0" in
{
name = "cargo-mutants",
# Mutation testing for Rust, built from source with the rust package. It drives
# whatever `cargo` is on PATH at run time (cargo build / cargo test on mutated
# copies of the tree) and ships no toolchain of its own, so rust is a test dep
# here, not a runtime dep: a session that uses it brings its own rust.
build_deps = [
{ file = "build.sh" } | Local,
{
# Mirror of https://github.com/sourcefrog/cargo-mutants/archive/refs/tags/v%{version}.tar.gz
url = "gs://minimal-staging-archives/sourcefrog/cargo-mutants/v%{version}.tar.gz",
sha256 = "e57d8c31a8edee7d9265949aef896768729c824626897938e98a5d162a82bda0",
extract = true,
strip_prefix = "cargo-mutants-%{version}",
} | Source,
base,
rust,
toolchain,
# Deterministic getrandom/getentropy for the offline build (see build.sh).
detbuild,
],

runtime_deps = [
glibc,
subsetOf gcc ["libgcc"],
],

# cargo fetch (see build.sh)
needs =
{
dns = {},
internet = {},
} | Needs,

cmd = "./build.sh",
build_args = { include version },
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit · build_args forwards version, but build.sh does not read MINIMAL_ARG_VERSION. The source extracts into the cwd through strip_prefix, so the script needs no version. Remove the line, as packages/zola/build.ncl does. packages/cargo-nextest/build.ncl has the same unused forward, so this is a small pattern and not one instance.


outputs = {
cargo-mutants = { glob = "usr/bin/cargo-mutants" } | OutputBin,
},

tests = {
version_check =
{
class = 'Standalone,
test_deps = [bash-bootstrap, grep],
cmds = [
["/bin/bash", "-c", "cargo-mutants mutants --version | grep -qx 'cargo-mutants %{version}'"],
],
} | Test,
# `cargo mutants --list` on a one-function crate: cargo finds the cargo-mutants
# subcommand on PATH, cargo-mutants runs `cargo metadata` and lists the mutants of
# `add`. Nothing is compiled, so no linker is needed.
list =
{
class = 'Standalone,
test_deps = [bash-bootstrap, grep, rust],
cmds = [
[
"/bin/bash",
"-c",
m%"
set -euo pipefail
export CARGO_HOME="$PWD/cargo-home"
mkdir -p tiny/src
cd tiny
printf '[package]\nname = "tiny"\nversion = "0.1.0"\nedition = "2021"\n' > Cargo.toml
printf 'pub fn add(a: i32, b: i32) -> i32 {\n a + b\n}\n' > src/lib.rs
out="$(cargo mutants --list --line-col=false)"
printf '%s\n' "$out"
grep -qx 'src/lib.rs: replace add -> i32 with 0' <<<"$out"
grep -qx 'src/lib.rs: replace + with - in add' <<<"$out"
"%
],
],
} | Test,
},

attrs =
{
upstream_version = version,
license_spdx = "MIT",
source_provenance = {
category = 'GithubRepo,
owner = "sourcefrog",
repo = "cargo-mutants",
},
} | Attrs,
} | BuildSpec
31 changes: 31 additions & 0 deletions packages/cargo-mutants/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
set -euo pipefail

export CC=gcc
export LD=gcc
# Reproducibility: codegen-units=1 and v0 mangling (the default parallel codegen emits
# functions in a different order every build; legacy mangling hashes the session into
# symbol names; see codex, nushell, zola), plus both source and cargo-home paths
# remapped out of the binary.
export RUSTFLAGS="-C linker=gcc -C codegen-units=1 -C symbol-mangling-version=v0 --remap-path-prefix=$(pwd)=/builddir --remap-path-prefix=$HOME/.cargo=/cargo"
export CARGO_INCREMENTAL=0

# All network access happens here, with real entropy: crates are fetched and checked
# against upstream's Cargo.lock before the shim below is loaded. cargo-mutants has no
# -sys crates and no build script that downloads anything (checked for 27.1.0).
cargo fetch --locked

# Deterministic build-time entropy (packages/detbuild) for the offline build only;
# `--frozen` refuses any network access.
LD_PRELOAD=/usr/lib/minimal/libdetbuild.so cargo build --frozen --release --bin cargo-mutants

install -Dm755 target/release/cargo-mutants "$OUTPUT_DIR/usr/bin/cargo-mutants"

# runtime_deps is glibc + libgcc (libgcc_s, for unwinding); fail closed if the binary
# ever NEEDs anything else.
needed=$(readelf -d "$OUTPUT_DIR/usr/bin/cargo-mutants" | sed -n 's/.*Shared library: \[\(.*\)\]/\1/p')
echo "$needed"
if grep -vxE 'libc\.so\.6|libm\.so\.6|libgcc_s\.so\.1|ld-linux-(x86-64|aarch64)\.so\.[12]' <<<"$needed"; then
echo "ERROR: cargo-mutants NEEDs a library outside glibc and libgcc_s (above)" >&2
exit 1
fi
Loading
0