mirror of
https://github.com/Cesarus85/ringfall-mjolnir-vr.git
synced 2026-10-23 12:00:30 +02:00
86 lines
3.0 KiB
Python
86 lines
3.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Builds one native port in one configuration, as the GitHub workflow does
|
|
(.github/workflows/build.yml), and collects what it built into dist/:
|
|
|
|
python tools/ci_build.py linux debug
|
|
python tools/ci_build.py android release
|
|
|
|
Builds are portable (any x86-64 processor), so they run on other
|
|
computers. Debug builds skip link-time and profile-guided optimisation,
|
|
which only make the build slower; release builds use both, as a local
|
|
release build does (profile-guided optimisation needs clang 22 or later,
|
|
and is skipped with an older one). CI_COMPILER_LAUNCHER (ccache, say) is
|
|
passed on as --compiler-launcher.
|
|
"""
|
|
|
|
import argparse
|
|
import os
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
|
|
# what each port's build leaves, and what goes into dist/
|
|
OUTPUTS = {
|
|
"linux": ["build/linux/halo"],
|
|
"windows": ["build/windows/halo.exe", "build/windows/SDL3.dll"],
|
|
"android": [], # the APK, below
|
|
}
|
|
APKS = {
|
|
"debug": "port/android/app/build/outputs/apk/debug/app-debug.apk",
|
|
"release": "port/android/app/build/outputs/apk/release/app-release.apk",
|
|
}
|
|
|
|
|
|
def run(command, cwd=ROOT):
|
|
print("+", " ".join(str(part) for part in command), flush=True)
|
|
subprocess.run([str(part) for part in command], cwd=cwd, check=True)
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
|
parser.add_argument("platform", choices=sorted(OUTPUTS))
|
|
parser.add_argument("config", choices=["debug", "release"])
|
|
args = parser.parse_args()
|
|
|
|
configure = [sys.executable, "configure.py", "--portable"]
|
|
if args.config == "release":
|
|
configure.append("--release")
|
|
else:
|
|
configure += ["--lto=off", "--pgo=off"]
|
|
launcher = os.environ.get("CI_COMPILER_LAUNCHER")
|
|
if launcher:
|
|
configure += ["--compiler-launcher", launcher]
|
|
run(configure)
|
|
|
|
if args.platform == "android":
|
|
# the native part, then the app around it (Gradle's variant of the
|
|
# same name: release is signed with the debug key, not debuggable)
|
|
run(["ninja", "android"])
|
|
gradlew = "gradlew.bat" if os.name == "nt" else "./gradlew"
|
|
run([gradlew, "--console=plain", "-q", f"assemble{args.config.capitalize()}"], cwd=ROOT / "port/android")
|
|
outputs = [APKS[args.config]]
|
|
else:
|
|
run(["ninja", args.platform])
|
|
outputs = OUTPUTS[args.platform]
|
|
|
|
dist = ROOT / "dist" / f"halo-{args.platform}-{args.config}"
|
|
if dist.exists():
|
|
shutil.rmtree(dist)
|
|
dist.mkdir(parents=True)
|
|
for output in outputs:
|
|
shutil.copy2(ROOT / output, dist)
|
|
print(f"{output} -> {dist.relative_to(ROOT)}", flush=True)
|
|
if args.platform != "android":
|
|
# the desktop builds' disc image reader (port/linux/src/xiso.c)
|
|
# follows extract-xiso, whose license asks binaries to carry its
|
|
# notice
|
|
shutil.copy2(ROOT / "port/third_party/extract-xiso/LICENSE.TXT", dist / "extract-xiso-LICENSE.txt")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|