# SPDX-FileCopyrightText: 2026 Matvey Shcherbinin # SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL # Build KOutNet on Windows with MSVC and KDE Craft dependencies. param( [switch]$Configure, [switch]$Build, [switch]$Test, [switch]$CheckArp, [switch]$CheckAcl, [switch]$All ) $ErrorActionPreference = "Stop" $buildDir = "$PSScriptRoot\build" function Write-Step { param([string]$Message) Write-Host "`n=== $Message ===" -ForegroundColor Cyan } function Test-BuildTools { Write-Step "Checking build tools" $tools = @{ "cmake" = "CMake not found. Install from https://cmake.org/download/" "ninja" = "Ninja not found. Install through KDE Craft or https://ninja-build.org/" } foreach ($tool in $tools.Keys) { $path = (Get-Command $tool -ErrorAction SilentlyContinue) if (-not $path) { Write-Host "ERROR: $($tools[$tool])" -ForegroundColor Red return $false } else { Write-Host "OK: $tool found at $($path.Source)" -ForegroundColor Green } } # Check the compiler. $cl = (Get-Command cl -ErrorAction SilentlyContinue) if (-not $cl) { Write-Host "MSVC compiler not found in PATH" -ForegroundColor Yellow Write-Host "Run this script from a Visual Studio developer shell" -ForegroundColor Yellow return $false } else { Write-Host "OK: MSVC found" -ForegroundColor Green } return $true } function Invoke-Configure { Write-Step "Configuring CMake" if (-not (Test-BuildTools)) { Write-Host "`nInstall the missing tools and retry." -ForegroundColor Red exit 1 } if (Test-Path $buildDir) { Write-Host "Removing the old build directory..." Remove-Item -Recurse -Force $buildDir } New-Item -ItemType Directory -Force -Path $buildDir | Out-Null Write-Host "Running cmake..." cmake -B $buildDir -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo if ($LASTEXITCODE -ne 0) { Write-Host "`nConfiguration failed. Check these dependencies:" -ForegroundColor Red Write-Host "- Qt 6.4+" -ForegroundColor Yellow Write-Host "- KDE Frameworks 6.8+" -ForegroundColor Yellow Write-Host "- libQuotient 0.9+" -ForegroundColor Yellow Write-Host "- libsodium 1.0.18+" -ForegroundColor Yellow Write-Host "`nInstall with KDE Craft: https://community.kde.org/Craft" -ForegroundColor Yellow exit 1 } Write-Host "Configuration complete." -ForegroundColor Green } function Invoke-Build { Write-Step "Building the project" if (-not (Test-Path "$buildDir\build.ninja")) { Write-Host "Configure first: .\build-windows.ps1 -Configure" -ForegroundColor Red exit 1 } Write-Host "Running ninja..." cmake --build $buildDir --parallel if ($LASTEXITCODE -ne 0) { Write-Host "`nBuild failed. See the errors above." -ForegroundColor Red exit 1 } Write-Host "Build complete." -ForegroundColor Green Write-Host "Executable: $buildDir\bin\KOutNet.exe" -ForegroundColor Cyan } function Invoke-Tests { Write-Step "Running tests" if (-not (Test-Path "$buildDir\bin")) { Write-Host "Build first: .\build-windows.ps1 -Build" -ForegroundColor Red exit 1 } Write-Host "Running ctest..." ctest --test-dir $buildDir --output-on-failure -C RelWithDebInfo if ($LASTEXITCODE -ne 0) { Write-Host "`nSome tests failed. See the output above." -ForegroundColor Yellow } else { Write-Host "All tests passed." -ForegroundColor Green } } function Test-ArpScanning { Write-Step "Checking ARP discovery" $exe = "$buildDir\bin\KOutNet.exe" if (-not (Test-Path $exe)) { Write-Host "Build first: .\build-windows.ps1 -Build" -ForegroundColor Red exit 1 } Write-Host "Enabling network debug logging..." $env:QT_LOGGING_RULES = "koutnet.network.debug=true" Write-Host "`nRunning KOutNet for 30 seconds to check ARP discovery..." Write-Host "Look for: 'ARP/NDP scan: pinged X neighbour(s)'" -ForegroundColor Yellow Write-Host "This message confirms that the neighbour scan ran." -ForegroundColor Yellow Write-Host "`nPress Ctrl+C to stop, or wait 30 seconds.`n" -ForegroundColor Cyan $job = Start-Job -ScriptBlock { param($exePath, $logRule) $env:QT_LOGGING_RULES = $logRule & $exePath 2>&1 } -ArgumentList $exe, $env:QT_LOGGING_RULES Wait-Job $job -Timeout 30 | Out-Null $output = Receive-Job $job Stop-Job $job -ErrorAction SilentlyContinue Remove-Job $job -ErrorAction SilentlyContinue Write-Host "`n--- Network log ---" -ForegroundColor Cyan $output | Select-String -Pattern "network|ARP|NDP" | ForEach-Object { Write-Host $_ } if ($output -match "ARP/NDP scan: pinged") { Write-Host "`nARP scan reported neighbours." -ForegroundColor Green } else { Write-Host "`nNo neighbours reported; the network may be empty." -ForegroundColor Yellow } } function Test-AclSecurity { Write-Step "Checking where secrets live" # Secrets are entries in the KWallet "KOutNet" folder; SecretStore never # writes a secret file of its own. On a Windows box without a wallet daemon # there is no persistence at all and every secret lasts one session, so # there is no secrets file whose ACL could leak. Write-Host "SecretStore is KWallet-backed; no secret file is written." -ForegroundColor Green if (Get-Command kwalletd6 -ErrorAction SilentlyContinue) { Write-Host "kwalletd6 found: secrets are under the KOutNet folder." -ForegroundColor Cyan } else { Write-Host "No wallet daemon: secrets stay in memory for this session only." -ForegroundColor Yellow } } if ($All) { Invoke-Configure Invoke-Build Invoke-Tests Test-ArpScanning Test-AclSecurity } elseif ($Configure) { Invoke-Configure } elseif ($Build) { Invoke-Build } elseif ($Test) { Invoke-Tests } elseif ($CheckArp) { Test-ArpScanning } elseif ($CheckAcl) { Test-AclSecurity } else { Write-Host @" Usage: .\build-windows.ps1 -All # Run all steps .\build-windows.ps1 -Configure # Configure CMake .\build-windows.ps1 -Build # Build the project .\build-windows.ps1 -Test # Run tests .\build-windows.ps1 -CheckArp # Check ARP discovery .\build-windows.ps1 -CheckAcl # Show where secrets live (KWallet vs in-memory) Requirements: - Visual Studio with the C++ compiler - A Visual Studio developer shell - Dependencies installed through KDE Craft: * Qt 6.4+ * KDE Frameworks 6.8+ * libQuotient 0.9+ * libsodium 1.0.18+ Craft documentation: https://community.kde.org/Craft "@ -ForegroundColor Cyan }