Skip to content

Commit b2265d3

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 875e02c commit b2265d3

File tree

5 files changed

+91
-16
lines changed

5 files changed

+91
-16
lines changed

doc/src/sgml/install-windows.sgml

+7-5
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
<para>
2121
There are several different ways of building PostgreSQL on
2222
<productname>Windows</productname>. The simplest way to build with
23-
Microsoft tools is to install <productname>Visual Studio 2019</productname>
23+
Microsoft tools is to install <productname>Visual Studio 2022</productname>
2424
and use the included compiler. It is also possible to build with the full
25-
<productname>Microsoft Visual C++ 2013 to 2019</productname>.
25+
<productname>Microsoft Visual C++ 2013 to 2022</productname>.
2626
In some cases that requires the installation of the
2727
<productname>Windows SDK</productname> in addition to the compiler.
2828
</para>
@@ -69,7 +69,7 @@
6969
<productname>Microsoft Windows SDK</productname>. If you do not already have a
7070
<productname>Visual Studio</productname> environment set up, the easiest
7171
ways are to use the compilers from
72-
<productname>Visual Studio 2019</productname> or those in the
72+
<productname>Visual Studio 2022</productname> or those in the
7373
<productname>Windows SDK 10</productname>, which are both free downloads
7474
from Microsoft.
7575
</para>
@@ -78,15 +78,15 @@
7878
Both 32-bit and 64-bit builds are possible with the Microsoft Compiler suite.
7979
32-bit PostgreSQL builds are possible with
8080
<productname>Visual Studio 2013</productname> to
81-
<productname>Visual Studio 2019</productname>,
81+
<productname>Visual Studio 2022</productname>,
8282
as well as standalone Windows SDK releases 8.1a to 10.
8383
64-bit PostgreSQL builds are supported with
8484
<productname>Microsoft Windows SDK</productname> version 8.1a to 10 or
8585
<productname>Visual Studio 2013</productname> and above. Compilation
8686
is supported down to <productname>Windows 7</productname> and
8787
<productname>Windows Server 2008 R2 SP1</productname> when building with
8888
<productname>Visual Studio 2013</productname> to
89-
<productname>Visual Studio 2019</productname>.
89+
<productname>Visual Studio 2022</productname>.
9090
<!--
9191
For 2013 requirements:
9292
https://docs.microsoft.com/en-us/visualstudio/productinfo/vs2013-sysrequirements-vs
@@ -96,6 +96,8 @@
9696
https://docs.microsoft.com/en-us/visualstudio/productinfo/vs2017-system-requirements-vs
9797
For 2019 requirements:
9898
https://docs.microsoft.com/en-us/visualstudio/releases/2019/system-requirements
99+
For 2022 requirements:
100+
https://docs.microsoft.com/en-us/visualstudio/releases/2022/system-requirements
99101
-->
100102
</para>
101103

src/tools/msvc/MSBuildProject.pm

+25
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

+7-7
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

+28
Original file line numberDiff line numberDiff line change
@@ -1316,6 +1316,34 @@ sub new
13161316
return $self;
13171317
}
13181318

1319+
package VS2022Solution;
1320+
1321+
#
1322+
# Package that encapsulates a Visual Studio 2022 solution file
1323+
#
1324+
1325+
use Carp;
1326+
use strict;
1327+
use warnings;
1328+
use base qw(Solution);
1329+
1330+
no warnings qw(redefine); ## no critic
1331+
1332+
sub new
1333+
{
1334+
my $classname = shift;
1335+
my $self = $classname->SUPER::_new(@_);
1336+
bless($self, $classname);
1337+
1338+
$self->{solutionFileVersion} = '12.00';
1339+
$self->{vcver} = '17.00';
1340+
$self->{visualStudioName} = 'Visual Studio 2022';
1341+
$self->{VisualStudioVersion} = '17.0.31903.59';
1342+
$self->{MinimumVisualStudioVersion} = '10.0.40219.1';
1343+
1344+
return $self;
1345+
}
1346+
13191347
sub GetAdditionalHeaders
13201348
{
13211349
my ($self, $f) = @_;

src/tools/msvc/VSObjectFactory.pm

+24-4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ sub CreateSolution
6161
{
6262
return new VS2019Solution(@_);
6363
}
64+
65+
# The version of nmake bundled in Visual Studio 2022 is greater
66+
# than 14.30 and less than 14.40. And the version number is
67+
# actually 17.00.
68+
elsif (
69+
($visualStudioVersion ge '14.30' && $visualStudioVersion lt '14.40')
70+
|| $visualStudioVersion eq '17.00')
71+
{
72+
return new VS2022Solution(@_);
73+
}
6474
else
6575
{
6676
croak
@@ -105,6 +115,16 @@ sub CreateProject
105115
{
106116
return new VC2019Project(@_);
107117
}
118+
119+
# The version of nmake bundled in Visual Studio 2022 is greater
120+
# than 14.30 and less than 14.40. And the version number is
121+
# actually 17.00.
122+
elsif (
123+
($visualStudioVersion ge '14.30' && $visualStudioVersion lt '14.40')
124+
|| $visualStudioVersion eq '17.00')
125+
{
126+
return new VC2022Project(@_);
127+
}
108128
else
109129
{
110130
croak
@@ -134,7 +154,7 @@ sub DetermineVisualStudioVersion
134154
else
135155
{
136156
# fake version
137-
return '16.00';
157+
return '17.00';
138158
}
139159
}
140160

@@ -143,13 +163,13 @@ sub _GetVisualStudioVersion
143163
my ($major, $minor) = @_;
144164

145165
# The major visual studio that is supported has nmake
146-
# version <= 14.30, so stick with it as the latest version
166+
# version <= 14.40, so stick with it as the latest version
147167
# if bumping on something even newer.
148-
if ($major >= 14 && $minor >= 30)
168+
if ($major >= 14 && $minor >= 40)
149169
{
150170
carp
151171
"The determined version of Visual Studio is newer than the latest supported version. Returning the latest supported version instead.";
152-
return '14.20';
172+
return '14.30';
153173
}
154174
elsif ($major < 12)
155175
{

0 commit comments

Comments
 (0)