Triforce v0.2.0

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ruckus7382sfgsgdf
2026-11-10 19:32:48 -06:00
commit 34b3683441
1730 changed files with 554853 additions and 0 deletions

155
scripts/linux/appimage.sh Executable file
View File

@@ -0,0 +1,155 @@
#!/bin/bash
# The Linux AppImage: Hookshot Builder with everything it needs to build the game on the player's PC. No game data and
# nothing made from it is in it: the game is built from the player's own copy, as on Windows.
#
# scripts/linux/deps.sh (first: the compiler, Python, FFmpeg, SDL2, headers into build-linux/deps)
# scripts/linux/appimage.sh -> build-linux/Hookshot-<version>-x86_64.AppImage
# The same image builds the game and, with --play, starts the one it saved.
#
# Built on the oldest system it is for (CI: Ubuntu 22.04): the sysroot it carries is that system's C library, so the
# game it builds runs on glibc 2.35 and newer. work/ (hot_funcs.txt, hot_order.txt, hookshot_pieces.prof,
# image/chunks.txt: addresses and counts from playing, no game code) is carried along when it is there.
set -euo pipefail
cd "$(dirname "$0")/../.."
ROOT=$PWD
B=$ROOT/build-linux
DEPS=${DEPS:-$B/deps}
APPDIR=$B/AppDir
VERSION=${HOOKSHOT_VERSION:-$(git describe --tags --always --match "v[0-9]*" 2>/dev/null || echo dev)}
export EMSDK=$DEPS/emsdk RX_CPM=$DEPS/cpm
PY=$DEPS/python/bin/python3
# ---- the Vulkan back end, built here once (it needs no game) ----
VKW=$B/vk-work
rm -rf "$VKW/sa/build/hookshot_vk.so"
OOT_WORK=$VKW RX_MARCH=x86-64-v3 RX_VK_ONLY=1 RX_RELEASE=1 "$PY" -I nx2/build.py --standalone --jobs "${JOBS:-$(nproc)}"
VK=$VKW/sa/build/hookshot_vk.so
[ -f "$VK" ] || { echo "hookshot_vk.so was not built"; exit 1; }
# ---- the tools' native helpers, built now: the AppImage is read-only. a64emit with its C++ runtime inside (the one this system
# builds with is newer than older systems have), and the stamp build_emit.py checks, so it is not built again ----
E=third_party/a64-kit/lift
"$EMSDK/upstream/bin/clang++" -std=c++20 -O2 -shared -fPIC -static-libstdc++ -static-libgcc -Wno-everything \
-o "$E/liba64emit.so" "$E/a64emit.cpp"
"$PY" -I -c "import hashlib, sys; f = ['$E/a64emit.cpp', '$E/suyu/arm64_to_c.h']; open('$E/liba64emit.so.sha1', 'w').write(hashlib.sha1(b''.join(open(x, 'rb').read() for x in f)).hexdigest())"
"$PY" -I third_party/a64-kit/lift/build_emit.py
"$PY" -I -c "import sys; sys.path.insert(0, 'nx2'); import zbic; zbic.lib()"
rm -rf "$APPDIR"
mkdir -p "$APPDIR/usr/share/hookshot" "$APPDIR/usr/lib/hookshot"
T=$APPDIR/usr/share/hookshot
L=$APPDIR/usr/lib/hookshot
# ---- the tools (the sources the player's build compiles, and the scripts) ----
cp -a nx2 host scripts LICENSE readme.md assets "$T/"
printf '%s
' "$VERSION" > "$T/VERSION" # (no git history in here: nx2/version.py reads the release name from it)
mkdir -p "$T/builder" "$T/gpu/render" "$T/gpu/vk" "$T/third_party"
cp -a builder/linux "$T/builder/"
cp -a gpu/render/*.h "$T/gpu/render/"
# (every gpu/vk header the host's sources include: v2.0.6 shipped without oot_cheat_items.h and no Linux build finished, issue 990.
# tests/test_appimage_headers.py checks that this covers what host/ includes)
for h in $(grep -rhoE 'gpu/vk/[A-Za-z0-9_]+[.]h' host | sort -u); do if [ -f "$h" ]; then cp -a "$h" "$T/gpu/vk/"; fi; done
cp -a third_party/opus "$T/third_party/"
cp -a third_party/kenney_input "$T/third_party/"
# (NVIDIA DLSS, when ticked in the builder: scripts/ngx_sdk.py and the Vulkan back end's sources, compiled with HOOKSHOT_NGX_SDK)
mkdir -p "$T/scripts"
cp scripts/ngx_sdk.py "$T/scripts/"
cp -a gpu/vk gpu/compat gpu/third_party "$T/gpu/"
cp -a third_party/imgui third_party/zstd third_party/fonts "$T/third_party/"
mkdir -p "$T/third_party/zbic" "$T/third_party/a64-kit"
cp -a third_party/zbic/zbic.so third_party/zbic/LICENSE third_party/zbic/PROVENANCE.md "$T/third_party/zbic/"
cp -a third_party/a64-kit/* "$T/third_party/a64-kit/"
rm -f "$T/third_party/a64-kit/tools/lld-link.exe"
if [ -d work ]; then
mkdir -p "$T/work/image"
for f in hot_funcs.txt hot_order.txt hookshot_pieces.prof pipeline_states.bin; do [ -f "work/$f" ] && cp "work/$f" "$T/work/"; done
[ -f work/image/chunks.txt ] && cp work/image/chunks.txt "$T/work/image/"
fi
find "$T" -name __pycache__ -prune -exec rm -rf {} +
# ---- what it builds with ----
cp -a "$DEPS/python" "$APPDIR/usr/python"
cp "$DEPS/tk/libtcl9tk9.0.so" "$DEPS/tk/libXft.so.2" "$DEPS/tk/libXrender.so.1" "$APPDIR/usr/python/lib/"
mkdir -p "$L/emsdk"
cp -a "$DEPS/emsdk/upstream" "$L/emsdk/"
cp -a "$DEPS/ffmpeg" "$L/ffmpeg"
cp "$VK" "$L/hookshot_vk.so"
cp "$DEPS/sdl2/libSDL2-2.0.so.0" "$L/libSDL2-2.0.so.0"
for d in "$DEPS"/cpm/*/*; do
mkdir -p "$T/cpm/${d#"$DEPS/cpm/"}"
cp -a "$d/include" "$T/cpm/${d#"$DEPS/cpm/"}/"
done
cp -a "$DEPS/licenses" "$T/licenses" # (LLVM, FFmpeg, dav1d, SDL2: what this AppImage carries besides Hookshot)
# ---- the licences of the third-party parts compiled into hookshot_vk.so (tests/test_appimage_licenses.py) ----
mkdir -p "$T/licenses/imgui" "$T/licenses/zstd" "$T/licenses/libertinus"
cp third_party/imgui/LICENSE.txt third_party/imgui/PROVENANCE.md "$T/licenses/imgui/"
cp third_party/zstd/LICENSE third_party/zstd/PROVENANCE.md "$T/licenses/zstd/"
cp third_party/fonts/libertinus/OFL.txt third_party/fonts/PROVENANCE.md "$T/licenses/libertinus/"
# ---- end of the licences ----
# the sysroot: this system's C library (headers, start files, the libraries to link against) and GCC's runtime pieces
S=$L/sysroot
mkdir -p "$S/usr/lib/x86_64-linux-gnu" "$S/usr/lib/gcc/x86_64-linux-gnu" "$S/lib64"
ln -s usr/lib "$S/lib"
cp -a /usr/include "$S/usr/"
rm -rf "$S/usr/include/c++" "$S/usr/include/x86_64-linux-gnu/c++" "$S/usr/include/llvm"* "$S/usr/include/clang"*
M=/usr/lib/x86_64-linux-gnu
for f in crt1.o crti.o crtn.o Scrt1.o rcrt1.o libc.so libc.so.6 libc_nonshared.a libm.so libm.so.6 libm.a libmvec.so libmvec.so.1 \
libmvec.a libpthread.so.0 libpthread.a libdl.so.2 libdl.a librt.so.1 librt.a libutil.a libgcc_s.so.1 ld-linux-x86-64.so.2; do
# System aliases can have absolute targets (e.g. libmvec.so). Carry their bytes;
# update parts refuse absolute-target symlinks, and must not use the host's library.
[ -e "$M/$f" ] && cp -aL "$M/$f" "$S/usr/lib/x86_64-linux-gnu/" || true
done
cp -aL /lib64/ld-linux-x86-64.so.2 "$S/lib64/"
GCC=$(ls -d /usr/lib/gcc/x86_64-linux-gnu/*/ | sort -V | tail -1)
GV=$(basename "$GCC")
G=$S/usr/lib/gcc/x86_64-linux-gnu/$GV
mkdir -p "$G" "$S/usr/include/c++" "$S/usr/include/x86_64-linux-gnu/c++"
cp -aL "/usr/include/c++/$GV" "$S/usr/include/c++/"
cp -aL "/usr/include/x86_64-linux-gnu/c++/$GV" "$S/usr/include/x86_64-linux-gnu/c++/"
for f in crtbegin.o crtbeginS.o crtbeginT.o crtend.o crtendS.o libgcc.a libgcc_eh.a libgcc_s.so libstdc++.a libstdc++fs.a libstdc++exp.a; do
[ -e "$GCC/$f" ] && cp -aL "$GCC/$f" "$G/" || true
done
# (libgcc_s.so is a linker script naming /lib/x86_64-linux-gnu/libgcc_s.so.1: found in the sysroot through lib -> usr/lib)
# ---- check: the bundled compiler builds and links a program against the sysroot, and it runs ----
cat > "$B/t.c" <<'EOF'
#include <pthread.h>
#include <stdio.h>
#include <math.h>
static void *f(void *p) { return p; }
int main(void) { pthread_t t; pthread_create(&t, 0, f, 0); pthread_join(t, 0); printf("ok %g\n", sqrt(2.0)); return 0; }
EOF
"$L/emsdk/upstream/bin/clang" --sysroot="$S" -fuse-ld=lld -O2 -march=x86-64-v3 "$B/t.c" -o "$B/t" -lpthread -lm
"$B/t"
cat > "$B/t.cpp" <<'EOF'
#include <algorithm>
#include <filesystem>
#include <format>
#include <string>
extern "C" int t_cpp(int v) { return (int)std::format("{}", v).size(); }
EOF
"$L/emsdk/upstream/bin/clang++" --sysroot="$S" -fuse-ld=lld -std=c++20 -O2 -march=x86-64-v3 -shared -fPIC -static-libstdc++ -static-libgcc \
"$B/t.cpp" -o "$B/t.so" -ldl -lpthread -lm
# ---- the AppDir's own files ----
cp builder/linux/AppRun "$APPDIR/AppRun"
cp builder/linux/hookshot-builder.desktop "$APPDIR/"
# (RecompLauncher reads this from inside the AppImage, at /recomplauncher.json)
cp recomplauncher.json "$APPDIR/recomplauncher.json"
cp assets/hookshot.png "$APPDIR/hookshot.png"
mkdir -p "$APPDIR/usr/share/icons/hicolor/256x256/apps"
cp assets/hookshot.png "$APPDIR/usr/share/icons/hicolor/256x256/apps/hookshot.png"
# (the update list, beside AppRun and not inside a hashed part: hookshot-linux.txt names each part's checksum)
# (the parts are served from the linux-parts release of the repository this is built in, where
# scripts/linux/publish_parts.sh uploads them: without --base the list named NotRexed/Hookshot's release, which a fork's
# CI does not upload to, so a fork's update list named parts that were not there)
python3 scripts/linux/make_parts.py "$APPDIR" "$VERSION" "$B/parts" \
--base "https://github.com/${GITHUB_REPOSITORY:-NotRexed/Hookshot}/releases/download/linux-parts"
OUT=$B/Hookshot-$VERSION-x86_64.AppImage
rm -f "$OUT"
ARCH=x86_64 APPIMAGE_EXTRACT_AND_RUN=1 "$DEPS/appimagetool" --runtime-file "$DEPS/runtime-x86_64" --comp zstd "$APPDIR" "$OUT"
echo "$OUT: $(du -h "$OUT" | cut -f1)"

View File

@@ -0,0 +1,51 @@
#!/bin/bash
# Game-free: a player's build started from what the AppImage carries, not from the repository. CI's AppImage job packages
# the builder but never builds a game with it, so a file the AppImage leaves out was found by every player instead: #1459
# made nx2/build.py write the menu's fonts from third_party/fonts at every build start, the AppImage does not carry that
# folder, and every Linux build stopped at LibertinusSans-Regular.ttf while CI stayed green (2026-11-10, #1567).
#
# scripts/linux/check_player_build.sh [<Hookshot-...-x86_64.AppImage>] (default: the newest in build-linux/)
#
# The image is extracted, as its runtime does, and run with AppRun's own environment (the AppImage's Python, compiler,
# sysroot, FFmpeg and the prebuilt Vulkan back end, HOOKSHOT_VK_PREBUILT) in an otherwise empty one, so nothing of the
# checkout or of CI's caches stands in for what the image lacks:
# - AppRun --cli --help: nx2/make_game.py, as the builder window starts it;
# - nx2/build.py --standalone --dry-run, as make_game.py runs it: its whole start-up up to the compile, which is where
# the game's lifted code is first needed. Every other file the compile would read must be in the image.
# Neither may write into the image's tree: on a player's PC it is read-only.
set -euo pipefail
cd "$(dirname "$0")/../.."
IMAGE=${1:-$(ls -t build-linux/Hookshot-*-x86_64.AppImage 2>/dev/null | head -1 || true)}
[ -n "$IMAGE" ] && [ -f "$IMAGE" ] || { echo "no AppImage to check (scripts/linux/appimage.sh makes one)"; exit 1; }
IMAGE=$(readlink -f "$IMAGE")
TMP=$(mktemp -d)
trap 'rm -rf "$TMP"' EXIT
(cd "$TMP" && "$IMAGE" --appimage-extract >/dev/null)
R=$TMP/squashfs-root
T=$R/usr/share/hookshot
mkdir -p "$TMP/home" "$TMP/work"
# (AppRun's environment, from AppRun itself: its lines before it starts Python, sourced with $0 naming it, so HERE is the image)
sed '/^PY=/,$d' "$R/AppRun" > "$TMP/apprun-env.sh"
in_image() {
env -i PATH=/usr/bin:/bin HOME="$TMP/home" LANG=C.UTF-8 bash -c '. "$1"; shift; exec "$@"' "$R/AppRun" "$TMP/apprun-env.sh" "$@"
}
touch "$TMP/before"
sleep 1 # (so a file written below is newer than the stamp)
echo "== AppRun --cli --help"
in_image "$R/AppRun" --cli --help > "$TMP/help.txt"
grep -q -- "--nup" "$TMP/help.txt" || { cat "$TMP/help.txt"; echo "nx2/make_game.py did not start"; exit 1; }
echo "== nx2/build.py --standalone --dry-run (as nx2/make_game.py runs it, with no game)"
# (-B: no __pycache__ written into the image's tree. make_game.py's other settings: nx2/make_game.py, the compile's run())
(cd "$T" && in_image env OOT_WORK="$TMP/work" RX_RELEASE=1 A64_HOT_CHUNK=1 PYTHONIOENCODING=utf-8 \
"$R/usr/python/bin/python3" -I -B -u -X utf8 nx2/build.py --standalone --jobs 1 --dry-run)
# (Python's own __pycache__ aside: AppRun runs Python with -I, which writes it where it can, and does without where it cannot)
written=$(find "$R" -type f -newer "$TMP/before" ! -path "*/__pycache__/*" -print)
if [ -n "$written" ]; then
echo "a player's build wrote into the AppImage's tree, which is read-only on a player's PC:"
echo "$written" | head -20
exit 1
fi
echo "a player's build starts from the AppImage's tree"

208
scripts/linux/deps.sh Executable file
View File

@@ -0,0 +1,208 @@
#!/bin/bash
# What the Linux AppImage carries, fetched and built into build-linux/deps (or $DEPS): each part once, kept while its
# version stays the same. Run on the oldest system the AppImage is for (CI: Ubuntu 22.04, glibc 2.35).
#
# emsdk/upstream/ LLVM's clang and lld (the layout third_party/a64-kit/tools/toolchain.py finds through EMSDK):
# the player's PC compiles the game with them. The play profile (work/hookshot_pieces.prof) wants
# LLVM 23 or newer.
# python/ CPython (python-build-standalone) with lz4, numpy, capstone, unicorn and zstandard: the tools
# (and nx2/prompt_requirements.txt's, which draw the button prompts)
# tk/ libtcl9tk9.0.so built with Xft, with libXft and libXrender: put over python/'s, which draws only
# X core fonts (under XWayland one 13 px bitmap font, whatever the size asked for or the screen)
# ffmpeg/ FFmpeg's libavcodec, libswscale, libswresample, libavutil, static and LGPL, with dav1d for OoT's
# AV1 movies (VP8 / VP9 too) - linked into the game
# sdl2/ libSDL2-2.0.so.0: the window, sound and controllers, placed beside the game
# cpm/ Vulkan-Headers, SPIRV-Headers and VulkanMemoryAllocator, in the CPM cache layout nx2/build.py reads
# appimagetool the AppImage packer
# runtime-x86_64 the AppImage runtime it puts in front of the image (pinned: appimagetool's own download of the
# 'continuous' one, at packing time, fails whenever GitHub answers 504)
set -euo pipefail
cd "$(dirname "$0")/../.."
DEPS=${DEPS:-$PWD/build-linux/deps}
DL=$DEPS/downloads
mkdir -p "$DEPS" "$DL"
JOBS=$(nproc)
LLVM_VER=23.1.5
PY_TAG=20261026
PY_VER=3.12.16
TCLTK_VER=9.0.4 # (python-build-standalone's Tcl and Tk: its tk9.0 scripts stay, beside this libtcl9tk9.0.so)
TCL_SHA256=d0aed49230bc02a65c1e0229e65f34590a4b037ec40d546f32573b467f7551ea
TK_SHA256=d7a146d2917eb8b5cc95276dbf0e3d03c7464d2b19c1675357857c989301dbb4
SDL_VER=2.32.10
FFMPEG_VER=9.0.2
DAV1D_VER=1.5.4
VK_HEADERS=v1.4.345
SPIRV_HEADERS=vulkan-sdk-1.4.341.0
VMA=v3.3.0
APPIMAGETOOL=1.9.1
APPIMAGE_RUNTIME=20251108
APPIMAGE_RUNTIME_SHA256=2fca8b443c92510f1483a883f60061ad09b46b978b2631c807cd873a47ec260d
# (the SHA-256 of each release download: a part whose download differs stops the script. Change them with the versions.
# GitHub's and GitLab's tag archives (dav1d, the headers) are made on demand and not pinned here)
LLVM_SHA256=f72edb0b36580ece7f52e23858f00c18fad4e87395ea7ad05d7e55c39f8fc78a
PY_SHA256=ce4f6d0a6cfdb3bed6e44c2f9affd85943c76a42e25ad3a259002f31d6fb8a20
FFMPEG_SHA256=8c3850283eb25fa026482078a04051e0be17347b09ef81a0849bec15a96e002e
SDL_SHA256=5f5993c530f084535c65a6879e9b26ad441169b3e25d789d83287040a9ca5165
APPIMAGETOOL_SHA256=ed4ce84f0d9caff66f50bcca6ff6f35aae54ce8135408b3fa33abfc3cb384eb0
CURL=(curl -fL --retry 5 --retry-delay 10 --proto '=https')
# A GitHub release link (github.com/O/R/releases/download/TAG/NAME) can answer 504 for a long while: the same file is
# then fetched through the GitHub API (with $GH_TOKEN when it is set).
fetch_github_api() { # url out
[[ $1 =~ ^https://github\.com/([^/]+/[^/]+)/releases/download/([^/]+)/([^/]+)$ ]] || return 1
local repo=${BASH_REMATCH[1]} tag=${BASH_REMATCH[2]} name=${BASH_REMATCH[3]} auth=() id
[ -n "${GH_TOKEN:-}" ] && auth=(-H "Authorization: Bearer $GH_TOKEN")
id=$("${CURL[@]}" -sS "${auth[@]}" "https://api.github.com/repos/$repo/releases/tags/$tag" |
python3 -c 'import json,sys; print(next(a["id"] for a in json.load(sys.stdin)["assets"] if a["name"] == sys.argv[1]))' "$name") ||
return 1
echo "release link failed: fetching $name through the GitHub API"
"${CURL[@]}" "${auth[@]}" -H "Accept: application/octet-stream" -o "$2" "https://api.github.com/repos/$repo/releases/assets/$id"
}
fetch() { # url file [sha256: checked on every run, the download removed when it differs]
if [ ! -f "$DL/$2" ]; then
"${CURL[@]}" -o "$DL/$2.part" "$1" || fetch_github_api "$1" "$DL/$2.part"
mv -f "$DL/$2.part" "$DL/$2"
fi
if [ -n "${3:-}" ] && ! echo "$3 $DL/$2" | sha256sum -c --quiet -; then
rm -f "$DL/$2"
echo "$2: not the expected download (SHA-256 differs)"
exit 1
fi
}
done_for() { [ -f "$DEPS/.$1" ] && [ "$(cat "$DEPS/.$1")" = "$2" ]; }
mark() { echo "$2" > "$DEPS/.$1"; }
# ---- LLVM: clang, lld and clang's own headers, nothing else ----
if ! done_for llvm "$LLVM_VER"; then
fetch "https://github.com/llvm/llvm-project/releases/download/llvmorg-$LLVM_VER/LLVM-$LLVM_VER-Linux-X64.tar.xz" llvm.tar.xz "$LLVM_SHA256"
rm -rf "$DEPS/emsdk" "$DEPS/llvm-x"
mkdir -p "$DEPS/llvm-x"
tar -xJf "$DL/llvm.tar.xz" -C "$DEPS/llvm-x" --strip-components=1 --wildcards \
'*/bin/clang' '*/bin/clang++' '*/bin/clang-[0-9]*' '*/bin/lld' '*/bin/ld.lld' '*/bin/llvm-profdata' '*/lib/clang/*'
U=$DEPS/emsdk/upstream
mkdir -p "$U/bin" "$U/lib"
mv "$DEPS/llvm-x/bin/"* "$U/bin/"
mv "$DEPS/llvm-x/lib/clang" "$U/lib/clang"
rm -rf "$DEPS/llvm-x"
# (the runtimes: only the profile and builtins libraries; no sanitizers)
find "$U"/lib/clang/*/lib -type f ! -name 'libclang_rt.profile*.a' ! -name 'libclang_rt.builtins*.a' -delete
strip "$U/bin/clang-"[0-9]* "$U/bin/lld" "$U/bin/llvm-profdata" 2>/dev/null || true
"$U/bin/clang" --version | head -1
[ -f "$U/lib/clang/${LLVM_VER%%.*}/include/stddef.h" ] || { echo "clang's own headers are missing"; exit 1; }
mark llvm "$LLVM_VER"
fi
# ---- Python and the tools' modules ----
PY_MARK="$PY_VER-$PY_TAG-$(sha256sum requirements.txt nx2/prompt_requirements.txt | sha256sum | cut -c1-12)" # (a new pin installs again)
if ! done_for python "$PY_MARK"; then
fetch "https://github.com/astral-sh/python-build-standalone/releases/download/$PY_TAG/cpython-$PY_VER+$PY_TAG-x86_64-unknown-linux-gnu-install_only_stripped.tar.gz" python.tar.gz "$PY_SHA256"
rm -rf "$DEPS/python"
tar -xzf "$DL/python.tar.gz" -C "$DEPS"
"$DEPS/python/bin/python3" -m pip install --no-cache-dir --only-binary :all: --disable-pip-version-check -q \
-r requirements.txt
rm -rf "$DEPS/python/lib/python3.12/test" "$DEPS/python/lib/python3.12/idlelib" "$DEPS/python/lib/python3.12/ensurepip"
find "$DEPS/python" -name __pycache__ -prune -exec rm -rf {} +
mark python "$PY_MARK"
fi
# ---- Tk with Xft (the builder window's fonts; Tcl is built only for Tk's configure and stub library) ----
if ! done_for tk "$TCLTK_VER"; then
fetch "https://downloads.sourceforge.net/project/tcl/Tcl/$TCLTK_VER/tcl$TCLTK_VER-src.tar.gz" "tcl$TCLTK_VER.tar.gz"
fetch "https://downloads.sourceforge.net/project/tcl/Tcl/$TCLTK_VER/tk$TCLTK_VER-src.tar.gz" "tk$TCLTK_VER.tar.gz"
printf '%s %s\n' "$TCL_SHA256" "$DL/tcl$TCLTK_VER.tar.gz" "$TK_SHA256" "$DL/tk$TCLTK_VER.tar.gz" | sha256sum -c -
rm -rf "$DEPS/src-tcl" "$DEPS/src-tk" "$DEPS/tk"
mkdir -p "$DEPS/src-tcl" "$DEPS/src-tk" "$DEPS/tk"
tar -xzf "$DL/tcl$TCLTK_VER.tar.gz" -C "$DEPS/src-tcl" --strip-components=1
tar -xzf "$DL/tk$TCLTK_VER.tar.gz" -C "$DEPS/src-tk" --strip-components=1
(cd "$DEPS/src-tcl/unix" && ./configure --enable-shared --with-system-libtommath=no && make -j"$JOBS" binaries)
# (no rpath: libXft and libXrender are found beside it through _tkinter's $ORIGIN/../..)
(cd "$DEPS/src-tk/unix" && ./configure --enable-shared --with-tcl="$DEPS/src-tcl/unix" --enable-xft --disable-libcups \
--disable-xss --disable-zipfs --disable-rpath && make -j"$JOBS" binaries)
cp "$DEPS/src-tk/unix/libtcl9tk9.0.so" "$DEPS/tk/"
strip --strip-unneeded "$DEPS/tk/libtcl9tk9.0.so"
readelf -d "$DEPS/tk/libtcl9tk9.0.so" | grep -q 'libXft\.so\.2' || { echo "Tk was built without Xft"; exit 1; }
cp -L /usr/lib/x86_64-linux-gnu/libXft.so.2 /usr/lib/x86_64-linux-gnu/libXrender.so.1 "$DEPS/tk/"
cp "$DEPS/src-tk/license.terms" "$DEPS/tk/Tk-license.terms"
rm -rf "$DEPS/src-tcl" "$DEPS/src-tk"
mark tk "$TCLTK_VER"
fi
# ---- dav1d and FFmpeg (static, position independent: linked into the game's executable) ----
P=$DEPS/ffmpeg
if ! done_for ffmpeg "$FFMPEG_VER-$DAV1D_VER"; then
rm -rf "$P" "$DEPS/src-dav1d" "$DEPS/src-ffmpeg"
fetch "https://code.videolan.org/videolan/dav1d/-/archive/$DAV1D_VER/dav1d-$DAV1D_VER.tar.gz" dav1d.tar.gz
mkdir -p "$DEPS/src-dav1d" && tar -xzf "$DL/dav1d.tar.gz" -C "$DEPS/src-dav1d" --strip-components=1
(cd "$DEPS/src-dav1d" && meson setup build --prefix="$P" --libdir=lib --buildtype=release --default-library=static \
-Db_staticpic=true -Denable_tools=false -Denable_tests=false -Denable_examples=false && ninja -C build install)
fetch "https://ffmpeg.org/releases/ffmpeg-$FFMPEG_VER.tar.xz" ffmpeg.tar.xz "$FFMPEG_SHA256"
mkdir -p "$DEPS/src-ffmpeg" && tar -xJf "$DL/ffmpeg.tar.xz" -C "$DEPS/src-ffmpeg" --strip-components=1
(cd "$DEPS/src-ffmpeg" && PKG_CONFIG_PATH="$P/lib/pkgconfig" ./configure --prefix="$P" --pkg-config-flags=--static \
--enable-static --disable-shared --enable-pic --disable-programs --disable-doc --disable-network --disable-autodetect \
--disable-everything --disable-avformat --disable-avfilter --disable-avdevice \
--enable-avcodec --enable-swscale --enable-swresample --enable-avutil \
--enable-libdav1d --enable-decoder=vp8,vp9,libdav1d --enable-parser=vp8,vp9,av1 \
&& make -j"$JOBS" && make install)
rm -rf "$DEPS/src-dav1d" "$DEPS/src-ffmpeg" "$P/share" "$P/lib/pkgconfig"
mark ffmpeg "$FFMPEG_VER-$DAV1D_VER"
fi
# ---- SDL2 (its X11, Wayland and sound back ends load their libraries at run time) ----
if ! done_for sdl2 "$SDL_VER"; then
fetch "https://github.com/libsdl-org/SDL/releases/download/release-$SDL_VER/SDL2-$SDL_VER.tar.gz" sdl2.tar.gz "$SDL_SHA256"
rm -rf "$DEPS/src-sdl2" "$DEPS/sdl2"
mkdir -p "$DEPS/src-sdl2" && tar -xzf "$DL/sdl2.tar.gz" -C "$DEPS/src-sdl2" --strip-components=1
cmake -S "$DEPS/src-sdl2" -B "$DEPS/src-sdl2/build" -G Ninja -DCMAKE_BUILD_TYPE=Release -DSDL_SHARED=ON -DSDL_STATIC=OFF \
-DSDL_TEST=OFF -DSDL_X11=ON -DSDL_WAYLAND=ON -DSDL_PULSEAUDIO=ON -DSDL_PIPEWIRE=ON -DSDL_ALSA=ON
ninja -C "$DEPS/src-sdl2/build"
mkdir -p "$DEPS/sdl2"
cp -L "$DEPS/src-sdl2/build/libSDL2-2.0.so.0" "$DEPS/sdl2/libSDL2-2.0.so.0"
strip "$DEPS/sdl2/libSDL2-2.0.so.0"
cp "$DEPS/src-sdl2/LICENSE.txt" "$DEPS/sdl2/LICENSE.txt"
rm -rf "$DEPS/src-sdl2"
mark sdl2 "$SDL_VER"
fi
# ---- the Vulkan back end's headers ----
if ! done_for cpm "$VK_HEADERS-$SPIRV_HEADERS-$VMA"; then
rm -rf "$DEPS/cpm"
get_headers() { # repo tag name
fetch "https://github.com/$1/archive/refs/tags/$2.tar.gz" "$3-$2.tar.gz"
mkdir -p "$DEPS/cpm/$3/$2"
tar -xzf "$DL/$3-$2.tar.gz" -C "$DEPS/cpm/$3/$2" --strip-components=1
}
get_headers KhronosGroup/Vulkan-Headers "$VK_HEADERS" vulkanheaders
get_headers KhronosGroup/SPIRV-Headers "$SPIRV_HEADERS" spirv-headers
get_headers GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator "$VMA" vulkanmemoryallocator
mark cpm "$VK_HEADERS-$SPIRV_HEADERS-$VMA"
fi
# ---- the licenses of what the AppImage carries (Python's and its modules' are in python/) ----
if ! done_for licenses "$LLVM_VER-$FFMPEG_VER-$DAV1D_VER-$SDL_VER-$TCLTK_VER"; then
L=$DEPS/licenses
rm -rf "$L" && mkdir -p "$L"
curl -fsSL -o "$L/LLVM-LICENSE.TXT" "https://raw.githubusercontent.com/llvm/llvm-project/llvmorg-$LLVM_VER/llvm/LICENSE.TXT"
curl -fsSL -o "$L/FFmpeg-COPYING.LGPLv2.1" "https://raw.githubusercontent.com/FFmpeg/FFmpeg/n$FFMPEG_VER/COPYING.LGPLv2.1"
curl -fsSL -o "$L/FFmpeg-LICENSE.md" "https://raw.githubusercontent.com/FFmpeg/FFmpeg/n$FFMPEG_VER/LICENSE.md"
curl -fsSL -o "$L/dav1d-COPYING" "https://code.videolan.org/videolan/dav1d/-/raw/$DAV1D_VER/COPYING"
cp "$DEPS/sdl2/LICENSE.txt" "$L/SDL2-LICENSE.txt"
cp "$DEPS/tk/Tk-license.terms" "$L/Tk-license.terms"
cp /usr/share/doc/libxft2/copyright "$L/libXft-copyright"
cp /usr/share/doc/libxrender1/copyright "$L/libXrender-copyright"
mark licenses "$LLVM_VER-$FFMPEG_VER-$DAV1D_VER-$SDL_VER-$TCLTK_VER"
fi
# ---- appimagetool ----
if ! done_for appimagetool "$APPIMAGETOOL"; then
fetch "https://github.com/AppImage/appimagetool/releases/download/$APPIMAGETOOL/appimagetool-x86_64.AppImage" appimagetool "$APPIMAGETOOL_SHA256"
cp "$DL/appimagetool" "$DEPS/appimagetool" && chmod +x "$DEPS/appimagetool"
mark appimagetool "$APPIMAGETOOL"
fi
if ! done_for runtime "$APPIMAGE_RUNTIME"; then
fetch "https://github.com/AppImage/type2-runtime/releases/download/$APPIMAGE_RUNTIME/runtime-x86_64" "runtime-x86_64-$APPIMAGE_RUNTIME"
echo "$APPIMAGE_RUNTIME_SHA256 $DL/runtime-x86_64-$APPIMAGE_RUNTIME" | sha256sum -c -
cp "$DL/runtime-x86_64-$APPIMAGE_RUNTIME" "$DEPS/runtime-x86_64"
mark runtime "$APPIMAGE_RUNTIME"
fi
echo "deps in $DEPS: $(du -sh --exclude=downloads "$DEPS" | cut -f1)"

117
scripts/linux/make_parts.py Normal file
View File

@@ -0,0 +1,117 @@
"""The parts a Linux update downloads (builder/linux/linux_update.py), from an AppDir.
python3 scripts/linux/make_parts.py <AppDir> <tag> <out folder> [--base <url>]
Each directory that changes on its own is one zip: the tools (every release), Python, clang, FFmpeg, the sysroot, and
the two libraries beside them. A zip is deterministic, so a directory whose files did not change has the same SHA-256
next time and the builder copies the one it already has. The zips are uploaded to the linux-parts release; the version's
own release carries hookshot-linux.txt, which names them.
The list is not inside a zip (it names the zips' checksums).
"""
import argparse
import hashlib
import os
import sys
import zipfile
sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))),
"builder", "linux"))
from part_links import SYSROOT_PART, is_absolute_link, relative_sysroot_link # noqa: E402
# (dest under the AppDir, and None for the whole directory or the file names when the directory holds other parts too)
PARTS = (
("usr/share/hookshot", None),
("usr/python", None),
("usr/lib/hookshot/emsdk", None),
("usr/lib/hookshot/ffmpeg", None),
("usr/lib/hookshot/sysroot", None),
("usr/lib/hookshot", ("hookshot_vk.so", "libSDL2-2.0.so.0")),
)
def _entries(root, dest, files):
base = os.path.join(root, dest)
if files is not None:
return [(name, os.path.join(base, name)) for name in files]
out = []
for dirpath, dirnames, names in os.walk(base, followlinks=False):
rel = os.path.relpath(dirpath, base)
real = []
for name in sorted(dirnames):
link = os.path.join(dirpath, name)
arc = name if rel == os.curdir else rel.replace(os.sep, "/") + "/" + name
if os.path.islink(link):
out.append((arc, link))
else:
real.append(name)
dirnames[:] = real
for name in sorted(names):
full = os.path.join(dirpath, name)
arc = name if rel == os.curdir else rel.replace(os.sep, "/") + "/" + name
out.append((arc, full))
return out
def write_zip(path, root, dest, files):
entries = _entries(root, dest, files)
with zipfile.ZipFile(path + ".new", "w", zipfile.ZIP_DEFLATED, compresslevel=6) as zipped:
for arc, full in entries:
info = zipfile.ZipInfo(arc, date_time=(2026, 1, 1, 0, 0, 0))
info.compress_type = zipfile.ZIP_DEFLATED
info.create_system = 3
if os.path.islink(full):
info.external_attr = 0o120777 << 16
link_to = os.readlink(full)
if dest == SYSROOT_PART and is_absolute_link(link_to):
link_to = relative_sysroot_link(os.path.join(root, dest), full, link_to)
zipped.writestr(info, link_to, compresslevel=6)
continue
info.external_attr = (0o755 if os.access(full, os.X_OK) else 0o644) << 16
with open(full, "rb") as handle:
zipped.writestr(info, handle.read(), compresslevel=6)
os.replace(path + ".new", path)
digest = hashlib.sha256()
with open(path, "rb") as handle:
while True:
block = handle.read(1 << 20)
if not block:
break
digest.update(block)
return digest.hexdigest(), os.path.getsize(path)
def main():
parser = argparse.ArgumentParser()
parser.add_argument("appdir")
parser.add_argument("tag")
parser.add_argument("out")
parser.add_argument("--base", default="https://github.com/NotRexed/Hookshot/releases/download/linux-parts")
args = parser.parse_args()
root = os.path.abspath(args.appdir)
if not os.path.isfile(os.path.join(root, "AppRun")):
sys.exit("not an AppDir: %s" % root)
os.makedirs(args.out, exist_ok=True)
base = args.base.rstrip("/")
lines = ["tag %s" % args.tag]
for dest, files in PARTS:
if not os.path.isdir(os.path.join(root, dest)):
sys.exit("the AppDir has no %s" % dest)
leaf = dest.replace("/", "-")
path = os.path.join(args.out, "HookshotLinux-%s.zip" % leaf)
digest, size = write_zip(path, root, dest, files)
named = os.path.join(args.out, "HookshotLinux-%s-%s.zip" % (leaf, digest[:12]))
os.replace(path, named)
lines.append("part %s %d %s %s/%s" % (digest, size, dest, base, os.path.basename(named)))
lines.append("tree" if files is None else "\n".join("file %s" % name for name in files))
print("%-32s %5d MB %s" % (dest, size >> 20, digest[:16]), flush=True)
text = "\n".join(lines) + "\n"
with open(os.path.join(args.out, "hookshot-linux.txt"), "w", encoding="utf-8", newline="\n") as handle:
handle.write(text)
# (beside AppRun, not inside a hashed part: the list names those checksums)
with open(os.path.join(root, "hookshot-linux.txt"), "w", encoding="utf-8", newline="\n") as handle:
handle.write(text)
if __name__ == "__main__":
main()

