postgresql/src/tools/msvc
Thomas Munro 1bf47d8977 Check for STATUS_DELETE_PENDING on Windows.
1.  Update our open() wrapper to check for NT's STATUS_DELETE_PENDING
and translate it to Unix-like errors.  This is done with
RtlGetLastNtStatus(), which is dynamically loaded from ntdll.  A new
file win32ntdll.c centralizes lookup of NT functions, in case we decide
to add more in the future.

2.  Remove non-working code that was trying to do something similar for
stat(), and just reuse the open() wrapper code.  As a side effect,
stat() also gains resilience against "sharing violation" errors.

3.  Since stat() is used very early in process startup, remove the
requirement that the Win32 signal event has been created before
pgwin32_open_handle() is reached.  Instead, teach pg_usleep() to fall
back to a non-interruptible sleep if reached before the signal event is
available.

This could be back-patched, but for now it's in master only.  The
problem has apparently been with us for a long time and generated only a
few complaints.  Proposed patches trigger it more often, which led to
this investigation and fix.

Reviewed-by: Andres Freund <andres@anarazel.de>
Reviewed-by: Alexander Lakhin <exclusion@gmail.com>
Reviewed-by: Juan José Santamaría Flecha <juanjo.santamaria@gmail.com>
Discussion: https://postgr.es/m/CA%2BhUKGJz_pZTF9mckn6XgSv69%2BjGwdgLkxZ6b3NWGLBCVjqUZA%40mail.gmail.com
(cherry picked from commit e2f0f8ed25)

Author: Thomas Munro <tmunro@postgresql.org>
Author: Alexandra Wang <alexandra.wang.oss@gmail.com>
2024-11-08 09:34:00 +10:30
..
dummylib Add a copyright notice to perl files lacking one. 2021-05-07 10:56:14 -04:00
.gitignore Ignore config.pl and buildenv.pl in src/tools/msvc. 2014-05-12 14:24:18 -04:00
build.bat Allow MSVC .bat wrappers to be called from anywhere 2022-01-07 16:14:04 -05:00
build.pl Add a copyright notice to perl files lacking one. 2021-05-07 10:56:14 -04:00
clean.bat Allow clean.bat to be run from anywhere 2022-01-20 10:20:40 -05:00
config_default.pl Add support for LZ4 build in MSVC scripts 2021-05-11 10:43:05 +09:00
ecpg_regression.proj Fix MSVC recipe for ecpg regression tests, redux. 2024-04-19 01:07:41 -04:00
gendef.pl Add a copyright notice to perl files lacking one. 2021-05-07 10:56:14 -04:00
install.bat Allow MSVC .bat wrappers to be called from anywhere 2022-01-07 16:14:04 -05:00
install.pl Add a copyright notice to perl files lacking one. 2021-05-07 10:56:14 -04:00
Install.pm Initial pgindent and pgperltidy run for v14. 2021-05-12 13:14:10 -04:00
mkvcbuild.pl Add a copyright notice to perl files lacking one. 2021-05-07 10:56:14 -04:00
Mkvcbuild.pm Check for STATUS_DELETE_PENDING on Windows. 2024-11-08 09:34:00 +10:30
MSBuildProject.pm Add support for Visual Studio 2022 in build scripts 2021-11-24 13:03:55 +09:00
pgbison.bat Allow MSVC .bat wrappers to be called from anywhere 2022-01-07 16:14:04 -05:00
pgbison.pl Remove extraneous newlines added by perl copyright patch 2021-05-07 11:37:37 -04:00
pgflex.bat Allow MSVC .bat wrappers to be called from anywhere 2022-01-07 16:14:04 -05:00
pgflex.pl Remove extraneous newlines added by perl copyright patch 2021-05-07 11:37:37 -04:00
Project.pm Add a copyright notice to perl files lacking one. 2021-05-07 10:56:14 -04:00
README Add support for Visual Studio 2022 in build scripts 2021-11-24 13:03:55 +09:00
Solution.pm Fix building with MSVC for TLS session disabling 2024-07-26 19:09:54 +02:00
vcregress.bat Allow MSVC .bat wrappers to be called from anywhere 2022-01-07 16:14:04 -05:00
vcregress.pl Don't force SQL_ASCII/no-locale for installcheck in vcregress.pl 2023-02-26 06:54:58 -05:00
VSObjectFactory.pm Add support for Visual Studio 2022 in build scripts 2021-11-24 13:03:55 +09:00

