Files
airdef/tools/airdef.py
T
chexit 67e8a19e2b Auto-install libclang for bindgen on Windows + NVIDIA RTX
The DLSS build failed on Windows at dlss_wgpu's bindgen step: libclang.dll
is neither in the DLSS SDK nor in the Vulkan headers. It is now part of the
same zero-manual toolchain.

Detection first, download last: an explicit LIBCLANG_PATH (directory with
libclang.dll or clang.dll) wins and disables auto-install; otherwise PATH,
Program Files\LLVM\bin (both Program Files roots) and LLVM shipped with
Visual Studio (vswhere -find VC\Tools\Llvm\x64\bin\libclang.dll) are
checked, then the cache.

When nothing is found, the NuGet package libclang.runtime.win-x64 is
downloaded (~34 MB, version from the flat-container index with pinned
23.1.5 fallback) and only runtimes/win-x64/native/libclang.dll (~89 MB) is
extracted to .horizon-cache/libclang/<version>/ behind the existing
staging + airdef-install.json marker pattern. The resolved directory is
passed to cargo as LIBCLANG_PATH.

libclang is resolved only when the DLSS SDK and Vulkan headers are already
available, so a missing SDK never triggers a useless download. Any
detection/download/extract failure warns and degrades to mods/TAAU, and
non-Windows/non-RTX still returns before any network access.

Tests cover PATH/Program Files/vswhere detection, explicit precedence,
numeric NuGet version choice and fallback, selective extraction and marker,
cache hit, damaged cache reinstall, package without the DLL, plan env
wiring and failure to mods-only.

Co-Authored-By: Kimi Code <noreply@moonshot.ai>
2026-11-21 15:55:12 +03:00

