Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
1d2b5ab
chore: reset crate versions to their last releases
JP-Ellis Oct 16, 2026
70f10d3
build: patch pact_matching by path alone
JP-Ellis Oct 16, 2026
3ef0131
build: configure release-plz for per-crate releases
JP-Ellis Oct 16, 2026
41ddd23
ci: block release PRs that need an unreleased workspace crate
JP-Ellis Oct 16, 2026
aed6eb5
ci: maintain one draft release PR per crate and tag merged releases
JP-Ellis Oct 16, 2026
9ec53fc
ci: publish crates through crates.io trusted publishing
JP-Ellis Oct 16, 2026
9914118
ci: build releases with dist
JP-Ellis Oct 16, 2026
6017fb3
ci: republish pre-dist asset names during a transition period
JP-Ellis Oct 16, 2026
7620cca
ci: publish the pact-verifier image after each CLI release
JP-Ellis Oct 16, 2026
aee481a
ci: release library-only crates from their tags
JP-Ellis Oct 16, 2026
3e3e21a
chore: remove manual release tooling
JP-Ellis Oct 16, 2026
7702982
fix(ci): tag the commit that set each released version
JP-Ellis Oct 16, 2026
29924fb
fix(ci): guard tagging and release PRs against crates.io state
JP-Ellis Oct 16, 2026
3b0c784
fix(ci): build Linux releases in containers to keep their linkage
JP-Ellis Oct 16, 2026
5b08c1b
fix(ci): give each musl crate its own CRT linkage, drop manual releas…
JP-Ellis Oct 16, 2026
e83e440
feat(ci): check release gate artifacts locally with legacy-artifacts.sh
JP-Ellis Oct 16, 2026
b57ecd7
docs: describe checking a release gate build before merge
JP-Ellis Oct 16, 2026
fcc897d
fix(ci): plan a release gate build for the release PR's own tag
JP-Ellis Oct 16, 2026
1e5c70e
fix(ci): install xz in the musl build containers
JP-Ellis Oct 16, 2026
402d821
fix(ci): run the header build from pact_ffi's directory
JP-Ellis Oct 16, 2026
18822c1
fix(ci): install the full mise toolset, with a timeout
JP-Ellis Oct 19, 2026
6264a65
fix(ci): cancel superseded release gate builds
JP-Ellis Oct 19, 2026
50e62c7
build: group build and CI commits in release changelogs
JP-Ellis Oct 19, 2026
d749730
docs: promote pre-release-plz changelog headings to level two
JP-Ellis Oct 19, 2026
f6b5c17
chore(ci): drop the release script tests
JP-Ellis Oct 19, 2026
b3ee795
docs: describe recovering each release step by hand
JP-Ellis Oct 19, 2026
44912c0
chore(ci): prefix the legacy-only release scripts with legacy-
JP-Ellis Oct 19, 2026
110368e
chore(ci): ask the crates.io API whether a version is published
JP-Ellis Oct 19, 2026
7308cce
chore(ci): inline the crates.io published check
JP-Ellis Oct 19, 2026
e041dd1
chore(ci): drop the legacy asset name lists
JP-Ellis Oct 19, 2026
9f973bd
chore(ci): set the legacy cut-off date in one place
JP-Ellis Oct 19, 2026
25fff99
chore(ci): check release dependencies by packaging the crate
JP-Ellis Oct 19, 2026
6b3a8a6
chore(ci): skip the container job for releases without an image
JP-Ellis Oct 19, 2026
d309fe7
chore(ci): gate release PR regeneration on one output
JP-Ellis Oct 19, 2026
7281067
fix(ci): create the legacy pact_ffi release at the release commit
JP-Ellis Oct 19, 2026
0de2cb3
chore(ci): add a release gate sentinel for branch protection
JP-Ellis Oct 19, 2026
e0ba1e7
docs: recover a GitHub release whose upload failed
JP-Ellis Oct 19, 2026
1775153
chore(ci): build the verifier image without emulation
JP-Ellis Oct 19, 2026
f9bf16f
chore(ci): lay out the dist config as tables
JP-Ellis Oct 19, 2026
5a5fe89
chore(ci): drop the concurrency and cbindgen hand edits
JP-Ellis Oct 19, 2026
b7b9384
chore(ci): check Linux linkage in every release build
JP-Ellis Oct 19, 2026
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
19 changes: 19 additions & 0 deletions .github/build-setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Steps dist runs before `dist build` in each per-target build job.

