Files
healer-man/scripts/runewaker-pipeline/build-native-collision-audit.ps1
T
2026-10-06 22:25:34 -04:00

69 lines
4.1 KiB
PowerShell

param(
[string]$RunewakerSourceRoot = $env:RUNEWAKER_SOURCE_ROOT,
[string]$PortableMsvcRoot = $env:MSVC_V142_ROOT,
[string]$WindowsSdkRoot = ${env:ProgramFiles(x86)} + '\Windows Kits\10'
)
$ErrorActionPreference = 'Stop'
$projectRoot = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..\..'))
if ([string]::IsNullOrWhiteSpace($RunewakerSourceRoot)) {
$RunewakerSourceRoot = [IO.Path]::GetFullPath((Join-Path $projectRoot '..\rom-pvt-server-backups\Runewaker\SourceCodeVS2019'))
}
if ([string]::IsNullOrWhiteSpace($PortableMsvcRoot)) {
$PortableMsvcRoot = Join-Path $env:USERPROFILE 'msvc-v142-portable\Contents\VC\Tools\MSVC'
}
if (-not (Test-Path -LiteralPath $RunewakerSourceRoot)) { throw "Runewaker source root not found: $RunewakerSourceRoot" }
if (-not (Test-Path -LiteralPath $PortableMsvcRoot)) { throw "Portable MSVC root not found: $PortableMsvcRoot" }
if (-not (Test-Path -LiteralPath $WindowsSdkRoot)) { throw "Windows SDK root not found: $WindowsSdkRoot" }
$msvcVersionRoot = Get-ChildItem -LiteralPath $PortableMsvcRoot -Directory |
Where-Object { Test-Path -LiteralPath (Join-Path $_.FullName 'bin\Hostx64\x64\cl.exe') } |
Sort-Object Name -Descending | Select-Object -First 1
$sdkVersionRoot = Get-ChildItem -LiteralPath (Join-Path $WindowsSdkRoot 'Include') -Directory |
Where-Object {
(Test-Path -LiteralPath (Join-Path $_.FullName 'um\Windows.h')) -and
(Test-Path -LiteralPath (Join-Path $WindowsSdkRoot ('Lib\' + $_.Name + '\um\x64\kernel32.lib')))
} | Sort-Object Name -Descending | Select-Object -First 1
if ($null -eq $msvcVersionRoot) { throw 'cl.exe was not found.' }
if ($null -eq $sdkVersionRoot) { throw 'No usable Windows SDK was found.' }
$msvcRoot = $msvcVersionRoot.FullName
$sdkVersion = $sdkVersionRoot.Name
$sdkIncludeRoot = Join-Path $WindowsSdkRoot ('Include\' + $sdkVersion)
$sdkLibRoot = Join-Path $WindowsSdkRoot ('Lib\' + $sdkVersion)
$compilerRoot = Join-Path $msvcRoot 'bin\Hostx64\x64'
$env:Path = $compilerRoot + ';' + (Join-Path $WindowsSdkRoot ('bin\' + $sdkVersion + '\x64')) + ';' + $env:Path
$env:Include = @((Join-Path $msvcRoot 'include'), (Join-Path $sdkIncludeRoot 'ucrt'), (Join-Path $sdkIncludeRoot 'shared'), (Join-Path $sdkIncludeRoot 'um'), (Join-Path $sdkIncludeRoot 'winrt')) -join ';'
$env:Lib = @((Join-Path $msvcRoot 'lib\x64'), (Join-Path $sdkLibRoot 'ucrt\x64'), (Join-Path $sdkLibRoot 'um\x64')) -join ';'
$outRoot = Join-Path $PSScriptRoot 'native\bin'
New-Item -ItemType Directory -Path $outRoot -Force | Out-Null
$librariesRoot = Join-Path $RunewakerSourceRoot 'Libraries'
$engineRoot = Join-Path $librariesRoot 'Rune Engine'
$compileArguments = @(
'/nologo', '/EHsc', '/O2', '/MD', '/std:c++17', '/DNDEBUG', '/D_LIB', '/DCLOSE_DEBUG', '/DWINDOWS_IGNORE_PACKING_MISMATCH',
'/I', $librariesRoot,
'/I', (Join-Path $RunewakerSourceRoot 'SDK'),
'/I', (Join-Path $RunewakerSourceRoot 'SDK\dx9'),
'/I', (Join-Path $RunewakerSourceRoot 'SDK\fmod'),
'/I', (Join-Path $RunewakerSourceRoot 'SDK\lua'),
'/I', (Join-Path $engineRoot 'Tools'),
'/I', (Join-Path $librariesRoot 'Tools\tools'),
'/I', (Join-Path $librariesRoot 'Tools\tools\lua'),
'/I', (Join-Path $librariesRoot 'Tools\tools\luabind'),
('/Fo' + (Join-Path $outRoot 'native-collision-audit.obj')),
('/Fe' + (Join-Path $outRoot 'native-collision-audit.exe')),
(Join-Path $PSScriptRoot 'native\native-collision-audit.cpp'),
'/link', '/LTCG',
('/LIBPATH:' + (Join-Path $RunewakerSourceRoot '_bin\Rune Engine\x64\Release')),
('/LIBPATH:' + (Join-Path $RunewakerSourceRoot '_bin\Rune Engine NULL\x64\Release')),
('/LIBPATH:' + (Join-Path $RunewakerSourceRoot '_bin\ToolsLib\Release')),
('/LIBPATH:' + (Join-Path $RunewakerSourceRoot 'SDK\lib')),
('/LIBPATH:' + (Join-Path $engineRoot 'Tools\granny\lib')),
'Rune.lib', 'Rune_NULL.lib', 'ToolsLib.lib', 'kernel32.lib', 'user32.lib', 'advapi32.lib', 'shell32.lib', 'ole32.lib', 'oleaut32.lib', 'uuid.lib', 'winmm.lib', 'ws2_32.lib'
)
& (Join-Path $compilerRoot 'cl.exe') $compileArguments
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
Write-Host "Built $(Join-Path $outRoot 'native-collision-audit.exe')"