mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02:00
This pull request refactors and standardizes the PowerToys build scripts to improve maintainability, reusability, and platform detection. The main changes are the introduction of a shared helper script (`build-common.ps1`), migration of build logic in individual scripts to use these helpers, and enhanced platform auto-detection. This makes the build pipeline more robust and easier to use from any directory within the repository. As the result of our recent changes, use the following guidance when working in the PowerToys repo: 1. Use `build-essentials.ps1` before any development in general - Purpose: restore NuGet packages for the full solution and build a small set of essential native projects (runner, settings). This is a fast way to ensure native artifacts required for local development are available. 2. Use `build.ps1` from any folder - Purpose: lightweight local builder. It auto-discovers the target platform (x64/arm64/x86) and builds projects it finds in the current directory. - Notes: you can pass additional MSBuild arguments positionally (e.g. `./tools/build/build.ps1 '/p:CIBuild=true'`) — the script will forward them to MSBuild. - Use `-RestoreOnly` to only restore packages for local projects. 3. Use `build-installer.ps1` to create a local installer (use with caution) - Purpose: runs the full pipeline that restores, builds the full solution, signs packages, and builds the installer (MSI/bootstrapper). - Caution: this script performs cleaning (git clean) and installer packaging steps that may remove untracked files under `installer/`. Additional notes - Shared helpers live in `build-common.ps1` and are used by the other scripts (`RunMSBuild`, `RestoreThenBuild`, `BuildProjectsInDirectory`, platform auto-detection). **Shared build logic and helper functions:** * Added new `tools/build/build-common.ps1` file containing reusable PowerShell functions for MSBuild invocation, solution/project restore and build, platform detection, and project discovery. All build scripts now dot-source this file for shared functionality. **Refactoring of build scripts to use shared helpers:** * Updated `tools/build/build-essentials.ps1` to use `build-common.ps1` helpers, including auto-detection of repository root and platform, and simplified project build logic. * Created new `tools/build/build.ps1` for quick local builds, using shared helpers and supporting extra MSBuild arguments and platform auto-detection. * Refactored `tools/build/build-installer.ps1` to remove duplicate build logic, use shared helpers, and support platform auto-detection and argument forwarding. [[1]](diffhunk://#diff-21888769485d767c43c0895fe315e6f6d7384da62f60ef917d8a61a610da10b9L55-R74) [[2]](diffhunk://#diff-21888769485d767c43c0895fe315e6f6d7384da62f60ef917d8a61a610da10b9L83-L126) **Improved platform detection and argument handling:** * All scripts now auto-detect the target platform if not specified, using the new `Get-DefaultPlatform` helper. This supports x64, arm64, and x86 hosts. [[1]](diffhunk://#diff-43764921d6c830dbb3a15fe875aebfbc46966ae5ff62f3179adb3ff046b47b9dR1-R166) [[2]](diffhunk://#diff-946ed85e16779fdbcfeb7de80f631eae2da0f7bd478e27e22621121b409dde88L1-R70) [[3]](diffhunk://#diff-7a444242b2a6d9c642341bd2ef45f51ba5698ad7827e5136e85eb483863967a7R1-R88) [[4]](diffhunk://#diff-21888769485d767c43c0895fe315e6f6d7384da62f60ef917d8a61a610da10b9L55-R74) **Consistent MSBuild invocation and logging:** * MSBuild calls now consistently use shared helpers, centralized logging, and support passing extra arguments such as `/p:CIBuild=true` and custom solution/project paths. [[1]](diffhunk://#diff-43764921d6c830dbb3a15fe875aebfbc46966ae5ff62f3179adb3ff046b47b9dR1-R166) [[2]](diffhunk://#diff-21888769485d767c43c0895fe315e6f6d7384da62f60ef917d8a61a610da10b9L137-R110) [[3]](diffhunk://#diff-21888769485d767c43c0895fe315e6f6d7384da62f60ef917d8a61a610da10b9L151-R125) [[4]](diffhunk://#diff-21888769485d767c43c0895fe315e6f6d7384da62f60ef917d8a61a610da10b9L162-R139) **Project and solution build improvements:** * Build scripts now discover and build projects in preferred order (.sln, .csproj, .vcxproj), and support restoring packages only if requested. [[1]](diffhunk://#diff-43764921d6c830dbb3a15fe875aebfbc46966ae5ff62f3179adb3ff046b47b9dR1-R166) [[2]](diffhunk://#diff-7a444242b2a6d9c642341bd2ef45f51ba5698ad7827e5136e85eb483863967a7R1-R88) Let me know if you need a walkthrough of the new helper functions or how to use the updated build scripts!
71 lines
2.8 KiB
PowerShell
71 lines
2.8 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
Build essential native PowerToys projects (runner and settings), restoring NuGet packages first.
|
|
|
|
.DESCRIPTION
|
|
Lightweight script to build a small set of essential C++ projects used by PowerToys' runner and native modules. This script first restores NuGet packages for the full solution (`PowerToys.sln`) and then builds the runner and settings projects. Intended for fast local builds during development.
|
|
|
|
.PARAMETER Platform
|
|
Target platform for the build (for example: 'x64', 'arm64'). If omitted the script will attempt to auto-detect the host platform.
|
|
|
|
.PARAMETER Configuration
|
|
Build configuration (for example: 'Debug' or 'Release'). Default is 'Debug'.
|
|
|
|
.EXAMPLE
|
|
.\tools\build\build-essentials.ps1
|
|
Restores packages for the solution and builds the default set of native projects using the auto-detected platform and Debug configuration.
|
|
|
|
.EXAMPLE
|
|
.\tools\build\build-essentials.ps1 -Platform arm64 -Configuration Release
|
|
Restores packages and builds the essentials in Release mode for ARM64, even if your machine is running on x64.
|
|
|
|
.NOTES
|
|
- This script dot-sources `build-common.ps1` and uses the shared helper `RunMSBuild`.
|
|
- It will call `RestoreThenBuild 'PowerToys.sln'` before building the essential projects to ensure NuGet packages are restored.
|
|
- The script attempts to locate the repository root automatically and can be run from any folder inside the repo.
|
|
#>
|
|
|
|
param (
|
|
[string]$Platform = '',
|
|
[string]$Configuration = 'Debug'
|
|
)
|
|
|
|
# Find repository root starting from the script location
|
|
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
|
|
$repoRoot = $ScriptDir
|
|
while ($repoRoot -and -not (Test-Path (Join-Path $repoRoot "PowerToys.sln"))) {
|
|
$parent = Split-Path -Parent $repoRoot
|
|
if ($parent -eq $repoRoot) {
|
|
Write-Error "Could not find PowerToys repository root."
|
|
exit 1
|
|
}
|
|
$repoRoot = $parent
|
|
}
|
|
|
|
# Export script-scope variables used by build-common helpers
|
|
Set-Variable -Name RepoRoot -Value $repoRoot -Scope Script -Force
|
|
|
|
# Load shared helpers
|
|
. "$PSScriptRoot\build-common.ps1"
|
|
|
|
# If platform not provided, auto-detect from host
|
|
if (-not $Platform -or $Platform -eq '') {
|
|
try {
|
|
$Platform = Get-DefaultPlatform
|
|
Write-Host ("[AUTO-PLATFORM] Detected platform: {0}" -f $Platform)
|
|
} catch {
|
|
Write-Warning "Failed to auto-detect platform; defaulting to 'x64'"
|
|
$Platform = 'x64'
|
|
}
|
|
}
|
|
|
|
# Ensure solution packages are restored
|
|
RestoreThenBuild 'PowerToys.sln' '' $Platform $Configuration $true
|
|
|
|
# Build both runner and settings
|
|
$ProjectsToBuild = @(".\src\runner\runner.vcxproj", ".\src\settings-ui\Settings.UI\PowerToys.Settings.csproj")
|
|
$ExtraArgs = "/p:SolutionDir=$repoRoot\"
|
|
foreach ($proj in $ProjectsToBuild) {
|
|
Write-Host ("[BUILD-ESSENTIALS] Building {0}" -f $proj)
|
|
RunMSBuild $proj $ExtraArgs $Platform $Configuration
|
|
} |