# musl builds run cargo through dist-cargo.sh, which links pact_ffi's musl
# CRT dynamically and keeps the cross-rs toolchain in charge of aarch64.
# dist checks for cargo-zigbuild before an aarch64-musl build; the stub
# satisfies that check and forwards to the same script. The cross-rs
# images lack xz, which dist's installer needs.
- name: Route musl builds through dist-cargo.sh
if: contains(join(matrix.targets, ','), 'musl')
shell: bash
run: |
command -v xz >/dev/null || { apt-get update -q && apt-get install -y -q --no-install-recommends xz-utils; }
script="$GITHUB_WORKSPACE/.github/scripts/dist-cargo.sh"
bin="$RUNNER_TEMP/dist-cargo-bin"
mkdir -p "$bin"
printf '#!/bin/sh\nexec "%s" "$@"\n' "$script" > "$bin/cargo-zigbuild"
chmod +x "$bin/cargo-zigbuild"
echo "$bin" >> "$GITHUB_PATH"
echo "CARGO=$script" >> "$GITHUB_ENV"
9 changes: 0 additions & 9 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,6 @@ cargo test --test v3_message
cargo test --test v4
```

Cross-platform MUSL builds use the project Docker image:

```bash
docker run --rm --user "$(id -u)":"$(id -g)" \
-v $(pwd):/workspace -w /workspace/rust \
-t -e TZ=UTC pactfoundation/rust-musl-build \
./scripts/ci-musl-build.sh
```

## High-level architecture

This repository is the Rust reference implementation of Pact and exposes the same core through Rust crates, a C-compatible FFI layer, and a verifier CLI.
Expand Down
20 changes: 20 additions & 0 deletions .github/scripts/changelog-section.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
# Prints the body of one version's section from a changelog whose
# sections are `##` headings. release-plz writes `## [<version>]`; the
# entries from before release-plz use `## <version> - <title>`.
#
# Usage: changelog-section.sh <CHANGELOG.md> <version>
# Exits 1 when the changelog has no section for <version>.
set -euo pipefail

changelog=$1
version=$2

awk -v heading="## [${version}]" '
/^## / {
if (found) exit
if (index($0, heading) == 1) { found = 1; next }
}
found { print }
END { exit found ? 0 : 1 }
' "$changelog"
62 changes: 62 additions & 0 deletions .github/scripts/check-linkage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env bash
# Fails when a Linux artifact in a dist build links against the wrong C
# library:
# - musl: a shared object must need musl's C library (`libc.so`, or
# Alpine's `libc.musl-<arch>.so.1`), never glibc's libc.so.6; an
# executable must be fully static.
# - gnu: no symbol may need a glibc version newer than GLIBC_FLOOR.
#
# Usage: check-linkage.sh <dir>
# <dir> holds dist's `<package>-<target>.tar.xz` archives, e.g. a release
# build's `artifacts-*` artifacts, merged.
set -euo pipefail

# The oldest glibc among supported major distributions: RHEL 8 and its
# rebuilds. dist-workspace.toml builds linux-gnu in manylinux_2_28 to match.
GLIBC_FLOOR=2.28

dir=$1
readelf=$(command -v readelf || command -v llvm-readelf \
|| { ls /usr/lib/llvm-*/bin/llvm-readelf /opt/homebrew/opt/llvm/bin/llvm-readelf 2>/dev/null || true; } | sort -V | tail -1)
[[ -n $readelf ]] || { echo "check-linkage.sh needs readelf" >&2; exit 1; }
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT

# Checks one ELF file against <flavour>: musl or gnu.
check() {
local file=$1 flavour=$2 needed newest
needed=$("$readelf" -d "$file" 2>/dev/null | sed -n 's/.*(NEEDED).*\[\(.*\)\].*/\1/p')
case "$flavour" in
musl)
if [[ "$("$readelf" -h "$file")" == *"EXEC (Executable file)"* || -z "$needed" ]]; then
[[ -z "$needed" ]] || { echo "::error::$file is not fully static: needs $needed"; return 1; }
elif grep -qx 'libc.so.6' <<<"$needed" || ! grep -qxE 'libc\.so|libc\.musl-[a-z0-9_]+\.so\.1' <<<"$needed"; then
echo "::error::$file does not link musl's libc.so: needs $(tr '\n' ' ' <<<"$needed")"
return 1
fi
;;
gnu)
newest=$("$readelf" -V "$file" | grep -o 'GLIBC_[0-9][0-9.]*' | sed 's/GLIBC_//' | sort -V | tail -1)
if [[ -n $newest && $(printf '%s\n%s\n' "$newest" "$GLIBC_FLOOR" | sort -V | tail -1) != "$GLIBC_FLOOR" ]]; then
echo "::error::$file needs glibc $newest, above the $GLIBC_FLOOR floor"
return 1
fi
;;
esac
}

