Skip to content

Commit 1061e41

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 54619a2 commit 1061e41

File tree

5 files changed

+87
-14
lines changed

5 files changed

+87
-14
lines changed

doc/src/sgml/install-windows.sgml

Lines changed: 5 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++ 2005 to 2019</productname>.
24+
<productname>Microsoft Visual C++ 2005 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>
@@ -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,7 +78,7 @@
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 2005</productname> to
81-
<productname>Visual Studio 2019</productname>,
81+
<productname>Visual Studio 2022</productname>,
8282
as well as standalone Windows SDK releases 6.0 to 10.
8383
64-bit PostgreSQL builds are supported with
8484
<productname>Microsoft Windows SDK</productname> version 6.0a to 10 or
@@ -90,7 +90,7 @@
9090
<productname>Visual Studio 2015</productname> is supported down to
9191
<productname>Windows Vista</productname> and <productname>Windows Server 2008</productname>.
9292
Building with <productname>Visual Studio 2017</productname> to
93-
<productname>Visual Studio 2019</productname> is supported
93+
<productname>Visual Studio 2022</productname> is supported
9494
down to <productname>Windows 7 SP1</productname> and <productname>Windows Server 2008 R2 SP1</productname>.
9595
</para>
9696

src/tools/msvc/MSBuildProject.pm

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,4 +573,29 @@ sub new
573573
return $self;
574574
}
575575

576+
package VC2022Project;
577+
578+
#
579+
# Package that encapsulates a Visual C++ 2022 project file
580+
#
581+
582+
use strict;
583+
use warnings;
584+
use base qw(VC2012Project);
585+
586+
no warnings qw(redefine); ## no critic
587+
588+
sub new
589+
{
590+
my $classname = shift;
591+
my $self = $classname->SUPER::_new(@_);
592+
bless($self, $classname);
593+
594+
$self->{vcver} = '17.00';
595+
$self->{PlatformToolset} = 'v143';
596+
$self->{ToolsVersion} = '17.0';
597+
598+
return $self;
599+
}
600+
576601
1;

src/tools/msvc/README

Lines changed: 6 additions & 6 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 2005 - 2019. This builds the whole backend, not just
7+
Microsoft Visual Studio 2005 - 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

@@ -92,13 +92,13 @@ These configuration arguments are passed over to Mkvcbuild::mkvcbuild
9292
(Mkvcbuild.pm) which creates the Visual Studio project and solution files.
9393
It does this by using VSObjectFactory::CreateSolution to create an object
9494
implementing the Solution interface (this could be either a VS2005Solution,
95-
a VS2008Solution, a VS2010Solution or a VS2012Solution or a VS2013Solution,
96-
or a VS2015Solution or a VS2017Solution or a VS2019Solution, all in
97-
Solution.pm, depending on the user's build environment) and adding objects
95+
a VS2008Solution, a VS2010Solution, a VS2012Solution, a VS2013Solution,
96+
a VS2015Solution, a VS2017Solution, a VS2019Solution or a VS2022Solution, all
97+
in Solution.pm, depending on the user's build environment) and adding objects
9898
implementing the corresponding Project interface (VC2005Project or
9999
VC2008Project from VCBuildProject.pm or VC2010Project or VC2012Project or
100-
VC2013Project or VC2015Project or VC2017Project or VC2019Project from
101-
MSBuildProject.pm) to it.
100+
VC2013Project or VC2015Project or VC2017Project or VC2019Project or
101+
VC2022Project from MSBuildProject.pm) to it.
102102
When Solution::Save is called, the implementations of Solution and Project
103103
save their content in the appropriate format.
104104
The final step of starting the appropriate build program (msbuild or vcbuild)

src/tools/msvc/Solution.pm

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,34 @@ sub new
10861086
return $self;
10871087
}
10881088

1089+
package VS2022Solution;
1090+
1091+
#
1092+
# Package that encapsulates a Visual Studio 2022 solution file
1093+
#
1094+
1095+
use Carp;
1096+
use strict;
1097+
use warnings;
1098+
use base qw(Solution);
1099+
1100+
no warnings qw(redefine); ## no critic
1101+
1102+
sub new
1103+
{
1104+
my $classname = shift;
1105+
my $self = $classname->SUPER::_new(@_);
1106+
bless($self, $classname);
1107+
1108+
$self->{solutionFileVersion} = '12.00';
1109+
$self->{vcver} = '17.00';
1110+
$self->{visualStudioName} = 'Visual Studio 2022';
1111+
$self->{VisualStudioVersion} = '17.0.31903.59';
1112+
$self->{MinimumVisualStudioVersion} = '10.0.40219.1';
1113+
1114+
return $self;
1115+
}
1116+
10891117
sub GetAdditionalHeaders
10901118
{
10911119
my ($self, $f) = @_;

src/tools/msvc/VSObjectFactory.pm

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ sub CreateSolution
7575
{
7676
return new VS2019Solution(@_);
7777
}
78+
79+
# The version of nmake bundled in Visual Studio 2022 is greater
80+
# than 14.30 and less than 14.40. And the version number is
81+
# actually 17.00.
82+
elsif (
83+
($visualStudioVersion ge '14.30' && $visualStudioVersion lt '14.40')
84+
|| $visualStudioVersion eq '17.00')
85+
{
86+
return new VS2022Solution(@_);
87+
}
7888
else
7989
{
8090
croak
@@ -135,6 +145,16 @@ sub CreateProject
135145
{
136146
return new VC2019Project(@_);
137147
}
148+
149+
# The version of nmake bundled in Visual Studio 2022 is greater
150+
# than 14.30 and less than 14.40. And the version number is
151+
# actually 17.00.
152+
elsif (
153+
($visualStudioVersion ge '14.30' && $visualStudioVersion lt '14.40')
154+
|| $visualStudioVersion eq '17.00')
155+
{
156+
return new VC2022Project(@_);
157+
}
138158
else
139159
{
140160
croak
@@ -166,13 +186,13 @@ sub _GetVisualStudioVersion
166186
my ($major, $minor) = @_;
167187

168188
# The major visual studio that is supported has nmake
169-
# version <= 14.30, so stick with it as the latest version
189+
# version <= 14.40, so stick with it as the latest version
170190
# if bumping on something even newer.
171-
if ($major >= 14 && $minor >= 30)
191+
if ($major >= 14 && $minor >= 40)
172192
{
173193
carp
174194
"The determined version of Visual Studio is newer than the latest supported version. Returning the latest supported version instead.";
175-
return '14.20';
195+
return '14.30';
176196
}
177197
elsif ($major < 6)
178198
{

0 commit comments

Comments
 (0)