Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d993e0f

Browse files
committed
Add support for OpenSSL 1.1.0 and newer versions in MSVC scripts
Up to now, the MSVC build scripts are able to support only one fixed version of OpenSSL, and they lacked logic to detect the version of OpenSSL a given compilation of Postgres is linking to (currently 1.0.2, the latest LTS of upstream which will be EOL'd at the end of 2019). This commit adds more logic to detect the version of OpenSSL used by a build and makes use of it to add support for compilation with OpenSSL 1.1.0 which requires a new set of compilation flags to work properly. The supported OpenSSL installers have changed their library layer with various library renames with the upgrade to 1.1.0, making the logic a bit more complicated. The scripts are now able to adapt to the new world order. Reported-by: Sergey Pashkov Author: Juan José Santamaría Flecha, Michael Paquier Reviewed-by: Álvaro Herrera Discussion: https://postgr.es/m/15789-8fc75dea3c5a17c8@postgresql.org
1 parent ce59b75 commit d993e0f

File tree

1 file changed

+106
-15
lines changed

1 file changed

+106
-15
lines changed

src/tools/msvc/Solution.pm

Lines changed: 106 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,34 @@ sub copyFile
114114
return;
115115
}
116116

117+
# Fetch version of OpenSSL based on a parsing of the command shipped with
118+
# the installer this build is linking to. This returns as result an array
119+
# made of the three first digits of the OpenSSL version, which is enough
120+
# to decide which options to apply depending on the version of OpenSSL
121+
# linking with.
122+
sub GetOpenSSLVersion
123+
{
124+
my $self = shift;
125+
126+
# Attempt to get OpenSSL version and location. This assumes that
127+
# openssl.exe is in the specified directory.
128+
my $opensslcmd =
129+
$self->{options}->{openssl} . "\\bin\\openssl.exe version 2>&1";
130+
my $sslout = `$opensslcmd`;
131+
132+
$? >> 8 == 0
133+
or croak
134+
"Unable to determine OpenSSL version: The openssl.exe command wasn't found.";
135+
136+
if ($sslout =~ /(\d+)\.(\d+)\.(\d+)(\D)/m)
137+
{
138+
return ($1, $2, $3);
139+
}
140+
141+
croak
142+
"Unable to determine OpenSSL version: The openssl.exe version could not be determined.";
143+
}
144+
117145
sub GenerateFiles
118146
{
119147
my $self = shift;
@@ -168,10 +196,9 @@ sub GenerateFiles
168196
print $o "#ifndef IGNORE_CONFIGURED_SETTINGS\n";
169197
print $o "#define USE_ASSERT_CHECKING 1\n"
170198
if ($self->{options}->{asserts});
171-
print $o "#define USE_LDAP 1\n" if ($self->{options}->{ldap});
172-
print $o "#define HAVE_LIBZ 1\n" if ($self->{options}->{zlib});
173-
print $o "#define USE_OPENSSL 1\n" if ($self->{options}->{openssl});
174-
print $o "#define ENABLE_NLS 1\n" if ($self->{options}->{nls});
199+
print $o "#define USE_LDAP 1\n" if ($self->{options}->{ldap});
200+
print $o "#define HAVE_LIBZ 1\n" if ($self->{options}->{zlib});
201+
print $o "#define ENABLE_NLS 1\n" if ($self->{options}->{nls});
175202

176203
print $o "#define BLCKSZ ", 1024 * $self->{options}->{blocksize},
177204
"\n";
@@ -219,6 +246,21 @@ sub GenerateFiles
219246
{
220247
print $o "#define ENABLE_GSS 1\n";
221248
}
249+
if ($self->{options}->{openssl})
250+
{
251+
print $o "#define USE_OPENSSL 1\n";
252+
253+
my ($digit1, $digit2, $digit3) = $self->GetOpenSSLVersion();
254+
255+
# More symbols are needed with OpenSSL 1.1.0 and above.
256+
if ($digit1 >= '1' && $digit2 >= '1' && $digit3 >= '0')
257+
{
258+
print $o "#define HAVE_ASN1_STRING_GET0_DATA 1\n";
259+
print $o "#define HAVE_BIO_GET_DATA 1\n";
260+
print $o "#define HAVE_BIO_METH_NEW 1\n";
261+
print $o "#define HAVE_OPENSSL_INIT_SSL 1\n";
262+
}
263+
}
222264
if ($self->{options}->{icu})
223265
{
224266
print $o "#define USE_ICU 1\n";
@@ -613,21 +655,70 @@ sub AddProject
613655
if ($self->{options}->{openssl})
614656
{
615657
$proj->AddIncludeDir($self->{options}->{openssl} . '\include');
616-
if (-e "$self->{options}->{openssl}/lib/VC/ssleay32MD.lib")
658+
my ($digit1, $digit2, $digit3) = $self->GetOpenSSLVersion();
659+
660+
# Starting at version 1.1.0 the OpenSSL installers have
661+
# changed their library names from:
662+
# - libeay to libcrypto
663+
# - ssleay to libssl
664+
if ($digit1 >= '1' && $digit2 >= '1' && $digit3 >= '0')
617665
{
618-
$proj->AddLibrary(
619-
$self->{options}->{openssl} . '\lib\VC\ssleay32.lib', 1);
620-
$proj->AddLibrary(
621-
$self->{options}->{openssl} . '\lib\VC\libeay32.lib', 1);
666+
my $dbgsuffix;
667+
my $libsslpath;
668+
my $libcryptopath;
669+
670+
# The format name of the libraries is slightly
671+
# different between the Win32 and Win64 platform, so
672+
# adapt.
673+
if (-e "$self->{options}->{openssl}/lib/VC/sslcrypto32MD.lib")
674+
{
675+
# Win32 here, with a debugging library set.
676+
$dbgsuffix = 1;
677+
$libsslpath = '\lib\VC\libssl32.lib';
678+
$libcryptopath = '\lib\VC\libcrypto32.lib';
679+
}
680+
elsif (-e "$self->{options}->{openssl}/lib/VC/sslcrypto64MD.lib")
681+
{
682+
# Win64 here, with a debugging library set.
683+
$dbgsuffix = 1;
684+
$libsslpath = '\lib\VC\libssl64.lib';
685+
$libcryptopath = '\lib\VC\libcrypto64.lib';
686+
}
687+
else
688+
{
689+
# On both Win32 and Win64 the same library
690+
# names are used without a debugging context.
691+
$dbgsuffix = 0;
692+
$libsslpath = '\lib\libssl.lib';
693+
$libcryptopath = '\lib\libcrypto.lib';
694+
}
695+
696+
$proj->AddLibrary($self->{options}->{openssl} . $libsslpath,
697+
$dbgsuffix);
698+
$proj->AddLibrary($self->{options}->{openssl} . $libcryptopath,
699+
$dbgsuffix);
622700
}
623701
else
624702
{
625-
# We don't expect the config-specific library to be here,
626-
# so don't ask for it in last parameter
627-
$proj->AddLibrary(
628-
$self->{options}->{openssl} . '\lib\ssleay32.lib', 0);
629-
$proj->AddLibrary(
630-
$self->{options}->{openssl} . '\lib\libeay32.lib', 0);
703+
# Choose which set of libraries to use depending on if
704+
# debugging libraries are in place in the installer.
705+
if (-e "$self->{options}->{openssl}/lib/VC/ssleay32MD.lib")
706+
{
707+
$proj->AddLibrary(
708+
$self->{options}->{openssl} . '\lib\VC\ssleay32.lib', 1);
709+
$proj->AddLibrary(
710+
$self->{options}->{openssl} . '\lib\VC\libeay32.lib', 1);
711+
}
712+
else
713+
{
714+
# We don't expect the config-specific library
715+
# to be here, so don't ask for it in last
716+
# parameter.
717+
$proj->AddLibrary(
718+
$self->{options}->{openssl} . '\lib\ssleay32.lib', 0);
719+
$proj->AddLibrary(
720+
$self->{options}->{openssl} . '\lib\libeay32.lib', 0);
721+
}
631722
}
632723
}
633724
if ($self->{options}->{nls})

0 commit comments

Comments
 (0)