upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorWasler <artemgulenko824@gmail.com>2026-11-23 00:04:40 +0200
committerWasler <artemgulenko824@gmail.com>2026-11-23 00:04:40 +0200
commit35616ce677e2acef2f18da4fbe8bedcda66e3325 (patch)
tree7a1e7f2ef6560d5356b91780e26078d21a842ace /scripts
parent4c52ce27a6cf4af2bbf07a343ede39c5f1572b8d (diff)
build_runtime.ps1: fall back to native cmake + ninja on PATH
# Conflicts: # scripts/build_runtime.ps1 # tests/test_build_runtime_fallback.py
Diffstat (limited to 'scripts')
-rw-r--r--scripts/build_runtime.ps149
1 files changed, 41 insertions, 8 deletions
diff --git a/scripts/build_runtime.ps1 b/scripts/build_runtime.ps1
index 46dc10291..0924def69 100644
--- a/scripts/build_runtime.ps1
+++ b/scripts/build_runtime.ps1
@@ -1,5 +1,6 @@
1# Builds runtime\build\gta6rt.exe with MSVC at BelowNormal priority, on half the cores by default. 1# Builds runtime\build\gta6rt.exe with MSVC at BelowNormal priority, on half the cores by default.
2# Uses VS's CMake + Ninja when the "C++ CMake tools" component is installed, otherwise calls cl.exe directly. 2# Uses VS's CMake + Ninja when the "C++ CMake tools" component is installed (or native Windows cmake + ninja on PATH),
3# otherwise calls cl.exe directly.
3# The GameInput controller shim (SDL3, docs/gameinput.md) is built only on the CMake path: with an installed SDL3, or 4# The GameInput controller shim (SDL3, docs/gameinput.md) is built only on the CMake path: with an installed SDL3, or
4# with -FetchSdl3, which lets CMake download the pinned SDL3 release. The cl.exe fallback never builds it. 5# with -FetchSdl3, which lets CMake download the pinned SDL3 release. The cl.exe fallback never builds it.
5param( 6param(
@@ -9,6 +10,30 @@ param(
9) 10)
10$ErrorActionPreference = "Stop" 11$ErrorActionPreference = "Stop"
11 12
13function Invoke-ToolProbe([string]$Exe, [string[]]$ProbeArgs) {
14 $prev = $ErrorActionPreference
15 $ErrorActionPreference = "Continue"
16 try {
17 $global:LASTEXITCODE = 0
18 $text = (& $Exe @ProbeArgs 2>$null) -join "`n"
19 if ($LASTEXITCODE -eq 0) { return $text }
20 } catch {
21 } finally {
22 $ErrorActionPreference = $prev
23 }
24 return $null
25}
26
27function Find-BuildTool([string]$Preferred, [string]$CommandName, [scriptblock]$Validate) {
28 if ($Preferred -and (Test-Path $Preferred)) { return $Preferred }
29 foreach ($cmd in @(Get-Command $CommandName -CommandType Application -All -ErrorAction SilentlyContinue)) {
30 if ($cmd.Source -and ($cmd.Source -match "\.(exe|cmd|bat)$") -and (Test-Path $cmd.Source) -and (& $Validate $cmd.Source)) {
31 return $cmd.Source
32 }
33 }
34 return ""
35}
36
12$root = Split-Path $PSScriptRoot -Parent 37$root = Split-Path $PSScriptRoot -Parent
13$installer = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer" 38$installer = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer"
14$vs = & "$installer\vswhere.exe" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath 39$vs = & "$installer\vswhere.exe" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath
@@ -20,22 +45,30 @@ $out = Join-Path $src "build"
20New-Item -ItemType Directory -Force $out | Out-Null 45New-Item -ItemType Directory -Force $out | Out-Null
21 46
22$cmakeDir = Join-Path $vs "Common7\IDE\CommonExtensions\Microsoft\CMake" 47$cmakeDir = Join-Path $vs "Common7\IDE\CommonExtensions\Microsoft\CMake"
23$cmake = Join-Path $cmakeDir "CMake\bin\cmake.exe" 48# Skip MSYS/devkitPro cmake on PATH (docs/design.md): native Windows builds advertise Visual Studio + Ninja generators.
24$ninja = Join-Path $cmakeDir "Ninja\ninja.exe" 49$cmake = Find-BuildTool (Join-Path $cmakeDir "CMake\bin\cmake.exe") "cmake" {
50 param($p)
51 $help = Invoke-ToolProbe $p @("--help")
52 ($null -ne $help) -and ($help -match "Visual Studio") -and ($help -match "\bNinja\b")
53}
54$ninja = Find-BuildTool (Join-Path $cmakeDir "Ninja\ninja.exe") "ninja" {
55 param($p)
56 $null -ne (Invoke-ToolProbe $p @("--version"))
57}
25$cfg = if ($Debug) { "Debug" } else { "RelWithDebInfo" } 58$cfg = if ($Debug) { "Debug" } else { "RelWithDebInfo" }
26$sdl = if ($FetchSdl3) { "-DLEONIDA_SDL3_FETCH=ON" } else { "" } 59$sdl = if ($FetchSdl3) { "-DLEONIDA_SDL3_FETCH=ON" } else { "" }
27# With VULKAN_SDK set, a configure that still finds no Vulkan headers fails instead of dropping the Vulkan D3D12 device. 60# With VULKAN_SDK set, a configure that still finds no Vulkan headers fails instead of dropping the Vulkan D3D12 device.
28$vk = if ($env:VULKAN_SDK) { "-DLEONIDA_REQUIRE_VULKAN=ON" } else { "" } 61$vk = if ($env:VULKAN_SDK) { "-DLEONIDA_REQUIRE_VULKAN=ON" } else { "" }
29 62
30if ((Test-Path $cmake) -and (Test-Path $ninja)) { 63if ($cmake -and $ninja) {
31 $body = @" 64 $body = @"
32"$cmake" -S "$src" -B "$out" -G Ninja "-DCMAKE_MAKE_PROGRAM=$ninja" -DCMAKE_BUILD_TYPE=$cfg $sdl $vk || exit /b 1 65call "$cmake" -S "$src" -B "$out" -G Ninja "-DCMAKE_MAKE_PROGRAM=$ninja" -DCMAKE_BUILD_TYPE=$cfg $sdl $vk || exit /b 1
33"$cmake" --build "$out" -j $jobs || exit /b 1 66call "$cmake" --build "$out" -j $jobs || exit /b 1
34"@ 67"@
35} else { 68} else {
36 # Keep this list in step with runtime\CMakeLists.txt. Optional parts that need a dependency are left out here: 69 # Keep this list in step with runtime\CMakeLists.txt. Optional parts that need a dependency are left out here:
37 # the GameInput shim (SDL3), so controllers go through the host's GameInput.dll, if any, as without the shim. 70 # the GameInput shim (SDL3), so controllers go through the host's GameInput.dll, if any, as without the shim.
38 Write-Warning "VS C++ CMake tools not found: building with cl.exe directly, without the GameInput shim (SDL3). Install the CMake tools component to get it." 71 Write-Warning "CMake and Ninja weren't found (neither VS C++ CMake tools nor native PATH tools): building with cl.exe directly, without the GameInput shim (SDL3). Install CMake + Ninja or VS's CMake tools component to get it."
39 $xtaskqueueDir = Join-Path $root "third_party\xtaskqueue" 72 $xtaskqueueDir = Join-Path $root "third_party\xtaskqueue"
40 $xtaskqueueFiles = "Source\Task\TaskQueue.cpp", "Source\Task\AsyncLib.cpp", "Source\Task\ThreadPool_win32.cpp", "Source\Task\WaitTimer_win32.cpp" | ForEach-Object { "`"$xtaskqueueDir\$_`"" } 73 $xtaskqueueFiles = "Source\Task\TaskQueue.cpp", "Source\Task\AsyncLib.cpp", "Source\Task\ThreadPool_win32.cpp", "Source\Task\WaitTimer_win32.cpp" | ForEach-Object { "`"$xtaskqueueDir\$_`"" }
41 $files = "src\main.cpp", "src\pe_loader.cpp", "shims\registry.cpp", "shims\file_system.cpp", "shims\xmem.cpp", "shims\d3d12_xs.cpp", "shims\d3d12_xs_device.cpp", "shims\d3d12_xs_rootsig.cpp", "shims\xgameruntime.cpp", "shims\winhttp_offline.cpp", "shims\library_loader.cpp", "shims\process.cpp" | ForEach-Object { "`"$src\$_`"" } 74 $files = "src\main.cpp", "src\pe_loader.cpp", "shims\registry.cpp", "shims\file_system.cpp", "shims\xmem.cpp", "shims\d3d12_xs.cpp", "shims\d3d12_xs_device.cpp", "shims\d3d12_xs_rootsig.cpp", "shims\xgameruntime.cpp", "shims\winhttp_offline.cpp", "shims\library_loader.cpp", "shims\process.cpp" | ForEach-Object { "`"$src\$_`"" }