Skip to content

Commit baef657

Browse files
committed
Add support for Visual Studio 2022 in build scripts
Documentation and any code paths related to VS are updated to keep the whole consistent. Similarly to 2017 and 2019, the version of VS and the version of nmake that we use to determine which code paths to use for the build are still inconsistent in their own way. Backpatch down to 10, so as buildfarm members are able to use this new version of Visual Studio on all the stable branches supported. Author: Hans Buschmann Discussion: https://postgr.es/m/1633101364685.39218@nidsa.net Backpatch-through: 10
1 parent d4f6a36 commit baef657

File tree

5 files changed

+91
-16
lines changed

5 files changed

+91
-16
lines changed

doc/src/sgml/install-windows.sgml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
<para>
2020
There are several different ways of building PostgreSQL on
2121
<productname>Windows</productname>. The simplest way to build with
22-
Microsoft tools is to install <productname>Visual Studio 2019</productname>
22+
Microsoft tools is to install <productname>Visual Studio 2022</productname>
2323
and use the included compiler. It is also possible to build with the full
24-
<productname>Microsoft Visual C++ 2013 to 2019</productname>.
24+
<productname>Microsoft Visual C++ 2013 to 2022</productname>.
2525
In some cases that requires the installation of the
2626
<productname>Windows SDK</productname> in addition to the compiler.
2727
</para>
@@ -68,7 +68,7 @@
6868
<productname>Microsoft Windows SDK</productname>. If you do not already have a
6969
<productname>Visual Studio</productname> environment set up, the easiest
7070
ways are to use the compilers from
71-
<productname>Visual Studio 2019</productname> or those in the
71+
<productname>Visual Studio 2022</productname> or those in the
7272
<productname>Windows SDK 10</productname>, which are both free downloads
7373
from Microsoft.
7474
</para>
@@ -77,15 +77,15 @@
7777
Both 32-bit and 64-bit builds are possible with the Microsoft Compiler suite.
7878
32-bit PostgreSQL builds are possible with
7979
<productname>Visual Studio 2013</productname> to
80-
<productname>Visual Studio 2019</productname>,
80+
<productname>Visual Studio 2022</productname>,
8181
as well as standalone Windows SDK releases 8.1a to 10.
8282
64-bit PostgreSQL builds are supported with
8383
<productname>Microsoft Windows SDK</productname> version 8.1a to 10 or
8484
<productname>Visual Studio 2013</productname> and above. Compilation
8585
is supported down to <productname>Windows 7</productname> and
8686
<productname>Windows Server 2008 R2 SP1</productname> when building with
8787
<productname>Visual Studio 2013</productname> to
88-
<productname>Visual Studio 2019</productname>.
88+
<productname>Visual Studio 2022</productname>.
8989
<!--
9090
For 2013 requirements:
9191
https://docs.microsoft.com/en-us/visualstudio/productinfo/vs2013-sysrequirements-vs
@@ -95,6 +95,8 @@
9595
https://docs.microsoft.com/en-us/visualstudio/productinfo/vs2017-system-requirements-vs
9696
For 2019 requirements:
9797
https://docs.microsoft.com/en-us/visualstudio/releases/2019/system-requirements
98+
For 2022 requirements:
99+
https://docs.microsoft.com/en-us/visualstudio/releases/2022/system-requirements
98100
-->
99101
</para>
100102

src/tools/msvc/MSBuildProject.pm

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,4 +505,29 @@ sub new
505505
return $self;
506506
}
507507

508+
package VC2022Project;
509+
510+
#
511+
# Package that encapsulates a Visual C++ 2022 project file
512+
#
513+
514+
use strict;
515+
use warnings;
516+
use base qw(MSBuildProject);
517+
518+
no warnings qw(redefine); ## no critic
519+
520+
sub new
521+
{
522+
my $classname = shift;
523+
my $self = $classname->SUPER::_new(@_);
524+
bless($self, $classname);
525+
526+
$self->{vcver} = '17.00';
527+
$self->{PlatformToolset} = 'v143';
528+
$self->{ToolsVersion} = '17.0';
529+
530+
return $self;
531+
}
532+
508533
1;

src/tools/msvc/README

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ MSVC build
44
==========
55

66
This directory contains the tools required to build PostgreSQL using
7-
Microsoft Visual Studio 2013 - 2019. This builds the whole backend, not just
7+
Microsoft Visual Studio 2013 - 2022. This builds the whole backend, not just
88
the libpq frontend library. For more information, see the documentation
99
chapter "Installation on Windows" and the description below.
1010

