[CmdletBinding()] param( [string]$HipRoot = $env:HIP_PATH, [string]$ZludaRoot, [string]$ToolchainRoot, [string]$BuildDirectory, [string]$InstallDirectory ) $ErrorActionPreference = 'Stop' $repo = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '../..')) if (!$HipRoot) { $HipRoot = 'C:\Program Files\AMD\ROCm\7.2' } if (!$BuildDirectory) { $BuildDirectory = Join-Path $repo 'build/windows-rdna4' } if (!$InstallDirectory) { $InstallDirectory = Join-Path $repo 'dist/windows-rdna4-diagnostics' } $HipRoot = [IO.Path]::GetFullPath($HipRoot).TrimEnd('\', '/') $BuildDirectory = [IO.Path]::GetFullPath($BuildDirectory).TrimEnd('\', '/') $InstallDirectory = [IO.Path]::GetFullPath($InstallDirectory).TrimEnd('\', '/') if (!$ZludaRoot -and (Test-Path (Join-Path $repo '.tools/zluda/zluda/nvcuda.dll'))) { $ZludaRoot = Join-Path $repo '.tools/zluda/zluda' } if (!$ToolchainRoot -and (Test-Path (Join-Path $repo '.tools/llvm-mingw-20260922-ucrt-x86_64'))) { $ToolchainRoot = Join-Path $repo '.tools/llvm-mingw-20260922-ucrt-x86_64' } $cmakeCommand = Get-Command cmake -ErrorAction SilentlyContinue $cmake = if ($cmakeCommand) { $cmakeCommand.Source } else { Join-Path $repo '.tools/python/cmake/data/bin/cmake.exe' } $ninjaCommand = Get-Command ninja -ErrorAction SilentlyContinue $ninja = if ($ninjaCommand) { $ninjaCommand.Source } else { Join-Path $repo '.tools/python/ninja/data/bin/ninja.exe' } if (!(Test-Path $ninja)) { $ninja = Join-Path $repo '.tools/python/bin/ninja.exe' } if (!(Test-Path $cmake) -or !(Test-Path $ninja)) { throw 'CMake >=3.24 and Ninja required. See docs/windows-rdna4-port.md for local tool setup.' } New-Item -ItemType Directory -Force $BuildDirectory | Out-Null $originalPath = $env:PATH try { $configure = @('--fresh', '-S', $repo, '-B', $BuildDirectory, '-G', 'Ninja', '-DCMAKE_BUILD_TYPE=RelWithDebInfo', "-DCMAKE_MAKE_PROGRAM=$ninja", "-DD4R_HIP_ROOT=$HipRoot", "-DCMAKE_INSTALL_PREFIX=$InstallDirectory") if ($ToolchainRoot) { $compiler = Join-Path $ToolchainRoot 'bin/x86_64-w64-mingw32-clang++.exe' if (!(Test-Path $compiler)) { throw "Compiler missing: $compiler" } $env:PATH = "$(Join-Path $ToolchainRoot 'bin');$originalPath" $configure += "-DCMAKE_CXX_COMPILER=$compiler" } if ($ZludaRoot) { $configure += "-DD4R_ZLUDA_ROOT=$ZludaRoot" } $ErrorActionPreference = 'Continue' & $cmake @configure 2>&1 | Tee-Object (Join-Path $BuildDirectory 'configure.log') $ErrorActionPreference = 'Stop' if ($LASTEXITCODE) { throw "CMake configure exit=$LASTEXITCODE" } $ErrorActionPreference = 'Continue' & $cmake --build $BuildDirectory --parallel 4 2>&1 | Tee-Object (Join-Path $BuildDirectory 'build.log') $ErrorActionPreference = 'Stop' if ($LASTEXITCODE) { throw "Build exit=$LASTEXITCODE" } $ErrorActionPreference = 'Continue' & $cmake --install $BuildDirectory 2>&1 | Tee-Object (Join-Path $BuildDirectory 'install.log') $ErrorActionPreference = 'Stop' if ($LASTEXITCODE) { throw "Install exit=$LASTEXITCODE" } Write-Host "Built diagnostics: $InstallDirectory" } finally { $env:PATH = $originalPath }