Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ skips the build on Windows.
On Linux, run `<out>/gta6rt.sh --dry-run` to inspect the packaged title's imports, then
`<out>/gta6rt.sh --init` to check TLS callbacks and DLL initialization. Use `<out>/gta6rt.sh --run` for startup.
These commands use the package in `game_path.txt`, the port's `overlay` for writes, and Vulkan by default.
To use the packaged image with extra runtime options, add `--packaged` before the mode. For example,
run `<out>/gta6rt.sh --packaged --run --trace "Z:$PWD/startup.jsonl"` to record startup in your current directory.

When the Vulkan backend is selected with `LEONIDA_D3D12=vulkan`, the packaged runtime finds the translated shaders
in `<work>/shaders/spirv` using `shader_path.txt` beside `gta6rt.exe`. Set `LEONIDA_SHADERS` to use another directory.
Expand Down
26 changes: 22 additions & 4 deletions make_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -2209,9 +2209,27 @@ def wine_launcher(out: str, work: str, image: str) -> str:
"""
return f"""#!/bin/sh
# Starts the Windows build of the loader with Wine. WINE picks another one, e.g. a Proton build's bin/wine.
here=$(dirname "$(readlink -f "$0")")
if [ "$#" -eq 1 ] && {{ [ "$1" = --dry-run ] || [ "$1" = --init ] || [ "$1" = --run ]; }}; then
game=$(cat "$here/game_path.txt" && printf .) || exit 1
launcher=$(readlink -f "$0") || {{
printf 'Could not resolve runtime launcher %s\\n' "$0" >&2
exit 1
}}
here=$(dirname "$launcher") || exit 1
use_package=
if [ "${{1-}}" = --packaged ]; then
shift
use_package=1
elif [ "$#" -eq 1 ]; then
case "$1" in --dry-run|--init|--run) use_package=1 ;; esac
fi
if [ "$use_package" ]; then
case "${{1-}}" in
--dry-run|--init|--run) mode=$1; shift ;;
*) printf 'Use --packaged with --dry-run, --init or --run.\\n' >&2; exit 2 ;;
esac
if ! game=$(cat "$here/game_path.txt" 2>/dev/null && printf .) || [ "$game" = . ]; then
printf 'Missing package path in %s/game_path.txt\\n' "$here" >&2
exit 1
fi
cd "${{game%.}}" || exit 1
image={shlex.quote(image)}
if [ ! -f "./$image" ]; then
Expand All @@ -2220,7 +2238,7 @@ def wine_launcher(out: str, work: str, image: str) -> str:
fi
# Wine maps the Unix filesystem root to Z:. The game reads from its package and writes to the port's overlay.
{moved_catalog} export LEONIDA_D3D12="${{LEONIDA_D3D12:-vulkan}}"
set -- "$1" "./$image" --overlay "Z:$here/overlay"
set -- "$mode" "./$image" --overlay "Z:$here/overlay" "$@"
fi
exec "${{WINE:-wine}}" "$here/gta6rt.exe" "$@"
"""
Expand Down
11 changes: 9 additions & 2 deletions scripts/build_runtime.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ function Invoke-ToolProbe([string]$Exe, [string[]]$ProbeArgs) {
}

function Find-BuildTool([string]$Preferred, [string]$CommandName, [scriptblock]$Validate) {
if ($Preferred -and (Test-Path $Preferred)) { return $Preferred }
if ($Preferred -and (Test-Path -LiteralPath $Preferred -PathType Leaf)) { return $Preferred }
foreach ($cmd in @(Get-Command $CommandName -CommandType Application -All -ErrorAction SilentlyContinue)) {
if ($cmd.Source -and ($cmd.Source -match "\.(exe|cmd|bat)$") -and (Test-Path $cmd.Source) -and (& $Validate $cmd.Source)) {
if ($cmd.Source -and ($cmd.Source -match "\.(exe|cmd|bat)$") -and
(Test-Path -LiteralPath $cmd.Source -PathType Leaf) -and (& $Validate $cmd.Source)) {
return $cmd.Source
}
}
Expand Down Expand Up @@ -169,4 +170,10 @@ while (-not $p.HasExited) {
Emit-NewLogLines -Offset ([ref]$outOff) -Path $stdoutLog
Emit-NewLogLines -Offset ([ref]$errOff) -Path $stderrLog
if ($p.ExitCode -ne 0) { throw "build failed ($($p.ExitCode))" }
foreach ($artifact in @("gta6rt.exe", "gta6rt_tls_host.dll")) {
$built = Join-Path $out $artifact
if (-not (Test-Path -LiteralPath $built -PathType Leaf)) {
throw "The runtime build did not produce $built."
}
}
Write-Output "built $out\gta6rt.exe"
18 changes: 17 additions & 1 deletion tests/test_build_runtime_cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ class Recorder {
for (int i = 0; i + 1 < args.Length; ++i)
if (args[i] == "-S" && !Directory.Exists(args[i + 1])) return 9;
}
return Environment.GetEnvironmentVariable("LEONIDA_CMAKE_FAIL") == stage ? 7 : 0;
string fail = Environment.GetEnvironmentVariable("LEONIDA_CMAKE_FAIL");
if (fail == stage) return 7;
if (build) {
File.WriteAllText(Path.Combine(args[1], "gta6rt.exe"), "synthetic runtime");
if (fail != "missing-tls")
File.WriteAllText(Path.Combine(args[1], "gta6rt_tls_host.dll"), "synthetic TLS host");
}
return 0;
}
}
'''
Expand Down Expand Up @@ -113,6 +120,15 @@ def test_native_and_batch_cmake_paths_and_exit_codes(self):
self.assertEqual(built.read_text(encoding="utf-8-sig").splitlines(),
["--build", str(out), "-j", "3"])

def test_build_without_the_tls_host_is_reported_as_failed(self):
with tempfile.TemporaryDirectory(dir=self.base) as tmp:
result, _, out, _ = self.run_build(Path(tmp), ".exe", "missing-tls")
self.assertTrue((out / "gta6rt.exe").is_file())
self.assertEqual(result.returncode, 1, (result.stdout + result.stderr).decode(errors="replace"))
self.assertIn(b"The runtime build did not produce", result.stderr)
self.assertIn(b"gta6rt_tls_host.dll", result.stderr)
self.assertNotIn(b"built ", result.stdout)


if __name__ == "__main__":
unittest.main()
6 changes: 3 additions & 3 deletions tests/test_build_runtime_fallback.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ def run_probe(vs_dir: Path, path_dirs: list[Path]) -> tuple[str, str]:
root = Path(tmp)
vs_empty = root / "vs_empty"
msys_dir = root / "msys_bin"
native_cmake_dir = root / "native_cmake_bin"
native_ninja_dir = root / "native_ninja_bin"
native_cmake_dir = root / "native [cmake] bin"
native_ninja_dir = root / "native [ninja] bin"
for d in (vs_empty, msys_dir, native_cmake_dir, native_ninja_dir):
d.mkdir()

Expand Down Expand Up @@ -194,7 +194,7 @@ def run_probe(vs_dir: Path, path_dirs: list[Path]) -> tuple[str, str]:
self.assertEqual(ninja, "")

# 4) VS bundled CMake + Ninja present -> must prefer VS over PATH.
vs_full = root / "vs_full"
vs_full = root / "vs [full]"
vs_cmake = vs_full / "Common7" / "IDE" / "CommonExtensions" / "Microsoft" / "CMake" / "CMake" / "bin" / "cmake.exe"
vs_ninja = vs_full / "Common7" / "IDE" / "CommonExtensions" / "Microsoft" / "CMake" / "Ninja" / "ninja.exe"
vs_cmake.parent.mkdir(parents=True)
Expand Down
24 changes: 24 additions & 0 deletions tests/test_make_game_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,20 @@ def test_wine_first_boot_uses_the_packaged_game_and_shader_paths(self):
env = dict(os.environ, WINE=sys.executable)
env.pop("LEONIDA_D3D12", None)
env.pop("LEONIDA_SHADERS", None)
path_file = os.path.join(self.out, "game_path.txt")
with open(path_file, "rb") as f:
path_bytes = f.read()
with open(os.path.join(self.root, image), "wb"), open(path_file, "wb"):
pass
empty_path = subprocess.run([launcher, "--run"], cwd=self.root, env=env, capture_output=True, text=True)
self.assertEqual(empty_path.returncode, 1)
self.assertIn("Missing package path", empty_path.stderr)
with open(path_file, "wb") as f:
f.write(path_bytes)
unresolved = subprocess.run([launcher, "--run", "other.exe"], cwd=self.root,
env=dict(env, PATH=self.root), capture_output=True, text=True)
self.assertEqual(unresolved.returncode, 1)
self.assertIn("Could not resolve runtime launcher", unresolved.stderr)
missing = subprocess.run([launcher, "--run"], cwd=self.root, env=env, capture_output=True, text=True)
self.assertNotEqual(missing.returncode, 0)
self.assertIn(image, missing.stderr)
Expand All @@ -271,6 +285,16 @@ def test_wine_first_boot_uses_the_packaged_game_and_shader_paths(self):
self.assertEqual(json.loads(result)[2:], ["D:/custom", "trace"])
result = subprocess.check_output([launcher, "--run", "other.exe", "--", "two words"], cwd=self.root, env=env)
self.assertEqual(json.loads(result)[:2], [self.root, ["--run", "other.exe", "--", "two words"]])
result = subprocess.check_output(
[launcher, "--packaged", "--run", "--trace", "Z:/trace file.jsonl", "--", "two words"],
cwd=self.root, env=env)
self.assertEqual(json.loads(result)[:2], [
self.game, ["--run", "./" + image, "--overlay", "Z:" + self.out + "/overlay",
"--trace", "Z:/trace file.jsonl", "--", "two words"],
])
invalid = subprocess.run([launcher, "--packaged"], cwd=self.root, env=env, capture_output=True, text=True)
self.assertEqual(invalid.returncode, 2)
self.assertIn("Use --packaged", invalid.stderr)

work = os.path.join(self.out, "Shader cache '$HOME'")
make_game.runtime(self.game, self.out, {"expected_exe": image}, self.build, work=work)
Expand Down