#!/bin/sh set -eu repository_root=${RIGFORGE_ROOT:-/workspace} state_file="$repository_root/config/desired-state.yaml" artifact_directory="$repository_root/artifacts/nam-lv2/arm64/current" staged_directory= work_directory= cleanup() { if [ -n "$staged_directory" ] && [ -e "$staged_directory" ]; then rm -rf "$staged_directory" fi if [ -n "$work_directory" ] && [ -e "$work_directory" ]; then rm -rf "$work_directory" fi } trap cleanup EXIT trap 'exit 129' HUP trap 'exit 130' INT trap 'exit 143' TERM case "$(dpkg --print-architecture)" in arm64) ;; *) printf '%s\n' "This build task requires an ARM64 container." >&2; exit 1 ;; esac python3 - "$repository_root" "$state_file" <<'PY' import sys from pathlib import Path import yaml repository_root = Path(sys.argv[1]) sys.path.insert(0, str(repository_root / "scripts")) from validate_desired_state import validate_state with Path(sys.argv[2]).open(encoding="utf-8") as stream: state = yaml.safe_load(stream) errors = validate_state(state) if errors: raise SystemExit("Invalid desired state: " + "; ".join(errors)) PY set -- $(python3 - "$state_file" <<'PY' import sys import yaml with open(sys.argv[1], encoding="utf-8") as stream: nam = yaml.safe_load(stream)["deployment"]["namlv2"] print(nam["source_url"]) print(nam["tag"]) PY ) source_url=$1 tag=$2 mkdir -p "$(dirname "$artifact_directory")" previous_directory="$artifact_directory.previous" if [ -e "$artifact_directory" ] || [ -e "$previous_directory" ]; then printf '%s\n' "Refusing to overwrite an existing NAM LV2 artifact; move it aside first." >&2 exit 1 fi work_directory=$(mktemp -d /tmp/nam-lv2-build.XXXXXX) staged_directory=$(mktemp -d "$(dirname "$artifact_directory")/.build.XXXXXX") source_directory="$work_directory/source" git clone --no-checkout "$source_url" "$source_directory" git -C "$source_directory" checkout --detach "refs/tags/$tag" git -C "$source_directory" submodule update --init --recursive source_commit=$(git -C "$source_directory" rev-parse HEAD) neural_audio_commit=$(git -C "$source_directory/deps/NeuralAudio" rev-parse HEAD) # Do not inherit the release workflow's -static-libstdc++/-static-libgcc flags. unset CFLAGS CXXFLAGS "$(command -v cmake)" -S "$source_directory" -B "$work_directory/build" \ -DCMAKE_BUILD_TYPE=Release \ -DBUILD_NAMCORE=ON \ -DBUILD_INTERNAL_STATIC_WAVENET=ON \ -DBUILD_INTERNAL_STATIC_LSTM=ON \ -DMULTIFRAME_8X8_CONVOLUTION=8 "$(command -v cmake)" --build "$work_directory/build" --target copy_binaries -j2 bundle="$work_directory/build/neural_amp_modeler.lv2" if [ ! -d "$bundle" ] || [ ! -f "$bundle/neural_amp_modeler.so" ]; then printf '%s\n' "NAM LV2 build did not produce the expected bundle." >&2 exit 1 fi install -d "$staged_directory/neural_amp_modeler.lv2" cp -a "$bundle/." "$staged_directory/neural_amp_modeler.lv2/" ldd "$staged_directory/neural_amp_modeler.lv2/neural_amp_modeler.so" \ > "$staged_directory/runtime-dependencies.txt" if grep -F 'not found' "$staged_directory/runtime-dependencies.txt"; then printf '%s\n' "Unresolved runtime dependency in NAM LV2 build." >&2 exit 1 fi if ! grep -F 'libstdc++.so.6 =>' "$staged_directory/runtime-dependencies.txt" >/dev/null; then printf '%s\n' "NAM LV2 must use the target's shared libstdc++ runtime." >&2 exit 1 fi binary_sha256=$(sha256sum "$staged_directory/neural_amp_modeler.lv2/neural_amp_modeler.so" | cut -d ' ' -f 1) cmake_version=$("$(command -v cmake)" --version | sed -n '1s/^cmake version //p') compiler_version=$(c++ --version | sed -n '1p') cat > "$staged_directory/provenance.json" <