interplane.Get Omega
Read in your language

ggml

[Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685)

Brought by drakestapleton

branch master Branches Tags History

ggml / scripts / check-release-apiabi.sh

128 lines · 4415 bytes Raw Blame History
1#!/bin/bash
2# Check API/ABI compatibility between the previous release tag and current HEAD.
3#
4# Finds the most recent vX.Y.Z tag, checks it out in a temporary git worktree,
5# builds both versions with shared libs enabled, and uses check-apiabi-compat.sh
6# to compare the results.
7#
8# Exit codes:
9# 0: compatible, or check was skipped
10# 1: backwards-incompatible changes found, or build failed
11#
12# Options:
13# --tag <version>: compare against this tag instead of the latest release
14#
15# Environment:
16# SKIP_APIABI_CHECK: set to 1 or true to skip
17# APIABI_COMPARE_TAG: equivalent to --tag (used by CI)
18# APIABI_REPORT_DIR: preserve reports and dumps in this directory, even if the comparison fails
19
20set -euo pipefail
21
22SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
23REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
24LIBS=(libggml libggml-base)
25
26usage() {
27 echo "Usage: $0 [--tag <version>]" >&2
28 echo " --tag <version> Compare against this release tag (default: latest)" >&2
29}
30
31COMPARE_TAG="${APIABI_COMPARE_TAG:-}"
32while [[ "$#" -gt 0 ]]; do
33 case "$1" in
34 --tag)
35 if [[ -z "${2:-}" ]]; then usage; exit 1; fi
36 COMPARE_TAG="$2"
37 shift 2
38 ;;
39 --tag=*)
40 COMPARE_TAG="${1#*=}"
41 shift
42 ;;
43 -h | --help)
44 usage; exit 0
45 ;;
46 *)
47 usage; exit 1
48 ;;
49 esac
50done
51
52if [[ "${SKIP_APIABI_CHECK:-}" == "1" || "${SKIP_APIABI_CHECK:-}" == "true" ]]; then
53 echo "SKIP_APIABI_CHECK is set - skipping API/ABI compatibility check"
54 exit 0
55fi
56
57if ! command -v abi-compliance-checker >/dev/null 2>&1 || ! command -v abidw >/dev/null 2>&1; then
58 echo "Warning: abi-compliance-checker or abigail-tools not installed - skipping API/ABI check"
59 exit 0
60fi
61
62if [[ -n "${COMPARE_TAG}" ]]; then
63 PREV_TAG="${COMPARE_TAG}"
64 if ! git -C "$REPO_ROOT" rev-parse --verify "${PREV_TAG}^{}" >/dev/null 2>&1; then
65 echo "Error: tag '${PREV_TAG}' not found in repository." >&2
66 exit 1
67 fi
68else
69 PREV_TAG=$(git -C "$REPO_ROOT" tag --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1 || true)
70 if [[ -z "${PREV_TAG}" ]]; then
71 echo "Warning: no previous release tag found - skipping API/ABI check"
72 exit 0
73 fi
74fi
75OLD_VERSION="${PREV_TAG#v}"
76OLD_MAJOR="${OLD_VERSION%%.*}"
77OLD_MINOR="${OLD_VERSION#*.}"; OLD_MINOR="${OLD_MINOR%%.*}"
78
79NEW_MAJOR=$(grep "set(GGML_VERSION_MAJOR" "$REPO_ROOT/CMakeLists.txt" | sed 's/.*MAJOR \([0-9]*\).*/\1/')
80NEW_MINOR=$(grep "set(GGML_VERSION_MINOR" "$REPO_ROOT/CMakeLists.txt" | sed 's/.*MINOR \([0-9]*\).*/\1/')
81
82if [[ "$NEW_MAJOR" -gt "$OLD_MAJOR" ]]; then
83 echo "Major version increment ($OLD_MAJOR -> $NEW_MAJOR): API/ABI breaking changes are expected, skipping compatibility check."
84 exit 0
85fi
86
87CHECK_FLAGS=()
88if [[ "$NEW_MINOR" -eq "$OLD_MINOR" ]]; then
89 echo "Patch version bump detected: checking for any API/ABI changes (a minor bump is required if any are found)..."
90 CHECK_FLAGS+=(--strict)
91else
92 echo "Minor version bump detected: checking for backwards-incompatible API/ABI changes..."
93fi
94
95echo "Checking API/ABI compatibility against ${PREV_TAG}..."
96
97WORKTREE_DIR=$(mktemp -d)
98BUILD_OLD=$(mktemp -d)
99BUILD_NEW=$(mktemp -d)
100
101cleanup() {
102 git -C "$REPO_ROOT" worktree remove --force "$WORKTREE_DIR" 2>/dev/null || true
103 rm -rf "$WORKTREE_DIR" "$BUILD_OLD" "$BUILD_NEW"
104}
105trap cleanup EXIT
106
107git -C "$REPO_ROOT" worktree add "$WORKTREE_DIR" "$PREV_TAG"
108
109cmake -S "$WORKTREE_DIR" -B "$BUILD_OLD" -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo
110cmake --build "$BUILD_OLD" --parallel "$(nproc)"
111
112cmake -S "$REPO_ROOT" -B "$BUILD_NEW" -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo
113cmake --build "$BUILD_NEW" --parallel "$(nproc)"
114
115(cd "$WORKTREE_DIR" && "$SCRIPT_DIR/check-apiabi-compat.sh" --generate "$BUILD_OLD" "${LIBS[@]}")
116(cd "$REPO_ROOT" && "$SCRIPT_DIR/check-apiabi-compat.sh" --generate "$BUILD_NEW" "${LIBS[@]}")
117
118CHECK_RESULT=0
119(cd "$REPO_ROOT" && "$SCRIPT_DIR/check-apiabi-compat.sh" "${CHECK_FLAGS[@]}" --check "$BUILD_OLD" "$BUILD_NEW") || CHECK_RESULT=$?
120
121if [[ -n "${APIABI_REPORT_DIR:-}" ]]; then
122 mkdir -p "$APIABI_REPORT_DIR/old" "$APIABI_REPORT_DIR/new"
123 cp -R "$BUILD_OLD/apiabi/." "$APIABI_REPORT_DIR/old/"
124 cp -R "$BUILD_NEW/apiabi/." "$APIABI_REPORT_DIR/new/"
125 echo "API/ABI reports saved to $APIABI_REPORT_DIR"
126fi
127
128exit "$CHECK_RESULT"