shopt -s nullglob
status=0 checked=0
for archive in "$dir"/*-unknown-linux-gnu.tar.xz "$dir"/*-unknown-linux-musl.tar.xz; do
name=$(basename "$archive" .tar.xz)
mkdir "$work/$name"
tar xJf "$archive" -C "$work/$name"
# Shared objects and executables; static archives link nothing.
while IFS= read -r -d '' file; do
check "$file" "${name##*-}" || status=1
echo "checked ${file#"$work/"}"
checked=$((checked + 1))
done < <(find "$work/$name" -type f \( -name '*.so' -o -perm -u+x \) -print0)
done
(( checked )) || { echo "::error::no Linux archives in $dir"; exit 1; }
exit "$status"
43 changes: 43 additions & 0 deletions .github/scripts/dist-cargo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash
# The cargo that dist runs in the musl build jobs (dist reads `CARGO`; see
# .github/build-setup.yml).
#
# - pact_ffi links the musl CRT dynamically: rustc drops a cdylib on a
# crt-static target. dist appends `+crt-static` to RUSTFLAGS for musl, so
# CARGO_ENCODED_RUSTFLAGS, which cargo prefers, overrides it for
# pact_ffi's build only. The CLI stays fully static. precise-builds gives
# each crate its own cargo invocation.
# - dist treats aarch64-musl in an x86_64 container as a cross build and
# runs `cargo zigbuild`. The cross-rs image already sets up its musl
# toolchain, so this runs a plain `cargo build`.
set -euo pipefail

args=("$@")
[[ ${args[0]-} == zigbuild ]] && args[0]=build

# Prints the crate name of a package spec: `name`, `name@ver`,
# `path+file:///.../name#ver` or `path+file:///...#name@ver`.
crate_name() {
local spec=$1 fragment
if [[ $spec == *'#'* ]]; then
fragment=${spec#*#}
if [[ $fragment == *@* ]]; then echo "${fragment%@*}"; else basename "${spec%%#*}"; fi
else
echo "${spec%@*}"
fi
}

if [[ ${args[0]-} == build ]]; then
target='' package=''
for ((i = 1; i < ${#args[@]}; i++)); do
case "${args[i]}" in
--target) target=${args[i + 1]-} ;;
--package) package=$(crate_name "${args[i + 1]-}") ;;
esac
done
if [[ $target == *-linux-musl && $package == pact_ffi ]]; then
export CARGO_ENCODED_RUSTFLAGS="-Ctarget-feature=-crt-static"
fi
fi

exec cargo "${args[@]}"
123 changes: 123 additions & 0 deletions .github/scripts/legacy-artifacts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#!/usr/bin/env bash
# Rebuilds the pre-dist asset names from a dist release's archives,
# without recompiling: each binary or library is gzipped under its old
# name with an `openssl dgst -r`-style `.sha256` file.
#
# Usage: legacy-artifacts.sh <tag> <out-dir>
# Reads the release's assets with gh (needs GH_TOKEN and
# GITHUB_REPOSITORY), or, with LEGACY_ARCHIVES set, from that directory:
# for example a release gate run's artifacts, to check them before a tag.
# Needs LLVM for the Windows import libraries (see legacy-import-lib.sh).
set -euo pipefail

# MARK: Cut-off

# CUTOFF is the single source of the legacy cut-off date. From that date
# this script writes nothing, so no legacy assets are published. After it,
# delete:
# - .github/workflows/legacy-artifacts.yml;
# - the `legacy-artifacts` entries in dist-workspace.toml, then run
# `dist generate` and re-apply the `hand edit` changes to release.yml;
# - every .github/scripts/legacy-* file;
# - RELEASING.md's legacy sections.
CUTOFF=2027-06-30

if [[ ! "$(date -u +%Y-%m-%d)" < "$CUTOFF" ]]; then
echo "::notice::Past the $CUTOFF legacy cut-off; no legacy assets are written."
exit 0
fi

# MARK: Build

scripts=$(cd "$(dirname "$0")" && pwd)

tag=$1
out=$(mkdir -p "$2" && cd "$2" && pwd)
package=${tag%-v*}
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT
cd "$work"

# Copies release asset <name> into <dir>.
download() {
local name=$1 dir=$2
if [[ -n ${LEGACY_ARCHIVES-} ]]; then
cp "$LEGACY_ARCHIVES/$name" "$dir/"
else
gh release download "$tag" --repo "$GITHUB_REPOSITORY" -p "$name" -D "$dir" --clobber
fi
}

gzip_and_sum() {
local src=$1 name=$2
gzip --no-name --best --stdout "$src" > "$out/$name"
(cd "$out" && sha256sum --binary "$name" > "$name.sha256")
}

# Prints the path of <file> after unpacking <target>'s archive. Archives
# may or may not wrap their files in a top-level directory.
extract() {
local target=$1 file=$2 archive path
if [[ ! -d "$target" ]]; then
if [[ $target == *windows* ]]; then archive="$package-$target.zip"; else archive="$package-$target.tar.xz"; fi
download "$archive" .
mkdir "$target"
case "$archive" in
*.zip) unzip -q "$archive" -d "$target" ;;
*) tar xJf "$archive" -C "$target" ;;
esac
fi
path=$(find "$target" -type f -name "$file" | head -1)
[[ -n "$path" ]] || { echo "$file not found in $archive" >&2; return 1; }
echo "$path"
}

case "$package" in
pact_verifier_cli)
# Linux names always pointed at the static musl builds.
for entry in \
x86_64-unknown-linux-musl:pact-verifier:pact-verifier-linux-x86_64.gz \
aarch64-unknown-linux-musl:pact-verifier:pact-verifier-linux-aarch64.gz \
x86_64-apple-darwin:pact-verifier:pact-verifier-macos-x86_64.gz \
aarch64-apple-darwin:pact-verifier:pact-verifier-macos-aarch64.gz \
x86_64-pc-windows-msvc:pact-verifier.exe:pact-verifier-windows-x86_64.exe.gz \
aarch64-pc-windows-msvc:pact-verifier.exe:pact-verifier-windows-aarch64.exe.gz
do
IFS=: read -r target file name <<<"$entry"
path=$(extract "$target" "$file")
gzip_and_sum "$path" "$name"
done
;;
pact_ffi)
for entry in \
x86_64-unknown-linux-gnu:linux-x86_64 \
aarch64-unknown-linux-gnu:linux-aarch64 \
x86_64-unknown-linux-musl:linux-x86_64-musl \
aarch64-unknown-linux-musl:linux-aarch64-musl
do
IFS=: read -r target suffix <<<"$entry"
gzip_and_sum "$(extract "$target" libpact_ffi.so)" "libpact_ffi-$suffix.so.gz"
gzip_and_sum "$(extract "$target" libpact_ffi.a)" "libpact_ffi-$suffix.a.gz"
done
for entry in x86_64-apple-darwin:macos-x86_64 aarch64-apple-darwin:macos-aarch64; do
IFS=: read -r target suffix <<<"$entry"
gzip_and_sum "$(extract "$target" libpact_ffi.dylib)" "libpact_ffi-$suffix.dylib.gz"
gzip_and_sum "$(extract "$target" libpact_ffi.a)" "libpact_ffi-$suffix.a.gz"
done
# dist ships the DLL and the static library, but not the DLL's
# import library; it is rebuilt from the DLL's export table.
for arch in x86_64 aarch64; do
target=$arch-pc-windows-msvc
dll=$(extract "$target" pact_ffi.dll)
"$scripts/legacy-import-lib.sh" "$dll" "$arch" "$target/pact_ffi.dll.lib"
gzip_and_sum "$dll" "pact_ffi-windows-$arch.dll.gz"
gzip_and_sum "$target/pact_ffi.dll.lib" "pact_ffi-windows-$arch.dll.lib.gz"
gzip_and_sum "$(extract "$target" pact_ffi.lib)" "pact_ffi-windows-$arch.lib.gz"
done
download pact.h "$out"
download pact-cpp.h "$out"
;;
*)
echo "No legacy assets for $package" >&2
;;
esac
63 changes: 63 additions & 0 deletions .github/scripts/legacy-import-lib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env bash
# Builds the MSVC import library (`<name>.dll.lib`) for a DLL from its
# export table. dist ships the DLL but not the import library that rustc
# writes beside it.
#
# Exports outside the executable section are data, and are marked DATA so
# the library gives them no call thunk, as rustc's does.
#
# Usage: legacy-import-lib.sh <dll> <x86_64|aarch64> <out.lib>
#
# Only legacy-artifacts.sh uses this. Delete it after the legacy cut-off
# date set in legacy-artifacts.sh.
set -euo pipefail

dll=$1
arch=$2
out=$3

llvm() {
local tool=$1
command -v "$tool" \
|| { ls /usr/lib/llvm-*/bin/"$tool" /opt/homebrew/opt/llvm/bin/"$tool" 2>/dev/null || true; } | sort -V | tail -1
}
readobj=$(llvm llvm-readobj)
dlltool=$(llvm llvm-dlltool)
[[ -n $readobj && -n $dlltool ]] || { echo "legacy-import-lib.sh needs llvm-readobj and llvm-dlltool" >&2; exit 1; }

