Skip to content

Commit 7d6ce96

Browse files
committed
feat(): Add functions for VS 2022 (#22)
Allows installation as well as usage of Visual Studio 2022.
1 parent bc1ea29 commit 7d6ce96

File tree

5 files changed

+124
-3
lines changed

5 files changed

+124
-3
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright (c) 2021, the WebKit for Windows project authors. Please see the
2+
# AUTHORS file for details. All rights reserved. Use of this source code is
3+
# governed by a BSD-style license that can be found in the LICENSE file.
4+
5+
<#
6+
.Synopsis
7+
Retrieves the location of a Visual Studio Build Tools 2022 installation.
8+
9+
.Description
10+
Interacts with Visual Studio Setup to find an instance of Visual Studio 2022.
11+
If not found the default path will be returned.
12+
13+
The path should be tested before using. No error checking is performed.
14+
#>
15+
Function Get-VSBuildTools2022InstallationPath {
16+
$installs = Get-VSSetupInstance;
17+
18+
foreach ($install in $installs) {
19+
if ($install.DisplayName -eq 'Visual Studio Build Tools 2022') {
20+
return $install.InstallationPath;
21+
}
22+
}
23+
24+
# If the Build Tools are not found, try Enterprise, then Professional, and
25+
# then Community.
26+
# These packages all contain the Build Tools as a component.
27+
foreach ($install in $installs) {
28+
if ($install.DisplayName -eq 'Visual Studio Enterprise 2022') {
29+
return $install.InstallationPath;
30+
}
31+
}
32+
33+
foreach ($install in $installs) {
34+
if ($install.DisplayName -eq 'Visual Studio Professional 2022') {
35+
return $install.InstallationPath;
36+
}
37+
}
38+
39+
foreach ($install in $installs) {
40+
if ($install.DisplayName -eq 'Visual Studio Community 2022') {
41+
return $install.InstallationPath;
42+
}
43+
}
44+
45+
# Return the default path
46+
return 'C:\Program Files\Microsoft Visual Studio\2022\BuildTools';
47+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright (c) 2021, the WebKit for Windows project authors. Please see the
2+
# AUTHORS file for details. All rights reserved. Use of this source code is
3+
# governed by a BSD-style license that can be found in the LICENSE file.
4+
5+
<#
6+
.Synopsis
7+
Retrieves the location for `vcvarsall.bat` within Visual Studio Build
8+
Tools 2022.
9+
10+
.Description
11+
Retrieves the location of a Visual Studio Build Tools 2022 install and
12+
appends the path to `vcvarsall.bat`.
13+
14+
The path should be tested before attempting to call the executable. No error
15+
checking is performed.
16+
#>
17+
Function Get-VSBuildTools2022VCVarsAllPath {
18+
return (Join-Path (Get-VSBuildTools2022InstallationPath) 'VC\Auxiliary\Build\vcvarsall.bat');
19+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright (c) 2021, the WebKit for Windows project authors. Please see the
2+
# AUTHORS file for details. All rights reserved. Use of this source code is
3+
# governed by a BSD-style license that can be found in the LICENSE file.
4+
5+
<#
6+
.Synopsis
7+
Installs Visual Studio Build Tools 2022.
8+
9+
.Description
10+
Downloads VS Build Tools and installs it silently on the host.
11+
12+
.Parameter InstallationPath
13+
The location to install to.
14+
#>
15+
Function Install-VSBuildTools2022 {
16+
Param(
17+
[Parameter()]
18+
[string[]] $workloads = @('Microsoft.VisualStudio.Workload.VCTools'),
19+
[Parameter()]
20+
[AllowNull()]
21+
[string] $installationPath
22+
)
23+
24+
$url = 'https://aka.ms/vs/17/release/vs_BuildTools.exe';
25+
26+
$options = @(
27+
'--quiet',
28+
'--norestart',
29+
'--nocache',
30+
'--wait'
31+
);
32+
33+
foreach ($workload in $workloads) {
34+
$options += @('--add', $workload);
35+
}
36+
37+
if ($installationPath) {
38+
$options += @('--installPath', $installationPath);
39+
}
40+
41+
Install-FromExe -Name 'VSBuildTools2022' -Url $url -Options $options -NoVerify;
42+
}

WebKitDev/Functions/Select-VSEnvironment.ps1

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,18 @@ Function Select-VSEnvironment {
2121
param(
2222
[ValidateSet('x86', 'amd64')]
2323
[string] $architecture = 'amd64',
24-
[ValidateSet('vs2015', 'vs2017', 'vs2019')]
24+
[ValidateSet('vs2015', 'vs2017', 'vs2019', 'vs2022')]
2525
[AllowNull()]
2626
[string] $version
2727
)
2828

2929
# Find version if not specified
3030
if (!$version) {
31-
if (Test-Path (Get-VSBuildTools2019InstallationPath)) {
31+
if (Test-Path (Get-VSBuildTools2022InstallationPath)) {
32+
Write-Host 'Found VS2022 Build Tools';
33+
$version = 'vs2022';
34+
}
35+
elseif (Test-Path (Get-VSBuildTools2019InstallationPath)) {
3236
Write-Host 'Found VS2019 Build Tools';
3337
$version = 'vs2019';
3438
}
@@ -49,7 +53,10 @@ Function Select-VSEnvironment {
4953
# Get vcvarsall.bat path
5054
$vcvars = $null;
5155

52-
if ($version -eq 'vs2019') {
56+
if ($version -eq 'vs2022') {
57+
$vcvars = Get-VSBuildTools2022VCVarsAllPath;
58+
}
59+
elseif ($version -eq 'vs2019') {
5360
$vcvars = Get-VSBuildTools2019VCVarsAllPath;
5461
}
5562
elseif ($version -eq 'vs2017') {

WebKitDev/WebKitDev.psd1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@
7878
'Functions/Get-VSBuildTools2017VCVarsAllPath.ps1',
7979
'Functions/Get-VSBuildTools2019InstallationPath.ps1',
8080
'Functions/Get-VSBuildTools2019VCVarsAllPath.ps1',
81+
'Functions/Get-VSBuildTools2022InstallationPath.ps1',
82+
'Functions/Get-VSBuildTools2022VCVarsAllPath.ps1',
8183
'Functions/Get-WebKitGitHubUrl.ps1',
8284
'Functions/Get-WebKitGitUrl.ps1',
8385
'Functions/Get-WebKitSVNSnapshotUrl.ps1',
@@ -113,6 +115,7 @@
113115
'Functions/Install-VSBuildTools2015.ps1',
114116
'Functions/Install-VSBuildTools2017.ps1',
115117
'Functions/Install-VSBuildTools2019.ps1',
118+
'Functions/Install-VSBuildTools2022.ps1',
116119
'Functions/Install-Windows10SDK.ps1',
117120
'Functions/Invoke-CMakeBuild.ps1',
118121
'Functions/Invoke-WebFileRequest.ps1',
@@ -135,6 +138,8 @@
135138
'Get-VSBuildTools2017VCVarsAllPath',
136139
'Get-VSBuildTools2019InstallationPath',
137140
'Get-VSBuildTools2019VCVarsAllPath',
141+
'Get-VSBuildTools2022InstallationPath',
142+
'Get-VSBuildTools2022VCVarsAllPath',
138143
'Get-WebKitGitHubUrl',
139144
'Get-WebKitGitUrl',
140145
'Get-WebKitSVNSnapshotUrl',
@@ -169,6 +174,7 @@
169174
'Install-VSBuildTools2015',
170175
'Install-VSBuildTools2017',
171176
'Install-VSBuildTools2019',
177+
'Install-VSBuildTools2022',
172178
'Install-Windows10SDK',
173179
'Install-Xampp',
174180
'Invoke-CMakeBuild',

0 commit comments

Comments
 (0)