char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
dfe45163e
char/aliceai-t5-moe
1#!/bin/sh 2# Check for backwards-incompatible API and ABI changes between two builds 3# 4# Backwards-incompatible API changes, such as removing a value from an enum, 5# are checked by abi-compliance-checker. Such changes can break compilation of 6# existing programs. 7# 8# Backwards-incompatible ABI changes, such as the removal of a public function, 9# are checked by libigail-tools. Such changes could break run-time dynamic 10# linking of existing binaries. (We don't use a-c-c for ABI checks because it 11# needs a debug build, whereas abigail does not.) 12# 13# Commands: 14# --generate <build-dir>: Creates API/ABI dumps in <build-dir> 15# <build-dir> is expected to be a CMake build result 16# --check <dir1> <dir2>: Compares dumps in <dir1> and <dir2> 17# Comparison exit codes 18# 0: all good 19# 1: backwards-incompatible changes found 20# 21# Options: 22# --include-path <dir>: a-c-c calls gcc on headers; use this option to add 23# directories to gcc's search path 24# 25# 26# This script would typically be used before cutting a release: 27# 28# 1. Generate API/ABI dump for the old version 29# 30# $ check-apiabi-compat.sh --generate <build-dir-old> libfoo [ libbar ...] 31# 32# 2. <update source> 33# 34# 3. Generate API/ABI dump for the new version 35# 36# $ check-apiabi-compat.sh --generate <build-dir-new> libfoo [ libbar ...] 37# 38# 4. Compare the two dumps 39# 40# $ check-apiabi-compat.sh --check <old-build-dir> <new-build-dir> 41# 42# If the check exits 0, all is fine. Otherwise, backwards-incompatible 43# changes were found, and the librar(ies) need a SOVER bump. 44set -eu 45 46# Preconditions 47if !command -v abi-compliance-checker> /dev/null2 >&1;then 48echo "abi-compliance-checker is not installed." >&2 49exit 1 50elif !command -v abidw> /dev/null2 >&1;then 51echo "abigail-tools are not installed." >&2 52exit 1 53fi 54 55# Some generic functions 56usage () { 57echo "Usage: $ 0 [ --include-path <dir> ] --generate <build-dir> libXXX [ libYYY ... ]" >&2 58echo " $ 0 --check <old-build-dir> <new-build-dir>" >&2 59} 60 61get_cmake_project_name () { 62sed -nr 's/^project\("(.*)".*$/\1/p' CMakeLists.txt 63} 64 65get_cmake_version () { 66major =" $( sed -nr 's/^set\([A-Z]+_VERSION_MAJOR ([0-9]+)\)$/\1/p' CMakeLists.txt) " 67minor =" $( sed -nr 's/^set\([A-Z]+_VERSION_MINOR ([0-9]+)\)$/\1/p' CMakeLists.txt) " 68patch =" $( sed -nr 's/^set\([A-Z]+_VERSION_PATCH ([0-9]+)\)$/\1/p' CMakeLists.txt) " 69echo " $ major . $ minor . $ patch " 70} 71 72# Option parsing and validation 73DO_GEN =0 74DO_CHECK =0 75BUILD_DIR = 76BUILD_DIR_NEW = 77INCLUDE_PATHS = 78while [" $ #" -gt 0 ];do 79case " $ 1 " in 80 --generate=*) 81DO_GEN =1 82BUILD_DIR =" ${ 1 #*=} " 83shift 84 ;; 85 --generate) 86DO_GEN =1 87if [ -z" ${ 2 :-} " ];then 88usage 89exit 1 90fi 91BUILD_DIR =" $ 2 " 92shift 2 93 ;; 94 --check) 95DO_CHECK =1 96if [ -z" ${ 2 :-} " ] || [ -z" ${ 3 :-} " ];then 97usage 98exit 1 99elif ! [ -d" $ 2 " ];then 100echo " $ 2 is not a directory." >&2 101exit 1 102elif ! [ -d" $ 3 " ];then 103echo " $ 3 is not a directory." >&2 104exit 1 105fi 106BUILD_DIR =" $ 2 " 107BUILD_DIR_NEW =" $ 3 " 108shift 3 109 ;; 110 --include-path=*) 111INCLUDE_PATHS =" $ INCLUDE_PATHS ${ 1 #*=} " 112shift 113 ;; 114 --include-path) 115if [ -z" ${ 2 :-} " ];then 116usage 117exit 1 118fi 119INCLUDE_PATHS =" $ INCLUDE_PATHS $ 2 " 120shift 2 121 ;; 122 -h| --help) 123usage 124exit 1 125 ;; 126 -?*) 127usage 128exit 1 129 ;; 130 *) 131break 132 ;; 133esac 134done 135if [ $((DO_GEN +DO_CHECK )) -gt 1 ];then 136echo "Can only use one --command." >&2 137exit 138fi 139PROJECT_NAME =" $( get_cmake_project_name ) " 140PROJECT_VERSION =" $( get_cmake_version ) " 141LIB_NAMES ="" 142while [" $ #" -gt 0 ];do 143if [" ${ 1 #lib} " =" $ 1 " ];then 144echo "Library to check must start with libXXX." >&2 145exit 1 146fi 147LIB_NAMES =" $ LIB_NAMES $ 1 " 148shift 149done 150 151dump_current_api () { 152echo "Dumping API..." 153 154DESCRIPTOR =" $ BUILD_DIR /apiabi/acc-descriptor.xml" 155mkdir -p " $ BUILD_DIR /apiabi" 156cat > " $ DESCRIPTOR " <<EOF 157<version> $ PROJECT_VERSION </version> 158<headers>include</headers> 159<add_include_paths> $ INCLUDE_PATHS </add_include_paths> 160EOF 161 162# This addresses a bug between a-c-c and universal-ctags, manifested when 163# a name is use both for a tag and a function name 164mkdir -p " $ BUILD_DIR /apiabi/.ctags.d" 165echo "--fields=-t" > " $ BUILD_DIR /apiabi/.ctags.d/acc.ctags" 166 167# Change HOME so that .ctags.d gets picked up by universal-ctags, if used 168HOME =" $ BUILD_DIR /apiabi" abi-compliance-checker \ 169-headers-only \ 170-lib " $ PROJECT_NAME " \ 171-dump " $ DESCRIPTOR " \ 172-log-path " $ BUILD_DIR /apiabi/acc.log" \ 173-dump-path " $ BUILD_DIR /apiabi/api.dump" 174# acc generates this file with an ancient timestamp, which confuses gzip 175touch " $ BUILD_DIR /apiabi/api.dump" 176} 177 178dump_current_abi () { 179echo "Dumping ABIs ..." 180mkdir -p " $ BUILD_DIR /apiabi" 181# The suppressions are needed to avoid including all the internal C++ 182# symbols, and system types 183cat > " $ BUILD_DIR /apiabi/abidw.suppress" <<EOF 184[suppress_function] 185 186label = suppress internal C++ mangled functions 187symbol_name_regexp = ^_Z 188drop = yes 189 190[suppress_variable] 191label = suppress internal C++ mangled variables 192symbol_name_regexp = ^_Z 193drop = yes 194 195[suppress_type] 196label = Suppress types outside of our own source 197source_location_not_regexp = ^include/ 198drop = yes 199EOF 200 201# In abidw 2.5, handling of undefined stuff was changed a bit 202abidw_version =" $( abidw --version | sed -r 's/^abidw: ([0-9]+\.[0-9]+).*$/\1/' ) " 203abidw_major =" ${ abidw_version %.*} " 204abidw_minor =" ${ abidw_version #*.} " 205if [" $ abidw_major " -gt 2 ] || [" $ abidw_minor " -gt 4 ];then 206abidw_undefined_syms_options ="--no-load-undefined-interfaces" 207else 208abidw_undefined_syms_options ="--drop-undefined-syms" 209fi 210 211for lib_name in $ LIB_NAMES ;do 212# Depending on where add_library resides, the libraries can end up in 213# build/src or build/bin 214lib_path =" $ BUILD_DIR /src/ $ lib_name .so" 215if ! [ -f" $ lib_path " ];then 216lib_path =" $ BUILD_DIR /bin/ $ lib_name .so" 217if ! [ -f" $ lib_path " ];then 218echo "Cannot find library $ lib_name .so" >&2 219exit 1 220fi 221fi 222abidw \ 223--headers-dir include \ 224" $ abidw_undefined_syms_options " \ 225--suppressions " $ BUILD_DIR /apiabi/abidw.suppress" \ 226--out-file " ${ BUILD_DIR } /apiabi/ $ lib_name .abi.xml" \ 227" $ lib_path " 228done 229} 230 231# Run the actual commands 232if [" $ DO_GEN " -eq 1 ];then 233dump_current_api 234dump_current_abi 235exit 0 236elif [" $ DO_CHECK " -eq 1 ];then 237# From here on, we don't want to exit on first error 238set +e 239 240abi-compliance-checker \ 241-strict \ 242-source \ 243-library " $ PROJECT_NAME " \ 244-old " $ BUILD_DIR /apiabi/api.dump" \ 245-new " $ BUILD_DIR_NEW /apiabi/api.dump" \ 246-src-report-path " $ BUILD_DIR_NEW /apiabi/api_compat_report.html" 247API_RESULT =$ ? 248 249ABI_RESULT =0 250for xml_file in " $ BUILD_DIR /apiabi/" lib*.abi.xml;do 251xml_file_new =" $ BUILD_DIR_NEW /apiabi/ $( basename " $ xml_file " ) " 252 253if ! [ -f" $ xml_file_new " ];then 254echo "Cannot compare, missing file: $ xml_file_new " >&2 255exit 1 256fi 257 258abidiff " $ xml_file " " $ xml_file_new " 259res =$ ? 260 ["$(( res & 8))" -ne 0 ]&& ABI_RESULT =1 261done 262 263if [" $ API_RESULT " -gt 0 ];then 264echo "ERROR: API changed with possible backwards-compatibility problems." >&2 265fi 266if [" $ ABI_RESULT " -gt 0 ];then 267echo "ERROR: ABI changed with possible backwards-compatibility problems." >&2 268fi 269if ["$(( API_RESULT + ABI_RESULT ))" -gt 0 ];then 270exit 1 271fi 272fi