case "$arch" in
x86_64) machine=i386:x86-64 ;;
aarch64) machine=arm64 ;;
*) echo "unknown arch: $arch" >&2; exit 1 ;;
esac

def=$(mktemp)
trap 'rm -f "$def"' EXIT
{
echo "LIBRARY $(basename "$dll")"
echo "EXPORTS"
# Pass 1 collects the executable sections' address ranges; pass 2
# prints each export, with DATA when its RVA falls outside them.
awk '
function hex(s, i, v) {
s = tolower(s); sub(/^0x/, "", s); v = 0
for (i = 1; i <= length(s); i++) v = v * 16 + index("0123456789abcdef", substr(s, i, 1)) - 1
return v
}
BEGIN { n = 0 }
NR == FNR {
if ($1 == "VirtualSize:") size = hex($2)
if ($1 == "VirtualAddress:") addr = hex($2)
if ($1 == "IMAGE_SCN_MEM_EXECUTE") { lo[n] = addr; hi[n] = addr + size; n++ }
next
}
$1 == "Name:" { name = $2 }
$1 == "RVA:" {
rva = hex($2); data = 1
for (i = 0; i < n; i++) if (rva >= lo[i] && rva < hi[i]) data = 0
print " " name (data ? " DATA" : "")
}
' <("$readobj" --sections "$dll") <("$readobj" --coff-exports "$dll")
} > "$def"