@@ -89,11 +89,11 @@ These configuration arguments are passed over to Mkvcbuild::mkvcbuild
8989
(Mkvcbuild.pm) which creates the Visual Studio project and solution files.
9090
It does this by using VSObjectFactory::CreateSolution to create an object
9191
implementing the Solution interface (this could be either VS2013Solution,
92-
VS2015Solution, VS2017Solution or VS2019Solution, all in Solution.pm,
93-
depending on the user's build environment) and adding objects implementing
94-
the corresponding Project interface (VC2013Project, VC2015Project,
95-
VC2017Project or VC2019Project from MSBuildProject.pm) to it.
96-
When Solution::Save is called, the implementations of Solution and Project
97-
save their content in the appropriate format.
92+
VS2015Solution, VS2017Solution, VS2019Solution or VS2022Solution, all in
93+
Solution.pm, depending on the user's build environment) and adding objects
94+
implementing the corresponding Project interface (VC2013Project,
95+
VC2015Project, VC2017Project, VC2019Project or VC2022Project from
96+
MSBuildProject.pm) to it. When Solution::Save is called, the implementations
97+
of Solution and Project save their content in the appropriate format.
9898
The final step of starting the appropriate build program (msbuild) is
9999
performed in build.pl again.

src/tools/msvc/Solution.pm

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,6 +1292,34 @@ sub new
12921292
return $self;
12931293
}
12941294

1295+
package VS2022Solution;
1296+
1297+
#
1298+
# Package that encapsulates a Visual Studio 2022 solution file
1299+
#
1300+
1301+
use Carp;
1302+
use strict;
1303+
use warnings;
1304+
use base qw(Solution);
1305+
1306+
no warnings qw(redefine); ## no critic
1307+
1308+
sub new
1309+
{
1310+
my $classname = shift;
1311+
my $self = $classname->SUPER::_new(@_);
1312+
bless($self, $classname);
1313+
1314+
$self->{solutionFileVersion} = '12.00';
1315+
$self->{vcver} = '17.00';
1316+
$self->{visualStudioName} = 'Visual Studio 2022';
1317+
$self->{VisualStudioVersion} = '17.0.31903.59';
1318+
$self->{MinimumVisualStudioVersion} = '10.0.40219.1';
1319+
1320+
return $self;
1321+
}
1322+
12951323
sub GetAdditionalHeaders
12961324
{
12971325
my ($self, $f) = @_;

src/tools/msvc/VSObjectFactory.pm

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ sub CreateSolution
5858
{
5959
return new VS2019Solution(@_);
6060
}
61+
62+
# The version of nmake bundled in Visual Studio 2022 is greater
63+
# than 14.30 and less than 14.40. And the version number is
64+
# actually 17.00.
65+
elsif (
66+
($visualStudioVersion ge '14.30' && $visualStudioVersion lt '14.40')
67+
|| $visualStudioVersion eq '17.00')
68+
{
69+
return new VS2022Solution(@_);
70+
}
6171
else
6272
{
6373
croak
@@ -102,6 +112,16 @@ sub CreateProject
102112
{
103113
return new VC2019Project(@_);
104114
}
115+
116+
# The version of nmake bundled in Visual Studio 2022 is greater
117+
# than 14.30 and less than 14.40. And the version number is
118+
# actually 17.00.
119+
elsif (
120+
($visualStudioVersion ge '14.30' && $visualStudioVersion lt '14.40')
121+
|| $visualStudioVersion eq '17.00')
122+
{
123+
return new VC2022Project(@_);
124+
}
105125
else
106126
{
107127
croak
@@ -131,7 +151,7 @@ sub DetermineVisualStudioVersion
131151
else
132152
{
133153
# fake version
134-
return '16.00';
154+
return '17.00';
135155
}
136156
}
137157

@@ -140,13 +160,13 @@ sub _GetVisualStudioVersion
140160
my ($major, $minor) = @_;
141161

142162
# The major visual studio that is supported has nmake
143-
# version <= 14.30, so stick with it as the latest version
163+
# version <= 14.40, so stick with it as the latest version
144164
# if bumping on something even newer.
145-
if ($major >= 14 && $minor >= 30)
165+
if ($major >= 14 && $minor >= 40)
146166
{
147167
carp
148168
"The determined version of Visual Studio is newer than the latest supported version. Returning the latest supported version instead.";
149-
return '14.20';
169+
return '14.30';
150170
}
151171
elsif ($major < 12)
152172
{

0 commit comments

Comments
 (0)