v0.1.1.4: Build scripts moved to scripts/ directory; enhanced documentation; automated release script
This commit is contained in:
22
scripts/build.sh
Normal file
22
scripts/build.sh
Normal file
@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
echo "Building PrivateBin API C++ (library + example)"
|
||||
|
||||
# Ensure vcpkg exists
|
||||
VCPKG_ROOT="${VCPKG_ROOT:-$HOME/vcpkg}"
|
||||
if [ ! -d "$VCPKG_ROOT" ]; then
|
||||
echo "vcpkg not found under $VCPKG_ROOT, cloning..."
|
||||
git clone https://github.com/microsoft/vcpkg.git "$VCPKG_ROOT"
|
||||
"$VCPKG_ROOT/bootstrap-vcpkg.sh" -disableMetrics
|
||||
fi
|
||||
|
||||
# Clean and configure
|
||||
rm -rf build
|
||||
cmake -S . -B build -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake"
|
||||
|
||||
# Build all targets
|
||||
cmake --build build --config Release
|
||||
|
||||
echo "Build completed. Artifacts:"
|
||||
echo " - Library: build/libprivatebinapi.so"
|
||||
echo " - Example: build/example/example"
|
||||
128
scripts/build_thinkpad.bat
Normal file
128
scripts/build_thinkpad.bat
Normal file
@ -0,0 +1,128 @@
|
||||
@echo off
|
||||
setlocal ENABLEDELAYEDEXPANSION
|
||||
echo Building PrivateBin API C++ DLL...
|
||||
|
||||
REM Proaktiv: VS-Entwicklungsumgebung initialisieren, wenn bekannt
|
||||
set "VSINSTALL_HINT=C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools"
|
||||
set "VSDEVCMD_HINT=%VSINSTALL_HINT%\Common7\Tools\VsDevCmd.bat"
|
||||
if not exist "%VSDEVCMD_HINT%" (
|
||||
set "VSINSTALL_HINT=C:\Program Files\Microsoft Visual Studio\2022\Community"
|
||||
set "VSDEVCMD_HINT=%VSINSTALL_HINT%\Common7\Tools\VsDevCmd.bat"
|
||||
)
|
||||
if exist "%VSDEVCMD_HINT%" (
|
||||
echo Initializing MSVC environment from "%VSDEVCMD_HINT%" for x64...
|
||||
call "%VSDEVCMD_HINT%" -arch=x64 >nul
|
||||
set "VCPKG_VISUAL_STUDIO_PATH=%VSINSTALL_HINT%"
|
||||
)
|
||||
|
||||
REM Ensure MSVC environment is loaded (cl.exe). Try via vswhere if not present.
|
||||
where cl >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
REM Ensure vswhere is on PATH (both PF and PF(x86))
|
||||
set "PATH=%ProgramFiles%\Microsoft Visual Studio\Installer;%ProgramFiles(x86)%\Microsoft Visual Studio\Installer;%PATH%"
|
||||
REM First try well-known VsDevCmd from BuildTools/Community to avoid vswhere dependency
|
||||
set "VSINSTALL=C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools"
|
||||
set "VSDEVCMD_CANDIDATE=%VSINSTALL%\Common7\Tools\VsDevCmd.bat"
|
||||
if not exist "%VSDEVCMD_CANDIDATE%" (
|
||||
set "VSINSTALL=C:\Program Files\Microsoft Visual Studio\2022\Community"
|
||||
set "VSDEVCMD_CANDIDATE=%VSINSTALL%\Common7\Tools\VsDevCmd.bat"
|
||||
)
|
||||
if exist "%VSDEVCMD_CANDIDATE%" (
|
||||
echo Initializing MSVC environment from "%VSDEVCMD_CANDIDATE%" for x64...
|
||||
call "%VSDEVCMD_CANDIDATE%" -arch=x64 >nul
|
||||
REM Provide VS path hint for vcpkg
|
||||
set "VCPKG_VISUAL_STUDIO_PATH=%VSINSTALL%"
|
||||
REM Re-check if cl is now available; if so, skip vswhere path
|
||||
where cl >nul 2>&1
|
||||
if not errorlevel 1 goto :after_vs_env
|
||||
)
|
||||
|
||||
set "VSWHERE=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"
|
||||
if not exist "%VSWHERE%" (
|
||||
set "VSWHERE=%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe"
|
||||
)
|
||||
if not exist "%VSWHERE%" (
|
||||
set "VSWHERE=c:\tools\vswhere.exe"
|
||||
)
|
||||
if exist "%VSWHERE%" (
|
||||
for /f "usebackq tokens=*" %%i in (`"%VSWHERE%" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do set "VSINSTALL=%%i"
|
||||
if defined VSINSTALL (
|
||||
set "VSDEVCMD=%VSINSTALL%\Common7\Tools\VsDevCmd.bat"
|
||||
if exist "%VSDEVCMD%" (
|
||||
echo Initializing MSVC environment from "%VSDEVCMD%" for x64...
|
||||
call "%VSDEVCMD%" -arch=x64 >nul
|
||||
set "VCPKG_VISUAL_STUDIO_PATH=%VSINSTALL%"
|
||||
) else (
|
||||
echo VsDevCmd.bat not found under "%VSINSTALL%". cl.exe may be unavailable.
|
||||
)
|
||||
) else (
|
||||
echo Visual Studio with C++ tools not found. Install "Desktop development with C++" workload.
|
||||
)
|
||||
) else (
|
||||
echo vswhere.exe not found. Consider installing Visual Studio 2022 with C++ tools.
|
||||
)
|
||||
)
|
||||
|
||||
:after_vs_env
|
||||
|
||||
REM Detect or bootstrap vcpkg
|
||||
if not defined VCPKG_ROOT (
|
||||
set "VCPKG_ROOT=%USERPROFILE%\vcpkg"
|
||||
)
|
||||
|
||||
if not exist "%VCPKG_ROOT%\scripts\buildsystems\vcpkg.cmake" (
|
||||
echo vcpkg not found at "%VCPKG_ROOT%". Cloning and bootstrapping...
|
||||
if not exist "%VCPKG_ROOT%" (
|
||||
git clone https://github.com/microsoft/vcpkg.git "%VCPKG_ROOT%"
|
||||
if errorlevel 1 (
|
||||
echo Failed to clone vcpkg
|
||||
exit /b 1
|
||||
)
|
||||
)
|
||||
call "%VCPKG_ROOT%\bootstrap-vcpkg.bat"
|
||||
if errorlevel 1 (
|
||||
echo Failed to bootstrap vcpkg
|
||||
exit /b 1
|
||||
)
|
||||
)
|
||||
|
||||
REM Ensure vcpkg manifest/config has a baseline; create vcpkg-configuration.json if missing
|
||||
REM Baseline wird außerhalb des Skripts gesetzt (vcpkg x-update-baseline)
|
||||
|
||||
REM Reset build directory to avoid stale CMake cache (e.g., CMAKE_GENERATOR_INSTANCE)
|
||||
if exist "build" rd /s /q build
|
||||
mkdir build
|
||||
pushd build
|
||||
|
||||
REM Generate build files with CMake and vcpkg (manifest mode with auto-baseline)
|
||||
set "VCPKG_DEFAULT_TRIPLET=x64-windows"
|
||||
REM Ensure no stale generator instance is leaking from environment
|
||||
set "CMAKE_GENERATOR_INSTANCE="
|
||||
|
||||
REM Ensure vcpkg manifest has a builtin-baseline (adds if missing)
|
||||
if exist "vcpkg.json" (
|
||||
"%VCPKG_ROOT%\vcpkg.exe" x-update-baseline --add-initial-baseline 1>nul 2>nul
|
||||
)
|
||||
|
||||
REM Use user vcpkg toolchain
|
||||
set "TOOLCHAIN_FILE=%VCPKG_ROOT%/scripts/buildsystems/vcpkg.cmake"
|
||||
cmake .. -G "Visual Studio 17 2022" -A x64 -DCMAKE_TOOLCHAIN_FILE="%TOOLCHAIN_FILE%"
|
||||
if errorlevel 1 (
|
||||
echo CMake configuration failed
|
||||
popd
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
REM Build the project
|
||||
cmake --build . --config Release
|
||||
set BUILD_ERROR=%ERRORLEVEL%
|
||||
|
||||
if %BUILD_ERROR% EQU 0 (
|
||||
echo Build completed successfully!
|
||||
) else (
|
||||
echo Build failed with error level %BUILD_ERROR%
|
||||
)
|
||||
|
||||
popd
|
||||
exit /b %BUILD_ERROR%
|
||||
|
||||
62
scripts/build_windows.ps1
Normal file
62
scripts/build_windows.ps1
Normal 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"
|
||||
|
||||
@ -30,3 +30,4 @@ Get-ChildItem -LiteralPath $OutDir -File | Format-Table Name,Length -AutoSize
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
95
scripts/create_release.ps1
Normal file
95
scripts/create_release.ps1
Normal file
@ -0,0 +1,95 @@
|
||||
param(
|
||||
[Parameter(Mandatory=$false)]
|
||||
[string]$Token,
|
||||
|
||||
[Parameter(Mandatory=$false)]
|
||||
[switch]$Build
|
||||
)
|
||||
|
||||
# Token aus Umgebungsvariable laden falls nicht als Parameter übergeben
|
||||
if (-not $Token) {
|
||||
$Token = $env:GITEA_TOKEN
|
||||
if (-not $Token) {
|
||||
Write-Host "Fehler: Kein Token angegeben und GITEA_TOKEN Umgebungsvariable nicht gesetzt!" -ForegroundColor Red
|
||||
Write-Host "Verwendung: .\create_release.ps1 -Token 'your_token' oder setze GITEA_TOKEN Umgebungsvariable" -ForegroundColor Yellow
|
||||
exit 1
|
||||
}
|
||||
Write-Host "Token aus Umgebungsvariable GITEA_TOKEN geladen" -ForegroundColor Green
|
||||
}
|
||||
|
||||
Write-Host "=== lib-privatebin Release Creator ===" -ForegroundColor Cyan
|
||||
|
||||
# Aktuelle Version ermitteln
|
||||
$lastTag = git describe --tags --abbrev=0 2>$null
|
||||
if (-not $lastTag) {
|
||||
$lastTag = "v0.1.0"
|
||||
}
|
||||
|
||||
Write-Host "Letzter Tag: $lastTag" -ForegroundColor Green
|
||||
|
||||
# Version parsen
|
||||
if ($lastTag -match "^v(\d+)\.(\d+)\.(\d+)(.*)$") {
|
||||
$major = [int]$matches[1]
|
||||
$minor = [int]$matches[2]
|
||||
$patch = [int]$matches[3]
|
||||
$suffix = $matches[4]
|
||||
|
||||
$newPatch = $patch + 1
|
||||
$newVersion = "v$major.$minor.$newPatch$suffix"
|
||||
|
||||
Write-Host "Neue Version: $newVersion" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "Fehler: Ungültiges Versionsformat: $lastTag" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Build falls gewünscht
|
||||
if ($Build) {
|
||||
Write-Host "Führe Build durch..." -ForegroundColor Yellow
|
||||
if (Test-Path "scripts\build_thinkpad.bat") {
|
||||
Write-Host "Verwende scripts\build_thinkpad.bat..." -ForegroundColor Yellow
|
||||
cmd /c scripts\build_thinkpad.bat
|
||||
} else {
|
||||
Write-Host "Verwende scripts\build_windows.ps1..." -ForegroundColor Yellow
|
||||
powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\build_windows.ps1
|
||||
}
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host "Build fehlgeschlagen!" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
# Änderungen committen
|
||||
$status = git status --porcelain
|
||||
if ($status) {
|
||||
git add -A
|
||||
git commit -m "Release $newVersion prepare for release"
|
||||
git push origin HEAD
|
||||
}
|
||||
|
||||
# Tag erstellen und pushen
|
||||
git tag -a $newVersion -m "Release $newVersion"
|
||||
git push origin $newVersion
|
||||
|
||||
# Release erstellen
|
||||
$releaseBody = "## What is New in $newVersion`n`n- AUTOMATED: Release created by script`n- VERSION: Bumped from $lastTag to $newVersion`n`n## Build Artifacts`n`n- privatebinapi.dll - Windows Dynamic Link Library`n- privatebinapi.lib - Windows Import Library`n- example.exe - Combined example program`n- privatebinapi.h - C++ header file"
|
||||
|
||||
$releaseData = @{
|
||||
tag_name = $newVersion
|
||||
name = "$newVersion - Automated Release"
|
||||
body = $releaseBody
|
||||
draft = $false
|
||||
prerelease = $false
|
||||
} | ConvertTo-Json -Depth 10
|
||||
|
||||
$headers = @{
|
||||
"Authorization" = "token $Token"
|
||||
"Content-Type" = "application/json"
|
||||
}
|
||||
|
||||
$releaseUri = "https://gitea.medisoftware.org/api/v1/repos/Markus/lib-privatebin/releases"
|
||||
$release = Invoke-RestMethod -Uri $releaseUri -Method Post -Headers $headers -Body $releaseData
|
||||
|
||||
Write-Host "Release erstellt: $($release.id)" -ForegroundColor Green
|
||||
Write-Host "URL: $($release.html_url)" -ForegroundColor Green
|
||||
|
||||
@ -35,3 +35,4 @@ Get-ChildItem -LiteralPath $BinDir -File | ForEach-Object {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -43,3 +43,4 @@ if ($resp.StatusCode -ge 200 -and $resp.StatusCode -lt 300) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -45,3 +45,4 @@ foreach ($f in $files) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -76,3 +76,4 @@ Write-Host 'Release notes updated with links.'
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user