"$dlltool" -m "$machine" -d "$def" -l "$out"
31 changes: 31 additions & 0 deletions .github/scripts/tag-releases.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
# Creates `<crate>-v<version>` for each workspace crate whose version has
# no tag, i.e. each crate whose release PR just merged, and pushes it.
# Each tag goes in its own push: GitHub fires no events for a push of
# more than three tags.
#
# Usage: tag-releases.sh <manifest-path> <remote>
set -euo pipefail

manifest=$1
remote=$2

cargo metadata --format-version 1 --no-deps --manifest-path "$manifest" \
| jq -r '.packages[] | [.name, .version, .manifest_path] | @tsv' \
| while IFS=$'\t' read -r name version crate_manifest; do
tag="$name-v$version"
git rev-parse -q --verify "refs/tags/$tag" >/dev/null && continue
# Published but untagged means a missing migration tag or a manual
# publish, never a release PR merge: tagging would start a release.
if curl -fso /dev/null -A 'pact-foundation/pact-reference release' "https://crates.io/api/v1/crates/$name/$version"; then
echo "::warning::$name $version is on crates.io but has no $tag tag; not tagging it." >&2
continue
fi
# Tag the commit on master's first-parent line that set this
# version, which is the release PR's merge (squash or merge commit),
# even when later commits have landed since.
commit=$(git log -1 --first-parent --diff-merges=first-parent --no-patch --format=%H -G "^version = \"${version//./\\.}\"" -- "$crate_manifest")
git tag -a "$tag" -m "$tag" "${commit:-HEAD}"
git push -q "$remote" "refs/tags/$tag"
echo "$tag"
done
Loading
Loading