Enhance Windows build scripts for improved functionality and user experience
- Refactored batch and PowerShell build scripts to streamline argument parsing and enhance error handling. - Added support for cleaning build directories and improved feedback for missing dependencies. - Updated project file generation logic to handle missing configuration files more gracefully. - Introduced a new validation script to ensure the build environment is correctly set up before building. - Removed obsolete setup scripts to simplify the repository structure.
This commit is contained in:
@@ -1,81 +1,133 @@
|
||||
# PowerShell script to build YAZE on Windows
|
||||
# This script sets up the environment and builds the project using Visual Studio
|
||||
# YAZE Windows Build Script
|
||||
# This script builds the YAZE project on Windows using MSBuild
|
||||
|
||||
param(
|
||||
[string]$Configuration = "Release",
|
||||
[string]$Platform = "x64",
|
||||
[switch]$Clean = $false,
|
||||
[switch]$Verbose = $false
|
||||
[switch]$Clean,
|
||||
[switch]$Verbose
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
# Set error handling
|
||||
$ErrorActionPreference = "Continue"
|
||||
|
||||
Write-Host "========================================" -ForegroundColor Cyan
|
||||
Write-Host "YAZE Windows Build Script" -ForegroundColor Cyan
|
||||
Write-Host "========================================" -ForegroundColor Cyan
|
||||
# Colors for output
|
||||
$Colors = @{
|
||||
Success = "Green"
|
||||
Warning = "Yellow"
|
||||
Error = "Red"
|
||||
Info = "Cyan"
|
||||
White = "White"
|
||||
}
|
||||
|
||||
function Write-Status {
|
||||
param([string]$Message, [string]$Color = "White")
|
||||
Write-Host $Message -ForegroundColor $Colors[$Color]
|
||||
}
|
||||
|
||||
function Test-Command {
|
||||
param([string]$Command)
|
||||
try {
|
||||
$null = Get-Command $Command -ErrorAction Stop
|
||||
return $true
|
||||
} catch {
|
||||
return $false
|
||||
}
|
||||
}
|
||||
|
||||
function Get-MSBuildPath {
|
||||
$vsWhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
|
||||
if (Test-Path $vsWhere) {
|
||||
$vsInstall = & $vsWhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath
|
||||
if ($vsInstall) {
|
||||
$msbuildPath = Join-Path $vsInstall "MSBuild\Current\Bin\MSBuild.exe"
|
||||
if (Test-Path $msbuildPath) {
|
||||
return $msbuildPath
|
||||
}
|
||||
}
|
||||
}
|
||||
return $null
|
||||
}
|
||||
|
||||
# Main script
|
||||
Write-Status "========================================" "Info"
|
||||
Write-Status "YAZE Windows Build Script" "Info"
|
||||
Write-Status "========================================" "Info"
|
||||
|
||||
# Validate parameters
|
||||
$ValidConfigs = @("Debug", "Release", "RelWithDebInfo", "MinSizeRel")
|
||||
$ValidPlatforms = @("x64", "x86", "ARM64")
|
||||
|
||||
if ($ValidConfigs -notcontains $Configuration) {
|
||||
Write-Status "ERROR: Invalid configuration '$Configuration'. Valid options: $($ValidConfigs -join ', ')" "Error"
|
||||
exit 1
|
||||
}
|
||||
|
||||
if ($ValidPlatforms -notcontains $Platform) {
|
||||
Write-Status "ERROR: Invalid platform '$Platform'. Valid options: $($ValidPlatforms -join ', ')" "Error"
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Status "Build Configuration: $Configuration" "Warning"
|
||||
Write-Status "Build Platform: $Platform" "Warning"
|
||||
|
||||
# Check if we're in the right directory
|
||||
if (-not (Test-Path "YAZE.sln")) {
|
||||
Write-Error "YAZE.sln not found. Please run this script from the project root directory."
|
||||
Write-Status "ERROR: YAZE.sln not found. Please run this script from the project root directory." "Error"
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host "✓ YAZE.sln found" -ForegroundColor Green
|
||||
Write-Status "✓ Found YAZE.sln" "Success"
|
||||
|
||||
# Check for Visual Studio
|
||||
Write-Host "Checking for Visual Studio..." -ForegroundColor Yellow
|
||||
try {
|
||||
$msbuildPath = Get-Command msbuild -ErrorAction Stop
|
||||
Write-Host "✓ MSBuild found at: $($msbuildPath.Source)" -ForegroundColor Green
|
||||
} catch {
|
||||
Write-Error "MSBuild not found. Please install Visual Studio 2022 or later with the C++ development workload."
|
||||
# Check for MSBuild
|
||||
$msbuildPath = Get-MSBuildPath
|
||||
if (-not $msbuildPath) {
|
||||
Write-Status "ERROR: MSBuild not found. Please install Visual Studio 2022 with C++ workload." "Error"
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Status "✓ MSBuild found at: $msbuildPath" "Success"
|
||||
|
||||
# Check for vcpkg
|
||||
Write-Host "Checking for vcpkg..." -ForegroundColor Yellow
|
||||
if (-not (Test-Path "vcpkg.json")) {
|
||||
Write-Error "vcpkg.json not found. Please ensure vcpkg is properly configured."
|
||||
exit 1
|
||||
Write-Status "WARNING: vcpkg.json not found. vcpkg integration may not work properly." "Warning"
|
||||
}
|
||||
|
||||
Write-Host "✓ vcpkg.json found" -ForegroundColor Green
|
||||
|
||||
# Display build configuration
|
||||
Write-Host "Build Configuration: $Configuration" -ForegroundColor Yellow
|
||||
Write-Host "Build Platform: $Platform" -ForegroundColor Yellow
|
||||
|
||||
# Create build directories
|
||||
Write-Host "Creating build directories..." -ForegroundColor Yellow
|
||||
Write-Status "Creating build directories..." "Warning"
|
||||
$directories = @("build", "build\bin", "build\obj")
|
||||
foreach ($dir in $directories) {
|
||||
if (-not (Test-Path $dir)) {
|
||||
New-Item -ItemType Directory -Path $dir -Force | Out-Null
|
||||
Write-Host "✓ Created directory: $dir" -ForegroundColor Green
|
||||
Write-Status "✓ Created directory: $dir" "Success"
|
||||
}
|
||||
}
|
||||
|
||||
# Clean build if requested
|
||||
if ($Clean) {
|
||||
Write-Host "Cleaning build directories..." -ForegroundColor Yellow
|
||||
Write-Status "Cleaning build directories..." "Warning"
|
||||
if (Test-Path "build\bin") {
|
||||
Remove-Item -Recurse -Force "build\bin\*" -ErrorAction SilentlyContinue
|
||||
}
|
||||
if (Test-Path "build\obj") {
|
||||
Remove-Item -Recurse -Force "build\obj\*" -ErrorAction SilentlyContinue
|
||||
}
|
||||
Write-Host "✓ Build directories cleaned" -ForegroundColor Green
|
||||
Write-Status "✓ Build directories cleaned" "Success"
|
||||
}
|
||||
|
||||
# Generate yaze_config.h if it doesn't exist
|
||||
if (-not (Test-Path "yaze_config.h")) {
|
||||
Write-Host "Generating yaze_config.h..." -ForegroundColor Yellow
|
||||
Write-Status "Generating yaze_config.h..." "Warning"
|
||||
if (Test-Path "src\yaze_config.h.in") {
|
||||
Copy-Item "src\yaze_config.h.in" "yaze_config.h"
|
||||
(Get-Content 'yaze_config.h') -replace '@yaze_VERSION_MAJOR@', '0' -replace '@yaze_VERSION_MINOR@', '3' -replace '@yaze_VERSION_PATCH@', '1' | Set-Content 'yaze_config.h'
|
||||
Write-Host "✓ Generated yaze_config.h" -ForegroundColor Green
|
||||
$content = Get-Content "yaze_config.h" -Raw
|
||||
$content = $content -replace '@yaze_VERSION_MAJOR@', '0'
|
||||
$content = $content -replace '@yaze_VERSION_MINOR@', '3'
|
||||
$content = $content -replace '@yaze_VERSION_PATCH@', '1'
|
||||
Set-Content "yaze_config.h" $content
|
||||
Write-Status "✓ Generated yaze_config.h" "Success"
|
||||
} else {
|
||||
Write-Warning "yaze_config.h.in not found, creating basic config"
|
||||
Write-Status "WARNING: yaze_config.h.in not found, creating basic config" "Warning"
|
||||
@"
|
||||
// yaze config file
|
||||
#define YAZE_VERSION_MAJOR 0
|
||||
@@ -86,7 +138,7 @@ if (-not (Test-Path "yaze_config.h")) {
|
||||
}
|
||||
|
||||
# Build using MSBuild
|
||||
Write-Host "Building with MSBuild..." -ForegroundColor Yellow
|
||||
Write-Status "Building with MSBuild..." "Warning"
|
||||
|
||||
$msbuildArgs = @(
|
||||
"YAZE.sln"
|
||||
@@ -94,7 +146,7 @@ $msbuildArgs = @(
|
||||
"/p:Platform=$Platform"
|
||||
"/p:VcpkgEnabled=true"
|
||||
"/p:VcpkgManifestInstall=true"
|
||||
"/m" # Multi-processor build
|
||||
"/m"
|
||||
)
|
||||
|
||||
if ($Verbose) {
|
||||
@@ -103,66 +155,66 @@ if ($Verbose) {
|
||||
$msbuildArgs += "/verbosity:minimal"
|
||||
}
|
||||
|
||||
$msbuildCommand = "msbuild $($msbuildArgs -join ' ')"
|
||||
Write-Host "Command: $msbuildCommand" -ForegroundColor Gray
|
||||
$msbuildCommand = "& `"$msbuildPath`" $($msbuildArgs -join ' ')"
|
||||
Write-Status "Command: $msbuildCommand" "Info"
|
||||
|
||||
try {
|
||||
& msbuild @msbuildArgs
|
||||
& $msbuildPath @msbuildArgs
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "MSBuild failed with exit code $LASTEXITCODE"
|
||||
}
|
||||
Write-Host "✓ Build completed successfully" -ForegroundColor Green
|
||||
Write-Status "✓ Build completed successfully" "Success"
|
||||
} catch {
|
||||
Write-Error "Build failed: $_"
|
||||
Write-Status "✗ Build failed: $_" "Error"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Verify executable was created
|
||||
$exePath = "build\bin\$Configuration\yaze.exe"
|
||||
if (-not (Test-Path $exePath)) {
|
||||
Write-Error "Executable not found at expected path: $exePath"
|
||||
Write-Status "ERROR: Executable not found at expected path: $exePath" "Error"
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host "✓ Executable created: $exePath" -ForegroundColor Green
|
||||
Write-Status "✓ Executable created: $exePath" "Success"
|
||||
|
||||
# Test that the executable runs (basic test)
|
||||
Write-Host "Testing executable startup..." -ForegroundColor Yellow
|
||||
# Test that the executable runs
|
||||
Write-Status "Testing executable..." "Warning"
|
||||
try {
|
||||
$testResult = & $exePath --help 2>&1
|
||||
$exitCode = $LASTEXITCODE
|
||||
|
||||
# Check if it's the test main or app main
|
||||
if ($testResult -match "Google Test|gtest") {
|
||||
Write-Error "Executable is running test main instead of app main!"
|
||||
Write-Host "Output: $testResult" -ForegroundColor Red
|
||||
Write-Status "ERROR: Executable is running test main instead of app main!" "Error"
|
||||
Write-Status "Output: $testResult" "Error"
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host "✓ Executable runs correctly (exit code: $exitCode)" -ForegroundColor Green
|
||||
Write-Status "✓ Executable runs correctly (exit code: $exitCode)" "Success"
|
||||
} catch {
|
||||
Write-Warning "Could not test executable: $_"
|
||||
Write-Status "WARNING: Could not test executable: $_" "Warning"
|
||||
}
|
||||
|
||||
# Display file info
|
||||
$exeInfo = Get-Item $exePath
|
||||
$fileSizeMB = [math]::Round($exeInfo.Length / 1MB, 2)
|
||||
Write-Host "Executable size: $fileSizeMB MB" -ForegroundColor Cyan
|
||||
Write-Status "Executable size: $fileSizeMB MB" "Info"
|
||||
|
||||
Write-Host "========================================" -ForegroundColor Cyan
|
||||
Write-Host "✓ YAZE Windows build completed successfully!" -ForegroundColor Green
|
||||
Write-Host "========================================" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
Write-Host "Build Configuration: $Configuration" -ForegroundColor White
|
||||
Write-Host "Build Platform: $Platform" -ForegroundColor White
|
||||
Write-Host "Executable: $exePath" -ForegroundColor White
|
||||
Write-Host ""
|
||||
Write-Host "To run YAZE:" -ForegroundColor Yellow
|
||||
Write-Host " $exePath" -ForegroundColor White
|
||||
Write-Host ""
|
||||
Write-Host "To build other configurations:" -ForegroundColor Yellow
|
||||
Write-Host " .\scripts\build-windows.ps1 -Configuration Debug -Platform x64" -ForegroundColor White
|
||||
Write-Host " .\scripts\build-windows.ps1 -Configuration Release -Platform x86" -ForegroundColor White
|
||||
Write-Host " .\scripts\build-windows.ps1 -Configuration RelWithDebInfo -Platform ARM64" -ForegroundColor White
|
||||
Write-Host " .\scripts\build-windows.ps1 -Clean" -ForegroundColor White
|
||||
Write-Host ""
|
||||
Write-Status "========================================" "Info"
|
||||
Write-Status "✓ YAZE Windows build completed successfully!" "Success"
|
||||
Write-Status "========================================" "Info"
|
||||
Write-Status ""
|
||||
Write-Status "Build Configuration: $Configuration" "White"
|
||||
Write-Status "Build Platform: $Platform" "White"
|
||||
Write-Status "Executable: $exePath" "White"
|
||||
Write-Status ""
|
||||
Write-Status "To run YAZE:" "Warning"
|
||||
Write-Status " $exePath" "White"
|
||||
Write-Status ""
|
||||
Write-Status "To build other configurations:" "Warning"
|
||||
Write-Status " .\scripts\build-windows.ps1 -Configuration Debug -Platform x64" "White"
|
||||
Write-Status " .\scripts\build-windows.ps1 -Configuration Release -Platform x86" "White"
|
||||
Write-Status " .\scripts\build-windows.ps1 -Configuration RelWithDebInfo -Platform ARM64" "White"
|
||||
Write-Status " .\scripts\build-windows.ps1 -Clean" "White"
|
||||
Write-Status ""
|
||||
Reference in New Issue
Block a user