15
scripts/linux/ngx-sdk.sh Executable file
View File

@@ -0,0 +1,15 @@
#!/bin/bash
# ngx-sdk.sh: NVIDIA's DLSS SDK files for a local Linux build with NVIDIA DLSS (HOOKSHOT_NGX_SDK): scripts/ngx_sdk.py, which
# says what it fetches and asks for NVIDIA's license (--accept-nvidia-license: accepted without the question).
#
# Usage: scripts/linux/ngx-sdk.sh [--accept-nvidia-license] [<sdk folder>] [<runtime folder>]
# <sdk folder>: default build-linux/ngx-sdk; <runtime folder>: libnvidia-ngx-dlss.so copied there too (a game folder's
# ngx/, or $XDG_DATA_HOME/hookshot/ngx; RX_VK_DLSS_DIR names another)
# Then build with HOOKSHOT_NGX_SDK=<sdk folder>.
set -euo pipefail
ROOT=$(cd "$(dirname "$0")/../.." && pwd)
accept=()
if [ "${1:-}" = --accept-nvidia-license ]; then accept=(--accept-nvidia-license); shift; fi
args=(--platform linux "${accept[@]}")
[ -n "${2:-}" ] && args+=(--runtime-dir "$2")
exec "${PYTHON:-python3}" -I "$ROOT/scripts/ngx_sdk.py" "${args[@]}" ${1:+"$1"}

