mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-19 06:29:58 -04:00
Build Ocarina natively on Linux with tools/make_game.py, and pack the kit as an AppImage.
make_game.py only knew MSYS2. On Linux it now does what tools/build_game.py's Linux path does: - clang, clang++ and lld from PATH (checked at start), the system's headers and libraries, vk_mem_alloc.h from the system or the pinned copy build_game.py fetches into toolchain/vma; - the runtime's *_sdl.* files and platform/linux.c in place of the Win32 ones; no shim.c (ui/menu_sdl.cpp defines menu_sdl_event), no windres, no DLLs to copy; - -fdeclspec for C++, as third_party/ffx_api/ffx_api.h declares __declspec(dllexport) unconditionally; - build_game.py's Linux link flags (-no-pie, noexecstack, rpath $ORIGIN, libstdc++ static) and libraries, plus dav1d (the AV1 movies), libatomic and libunwind (the previous commit's plat_frame_capture); - ocarina and nx2navi_xlate without .exe; the translator from the kit's bin/ or a checkout's build/xlate. Windows is unchanged: every difference is under os.name. tools/make_appimage.py packs the kit (tools, recomp, runtime, the built translator, VMA) with a relocatable CPython 3.14 and numpy, lz4, zstandard and fonttools into NX2navi-Linux-<version>-x86_64.AppImage. Its AppRun checks for the compiler and headers and names the packages for Arch, Fedora and Debian/Ubuntu, installs zbic (GPL-2.0, not bundled) with pip into ~/.local/share/nx2navi/pydeps on the first run, picks --jobs from the memory, builds and writes play.sh beside the game. README-BuildKit.md has a Linux section. Tested on CachyOS (kernel 7.3, clang 23, RTX 3080, NVIDIA 620.70.06, 16 GB): make_game.py --nup ... --jobs 4 builds ocarina in 9.9 minutes from a 1.1.1 dump, which passes --probe-cfg; a build with the same sources and flags (compiled by hand before this script could) starts, loads a save and plays. With one compile per thread on 16 GB the build filled memory and swap and the kernel stopped desktop processes, hence the --jobs advice. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
187
tools/make_appimage.py
Normal file
187
tools/make_appimage.py
Normal file
@@ -0,0 +1,187 @@
|
||||
"""Build NX2navi-Linux-<version>-x86_64.AppImage: the Linux build kit as one file, which builds Ocarina of Time on the
|
||||
player's PC from their own dump with tools/make_game.py, as NX2navi-Setup.exe does on Windows.
|
||||
|
||||
python3 tools/make_appimage.py --python <standalone CPython 3.14> --appimagetool <appimagetool> [--out dist]
|
||||
|
||||
The AppImage holds no game files: the kit's tools/, recomp/, runtime/ and docs, the shader translator built by
|
||||
tools/build_xlate.py (bin/nx2navi_xlate), the pinned Vulkan Memory Allocator header, and a relocatable CPython 3.14
|
||||
(python-build-standalone, as `uv python install 3.14` puts in ~/.local/share/uv/python) with numpy, lz4, zstandard and
|
||||
fonttools. zbic, the GPL package that unpacks the game's program files, is not bundled: the AppImage installs it with
|
||||
pip into ~/.local/share/nx2navi/pydeps the first time it runs, as the Windows launcher downloads it.
|
||||
|
||||
The compiler and the libraries come from the system (README-BuildKit.md, "Linux"): the AppImage checks for clang,
|
||||
clang++, lld and the headers before it starts, and names the packages for Arch, Fedora and Debian/Ubuntu.
|
||||
"""
|
||||
import argparse
|
||||
import os
|
||||
import shutil
|
||||
import stat
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
KIT_DIRS = ('recomp', 'runtime')
|
||||
KIT_FILES = ('VERSION', 'LICENSE', 'LICENSE-ADDITIONS', 'THIRD_PARTY_NOTICES.md', 'nx2navi.ini.example')
|
||||
TOOLS_SKIP = ('vendor', 'xlate', '__pycache__') # the translator ships built (bin/); its sources stay out
|
||||
PACKAGES = ('numpy==2.5.4', 'lz4==4.4.5', 'zstandard==0.25.0', 'fonttools==4.68.0')
|
||||
|
||||
APPRUN = r'''#!/bin/bash
|
||||
# NX2navi build kit for Linux: builds Ocarina of Time (Switch 2, game 1.1.1) from the player's own dump.
|
||||
HERE="$(dirname "$(readlink -f "$0")")"
|
||||
PY="$HERE/usr/python/bin/python3"
|
||||
KIT="$HERE/usr/kit"
|
||||
DATA="${XDG_DATA_HOME:-$HOME/.local/share}/nx2navi"
|
||||
PYDEPS="$DATA/pydeps"
|
||||
unset PYTHONPATH PYTHONHOME
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
NX2navi $(cat "$KIT/VERSION") - build Ocarina of Time (Switch 2, game 1.1.1) natively for Linux from your own dump.
|
||||
|
||||
$(basename "${APPIMAGE:-$0}") <your game.nup> [game folder] build (default folder: ~/Games/Ocarina)
|
||||
$(basename "${APPIMAGE:-$0}") --check <your game.nup> only check the dump's version
|
||||
$(basename "${APPIMAGE:-$0}") --make-game <make_game.py options> run tools/make_game.py directly
|
||||
|
||||
The game folder then holds 'ocarina' and 'play.sh', which starts it. Nothing of the game is in this file:
|
||||
everything the build writes comes from your dump, so keep it to yourself.
|
||||
EOF
|
||||
}
|
||||
|
||||
case "$1" in ""|-h|--help) usage; exit 0 ;; esac
|
||||
|
||||
missing=()
|
||||
for tool in clang clang++ ld.lld; do command -v "$tool" >/dev/null || missing+=("$tool"); done
|
||||
for h in SDL3/SDL.h vulkan/vulkan.h opus/opus.h vpx/vpx_decoder.h dav1d/dav1d.h zstd.h libunwind.h; do
|
||||
[ -e "/usr/include/$h" ] || [ -e "/usr/local/include/$h" ] || missing+=("$h")
|
||||
done
|
||||
if [ ${#missing[@]} -gt 0 ]; then
|
||||
cat >&2 <<EOF
|
||||
Missing: ${missing[*]}
|
||||
Install the compiler and libraries, then run this again:
|
||||
Arch, CachyOS, Manjaro, SteamOS (developer mode):
|
||||
sudo pacman -S --needed clang lld sdl3 opus libvpx dav1d zstd libunwind vulkan-headers vulkan-icd-loader
|
||||
Fedora:
|
||||
sudo dnf install clang lld SDL3-devel opus-devel libvpx-devel libdav1d-devel libzstd-devel libunwind-devel \\
|
||||
vulkan-headers vulkan-loader-devel libstdc++-static libatomic
|
||||
Debian, Ubuntu:
|
||||
sudo apt install clang lld libsdl3-dev libopus-dev libvpx-dev libdav1d-dev libzstd-dev libunwind-dev libvulkan-dev
|
||||
EOF
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! PYTHONPATH="$PYDEPS" "$PY" -c 'import zbic' 2>/dev/null; then
|
||||
echo "Installing zbic (GPL-2.0, unpacks the game's program files) into $PYDEPS ..."
|
||||
"$PY" -m pip install --quiet --disable-pip-version-check --target "$PYDEPS" zbic || {
|
||||
echo "error: pip could not install zbic (it needs the internet once)" >&2; exit 1; }
|
||||
fi
|
||||
|
||||
# One compile per 4 GB of RAM at most: with 16 GB, one per thread beside the RomFS image fills memory and swap.
|
||||
mem_gb=$(awk '/MemTotal/ {print int($2 / 1048576)}' /proc/meminfo)
|
||||
jobs=$(( mem_gb / 4 )); [ "$jobs" -lt 2 ] && jobs=2; [ "$jobs" -gt "$(nproc)" ] && jobs=$(nproc)
|
||||
|
||||
run_make_game() {
|
||||
"$PY" -I -c 'import sys; sys.path[:0] = [sys.argv[1], sys.argv[2] + "/tools"]; s = sys.argv[2] + "/tools/make_game.py"; sys.argv = [s] + sys.argv[3:]; import runpy; runpy.run_path(s, run_name="__main__")' \
|
||||
"$PYDEPS" "$KIT" "$@"
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
--make-game) shift; run_make_game "$@"; exit $? ;;
|
||||
--check) run_make_game --nup "$2" --check; exit $? ;;
|
||||
esac
|
||||
|
||||
NUP="$1"
|
||||
OUT="${2:-$HOME/Games/Ocarina}"
|
||||
[ -f "$NUP" ] || { echo "error: $NUP is not a file" >&2; usage; exit 1; }
|
||||
echo "Building into $OUT with $jobs compiles at a time (${mem_gb} GB of RAM); this takes 10 to 25 minutes."
|
||||
run_make_game --nup "$NUP" --out "$OUT" --jobs "$jobs" || exit $?
|
||||
|
||||
# play.sh: the environment the game wants on this machine, then the game
|
||||
{
|
||||
echo '#!/bin/bash'
|
||||
echo 'cd "$(dirname "$(readlink -f "$0")")"'
|
||||
if [ -e /proc/driver/nvidia/version ]; then
|
||||
echo '# NVIDIA: the default shadow storage leaves the 3D world black (issue #72)'
|
||||
echo 'export NX2NAVI_SHADOW="${NX2NAVI_SHADOW:-0}"'
|
||||
fi
|
||||
echo 'exec ./ocarina "$@"'
|
||||
} > "$OUT/play.sh"
|
||||
chmod +x "$OUT/play.sh"
|
||||
echo
|
||||
echo "Done. Start the game with: $OUT/play.sh"
|
||||
'''
|
||||
|
||||
DESKTOP = '''[Desktop Entry]
|
||||
Type=Application
|
||||
Name=NX2navi
|
||||
Comment=Build Ocarina of Time natively for Linux from your own dump
|
||||
Exec=AppRun
|
||||
Icon=nx2navi
|
||||
Terminal=true
|
||||
Categories=Game;
|
||||
'''
|
||||
|
||||
|
||||
def copy_tree(src, dst, skip=()):
|
||||
shutil.copytree(src, dst, ignore=lambda d, names: [n for n in names if n in skip or n == '__pycache__'])
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
||||
ap.add_argument('--python', type=Path, required=True,
|
||||
help='a relocatable CPython 3.14 folder (python-build-standalone, ~/.local/share/uv/python/cpython-3.14*)')
|
||||
ap.add_argument('--appimagetool', type=Path, required=True, help='appimagetool-x86_64.AppImage')
|
||||
ap.add_argument('--out', type=Path, default=ROOT / 'dist', help='where the AppImage goes (default dist/)')
|
||||
a = ap.parse_args()
|
||||
|
||||
version = (ROOT / 'VERSION').read_text(encoding='utf-8').strip()
|
||||
xlate = ROOT / 'build' / 'xlate'
|
||||
for need in (xlate / 'nx2navi_xlate', xlate / 'nx2navi_xlate.id', ROOT / 'toolchain' / 'vma' / 'vk_mem_alloc.h',
|
||||
a.python / 'bin' / 'python3'):
|
||||
if not need.exists():
|
||||
sys.exit(f'{need} is missing (tools/build_xlate.py builds the translator; tools/build_game.py fetches VMA)')
|
||||
|
||||
app = ROOT / 'build' / 'appimage' / 'NX2navi.AppDir'
|
||||
shutil.rmtree(app, ignore_errors=True)
|
||||
kit = app / 'usr' / 'kit'
|
||||
kit.mkdir(parents=True)
|
||||
for d in KIT_DIRS:
|
||||
copy_tree(ROOT / d, kit / d)
|
||||
copy_tree(ROOT / 'tools', kit / 'tools', TOOLS_SKIP)
|
||||
for f in KIT_FILES:
|
||||
shutil.copy2(ROOT / f, kit / f)
|
||||
(kit / 'docs').mkdir()
|
||||
shutil.copy2(ROOT / 'docs' / 'README-BuildKit.md', kit / 'docs' / 'README-BuildKit.md')
|
||||
(kit / 'bin').mkdir()
|
||||
for f in ('nx2navi_xlate', 'nx2navi_xlate.id'):
|
||||
shutil.copy2(xlate / f, kit / 'bin' / f)
|
||||
(kit / 'toolchain' / 'vma').mkdir(parents=True)
|
||||
shutil.copy2(ROOT / 'toolchain' / 'vma' / 'vk_mem_alloc.h', kit / 'toolchain' / 'vma' / 'vk_mem_alloc.h')
|
||||
|
||||
py = app / 'usr' / 'python'
|
||||
shutil.copytree(a.python, py, symlinks=True)
|
||||
for marker in py.glob('lib/python3*/EXTERNALLY-MANAGED'): # uv marks its Pythons; this copy is the AppImage's own
|
||||
marker.unlink()
|
||||
subprocess.run([py / 'bin' / 'python3', '-m', 'pip', 'install', '--quiet', '--disable-pip-version-check',
|
||||
'--no-warn-script-location', *PACKAGES], check=True)
|
||||
for cache in py.rglob('__pycache__'):
|
||||
shutil.rmtree(cache, ignore_errors=True)
|
||||
|
||||
(app / 'AppRun').write_text(APPRUN, encoding='utf-8')
|
||||
(app / 'AppRun').chmod(0o755)
|
||||
(app / 'nx2navi.desktop').write_text(DESKTOP, encoding='utf-8')
|
||||
from PIL import Image # the window icon of runtime/nx2navi.ico, as PNG
|
||||
with Image.open(ROOT / 'runtime' / 'nx2navi.ico') as ico:
|
||||
ico.size = max(ico.ico.sizes())
|
||||
ico.convert('RGBA').save(app / 'nx2navi.png')
|
||||
|
||||
a.out.mkdir(parents=True, exist_ok=True)
|
||||
target = a.out / f'NX2navi-Linux-{version}-x86_64.AppImage'
|
||||
env = dict(os.environ, ARCH='x86_64')
|
||||
subprocess.run([a.appimagetool, '--no-appstream', app, target], check=True, env=env)
|
||||
target.chmod(target.stat().st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
|
||||
print(f'{target} ({target.stat().st_size / 1e6:.0f} MB)')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user