SPB Git

Repository Public License

build.sh 6.7 KB 119 lines shellscript

1#!/bin/bash2# ORIX Convert — EmbeddedEngines/libarchive/build.sh3# Description: Builds libarchive with static liblzma (xz) and libzstd from pinned, checksummed source releases and4#              wraps them into CArchive.xcframework (arm64, macOS 15.0+), consumed by Packages/EngineArchive.5# Author: Simon-Pierre Boucher — contact@spboucher.ai6set -euo pipefail7cd "$(dirname "$0")"8export LC_ALL=C9export MACOSX_DEPLOYMENT_TARGET=15.01011# Pinned releases. xz 5.6.0 and 5.6.1 carried the CVE-2024-3094 backdoor; 5.8.x is a clean, later line, and the12# archive is the upstream release tarball whose SHA-256 matches the digest published on the GitHub release.13LIBARCHIVE_VERSION="3.8.11"14LIBARCHIVE_SHA256="a3dc0872b1b39da34dc18ef1b944f0f11ffd37425d70ae04be679279f1cf43d2"15LIBARCHIVE_URL="https://github.com/libarchive/libarchive/releases/download/v${LIBARCHIVE_VERSION}/libarchive-${LIBARCHIVE_VERSION}.tar.xz"16XZ_VERSION="5.8.4"17XZ_SHA256="4ce24038fd4221e0d13bc1a2de7a4db56e90b92b3bf75321f6c14be73f65de4b"18XZ_URL="https://github.com/tukaani-project/xz/releases/download/v${XZ_VERSION}/xz-${XZ_VERSION}.tar.xz"19ZSTD_VERSION="1.5.7"20ZSTD_SHA256="eb33e51f49a15e023950cd7825ca74a4a2b43db8354825ac24fc1b7ee09e6fa3"21ZSTD_URL="https://github.com/facebook/zstd/releases/download/v${ZSTD_VERSION}/zstd-${ZSTD_VERSION}.tar.gz"2223if [[ -d CArchive.xcframework && "${1:-}" != "--force" ]]; then24    echo "CArchive.xcframework already present (use --force to rebuild)"; exit 025fi26case "$XZ_VERSION" in 5.6.0|5.6.1) echo "refusing to build a backdoored xz release"; exit 1;; esac2728CMAKE="$(command -v cmake || true)"29[[ -n "$CMAKE" ]] || { echo "cmake is required to build libarchive (build-time only)"; exit 1; }30JOBS="$(sysctl -n hw.ncpu)"31PREFIX="$PWD/prefix"3233rm -rf src work prefix CArchive.xcframework34mkdir -p src/libarchive src/xz src/zstd work prefix3536fetch() { # url sha256 file dir37    curl -fsSL -o "work/$3" "$1"38    echo "$2  work/$3" | shasum -a 256 -c -39    tar -xf "work/$3" -C "$4" --strip-components 140}41fetch "$XZ_URL" "$XZ_SHA256" xz.tar.xz src/xz42fetch "$ZSTD_URL" "$ZSTD_SHA256" zstd.tar.gz src/zstd43fetch "$LIBARCHIVE_URL" "$LIBARCHIVE_SHA256" libarchive.tar.xz src/libarchive4445COMMON=(-G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES=arm6446        -DCMAKE_OSX_DEPLOYMENT_TARGET=15.0 -DCMAKE_INSTALL_PREFIX="$PREFIX" -DCMAKE_POSITION_INDEPENDENT_CODE=ON47        -DBUILD_SHARED_LIBS=OFF -DCMAKE_IGNORE_PREFIX_PATH="/opt/homebrew;/usr/local;/opt/local"48        -DCMAKE_FIND_FRAMEWORK=NEVER)4950# liblzma only: no xz/xzdec/lzmainfo tools, no scripts, no translations.51"$CMAKE" -S src/xz -B work/xz "${COMMON[@]}" \52    -DXZ_TOOL_XZ=OFF -DXZ_TOOL_XZDEC=OFF -DXZ_TOOL_LZMADEC=OFF -DXZ_TOOL_LZMAINFO=OFF -DXZ_TOOL_SCRIPTS=OFF \53    -DXZ_NLS=OFF -DXZ_DOC=OFF -DXZ_THREADS=posix -DBUILD_TESTING=OFF > work/xz-configure.log54"$CMAKE" --build work/xz --parallel "$JOBS" > work/xz-build.log55"$CMAKE" --install work/xz > work/xz-install.log5657# libzstd only (multithreaded compression enabled).58"$CMAKE" -S src/zstd/build/cmake -B work/zstd "${COMMON[@]}" \59    -DZSTD_BUILD_STATIC=ON -DZSTD_BUILD_SHARED=OFF -DZSTD_BUILD_PROGRAMS=OFF -DZSTD_BUILD_TESTS=OFF \60    -DZSTD_BUILD_CONTRIB=OFF -DZSTD_MULTITHREAD_SUPPORT=ON -DZSTD_LEGACY_SUPPORT=OFF > work/zstd-configure.log61"$CMAKE" --build work/zstd --parallel "$JOBS" > work/zstd-build.log62"$CMAKE" --install work/zstd > work/zstd-install.log6364# libarchive: zlib, bzip2 and iconv come from the macOS SDK; AES / PBKDF2 / digests from CommonCrypto.65# No OpenSSL, Nettle, mbedTLS, lz4, lzo, libb2, XML parser, PCRE, ACL; no bsdtar/bsdcpio/bsdcat/bsdunzip.66"$CMAKE" -S src/libarchive -B work/libarchive "${COMMON[@]}" \67    -DCMAKE_PREFIX_PATH="$PREFIX" \68    -DLIBLZMA_INCLUDE_DIR="$PREFIX/include" -DLIBLZMA_LIBRARY="$PREFIX/lib/liblzma.a" \69    -DZSTD_INCLUDE_DIR="$PREFIX/include" -DZSTD_LIBRARY="$PREFIX/lib/libzstd.a" \70    -DENABLE_OPENSSL=OFF -DENABLE_NETTLE=OFF -DENABLE_MBEDTLS=OFF -DENABLE_LIBB2=OFF -DENABLE_LZ4=OFF \71    -DENABLE_LZO=OFF -DENABLE_LZMA=ON -DENABLE_ZSTD=ON -DENABLE_ZLIB=ON -DENABLE_BZip2=ON \72    -DENABLE_LIBXML2=OFF -DENABLE_BSDXML=OFF -DENABLE_EXPAT=OFF -DENABLE_PCREPOSIX=OFF -DENABLE_PCRE2POSIX=OFF \73    -DENABLE_LIBGCC=OFF -DENABLE_TAR=OFF -DENABLE_CPIO=OFF -DENABLE_CAT=OFF -DENABLE_UNZIP=OFF \74    -DENABLE_XATTR=ON -DENABLE_ACL=OFF -DENABLE_ICONV=ON -DENABLE_TEST=OFF -DENABLE_WERROR=OFF \75    > work/libarchive-configure.log76"$CMAKE" --build work/libarchive --parallel "$JOBS" > work/libarchive-build.log77"$CMAKE" --install work/libarchive > work/libarchive-install.log7879# Facts the engine relies on, checked from the generated configuration rather than assumed.80CONFIG=work/libarchive/config.h81for macro in HAVE_LIBZ HAVE_BZLIB_H HAVE_LZMA_H HAVE_ZSTD_H HAVE_LIBZSTD HAVE_ZSTD_compressStream HAVE_LZMA_STREAM_ENCODER_MT HAVE_ICONV ARCHIVE_CRYPTO_SHA1_LIBSYSTEM; do82    grep -Eq "^#define ${macro} 1" "$CONFIG" || { echo "libarchive configuration lacks ${macro}"; exit 1; }83done84if grep -Eq "^#define HAVE_(LIBCRYPTO|LIBNETTLE|LIBMBEDCRYPTO|LIBLZ4|LIBB2|LIBXML2|LIBEXPAT) 1" "$CONFIG"; then85    echo "libarchive picked up a library that must not be linked"; exit 186fi8788# External-program filters are removed from the archive: the objects that fork/exec a helper program89# (archive_read_support_filter_program, archive_write_add_filter_program, the posix_spawn pipe helper) are deleted,90# so any code path that would launch `lz4`, `lzop`, `grzip`, `lrzip`… cannot even be linked.91cp prefix/lib/libarchive.a work/libarchive-stripped.a92ar -d work/libarchive-stripped.a filter_fork_posix.c.o archive_read_support_filter_program.c.o \93    archive_write_add_filter_program.c.o94ranlib work/libarchive-stripped.a 2> /dev/null95if nm -g work/libarchive-stripped.a 2> /dev/null | grep -Eq " T ___?archive_(read_support_filter_program|write_add_filter_program|filter_fork)"; then96    echo "program filters are still present"; exit 197fi9899libtool -static -o work/libCArchive.a work/libarchive-stripped.a prefix/lib/liblzma.a prefix/lib/libzstd.a 2> work/libtool.log100101rm -rf work/Headers && mkdir -p work/Headers102cp prefix/include/archive.h prefix/include/archive_entry.h work/Headers/103cat > work/Headers/module.modulemap <<'MAP'104module CArchive {105    header "archive.h"106    header "archive_entry.h"107    link "z"108    link "bz2"109    link "iconv"110    export *111}112MAP113114xcodebuild -create-xcframework -library work/libCArchive.a -headers work/Headers -output CArchive.xcframework > work/xcframework.log115echo "libarchive ${LIBARCHIVE_VERSION} + xz ${XZ_VERSION} + zstd ${ZSTD_VERSION} ready: $(lipo -archs work/libCArchive.a), $(du -sh CArchive.xcframework | cut -f1)"116117# Keep module maps out of the shared include directory Xcode builds (see normalize-xcframework.sh).118"$(cd "$(dirname "$0")/.." && pwd)/normalize-xcframework.sh" "$(cd "$(dirname "$0")" && pwd)"/*.xcframework119
Files main
Menu

Theme