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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
# vim: set sts=2 sw=2 et :
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;
. "$PSScriptRoot\common.ps1"
# Disable progress bars, which are super slow especially Invoke-WebRequest
# which updates the progress bar for each byte
$ProgressPreference = 'SilentlyContinue'
$cmake_req = '3.10.2'
$git_req = '2.0' # placeholder
$python_req = '3.7'
$wix_req = '3.0' # placeholder
$vs2019_url = 'https://aka.ms/vs/16/release/vs_buildtools.exe'
$vs2022_url = 'https://aka.ms/vs/17/release/vs_buildtools.exe'
$choco_url = 'https://chocolatey.org/install.ps1'
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
function Check-VS {
if (!(Test-Path $vswhere)) {
return $false
}
# Check whether we have VS 2019 or newer with the Windows 11 SDK installed
$json = (& $vswhere -utf8 -version 16 -nologo -format json -latest -all -prerelease -requires '*Windows11*')
if ($json) {
return $true
}
# Check whether we have a VS 2019 or newer install at all
$json = (& $vswhere -utf8 -version 16 -nologo -format json -latest -all -prerelease)
if (!$json) {
return $false
}
$latest = ConvertFrom-Json -InputObject "$json"
# VS newer than 2019, nothing special needed
if (!($latest.installationVersion -clike "16.*")) {
return $true
}
$confirm = Read-Host "Need Windows 11 SDK with Visual Studio 2019, do you want to install it right now? [Y/n] "
if ($confirm -eq 'n') {
Write-Host "Please run the Visual Studio installer, click 'modify' and install the 'Windows 11 SDK' workload"
return $true
}
& $latest.properties.setupEngineFilePath modify `
--productId $latest.productId `
--channelId $latest.channelId `
--add Microsoft.VisualStudio.Component.Windows11SDK.22000 `
--quiet --nocache --norestart
return $true
}
function Install-VS {
$version = ''
$vs_arglist = '--wait --quiet --norestart --nocache --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended'
while (1) {
$version = Read-Host "Pick the Visual Studio version: 2019 or 2022? [2019/2022] "
if ($version -eq '2022') {
$vs_url = $vs2022_url
break
} elseif ($version -eq '2019') {
$vs_url = $vs2019_url
$vs_arglist += ' --add Microsoft.VisualStudio.Component.Windows11SDK.22000'
break
} elseif ($version -eq 'q') {
return $true
} else {
Write-Host "Selected invalid version $version, retry or press 'q' to quit"
}
}
Get-Date
Write-Host "Downloading Visual Studio $version build tools"
Invoke-WebRequest -Uri $vs_url -OutFile "$env:TEMP\vs_buildtools.exe"
Get-Date
Write-Host "Installing Visual Studio $version build tools"
Start-Process -NoNewWindow -Wait "$env:TEMP\vs_buildtools.exe" -ArgumentList $vs_arglist
if (!$?) {
Write-Host "Failed to install Visual Studio build tools"
return $false
}
Remove-Item "$env:TEMP\vs_buildtools.exe" -Force
return $true
}
Get-Date
$choco_psm = "$env:ProgramData\chocolatey\helpers\chocolateyProfile.psm1"
if (Test-Path $choco_psm) {
Import-Module $choco_psm
Update-SessionEnvironment
Write-Host "Found Chocolatey, upgrading it first"
choco upgrade -y chocolatey
} else {
Write-Host "Installing Chocolatey"
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString($choco_url))
Import-Module $choco_psm
Update-SessionEnvironment
}
choco feature enable --name="'useEnhancedExitCodes'"
choco list vcredist140
if (!$?) {
Write-Host "Installing vcredist140"
choco install -y vcredist140
}
if (!(Is-Newer 'cmake' $cmake_req)) {
Write-Host "CMake >= $cmake_req not found, installing..."
choco install -y cmake --installargs 'ADD_CMAKE_TO_PATH=System'
}
if (!(Is-Newer 'git' $git_req)) {
Write-Host "git >= $git_req not found, installing..."
choco install -y git --params "/NoAutoCrlf /NoCredentialManager /NoShellHereIntegration /NoGuiHereIntegration /NoShellIntegration"
}
if (!(Is-Newer 'git-lfs' $git_req)) {
Write-Host "git-lfs not found, installing..."
choco install -y git-lfs
}
if (!(Is-Newer 'py' $python_req)) {
Write-Host "Python >= $python_req not found, installing..."
choco install -y python3
}
if (!(Is-Newer "$env:WIX\bin\light" $wix_req)) {
Write-Host "WiX >= $wix_req not found, installing..."
choco install -y wixtoolset
}
$MSYS2_Dir = (Get-MSYS2)
if (!$MSYS2_Dir) {
Write-Host "MSYS2 not found, installing..."
choco install msys2 --params "/InstallDir:C:\msys64"
$MSYS2_Dir = "C:\msys64"
}
& $MSYS2_Dir\usr\bin\bash -lc 'pacman -Qq winpty &>/dev/null'
if (!$?) {
& $MSYS2_Dir\usr\bin\bash -lc 'pacman --noconfirm -S --needed winpty'
}
if (!((Get-Content "$MSYS2_Dir\ucrt64.ini") -clike "MSYS2_PATH_TYPE=inherit")) {
Add-Content "$MSYS2_Dir\ucrt64.ini" "`nMSYS2_PATH_TYPE=inherit"
}
Copy-Item "$PSScriptRoot\..\data\msys2\profile.d\aliases.sh" -Destination "$MSYS2_Dir\etc\profile.d"
if (!(Check-VS)) {
$confirm = Read-Host "Visual Studio 2019 or 2022 not found, do you want to Visual Studio build tools now? [Y/n] "
if ($confirm -ne 'n' -and !(Install-VS)) {
exit 1
}
}
Write-Host "Windows Dependencies Installation Completed"
|