#!/bin/bash set -euo pipefail ROOT="$(cd "$(dirname "$0")/../.." && pwd)" BUILD="$ROOT/.video-build" SDK_VERSION=6.4.0.2 SDK_SHA256=b4a57a774795cf12da19a777a5d306e970905bf9758a4c4765e5e4593428ae0b SDK="$BUILD/hexagon-sdk/$SDK_VERSION" # The headers the app's NDK compile reads (scripts/video/hexagon-prebuilt.cmake), copied out of the # 3.1 GB SDK so CI can cache the runtime without the SDK. Cheap: redone whenever the SDK is present. copy_sdk_headers() { rm -rf "$BUILD/hexagon-runtime/sdk" mkdir -p "$BUILD/hexagon-runtime/sdk/ipc/fastrpc/rpcmem" cp -R "$SDK/incs" "$BUILD/hexagon-runtime/sdk/incs" cp -R "$SDK/ipc/fastrpc/rpcmem/inc" "$BUILD/hexagon-runtime/sdk/ipc/fastrpc/rpcmem/inc" } if [ -f "$SDK/hexagon_sdk.json" ] && [ -d "$BUILD/hexagon-runtime" ]; then copy_sdk_headers; fi # Reuse the DSP artifacts when their source revision and SDK match. REVISION="$(cat "$ROOT/scripts/video/revision")" READY="$BUILD/hexagon-runtime/ready" COMPLETE=true for file in htp_iface_stub.c htp_iface.h sdk/incs/stddef/AEEStdDef.h sdk/ipc/fastrpc/rpcmem/inc/rpcmem.h; do [ -s "$BUILD/hexagon-runtime/$file" ] || COMPLETE=false done for arch in v73 v75 v79 v81; do [ -s "$BUILD/hexagon-assets/video-hexagon/liboffgrid-video-htp-$arch.so" ] || COMPLETE=false done if $COMPLETE && [ "$(cat "$READY" 2>/dev/null || true)" = "$REVISION:$SDK_VERSION" ]; then exit 0; fi mkdir -p "$BUILD/hexagon-sdk" "$BUILD/hexagon-runtime" "$BUILD/hexagon-assets/video-hexagon" if [ ! -f "$SDK/hexagon_sdk.json" ]; then curl -fL --retry 3 -C - "https://github.com/snapdragon-toolchain/hexagon-sdk/releases/download/v$SDK_VERSION/hexagon-sdk-v$SDK_VERSION-amd64-lnx.tar.xz" -o "$BUILD/hexagon-sdk.tar.xz" # A bad archive is removed: `curl -C -` would otherwise resume from the same bad bytes every build. if ! printf '%s %s\n' "$SDK_SHA256" "$BUILD/hexagon-sdk.tar.xz" | shasum -a 256 -c -; then rm -f "$BUILD/hexagon-sdk.tar.xz" echo "Hexagon SDK archive failed its checksum and was removed; run the build again." >&2 exit 1 fi tar -xJf "$BUILD/hexagon-sdk.tar.xz" -C "$BUILD/hexagon-sdk" fi # The official Hexagon tools run on Linux. Only this build directory is mounted. docker run --rm --platform linux/amd64 -v "$BUILD:/work" -w /work ubuntu:22.04 bash -euc ' apt-get update -qq DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends ninja-build python3 python3-pip build-essential libncurses5 libtinfo5 python3 -m pip install --no-cache-dir cmake==3.31.6 export HEXAGON_SDK_ROOT=/work/hexagon-sdk/6.4.0.2 export HEXAGON_TOOLS_ROOT=$HEXAGON_SDK_ROOT/tools/HEXAGON_Tools/19.0.04 export DEFAULT_HLOS_ARCH=64 DEFAULT_TOOLS_VARIANT=toolv19 DEFAULT_NO_QURT_INC=0 for arch in v73 v75 v79 v81; do cmake -S source/ggml/src/ggml-hexagon/htp -B hexagon-build/$arch -G Ninja \ -DCMAKE_TOOLCHAIN_FILE=/work/source/ggml/src/ggml-hexagon/htp/cmake-toolchain.cmake \ -DCMAKE_BUILD_TYPE=Release -DHEXAGON_SDK_ROOT=$HEXAGON_SDK_ROOT \ -DHEXAGON_TOOLS_ROOT=$HEXAGON_TOOLS_ROOT -DDSP_VERSION=$arch \ -DPREBUILT_LIB_DIR=toolv19_$arch -DHEXAGON_HTP_DEBUG=OFF cmake --build hexagon-build/$arch --parallel 2 cp hexagon-build/$arch/libggml-htp-$arch.so hexagon-assets/video-hexagon/liboffgrid-video-htp-$arch.so done cp hexagon-build/v73/htp_iface_stub.c hexagon-build/v73/htp_iface.h hexagon-runtime/ ' copy_sdk_headers cp "$ROOT/scripts/video/revision" "$BUILD/hexagon-runtime/revision" printf '%s:%s\n' "$REVISION" "$SDK_VERSION" > "$READY"