src/tools/msvc/README

MSVC build
==========

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


Notes about Visual Studio Express
---------------------------------
To build PostgreSQL using Visual Studio Express, the Microsoft Windows SDK
has to be installed. Since this is not included in the product
originally, extra steps are needed to make it work.

First, download and install a supported version of the Microsoft Windows SDK
from www.microsoft.com (v8.1a or greater).

Locate the files vcprojectengine.dll.express.config and
vcprojectengine.dll.config in the vc\vcpackages directory of
the Visual C++ Express installation. In these files, add the paths
to the Platform SDK to the Include, Library and Path tags. Be sure
to add them to the beginning of the list.

This should work for both GUI and commandline builds, but a restart
may be necessary.

If you are using a recent version of the Microsoft Windows SDK that includes
the compilers and build tools you probably don't even need Visual Studio
Express to build PostgreSQL.


Structure of the build tools
----------------------------
The tools for building PostgreSQL using Microsoft Visual Studio currently
consist of the following files:

- Configuration files -
config_default.pl      default configuration arguments

A typical build environment has two more files, buildenv.pl and config.pl
that contain the user's build environment settings and configuration
arguments.


- User tools -
build.pl               tool to build the binaries
clean.bat              batch file for cleaning up generated files
install.pl             tool to install the generated files
mkvcbuild.pl           tool to generate the Visual Studio build files
vcregress.pl           tool to run the regression tests


- Internal tools -
gendef.pl              internal tool to generate .DEF files
pgbison.pl             internal tool to process .y files using bison
pgflex.pl              internal tool to process .l files using flex

Many of those .pl files also have a corresponding .bat-wrapper that doesn't
contain any additional logic.


- Internal modules -
Install.pm             module containing the install logic
Mkvcbuild.pm           module containing the code to generate the Visual
                       Studio build (project/solution) files
MSBuildProject.pm      module containing the code to generate MSBuild based
                       project files (Visual Studio 2013 or greater)
Project.pm             module containing the common code to generate the
                       Visual Studio project files. Also provides the
                       common interface of all project file generators
Solution.pm            module containing the code to generate the Visual
                       Studio solution files.
VSObjectFactory.pm     factory module providing the code to create the
                       appropriate project/solution files for the current
                       environment


Description of the internals of the Visual Studio build process
---------------------------------------------------------------
By typing 'build' the user starts the build.bat wrapper which simply passes
its arguments to build.pl.
In build.pl the user's buildenv.pl is used to set up the build environment
(i. e. path to bison and flex). In addition his config.pl file is merged into
config_default.pl to create the configuration arguments.
These configuration arguments are passed over to Mkvcbuild::mkvcbuild
(Mkvcbuild.pm) which creates the Visual Studio project and solution files.
It does this by using VSObjectFactory::CreateSolution to create an object
implementing the Solution interface (this could be either VS2013Solution,
VS2015Solution, VS2017Solution, VS2019Solution or VS2022Solution, all in
Solution.pm, depending on the user's build environment) and adding objects
implementing the corresponding Project interface (VC2013Project,
VC2015Project, VC2017Project, VC2019Project or VC2022Project from
MSBuildProject.pm) to it. When Solution::Save is called, the implementations
of Solution and Project save their content in the appropriate format.
The final step of starting the appropriate build program (msbuild) is
performed in build.pl again.