1014 lines
50 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""AirDef: сборка, установка и запуск на Windows, macOS и Linux. Только стандартная библиотека Python.
python3 tools/airdef.py fork # инициализировать закреплённый сабмодуль Horizon (horizon/)
python3 tools/airdef.py game # собрать игру (форк) — нужен Rust; на Windows + NVIDIA RTX сам скачивает DLSS SDK, Vulkan-заголовки и libclang
python3 tools/airdef.py mod # собрать мод airdef.hmod — нужен Rust с wasm32
python3 tools/airdef.py install # положить мод в папку игры и включить
python3 tools/airdef.py play [аргументы игры] # запустить форк на папке игры
python3 tools/airdef.py all # всё по порядку: fork, game, mod, install
python3 tools/airdef.py check # совпадают ли форк, упаковщик, уровень API мода и ресурсы
python3 tools/airdef.py test-wasm # собрать и прогнать настоящий .hmod в песочнице без GPU
python3 tools/airdef.py test-budgets # тяжёлый WASM budget сценарий + JSON provenance
Переменные окружения: HORIZON_HOME (папка игры), HORIZON_RESOURCES (подготовленные ресурсы
Minecraft 26.3), AIRDEF_GAME (готовый horizon-client вместо собранного).
На Windows + NVIDIA RTX сборка с DLSS (feature dlss) сама скачивает DLSS SDK, заголовки Vulkan и
libclang для bindgen в .horizon-cache/ и кладёт nvngx_dlss.dll рядом с horizon-client.exe. Явные
DLSS_SDK, VULKAN_SDK и LIBCLANG_PATH по-прежнему имеют приоритет над автоскачиванием; при сбое сети
собирается обычный mods/TAAU.
"""
import glob
import hashlib
import json
import os
import platform
import re
import shutil
import subprocess
import sys
import tempfile
import urllib.request
import zipfile
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
FORK = ROOT / "horizon"
EXE = ".exe" if os.name == "nt" else ""
def data_dir() -> Path:
"""Как `dirs::data_dir()` в Horizon."""
system = platform.system()
if system == "Windows":
return Path(os.environ["APPDATA"])
if system == "Darwin":
return Path.home() / "Library" / "Application Support"
return Path(os.environ.get("XDG_DATA_HOME", Path.home() / ".local" / "share"))
def game_home() -> Path:
return Path(os.environ.get("HORIZON_HOME") or data_dir() / "horizon")
def run(cmd, cwd=None, env=None):
print("+", " ".join(str(c) for c in cmd), flush=True)
subprocess.run([str(c) for c in cmd], cwd=cwd, env=env, check=True)
def cargo() -> str:
found = shutil.which("cargo") or str(Path.home() / ".cargo" / "bin" / ("cargo" + EXE))
if not Path(found).exists() and not shutil.which("cargo"):
sys.exit("Нужен Rust: https://rustup.rs (затем: rustup target add wasm32-unknown-unknown)")
return found
def engine_commit() -> str:
"""The index pins the engine, including a deliberate not-yet-committed gitlink update."""
row = subprocess.check_output(["git", "ls-files", "--stage", "--", "horizon"], cwd=ROOT, text=True).strip().split()
if len(row) < 2 or row[0] != "160000":
sys.exit("Нет закреплённого сабмодуля horizon/: проверьте checkout AirDef")
return row[1]
def engine_identity() -> str:
commit = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=FORK, text=True).strip()
diff = subprocess.check_output(["git", "diff", "--binary", "HEAD"], cwd=FORK)
return commit + ("-" + hashlib.sha256(diff).hexdigest()[:16] if diff else "")
def fork():
"""Initialize the exact gitlink; never replace a modified developer checkout."""
expected = engine_commit()
matched = False
if (FORK / ".git").exists():
current = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=FORK, text=True).strip()
matched = current == expected
dirty = subprocess.check_output(["git", "status", "--porcelain"], cwd=FORK, text=True).strip()
if not matched and dirty:
sys.exit("horizon/: есть изменения при другом закреплённом SHA; сохраните их перед обновлением сабмодуля")
if (FORK / ".git").is_dir():
# Migrate the old standalone clone without deleting it or any local branches.
run(["git", "submodule", "absorbgitdirs", "--", "horizon"], cwd=ROOT)
url = subprocess.check_output(["git", "config", "-f", ".gitmodules", "--get", "submodule.horizon.url"], cwd=ROOT, text=True).strip()
run(["git", "remote", "set-url", "origin", url], cwd=FORK)
elif FORK.exists() and any(FORK.iterdir()):
sys.exit("horizon/: непустой каталог без Git; сохраните его перед инициализацией сабмодуля")
# Existing clones cache the previous upstream URL in local Git configuration.
# Synchronize even when HEAD already matches: the next pin may exist only in our fork.
run(["git", "submodule", "sync", "--recursive", "--", "horizon"], cwd=ROOT)
if matched:
print(f"horizon/: закреплённый коммит {expected}")
return
run(["git", "submodule", "update", "--init", "--recursive", "--", "horizon"], cwd=ROOT)
current = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=FORK, text=True).strip()
if current != expected:
sys.exit(f"horizon/: ожидался {expected}, получен {current}")
DLSS_SDK_URL = "https://github.com/NVIDIA/DLSS"
DLSS_TAGS_API = "https://api.github.com/repos/NVIDIA/DLSS/tags?per_page=30"
DLSS_RAW = "https://raw.githubusercontent.com/NVIDIA/DLSS/{tag}/{path}"
DLSS_TAG_PINNED = "v310.9.1"
# Автоскачивание берёт только стабильные v310.9.x; закреплённая версия — резерв при сбое API.
DLSS_TAG = re.compile(r"^v310\.9\.(\d+)$")
DLSS_INCLUDE_FALLBACK = (
"nvsdk_ngx.h", "nvsdk_ngx_defs.h", "nvsdk_ngx_defs_dlssd.h", "nvsdk_ngx_defs_dlssg.h",
"nvsdk_ngx_defs_vk.h", "nvsdk_ngx_helpers.h", "nvsdk_ngx_helpers_cuda.h",
"nvsdk_ngx_helpers_d3d.h", "nvsdk_ngx_helpers_dlssd.h", "nvsdk_ngx_helpers_dlssd_cuda.h",
"nvsdk_ngx_helpers_dlssd_d3d.h", "nvsdk_ngx_helpers_dlssd_vk.h", "nvsdk_ngx_helpers_dlssg.h",
"nvsdk_ngx_helpers_dlssg_d3d.h", "nvsdk_ngx_helpers_dlssg_vk.h", "nvsdk_ngx_helpers_vk.h",
"nvsdk_ngx_loader.h", "nvsdk_ngx_params.h", "nvsdk_ngx_params_dlssd.h",
"nvsdk_ngx_params_dlssg.h", "nvsdk_ngx_standalone_common.h", "nvsdk_ngx_standalone_cuda.h",
"nvsdk_ngx_vk.h",
)
# dlss_wgpu линкует static-библиотеку (nvsdk_ngx_d, либо nvsdk_ngx_s при crt-static).
DLSS_LIBS = ("lib/Windows_x86_64/x64/nvsdk_ngx_d.lib", "lib/Windows_x86_64/x64/nvsdk_ngx_s.lib")
DLSS_RUNTIME = "lib/Windows_x86_64/rel/nvngx_dlss.dll"
VULKAN_SDK_URL = "https://vulkan.lunarg.com/sdk/home"
VULKAN_TAG_PINNED = "vulkan-sdk-1.4.363.0"
VULKAN_RAW = "https://raw.githubusercontent.com/KhronosGroup/Vulkan-Headers/{tag}/include/{path}"
# build.rs использует только заголовки ({VULKAN_SDK}/Include), полный LunarG SDK не нужен.
VULKAN_HEADERS = (
"vulkan/vulkan.h", "vulkan/vulkan_core.h", "vulkan/vk_platform.h",
"vk_video/vulkan_video_codec_av1std.h", "vk_video/vulkan_video_codec_av1std_decode.h",
"vk_video/vulkan_video_codec_av1std_encode.h", "vk_video/vulkan_video_codec_h264std.h",
"vk_video/vulkan_video_codec_h264std_decode.h", "vk_video/vulkan_video_codec_h264std_encode.h",
"vk_video/vulkan_video_codec_h265std.h", "vk_video/vulkan_video_codec_h265std_decode.h",
"vk_video/vulkan_video_codec_h265std_encode.h", "vk_video/vulkan_video_codec_vp9std.h",
"vk_video/vulkan_video_codec_vp9std_decode.h", "vk_video/vulkan_video_codecs_common.h",
)
# bindgen из dlss_wgpu ищет libclang.dll; в DLSS SDK и Vulkan-заголовках его нет.
LIBCLANG_NUGET = "libclang.runtime.win-x64"
LIBCLANG_INDEX = "https://api.nuget.org/v3-flatcontainer/libclang.runtime.win-x64/index.json"
LIBCLANG_PACKAGE = ("https://api.nuget.org/v3-flatcontainer/libclang.runtime.win-x64/{version}/"
"libclang.runtime.win-x64.{version}.nupkg")
LIBCLANG_VERSION_PINNED = "23.1.5"
LIBCLANG_NATIVE = "runtimes/win-x64/native/libclang.dll"
LIBCLANG_URL = "https://www.nuget.org/packages/libclang.runtime.win-x64"
CACHE = ROOT / ".horizon-cache"
DLSS_CACHE = CACHE / "dlss-sdk"
VULKAN_CACHE = CACHE / "vulkan-headers"
LIBCLANG_CACHE = CACHE / "libclang"
INSTALL_MARKER = "airdef-install.json"
class DownloadError(RuntimeError):
"""Сеть или неполный файл при автоскачивании; вызывающий код откатывается на mods."""
def open_url(url):
request = urllib.request.Request(url, headers={"User-Agent": "airdef-dlss-autoinstall"})
return urllib.request.urlopen(request, timeout=120)
def fetch_json(url):
"""JSON с GitHub API или nuget.org: общий транспорт для версий и списков файлов."""
with open_url(url) as response:
return json.load(response)
def download(url, dest):
"""Один файл потоком во временный .part и атомарная замена; прогресс для больших файлов."""
dest = Path(dest)
dest.parent.mkdir(parents=True, exist_ok=True)
part = dest.with_name(dest.name + ".part")
try:
try:
response = open_url(url)
except Exception as exc:
raise DownloadError(f"{url}: {exc}") from exc
with response, open(part, "wb") as out:
total = int(response.headers.get("Content-Length") or 0)
big = total >= 8_000_000
if big:
print(f" {dest.name}: {total / 1e6:.1f} МБ", flush=True)
done, step = 0, 0
while True:
chunk = response.read(1 << 20)
if not chunk:
break
out.write(chunk)
done += len(chunk)
if big and done * 10 // total > step:
step = done * 10 // total
print(f" {dest.name}: {min(step * 10, 100)}%", flush=True)
if total and done < total:
raise DownloadError(f"{url}: получено {done} из {total} байт")
os.replace(part, dest)
finally:
if part.exists():
part.unlink()
def dlss_latest_tag():
"""Новейший стабильный тег v310.9.x с GitHub; при сбое API — закреплённый v310.9.1."""
try:
tags = fetch_json(DLSS_TAGS_API)
except Exception as exc:
print(f"Внимание: не удалось получить теги DLSS ({exc}); беру {DLSS_TAG_PINNED}.", flush=True)
return DLSS_TAG_PINNED
versions = []
for entry in tags if isinstance(tags, list) else []:
name = entry.get("name", "") if isinstance(entry, dict) else ""
match = DLSS_TAG.match(name)
if match:
versions.append((int(match.group(1)), name))
if not versions:
print(f"Внимание: среди тегов DLSS нет v310.9.x; беру {DLSS_TAG_PINNED}.", flush=True)
return DLSS_TAG_PINNED
return max(versions)[1]
def dlss_include_files(tag):
"""Список include/*.h тега из API; при сбое — закреплённый набор v310.9.x."""
try:
entries = fetch_json(f"https://api.github.com/repos/NVIDIA/DLSS/contents/include?ref={tag}")
names = [entry["name"] for entry in entries if isinstance(entry, dict)
and str(entry.get("name", "")).endswith(".h")]
if names:
return names
except Exception:
pass
return list(DLSS_INCLUDE_FALLBACK)
def read_marker(path):
"""Манифест установки в кэше (версия, размер DLL); None, если его нет или он битый."""
try:
return json.loads((Path(path) / INSTALL_MARKER).read_text(encoding="utf-8"))
except (OSError, ValueError):
return None
def dlss_sdk_complete(path) -> bool:
"""Полный набор для сборки: include, обе static .lib и runtime DLL."""
path = Path(path)
return valid_dlss_sdk(path) and all((path / rel).is_file() for rel in DLSS_LIBS + (DLSS_RUNTIME,))
def dlss_tag_key(name):
match = DLSS_TAG.match(name)
return int(match.group(1)) if match else -1
def cached_dlss_sdk():
"""Самый новый полностью скачанный SDK в кэше или None."""
try:
for path in sorted(DLSS_CACHE.iterdir(), key=lambda p: dlss_tag_key(p.name), reverse=True):
state = read_marker(path)
if state and state.get("tag") == path.name and dlss_sdk_complete(path):
return path
except OSError:
pass
return None
def install_dlss_sdk(tag=None):
"""Скачивает только нужные файлы NVIDIA/DLSS в .horizon-cache/dlss-sdk/<tag>.
Раскладка ровно та, которую ожидает dlss_wgpu: include/nvsdk_ngx*.h и lib/Windows_x86_64/{x64,rel}.
"""
tag = tag or dlss_latest_tag()
dest = DLSS_CACHE / tag
state = read_marker(dest)
if state and state.get("tag") == tag and dlss_sdk_complete(dest):
print(f"DLSS SDK {tag}: уже в кэше {dest}", flush=True)
return dest
print(f"DLSS SDK {tag}: скачиваю заголовки, .lib и nvngx_dlss.dll (~67 МБ) с {DLSS_SDK_URL}", flush=True)
staging = DLSS_CACHE / f".{tag}.part"
shutil.rmtree(staging, ignore_errors=True)
try:
for name in dlss_include_files(tag):
download(DLSS_RAW.format(tag=tag, path=f"include/{name}"), staging / "include" / name)
for rel in DLSS_LIBS + (DLSS_RUNTIME,):
download(DLSS_RAW.format(tag=tag, path=rel), staging / rel)
if not dlss_sdk_complete(staging):
raise DownloadError(f"DLSS SDK {tag}: после скачивания нет полного набора include/ и lib/Windows_x86_64")
(staging / INSTALL_MARKER).write_text(json.dumps({
"tag": tag, "source": DLSS_SDK_URL,
"dll_bytes": (staging / DLSS_RUNTIME).stat().st_size}, indent=2) + "\n", encoding="utf-8")
shutil.rmtree(dest, ignore_errors=True)
staging.rename(dest)
except Exception:
shutil.rmtree(staging, ignore_errors=True)
raise
print(f"DLSS SDK {tag}: готов, {dest}", flush=True)
return dest
def vulkan_headers_ok(path) -> bool:
"""dlss_wgpu ищет Include/vulkan/vulkan.h (Windows) или include/vulkan/vulkan.h."""
if not path:
return False
path = Path(path)
return any((path / part).is_file() for part in
("Include/vulkan/vulkan.h", "include/vulkan/vulkan.h"))
def vulkan_cache_ok(path, tag) -> bool:
state = read_marker(path)
return bool(state) and state.get("tag") == tag and vulkan_headers_ok(path) \
and (Path(path) / "Include" / "vk_video" / "vulkan_video_codecs_common.h").is_file()
def cached_vulkan_headers():
path = VULKAN_CACHE / VULKAN_TAG_PINNED
return path if vulkan_cache_ok(path, VULKAN_TAG_PINNED) else None
def install_vulkan_headers(tag=VULKAN_TAG_PINNED):
"""Только заголовки Khronos в <cache>/Include: build.rs линкует Vulkan-библиотеку сам."""
dest = VULKAN_CACHE / tag
if vulkan_cache_ok(dest, tag):
print(f"Vulkan-заголовки {tag}: уже в кэше {dest}", flush=True)
return dest
print(f"Vulkan-заголовки {tag}: скачиваю include/ (полный LunarG SDK не нужен)", flush=True)
staging = VULKAN_CACHE / f".{tag}.part"
shutil.rmtree(staging, ignore_errors=True)
try:
for rel in VULKAN_HEADERS:
download(VULKAN_RAW.format(tag=tag, path=rel), staging / "Include" / rel)
if not vulkan_headers_ok(staging):
raise DownloadError(f"Vulkan-заголовки {tag}: после скачивания нет Include/vulkan/vulkan.h")
(staging / INSTALL_MARKER).write_text(json.dumps({"tag": tag, "source": VULKAN_SDK_URL},
indent=2) + "\n", encoding="utf-8")
shutil.rmtree(dest, ignore_errors=True)
staging.rename(dest)
except Exception:
shutil.rmtree(staging, ignore_errors=True)
raise
print(f"Vulkan-заголовки {tag}: готовы, {dest}", flush=True)
return dest
def version_key(text):
"""Числовой ключ версии NuGet: 23.1.10 новее 23.1.5 (строкой было бы наоборот)."""
numbers = tuple(int(part) for part in re.findall(r"\d+", str(text)))
return numbers or (0,)
def libclang_root(path):
"""Каталог, в котором bindgen найдёт libclang.dll (или clang.dll), либо None."""
if not path:
return None
path = Path(path)
return path if any((path / name).is_file() for name in ("libclang.dll", "clang.dll")) else None
def vs_libclang():
"""LLVM из Visual Studio (VC\\Tools\\Llvm\\x64\\bin) через vswhere; вне Windows — None."""
if platform.system() != "Windows":
return None
base = os.environ.get("ProgramFiles(x86)") or os.environ.get("ProgramFiles")
vswhere = Path(base) / "Microsoft Visual Studio" / "Installer" / "vswhere.exe" if base else None
if vswhere is None or not vswhere.is_file():
return None
flags = getattr(subprocess, "CREATE_NO_WINDOW", 0)
try:
out = subprocess.run([str(vswhere), "-products", "*", "-latest",
"-find", "VC\\Tools\\Llvm\\x64\\bin\\libclang.dll"],
capture_output=True, text=True, timeout=30,
creationflags=flags, errors="replace")
except (OSError, ValueError, subprocess.SubprocessError):
return None
for line in out.stdout.splitlines():
found = libclang_root(Path(line.strip()).parent)
if found:
return found
return None
def system_libclang():
"""Уже установленный libclang: PATH, Program Files\\LLVM\\bin, LLVM из Visual Studio."""
for entry in os.environ.get("PATH", "").split(os.pathsep):
found = libclang_root(entry)
if found:
return found
for env in ("ProgramFiles", "ProgramFiles(x86)"):
if os.environ.get(env):
found = libclang_root(Path(os.environ[env]) / "LLVM" / "bin")
if found:
return found
return vs_libclang()
def libclang_latest_version():
"""Последняя стабильная версия libclang.runtime.win-x64 с NuGet; pinned при сбое API."""
try:
data = fetch_json(LIBCLANG_INDEX)
versions = [v for v in data.get("versions", [])
if isinstance(v, str) and "-" not in v and version_key(v) != (0,)]
except Exception as exc:
print(f"Внимание: не удалось получить версии libclang ({exc}); беру {LIBCLANG_VERSION_PINNED}.",
flush=True)
return LIBCLANG_VERSION_PINNED
if not versions:
print(f"Внимание: NuGet не вернул стабильные версии libclang; беру {LIBCLANG_VERSION_PINNED}.",
flush=True)
return LIBCLANG_VERSION_PINNED
return max(versions, key=version_key)
def libclang_cache_ok(path, version):
"""Кэш libclang: маркер этой версии и DLL того же размера (иначе — перекачать)."""
state = read_marker(path)
dll = Path(path) / "libclang.dll"
return bool(state) and state.get("tag") == version and dll.is_file() \
and state.get("dll_bytes") == dll.stat().st_size
def cached_libclang():
try:
candidates = sorted(LIBCLANG_CACHE.iterdir(), key=lambda p: version_key(p.name), reverse=True)
except OSError:
return None
for path in candidates:
if libclang_cache_ok(path, path.name):
return path
return None
def install_libclang(version=None):
"""libclang.dll из NuGet-пакета libclang.runtime.win-x64 в .horizon-cache/libclang/<ver>.
Пакет (~34 МБ) распаковывается выборочно: нужен только runtimes/win-x64/native/libclang.dll.
"""
version = version or libclang_latest_version()
dest = LIBCLANG_CACHE / version
if libclang_cache_ok(dest, version):
print(f"libclang {version}: уже в кэше {dest}", flush=True)
return dest
url = LIBCLANG_PACKAGE.format(version=version)
print(f"libclang {version}: скачиваю {LIBCLANG_NUGET} (~34 МБ) с nuget.org", flush=True)
staging = LIBCLANG_CACHE / f".{version}.part"
shutil.rmtree(staging, ignore_errors=True)
package = staging / f"libclang.runtime.win-x64.{version}.nupkg"
try:
download(url, package)
with zipfile.ZipFile(package) as archive:
with archive.open(LIBCLANG_NATIVE) as src, open(staging / "libclang.dll", "wb") as out:
shutil.copyfileobj(src, out)
package.unlink()
dll = staging / "libclang.dll"
if not dll.is_file() or dll.stat().st_size == 0:
raise DownloadError(f"libclang {version}: в пакете нет {LIBCLANG_NATIVE}")
(staging / INSTALL_MARKER).write_text(json.dumps({
"tag": version, "source": LIBCLANG_URL,
"dll_bytes": dll.stat().st_size}, indent=2) + "\n", encoding="utf-8")
shutil.rmtree(dest, ignore_errors=True)
staging.rename(dest)
except (KeyError, zipfile.BadZipFile) as exc:
shutil.rmtree(staging, ignore_errors=True)
raise DownloadError(f"libclang {version}: {exc}") from exc
except Exception:
shutil.rmtree(staging, ignore_errors=True)
raise
print(f"libclang {version}: готов, {dest / 'libclang.dll'}", flush=True)
return dest
def gpu_names():
"""Имена видеоадаптеров Windows. Сбой опроса — пустой список (это «нет DLSS», а не ошибка сборки)."""
if platform.system() != "Windows":
return []
flags = getattr(subprocess, "CREATE_NO_WINDOW", 0)
for cmd in (["powershell", "-NoProfile", "-Command", "(Get-CimInstance Win32_VideoController).Name"],
["wmic", "path", "win32_VideoController", "get", "name"]):
try:
out = subprocess.run(cmd, capture_output=True, text=True, timeout=30,
creationflags=flags, errors="replace")
except (OSError, ValueError, subprocess.SubprocessError):
continue
if out.returncode != 0:
continue
# У wmic первая строка — заголовок Name.
names = [line.strip() for line in out.stdout.splitlines()
if line.strip() and line.strip().lower() != "name"]
if names:
return names
return []
def rtx_gpu(names) -> bool:
"""NVIDIA RTX среди адаптеров: в имени есть и NVIDIA, и RTX."""
return any("nvidia" in name.lower() and "rtx" in name.lower() for name in names)
def valid_dlss_sdk(path) -> bool:
"""Каталоги, без которых dlss_wgpu не соберётся: include/nvsdk_ngx*.h и lib/Windows_x86_64/x64."""
return bool(path) and (path / "include").is_dir() and list((path / "include").glob("nvsdk_ngx*.h")) \
and (path / "lib" / "Windows_x86_64" / "x64").is_dir()
def dlss_sdk_path():
"""Корень уже установленного NVIDIA DLSS SDK (DLSS_SDK, ROOT/DLSS, Program Files) или None."""
candidates = []
if os.environ.get("DLSS_SDK"):
candidates.append(Path(os.environ["DLSS_SDK"]))
candidates += [ROOT / "DLSS", ROOT / "dlss-sdk"]
for env in ("ProgramFiles", "ProgramFiles(x86)"):
if os.environ.get(env):
candidates += sorted((Path(os.environ[env]) / "NVIDIA" / "DLSS").glob("*"), reverse=True)
for path in candidates:
if valid_dlss_sdk(path):
return path
return None
def _auto_install(install, label):
"""Автоскачивание не должно ломать сборку: любая ошибка — предупреждение и mods/TAAU."""
try:
return install()
except Exception as exc:
print(f"Внимание: {label} не скачался: {exc}", flush=True)
return None
def dlss_build_plan(system=None, gpus=None, sdk=None) -> dict:
"""Features сборки и окружение DLSS_SDK/VULKAN_SDK/LIBCLANG_PATH для Windows + NVIDIA RTX.
Возвращает {"features", "env", "sdk", "dll"}. Без явного SDK на Windows + RTX сам скачивает
DLSS SDK, заголовки Vulkan и libclang для bindgen в .horizon-cache. Явные
DLSS_SDK/VULKAN_SDK/LIBCLANG_PATH (или аргумент sdk) имеют приоритет и отключают автоскачивание
своего компонента; неполный явный путь — предупреждение и mods.
"""
plan = {"features": "mods", "env": {}, "sdk": None, "dll": None}
system = platform.system() if system is None else system
if system != "Windows":
return plan
names = gpu_names() if gpus is None else gpus
if not rtx_gpu(names):
return plan
env_sdk = os.environ.get("DLSS_SDK")
explicit_sdk = sdk is not None or bool(env_sdk)
if sdk is not None:
candidate = Path(sdk)
sdk_root = candidate if valid_dlss_sdk(candidate) else None
elif env_sdk:
candidate = Path(env_sdk)
sdk_root = candidate if valid_dlss_sdk(candidate) else None
else:
sdk_root = dlss_sdk_path() or cached_dlss_sdk()
if sdk_root is None:
sdk_root = _auto_install(install_dlss_sdk, "NVIDIA DLSS SDK")
env_vulkan = os.environ.get("VULKAN_SDK")
explicit_vulkan = bool(env_vulkan)
if env_vulkan:
vulkan_root = Path(env_vulkan) if vulkan_headers_ok(env_vulkan) else None
else:
vulkan_root = cached_vulkan_headers()
if vulkan_root is None:
vulkan_root = _auto_install(install_vulkan_headers, "Vulkan-заголовки")
# libclang нужен только bindgen'у из dlss_wgpu, поэтому качаем его лишь когда SDK и Vulkan уже есть.
env_libclang = os.environ.get("LIBCLANG_PATH")
explicit_libclang = bool(env_libclang)
clang_root = None
if sdk_root is not None and vulkan_root is not None:
if env_libclang:
clang_root = libclang_root(env_libclang)
else:
clang_root = system_libclang() or cached_libclang()
if clang_root is None:
clang_root = _auto_install(install_libclang, "libclang для bindgen")
missing = []
if sdk_root is None:
missing.append("NVIDIA DLSS SDK")
if vulkan_root is None:
missing.append("заголовки Vulkan")
if sdk_root is not None and vulkan_root is not None and clang_root is None:
missing.append("libclang для bindgen")
if missing:
print("Внимание: NVIDIA RTX найден, но DLSS-сборка пропущена — нет " + " и ".join(missing) + ".",
flush=True)
incomplete = []
if explicit_sdk and sdk_root is None:
incomplete.append("DLSS_SDK")
if explicit_vulkan and vulkan_root is None:
incomplete.append("VULKAN_SDK")
if explicit_libclang and clang_root is None and sdk_root is not None and vulkan_root is not None:
incomplete.append("LIBCLANG_PATH")
if incomplete:
print(f" {', '.join(incomplete)}: путь неполный. Убери переменную, и airdef.py скачает всё сам.",
flush=True)
else:
print(" Автоскачивание не удалось: проверь сеть/прокси и повтори сборку.", flush=True)
print(f" Вручную: DLSS SDK {DLSS_SDK_URL} (переменная DLSS_SDK), Vulkan SDK или только "
f"заголовки (VULKAN_SDK, {VULKAN_SDK_URL}); libclang — winget install LLVM.LLVM "
"(переменная LIBCLANG_PATH).", flush=True)
print(" Собираю --features mods: DLSS выключен, native TAAU остаётся.", flush=True)
return plan
plan.update(features="mods,dlss", sdk=sdk_root, dll=Path(sdk_root) / DLSS_RUNTIME,
env={"DLSS_SDK": str(sdk_root), "VULKAN_SDK": str(vulkan_root),
"LIBCLANG_PATH": str(clang_root)})
print(f"DLSS: NVIDIA RTX, SDK {sdk_root}, libclang {clang_root}; собираю --features mods,dlss",
flush=True)
print(" nvngx_dlss.dll из SDK кладу рядом с horizon-client.exe после сборки; DLSS включён по умолчанию — переключатель в настройках мода (N → DLSS), HORIZON_DLSS=1|0 переопределяет.", flush=True)
return plan
def dlss_build_features(system=None, gpus=None, sdk=None) -> str:
"""Строка features для cargo build: 'mods,dlss' только на Windows + RTX с полным SDK."""
return dlss_build_plan(system=system, gpus=gpus, sdk=sdk)["features"]
def built_client_candidates():
paths = []
if os.environ.get("AIRDEF_GAME"):
paths.append(Path(os.environ["AIRDEF_GAME"]))
paths += [FORK / "target" / "fast" / ("horizon-client" + EXE), ROOT / ("horizon-client" + EXE)]
return paths
def place_dlss_runtime(sdk_root):
"""Копирует свежий nvngx_dlss.dll из SDK рядом с собранным horizon-client.exe."""
dll = Path(sdk_root) / DLSS_RUNTIME
if not dll.is_file():
print(f"Внимание: в SDK {sdk_root} нет {DLSS_RUNTIME}; положи nvngx_dlss.dll рядом с клиентом вручную.",
flush=True)
return None
for exe in built_client_candidates():
if not exe.is_file():
continue
target = exe.with_name(dll.name)
try:
# Всегда свежая DLL: старый nvngx_dlss.dll рядом с клиентом не должен пережить пересборку.
shutil.copy2(dll, target)
print(f" nvngx_dlss.dll ({dll.stat().st_size / 1e6:.1f} МБ) рядом с {exe}", flush=True)
return target
except OSError as exc:
print(f"Внимание: не удалось положить {dll.name} рядом с {exe}: {exc}", flush=True)
print("Внимание: собранный horizon-client.exe не найден; nvngx_dlss.dll нужно положить рядом с ним вручную.",
flush=True)
return None
def game():
fork()
plan = dlss_build_plan()
env = dict(os.environ)
env.update(plan["env"])
run([cargo(), "build", "--profile", "fast", "-p", "horizon-client", "--features", plan["features"]],
cwd=FORK, env=env)
if plan["sdk"] is not None:
place_dlss_runtime(plan["sdk"])
def built_game() -> Path:
if os.environ.get("AIRDEF_GAME"):
return Path(os.environ["AIRDEF_GAME"])
for name in (FORK / "target" / "fast" / ("horizon-client" + EXE), ROOT / ("horizon-client" + EXE)):
if name.exists():
return name
sys.exit("Нет собранной игры: python3 tools/airdef.py game (или AIRDEF_GAME=путь к horizon-client)")
def packer_path() -> Path:
return ROOT / ".horizon-cache" / "packer" / engine_identity() / "bin" / ("cargo-horizon-mod" + EXE)
def mod():
fork()
tool = packer_path()
if not tool.exists():
run([cargo(), "install", "--locked", "--no-default-features", "--target-dir", FORK / "target", "--root", tool.parent.parent,
"--path", FORK / "crates" / "cargo-horizon-mod"])
# Invoke the pinned executable directly; PATH may contain an unrelated old packer.
build_env = dict(os.environ)
build_env["PATH"] = str(Path(cargo()).parent) + os.pathsep + build_env.get("PATH", "")
run([tool, "horizon-mod", "build"], cwd=ROOT / "airdef-mod", env=build_env)
artifact = hmod()
identity = {"airdef": subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=ROOT, text=True).strip(),
"engine": engine_identity(), "engine_pin": engine_commit(),
"wit_sha256": hashlib.sha256((FORK / "crates/horizon-mod-sdk/wit/horizon.wit").read_bytes()).hexdigest(),
"artifact_sha256": hashlib.sha256(artifact.read_bytes()).hexdigest(),
"airdef_dirty": bool(subprocess.check_output(["git", "status", "--porcelain", "--untracked-files=no"], cwd=ROOT)),
"airdef_diff_sha256": hashlib.sha256(subprocess.check_output(["git", "diff", "--binary", "HEAD"], cwd=ROOT)).hexdigest()}
artifact.with_name("build-identity.json").write_text(json.dumps(identity, indent=2) + "\n")
def hmod() -> Path:
for p in (ROOT / "airdef-mod" / "target" / "horizon-mod" / "airdef.hmod", ROOT / "airdef.hmod"):
if p.exists():
return p
sys.exit("Нет airdef.hmod: python3 tools/airdef.py mod")
def test_wasm():
"""The real component and host ABI, with the engine's normal fuel/memory limits."""
mod()
build_env = dict(os.environ)
build_env["PATH"] = str(Path(cargo()).parent) + os.pathsep + build_env.get("PATH", "")
# `full` is the packer's default feature; the lightweight release packer has no runtime.
run([cargo(), "run", "--locked", "--manifest-path", FORK / "Cargo.toml",
"-p", "cargo-horizon-mod", "--", "horizon-mod", "test", "--hmod", hmod()],
cwd=ROOT / "airdef-mod", env=build_env)
BUDGET_SCENARIO = "tests/budgets/wasm_flat_budget.toml"
BUDGET_ASSERTED_SHA256 = "eaee000d05aa1da232db5dfb225fa067e29bb554edcb0a90ddf1aad18a8aae29"
def fuel_measurements(output):
"""Read the pinned host's callback counters; never infer them from source caps."""
samples = []
for mod_id, callback, calls, maximum, budget, failures in re.findall(
r"(?m)^fuel (\S+) (\S+): calls=(\d+) max=(\d+) budget=(\d+) failures=(\d+)\s*$", output):
samples.append({"mod": mod_id, "callback": callback, "calls": int(calls),
"max_used": int(maximum), "budget": int(budget), "failures": int(failures)})
return samples
def test_budgets():
"""Run the opt-in heavy scenario and always write a machine-readable report."""
report_path = Path(os.environ.get("AIRDEF_BUDGET_REPORT") or
ROOT / ".horizon-cache" / "wasm-budget-report.json")
report = {
"schema": 1,
"command": "test-budgets",
"scenario": BUDGET_SCENARIO,
"scenario_render_world": None,
"status": "failed",
"exit_code": None,
"scenario_counts": {"scripts": 1, "steps": None, "raid_requests": None,
"raid_units_requested": None, "air_defense_units": None,
"layout_unit_limit": None, "frames": None, "ticks": None,
"accepted_raids_asserted": None, "snapshot_airborne_asserted": None,
"snapshot_tick": None, "peak_airborne_observed": None},
"runtime_limits": {"source": "horizon/crates/horizon-mods/src/runtime.rs",
"metering": "source_configured"},
"measured_fuel": {"available": False, "callbacks": [],
"scope": "guest callback fuel; excludes host CPU, memory and GPU time"},
}
def git(*args, text=True):
return subprocess.check_output(["git", *args], cwd=ROOT,
text=text, stderr=subprocess.DEVNULL)
try:
report["airdef"] = {
"sha": git("rev-parse", "HEAD").strip(),
"dirty": bool(git("status", "--porcelain", "--untracked-files=no").strip()),
"diff_sha256": hashlib.sha256(git("diff", "--binary", "HEAD", text=False)).hexdigest(),
}
report["engine"] = {"pin": engine_commit(), "identity": engine_identity()}
wit = FORK / "crates" / "horizon-mod-sdk" / "wit" / "horizon.wit"
report["api_level"] = fork_api()[0] if fork_api() else None
report["wit_sha256"] = hashlib.sha256(wit.read_bytes()).hexdigest() if wit.is_file() else None
runtime = (FORK / "crates" / "horizon-mods" / "src" / "runtime.rs").read_text()
layout = (ROOT / "airdef-mod" / "src" / "layout.rs").read_text()
limit = re.search(r"pub const MAX_UNITS: usize = (\d+);", layout)
report["scenario_counts"]["layout_unit_limit"] = int(limit.group(1)) if limit else None
memory = re.search(r"const MEMORY: usize = (\d+) << (\d+);", runtime)
report["runtime_limits"].update({
"memory_bytes": int(memory.group(1)) << int(memory.group(2)) if memory else None,
"fuel_per_call": {name.lower(): int(value) for name, value in
re.findall(r"const FUEL_(INIT|TICK|FRAME|EVENT): u64 = ([\d_]+);", runtime)
for value in [value.replace("_", "")]},
"wasmtime_component_model": bool(re.search(r"wasm_component_model\(true\)", runtime)),
"wasmtime_fuel_metering": bool(re.search(r"consume_fuel\(true\)", runtime)),
})
lock_text = (ROOT / "horizon" / "Cargo.lock").read_text()
wasmtime = re.search(r'\[\[package\]\]\s*name = "wasmtime"\s*version = "([^"]+)"', lock_text)
report["wasmtime_version"] = wasmtime.group(1) if wasmtime else None
fixture = ROOT / "airdef-mod" / BUDGET_SCENARIO
fixture_bytes = fixture.read_bytes()
fixture_text = fixture_bytes.decode("utf-8")
flat_heights = list(dict.fromkeys(re.findall(r"(?m)^render-ground-y\s*=\s*(-?\d+)\s*$", fixture_text)))
if flat_heights:
report["scenario_render_world"] = "flat at y=" + ",".join(flat_heights)
counts = report["scenario_counts"]
counts["steps"] = len(re.findall(r"(?m)^\[\[step\]\]$", fixture_text))
counts["air_defense_units"] = len(re.findall(r'(?m)^command = "airdef deploy [^"]+"', fixture_text))
requests = re.findall(r'(?m)^command = "airdef wave \S+ (\d+)(?: [^"]*)?"', fixture_text)
counts["raid_requests"] = len(requests)
counts["raid_units_requested"] = sum(map(int, requests))
for field in ("ticks", "frames"):
counts[field] = sum(map(int, re.findall(rf"(?m)^{field}\s*=\s*(\d+)\s*$", fixture_text)))
report["scenario_sha256"] = hashlib.sha256(fixture_bytes).hexdigest()
mod()
artifact = hmod()
report["artifact_sha256"] = hashlib.sha256(artifact.read_bytes()).hexdigest()
identity_path = artifact.with_name("build-identity.json")
identity = json.loads(identity_path.read_text())
identity_checks = {
"engine_pin": identity.get("engine_pin") == report["engine"]["pin"],
"engine_identity": identity.get("engine") == report["engine"]["identity"],
"airdef_sha": identity.get("airdef") == report["airdef"]["sha"],
"airdef_dirty": identity.get("airdef_dirty") == report["airdef"]["dirty"],
"airdef_diff_sha256": identity.get("airdef_diff_sha256") == report["airdef"]["diff_sha256"],
"artifact_sha256": identity.get("artifact_sha256") == report["artifact_sha256"],
"wit_sha256": identity.get("wit_sha256") == report["wit_sha256"],
}
report["build_identity"] = {"path": str(identity_path), "checks": identity_checks,
"matches": all(identity_checks.values())}
if not report["build_identity"]["matches"]:
raise RuntimeError("build identity is stale or does not match the tested artifact: " +
", ".join(k for k, ok in identity_checks.items() if not ok))
build_env = dict(os.environ)
build_env["PATH"] = str(Path(cargo()).parent) + os.pathsep + build_env.get("PATH", "")
with tempfile.TemporaryDirectory(prefix="airdef-wasm-budget-") as temp:
isolated = Path(temp)
(isolated / "tests").mkdir()
(isolated / "tests" / "wasm_budget.toml").write_bytes(fixture_bytes)
command = [cargo(), "run", "--locked", "--manifest-path", FORK / "Cargo.toml",
"-p", "cargo-horizon-mod", "--", "horizon-mod", "test", "--hmod", artifact,
"--fuel-profile", "budget"]
print("+", " ".join(str(c) for c in command), flush=True)
result = subprocess.run([str(c) for c in command], cwd=isolated, env=build_env,
text=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
print(result.stdout, end="", flush=True)
report["exit_code"] = result.returncode
report["status"] = "passed" if result.returncode == 0 else "failed"
report["output"] = result.stdout[-12000:]
samples = fuel_measurements(result.stdout)
report["measured_fuel"].update({"available": bool(samples), "callbacks": samples})
if result.returncode == 0 and not samples:
report["status"] = "failed"
raise RuntimeError("pinned runtime did not return requested callback fuel counters")
# These assertions belong to this exact fixture, not to arbitrary edited scripts.
# Two `airdef wave oreshnik` orders plus two Smart orders through the UI launch
# path (`airdef preset` + `airdef raid`, the wave screen's ПУСК handler, #122).
if result.returncode == 0 and report["scenario_sha256"] == BUDGET_ASSERTED_SHA256:
counts["accepted_raids_asserted"] = 4
counts["snapshot_airborne_asserted"] = 184
counts["snapshot_tick"] = 2102
except Exception as exc:
report["error"] = f"{type(exc).__name__}: {exc}"
except SystemExit as exc:
report["error"] = f"SystemExit: {exc.code}"
finally:
report_path.parent.mkdir(parents=True, exist_ok=True)
report_path.write_text(json.dumps(report, indent=2, sort_keys=True) + "\n")
print(f"Budget report: {report_path}", flush=True)
if report["status"] != "passed":
sys.exit(f"WASM budget scenario failed; see {report_path}")
def install():
home = game_home()
mods = home / "horizon-mods"
mods.mkdir(parents=True, exist_ok=True)
shutil.rmtree(mods / "airdef", ignore_errors=True) # первая версия мода была папкой
shutil.copy2(hmod(), mods / "airdef.hmod")
listing = home / "horizon-mods.txt"
lines = listing.read_text().splitlines() if listing.exists() else []
lines = [l for l in lines if not l.startswith("mod.airdef:")] + ["mod.airdef:true"]
listing.write_text("\n".join(lines) + "\n")
print(f"Мод установлен в {mods} и включён")
def resources() -> Path:
if os.environ.get("HORIZON_RESOURCES"):
return Path(os.environ["HORIZON_RESOURCES"])
found = sorted(glob.glob(str(data_dir() / "horizon-launcher" / "versions" / "*" / ".local" / "horizon-client" / "26.3")))
local = FORK / ".local" / "horizon-client" / "26.3"
if local.exists():
found.append(str(local))
if not found:
sys.exit("Не найдены ресурсы игры. Установи Horizon через лаунчер и запусти его один раз "
"(он подготовит ресурсы из твоего Minecraft 26.3), либо задай HORIZON_RESOURCES.")
return Path(found[-1])
def play(args):
exe = built_game().resolve()
home = game_home()
home.mkdir(parents=True, exist_ok=True)
# Игра хранит настройки, моды и миры в текущей папке.
run([exe, "--resources", resources(), *args], cwd=home)
def fork_api():
"""Новейший уровень API форка и его таблица функций (horizon-mods/src/api_level.rs); None без форка."""
try:
text = (FORK / "crates" / "horizon-mods" / "src" / "api_level.rs").read_text(encoding="utf-8")
except OSError:
return None
try:
level = int(re.search(r"pub const LEVEL: u32 = (\d+);", text).group(1))
table = text[text.index("pub const FUNCTIONS"):]
table = table[:table.index("];")]
except (AttributeError, ValueError):
return None
return level, [(name, int(lvl)) for name, lvl in re.findall(r'\("([a-z.\-]+)", (\d+)\)', table)]
def needed_level(wasm: bytes, table) -> tuple:
"""Уровень, который нужен модулю: самая новая функция, которую он импортирует (как api_level::needed).
В компоненте имя функции записано как 0x00, длина, UTF-8 имя; по этим байтам и ищем."""
need = (0, None)
for name, level in table:
part = name.split(".", 1)[1].encode()
if level > need[0] and b"\x00" + bytes([len(part)]) + part in wasm:
need = (level, name)
return need
def game_level():
"""Уровень, который игра записала в себя (метка horizon-mod-api-level:NNNN;); None, если игры нет.
Игра без метки считается уровня 0, как в api_level::read_mark."""
try:
exe = built_game()
except SystemExit:
return None
if not exe.exists():
return None
found = re.search(rb"horizon-mod-api-level:(\d{4});", exe.read_bytes())
return int(found.group(1)) if found else 0
def check():
"""Говорит прямо, совпадают ли форк, упаковщик, уровень API мода с игрой и ресурсы. Код 0 — да, 1 — нет."""
commit = engine_commit()
problems = []
def line(name, ok, text):
print(f"[{'ok' if ok else 'нет'}] {name}: {text}")
if not ok:
problems.append(name)
current = subprocess.run(["git", "rev-parse", "HEAD"], cwd=FORK, capture_output=True, text=True).stdout.strip() if (FORK / ".git").exists() else ""
fork_ok = current == commit
line("форк", fork_ok, f"gitlink {commit}, checkout {current or 'не инициализирован'}")
packer_ok = fork_ok and packer_path().exists()
line("упаковщик", packer_ok, "repo-local, соответствует engine identity" if packer_ok else
"нет упаковщика этого форка: python3 tools/airdef.py mod")
api = fork_api()
try:
mod_file = hmod()
except SystemExit:
mod_file = None
if api is None:
line("уровень API", False, "нет или не читается horizon/crates/horizon-mods/src/api_level.rs: python3 tools/airdef.py fork")
elif mod_file is None:
line("уровень API", False, "нет airdef.hmod: python3 tools/airdef.py mod")
else:
level, table = api
with zipfile.ZipFile(mod_file) as z:
wasm = z.read("mod.wasm") if "mod.wasm" in z.namelist() else b""
need, function = needed_level(wasm, table)
game = game_level()
text = f"мод нужен {need} ({function}), форк {level}, игра " + ("не собрана" if game is None else str(game))
if game is None:
line("уровень API", False, text + ": python3 tools/airdef.py game")
else:
# Сравнивается уровень, не код: одинаковый уровень не доказывает одинаковые патчи.
supported = need <= game and game == level
line("уровень API", supported, text if supported else
text + ": игра не поддерживает мод или собрана из другого форка")
try:
res = resources()
except SystemExit as e:
res = None
line("ресурсы", False, str(e.code))
if res is not None:
try:
preparer = (FORK / "crates" / "horizon-prepare" / "src" / "lib.rs").read_text(encoding="utf-8")
schema = int(re.search(r"pub const SCHEMA: i64 = (\d+);", preparer).group(1))
except (OSError, AttributeError):
schema = None
try:
manifest = json.loads((res / "horizon-resources.json").read_text(encoding="utf-8"))
except (OSError, ValueError):
manifest = {}
ok = schema is not None and manifest.get("schema") == schema and manifest.get("minecraft") == "26.3"
line("ресурсы", ok, f"{res}, схема {schema}, Minecraft 26.3" if ok else
f"{res}: схема {manifest.get('schema')}, Minecraft {manifest.get('minecraft')}; нужны схема {schema} и Minecraft 26.3")
if problems:
sys.exit("Не совпадает: " + ", ".join(problems) + ".")
print("Всё совпадает: форк, упаковщик, уровень API мода и ресурсы.")
def main():
if len(sys.argv) < 2:
sys.exit(__doc__)
cmd, rest = sys.argv[1], sys.argv[2:]
steps = {"fork": fork, "game": game, "mod": mod, "install": install, "check": check, "test-wasm": test_wasm, "test-budgets": test_budgets}
if cmd == "play":
play(rest)
elif cmd == "all":
for step in ("fork", "game", "mod", "install"):
steps[step]()
elif cmd in steps:
steps[cmd]()
else:
sys.exit(__doc__)
if __name__ == "__main__":
main()