build(windows): add build_windows.ps1; docs: add Windows quick start and packaging

This commit is contained in:
2025-08-28 16:28:50 +02:00
parent 8c4926cbae
commit 48eec02cca
2 changed files with 83 additions and 1 deletions

View File

@ -278,4 +278,24 @@ cmd /c "call ""C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Co
Notes: Notes:
- If Ninja is not available, you can use the VS generator, but Ninja is recommended for clang. - If Ninja is not available, you can use the VS generator, but Ninja is recommended for clang.
- You can override `LLVM_PROFDATA` and `LLVM_COV` cache variables to absolute tool paths if needed. - You can override `LLVM_PROFDATA` and `LLVM_COV` cache variables to absolute tool paths if needed.
### Windows Quick start (vcpkg + VS 2022)
Build and package using the helper script:
```powershell
$env:VCPKG_ROOT = "$env:USERPROFILE\vcpkg"
if (-not (Test-Path $env:VCPKG_ROOT)) { git clone https://github.com/microsoft/vcpkg $env:VCPKG_ROOT; & "$env:VCPKG_ROOT\bootstrap-vcpkg.bat" }
powershell -NoProfile -ExecutionPolicy Bypass -File .\build_windows.ps1
```
Artifacts:
- DLL/LIB in `build\Release` and packaged zip at `dist\lib-privatebin-v0.1.1.3-windows-x64.zip`
- Example: `build\example\Release\example.exe` (also included in the zip if present)
Notes:
- Ensure Visual Studio 2022 Build Tools (C++ workload) and Windows 11 SDK are installed.
- The example links against the in-tree library target. The script copies DLL/LIB/PDB (if available), headers, README, and LICENSE into the package.

62
build_windows.ps1 Normal file
View File

@ -0,0 +1,62 @@
# Requires: PowerShell, Visual Studio 2022 Build Tools (C++), vcpkg (will be bootstrapped), Git
# Usage:
# powershell -NoProfile -ExecutionPolicy Bypass -File .\build_windows.ps1
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
Write-Host "Building PrivateBin API C++ (Windows, x64, Release)" -ForegroundColor Cyan
# Resolve vcpkg root
if (-not $env:VCPKG_ROOT) {
$env:VCPKG_ROOT = Join-Path $env:USERPROFILE 'vcpkg'
}
if (-not (Test-Path $env:VCPKG_ROOT)) {
Write-Host "Cloning vcpkg into $env:VCPKG_ROOT ..."
git clone https://github.com/microsoft/vcpkg $env:VCPKG_ROOT
& "$env:VCPKG_ROOT\bootstrap-vcpkg.bat"
}
# Choose generator (VS 2022)
$generator = 'Visual Studio 17 2022'
$arch = 'x64'
# Clean and configure
if (Test-Path build) { Remove-Item -Recurse -Force build }
cmake -S . -B build -G "$generator" -A $arch -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_ROOT\scripts\buildsystems\vcpkg.cmake"
# Build
cmake --build build --config Release
Write-Host "Build completed." -ForegroundColor Green
# Package artifacts (zip)
$dist = Join-Path (Get-Location) 'dist\windows'
if (Test-Path $dist) { Remove-Item -Recurse -Force $dist }
New-Item -ItemType Directory -Force -Path $dist | Out-Null
# Collect artifacts
$binDir = Join-Path (Get-Location) 'build\Release'
$exampleDir = Join-Path (Get-Location) 'build\example\Release'
$dll = Join-Path $binDir 'privatebinapi.dll'
$lib = Join-Path $binDir 'privatebinapi.lib'
$pdb = Join-Path $binDir 'privatebinapi.pdb'
$exe = Join-Path $exampleDir 'example.exe'
Copy-Item -Path $dll -Destination $dist -ErrorAction SilentlyContinue
Copy-Item -Path $lib -Destination $dist -ErrorAction SilentlyContinue
Copy-Item -Path $pdb -Destination $dist -ErrorAction SilentlyContinue
Copy-Item -Path $exe -Destination $dist -ErrorAction SilentlyContinue
Copy-Item -Path (Join-Path (Get-Location) 'include') -Destination $dist -Recurse
Copy-Item -Path (Join-Path (Get-Location) 'README.md') -Destination $dist
Copy-Item -Path (Join-Path (Get-Location) 'LICENSE') -Destination $dist -ErrorAction SilentlyContinue
$zipPath = Join-Path (Get-Location) 'dist\lib-privatebin-v0.1.1.3-windows-x64.zip'
if (Test-Path $zipPath) { Remove-Item -Force $zipPath }
Compress-Archive -Path (Join-Path $dist '*') -DestinationPath $zipPath
Write-Host "Windows artifact packaged:" -ForegroundColor Cyan
Write-Host " $zipPath"