-
-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathBuild.ps1
More file actions
115 lines (94 loc) · 3.07 KB
/
Copy pathBuild.ps1
File metadata and controls
115 lines (94 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<#
.SYNOPSIS
Configures and builds the Rux compiler and C++ unit-test target.
.PARAMETER Configuration
The CMake configuration to build. Defaults to Release.
.PARAMETER BuildDirectory
The CMake build directory, relative to the repository root unless absolute.
.EXAMPLE
./Build.ps1
.EXAMPLE
./Build.ps1 -Configuration Debug
#>
[CmdletBinding()]
param(
[ValidateSet("Debug", "Release")]
[string]$Configuration = "Release",
[string]$BuildDirectory = "Build"
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
function Find-Tool {
param(
[Parameter(Mandatory)]
[string]$Name
)
$command = Get-Command $Name -CommandType Application -ErrorAction SilentlyContinue
if ($command) {
return $command.Source
}
throw "Required tool not found: $Name"
}
function Invoke-Checked {
param(
[Parameter(Mandatory)]
[string]$FilePath,
[Parameter()]
[string[]]$ArgumentList = @()
)
& $FilePath @ArgumentList
if ($LASTEXITCODE -ne 0) {
throw "Command failed with exit code ${LASTEXITCODE}: $FilePath $($ArgumentList -join ' ')"
}
}
function Write-Step {
param(
[Parameter(Mandatory)]
[string]$Message
)
Write-Host ""
Write-Host "==> $Message" -ForegroundColor Cyan
}
$repositoryRoot = $PSScriptRoot
$buildPath = if ([System.IO.Path]::IsPathRooted($BuildDirectory)) {
$BuildDirectory
}
else {
Join-Path $repositoryRoot $BuildDirectory
}
$cmake = Find-Tool -Name "cmake"
$compilerTarget = switch ([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture) {
([System.Runtime.InteropServices.Architecture]::X64) { "x86_64-pc-windows-msvc" }
([System.Runtime.InteropServices.Architecture]::Arm64) { "aarch64-pc-windows-msvc" }
default { throw "Unsupported Windows architecture: $([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)" }
}
$startedAt = Get-Date
Push-Location $repositoryRoot
try {
Write-Step "Configuring $Configuration build"
Invoke-Checked -FilePath $cmake -ArgumentList @(
"-S", $repositoryRoot,
"-B", $buildPath,
"-G", "Ninja",
"-DCMAKE_BUILD_TYPE=$Configuration",
"-DCMAKE_CXX_COMPILER=clang++",
"-DCMAKE_CXX_COMPILER_TARGET=$compilerTarget",
"-DCMAKE_EXPORT_COMPILE_COMMANDS=ON",
"-DRUX_WERROR=ON",
"-DRUX_BUILD_TESTS=ON"
)
Write-Step "Building compiler and unit tests"
Invoke-Checked -FilePath $cmake -ArgumentList @("--build", $buildPath, "--config", $Configuration)
$runningOnWindows = [System.Environment]::OSVersion.Platform -eq [System.PlatformID]::Win32NT
$ruxFileName = if ($runningOnWindows) { "rux.exe" } else { "rux" }
$rux = Join-Path $repositoryRoot "Bin/$ruxFileName"
if (-not (Test-Path -LiteralPath $rux -PathType Leaf)) {
throw "Build completed without producing the expected compiler at '$rux'."
}
$elapsed = (Get-Date) - $startedAt
Write-Host ""
Write-Host ("Build passed in {0:mm\:ss}: {1}" -f $elapsed, $rux) -ForegroundColor Green
}
finally {
Pop-Location
}