47
scripts/linux/publish_parts.sh Executable file
View File

@@ -0,0 +1,47 @@
#!/bin/bash
# Upload the Linux builder's parts (scripts/linux/make_parts.py) to the linux-parts release, which is not "latest".
# A zip whose name is already there is left (its checksum is in the name). hookshot-linux.txt itself goes on the
# version release, with the AppImage. Run from CI on a tag, with GH_TOKEN and GITHUB_REPOSITORY.
set -euo pipefail
ROOT=$(cd "$(dirname "$0")/../.." && pwd)
PARTS=${1:-$ROOT/build-linux/parts}
REPO=${GITHUB_REPOSITORY:?}
TOKEN=${GH_TOKEN:?}
API="https://api.github.com/repos/$REPO"
AUTH=(-H "Authorization: Bearer $TOKEN" -H "Accept: application/vnd.github+json" -H "User-Agent: Hookshot")
J=$(mktemp) # (the release's JSON: a private file, not a fixed name in /tmp)
trap 'rm -f "$J"' EXIT
code=$(curl -s -o "$J" -w '%{http_code}' "${AUTH[@]}" "$API/releases/tags/linux-parts")
if [ "$code" = "404" ]; then
curl -fsSL "${AUTH[@]}" -X POST "$API/releases" -d "$(python3 - <<'PY'
import json, os
print(json.dumps({
"tag_name": "linux-parts",
"target_commitish": os.environ["GITHUB_SHA"],
"name": "Linux builder parts",
"body": "Parts Hookshot's Linux builder downloads. A file's name is its checksum; a part that did not change is not uploaded again. This release is not a version of the game.",
"prerelease": True,
"make_latest": "false",
}))
PY
)" > "$J"
fi
python3 - "$J" <<'PY'
import json, sys
json.load(open(sys.argv[1]))["upload_url"]
PY
upload=$(python3 -c 'import json, sys; print(json.load(open(sys.argv[1]))["upload_url"].split("{")[0])' "$J")
have=$(python3 -c 'import json, sys; print("\n".join(a["name"] for a in json.load(open(sys.argv[1])).get("assets", [])))' "$J")
for zip in "$PARTS"/HookshotLinux-*.zip; do
[ -f "$zip" ] || continue
name=$(basename "$zip")
if printf '%s\n' "$have" | grep -qx "$name"; then
echo "already on linux-parts: $name"
continue
fi
echo "uploading $name"
curl -fsSL --retry 5 --retry-delay 10 -X POST "${AUTH[@]}" -H "Content-Type: application/zip" \
--data-binary @"$zip" "$upload?name=$name" >/dev/null
done
echo "parts published"