Working With VisualStudio

From PostgreSQL wiki
Jump to: navigation, search

Pre-requisites

Visual Studio 2017

PostgreSQL can be built using the Visual C++ compiler suite from Microsoft. These compilers are present in Visual Studio.

After installing Visual Studio, open Visual Studio application and click on ‘Tools’ option and select ‘Get Tools and Features’.

01 Tools and Features.png

The following workloads need to be installed. Workloads required are .NET desktop development and Desktop development with C++.

02 Workloads.png

Apart from these workloads individual components like VC++ development toolkit and Windows Universal CRT SDK also need to be installed. (Switch to Individual Components tab to install)

03 Individual Components.png

It is advised to install both Windows 10 SDK and Windows 8.1 SDK as the build fails with Windows 10 SDK in some machines.

04 Windows SDK.png

Bison and Flex

Bison and Flex are aging unix utilities that help you write very fast parsers for almost arbitrary file formats

Bison and Flex are required to build from Git. Bison must be version 2.2 or later. Flex must be version 2.5.31 or later.

Both Bison and Flex are included in the msys tool suite, as part of the MinGW compiler suite.

The MinGW installer can be downloaded from https://osdn.net/projects/mingw/downloads/68260/mingw-get-setup.exe

After the installer is up and running, the following packages need to be selected.

Once it is done, include the path of bison and flex in Windows PATH variable. By default, they are under C:\MinGW\msys\1.0\bin

05 MinGW Installer.png

Perl

ActiveState Perl is required to run the build generation scripts.

MinGW or Cygwin Perl will not work.

Binaries can be downloaded from https://www.activestate.com

This also must be present in the Windows PATH variable.

06 ActiveState Perl.png

Build and Installation

Create a local repository to store source code for PostgreSQL.

Clone/download the source code from GitHub to the local repository using following command: git clone “https://github.com/postgres/postgres.git”


Under the local repository move to tools section: Postgres/src/tools/msvc .

Open the ‘Developer Command Prompt for VS 2017’(Using Windows Search) and change the directory path to msvc.

07 Developer Command Prompt.png

We use the following command to intiate the build. perl mkvcbuild.pl

If there are no errors in the console, solution file corresponding to the PostgreSQL code is generated.

08 Pgsql solution.png

Open solution file in Visual Studio, right click on the Solution ‘pgsql’ and select Build Solution to build.

09 Build Solution VS.png

Post successful build, run the install command to complete the installation for PostgreSQL, create local directory where the installed files should be placed and pass it to INSTALL command

10 Install Command.png

After installation, all the binaries would be available under bin folder.

11 Binaries.png

These binaries can be run through the command prompt.

Running regression tests

Redirect to path postgres/src/tools/msvc using command prompt

Run the vcregress check command to run all the SQL regression tests.

12 Regression Tests.png

To run a new perl test use the command vcregress taptest src\bin\<Test_Folder_name>

13 Perl Test.png