-
Notifications
You must be signed in to change notification settings - Fork 24
/
build_common.ps1
118 lines (102 loc) · 3.75 KB
/
build_common.ps1
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
116
117
118
#
# Copyright (c) 2022-2023, NVIDIA CORPORATION. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
function SetupVS {
param(
[Parameter(Mandatory)]
[string]$Platform
)
#
# Find vswhere (installed with recent Visual Studio versions).
#
If ($vsWhere = Get-Command "vswhere.exe" -ErrorAction SilentlyContinue) {
$vsWhere = $vsWhere.Path
} ElseIf (Test-Path "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe") {
$vsWhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
}
Else {
Write-Error "vswhere not found. Aborting." -ErrorAction Stop
}
Write-Host "vswhere found at: $vsWhere" -ForegroundColor Yellow
#
# Get path to Visual Studio installation using vswhere.
#
$vsPath = &$vsWhere -latest -version "[16.0,18.0)" -products * `
-requires Microsoft.Component.MSBuild `
-property installationPath
If ([string]::IsNullOrEmpty("$vsPath")) {
Write-Error "Failed to find Visual Studio 2019 installation. Aborting." -ErrorAction Stop
}
Write-Host "Using Visual Studio installation at: ${vsPath}" -ForegroundColor Yellow
#
# Make sure the Visual Studio Command Prompt variables are set.
#
#If (Test-Path env:LIBPATH) {
# Write-Host "Visual Studio Command Prompt variables already set." -ForegroundColor Yellow
#} Else {
# Load VC vars
Push-Location "${vsPath}\VC\Auxiliary\Build"
cmd /c "vcvarsall.bat $Platform &set" |
ForEach-Object {
If ($_ -match "=") {
$v = $_.split("="); Set-Item -Force -Path "ENV:\$($v[0])" -Value "$($v[1])"
}
}
Pop-Location
Write-Host "Visual Studio Command Prompt variables set." -ForegroundColor Yellow
#}
}
function PerformBuild {
param(
[Parameter(Mandatory)]
[string]$Backend,
[Parameter(Mandatory)]
[string]$Platform,
[Parameter(Mandatory)]
[string]$BuildFlavour,
[Parameter(Mandatory)]
[string]$BuildSubDir,
[string]$BuildTarget
)
$CurrentDir = Get-Location
$OutputDir = [IO.Path]::Combine($CurrentDir, "_output")
$BuildDir = [IO.Path]::Combine($CurrentDir, $BuildSubDir)
Push-Location $CurrentDir
$mesonArgs = "setup --buildtype `"$BuildFlavour`" --backend `"$Backend`" `"$BuildSubDir`" --debug"
if ( $BuildTarget ) {
$mesonArgs += " -Denable_tests=`"$true`""
}
Start-Process "meson" -ArgumentList $mesonArgs -wait
Pop-Location
if ( $LASTEXITCODE -ne 0 ) {
Write-Output "Failed to run meson setup"
exit $LASTEXITCODE
}
# Note: Remove this if we modify Meson to include this copy step instead. For now only here so it only executes on build machines.
Copy-Item "Directory.Build.Props" -Destination $BuildDir
Push-Location $BuildDir
& meson compile
Pop-Location
if ( $LASTEXITCODE -ne 0 ) {
Write-Output "Failed to run msbuild step"
exit $LASTEXITCODE
}
}