#Requires -Version 5.1 <# .SYNOPSIS Build boringtun (Cloudflare WireGuard FFI library) for Windows. .DESCRIPTION Clones or updates the boringtun repository, builds it with Cargo in release mode, and copies the resulting static library to deps/boringtun/. .PARAMETER Target Rust target triple. Defaults to x86_64-pc-windows-msvc. Use aarch64-pc-windows-msvc for ARM64. .EXAMPLE pwsh scripts/build-boringtun-win.ps1 pwsh scripts/build-boringtun-win.ps1 -Target aarch64-pc-windows-msvc .NOTES Prerequisites: - Rust toolchain (https://rustup.rs) with the target installed: rustup target add x86_64-pc-windows-msvc - Visual Studio Build Tools 2019+ (for link.exe / lib.exe) - Git #> param( [string]$Target = "x86_64-pc-windows-msvc" ) Set-StrictMode -Version Latest $ErrorActionPreference = "Stop" $Root = Split-Path -Parent (Split-Path -Parent $PSCommandPath) $DepsDir = Join-Path $Root "deps\boringtun" $CloneDir = Join-Path $Root "build\boringtun-src" $RepoURL = "https://github.com/cloudflare/boringtun.git" function Info($msg) { Write-Host " $msg" -ForegroundColor Cyan } function Ok($msg) { Write-Host " OK: $msg" -ForegroundColor Green } function Fail($msg) { Write-Host " FAIL: $msg" -ForegroundColor Red; exit 1 } # Validate prerequisites Info "Checking prerequisites..." if (-not (Get-Command cargo -ErrorAction SilentlyContinue)) { Fail "cargo not found. Install Rust from https://rustup.rs" } if (-not (Get-Command git -ErrorAction SilentlyContinue)) { Fail "git not found. Install Git from https://git-scm.com" } $installed = rustup target list --installed 2>&1 if ($installed -notmatch [regex]::Escape($Target)) { Info "Installing Rust target $Target..." rustup target add $Target } Ok "Prerequisites satisfied" # Clone / update boringtun if (-not (Test-Path $CloneDir)) { Info "Cloning boringtun..." git clone --depth 1 $RepoURL $CloneDir } else { Info "Updating boringtun..." Push-Location $CloneDir git pull --ff-only Pop-Location } Ok "Source ready at $CloneDir" # Build Info "Building boringtun (--release, target=$Target)..." Push-Location $CloneDir cargo build --release --target $Target --features ffi-bindings 2>&1 | Write-Host if ($LASTEXITCODE -ne 0) { Fail "cargo build failed" } Pop-Location Ok "Build complete" # Copy artifacts New-Item -ItemType Directory -Force -Path $DepsDir | Out-Null $LibSrc = Join-Path $CloneDir "target\$Target\release\boringtun.lib" if (-not (Test-Path $LibSrc)) { $LibSrc = Join-Path $CloneDir "target\$Target\release\boringtun_cli.lib" } if (-not (Test-Path $LibSrc)) { Fail "Could not find boringtun.lib in $CloneDir\target\$Target\release\" } Copy-Item $LibSrc (Join-Path $DepsDir "boringtun.lib") -Force Ok "Copied boringtun.lib" $HdrSrc = Join-Path $CloneDir "boringtun\src\ffi\wireguard_ffi.h" if (Test-Path $HdrSrc) { Copy-Item $HdrSrc (Join-Path $DepsDir "wireguard_ffi.h") -Force Ok "Copied wireguard_ffi.h" } Write-Host "" Write-Host " Build successful. Output in:" -ForegroundColor Green Write-Host " $DepsDir" -ForegroundColor White Write-Host "" Write-Host " Next steps:" -ForegroundColor Yellow Write-Host " 1. Place wintun.dll (x64) next to your Artemis executable" -ForegroundColor White Write-Host " Download from https://www.wintun.net" -ForegroundColor White Write-Host " 2. cmake -B build -DCMAKE_BUILD_TYPE=Release" -ForegroundColor White Write-Host " 3. cmake --build build --config Release" -ForegroundColor White