Skip to content

Commit 6a30027

Browse files
committed
meson: Make auto the default of the ssl option
The 'ssl' option is of type 'combo', but we add a choice 'auto' that simulates the behavior of a feature option. This way, openssl is used automatically by default if present, but we retain the ability to potentially select another ssl library. Author: Nazir Bilal Yavuz <byavuz81@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/ad65ffd1-a9a7-fda1-59c6-f7dc763c3051%40enterprisedb.com
1 parent 1f282c2 commit 6a30027

File tree

7 files changed

+80
-59
lines changed

7 files changed

+80
-59
lines changed

.cirrus.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ task:
181181
su postgres <<-EOF
182182
meson setup \
183183
--buildtype=debug \
184-
-Dcassert=true -Dssl=openssl -Duuid=bsd -Dtcl_version=tcl86 -Ddtrace=auto \
184+
-Dcassert=true -Duuid=bsd -Dtcl_version=tcl86 -Ddtrace=auto \
185185
-DPG_TEST_EXTRA="$PG_TEST_EXTRA" \
186186
-Dextra_lib_dirs=/usr/local/lib -Dextra_include_dirs=/usr/local/include/ \
187187
build
@@ -243,7 +243,6 @@ LINUX_CONFIGURE_FEATURES: &LINUX_CONFIGURE_FEATURES >-
243243

244244
LINUX_MESON_FEATURES: &LINUX_MESON_FEATURES >-
245245
-Dllvm=enabled
246-
-Dssl=openssl
247246
-Duuid=e2fs
248247

249248

@@ -497,7 +496,7 @@ task:
497496
-Dextra_include_dirs=${brewpath}/include \
498497
-Dextra_lib_dirs=${brewpath}/lib \
499498
-Dcassert=true \
500-
-Dssl=openssl -Duuid=e2fs -Ddtrace=auto \
499+
-Duuid=e2fs -Ddtrace=auto \
501500
-Dsegsize_blocks=6 \
502501
-DPG_TEST_EXTRA="$PG_TEST_EXTRA" \
503502
build
@@ -568,7 +567,7 @@ task:
568567
# Use /DEBUG:FASTLINK to avoid high memory usage during linking
569568
configure_script: |
570569
vcvarsall x64
571-
meson setup --backend ninja --buildtype debug -Dc_link_args=/DEBUG:FASTLINK -Dcassert=true -Db_pch=true -Dssl=openssl -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=%TAR% -DPG_TEST_EXTRA="%PG_TEST_EXTRA%" build
570+
meson setup --backend ninja --buildtype debug -Dc_link_args=/DEBUG:FASTLINK -Dcassert=true -Db_pch=true -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=%TAR% -DPG_TEST_EXTRA="%PG_TEST_EXTRA%" build
572571
573572
build_script: |
574573
vcvarsall x64

doc/src/sgml/installation.sgml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2474,7 +2474,7 @@ ninja install
24742474
</varlistentry>
24752475

24762476
<varlistentry id="configure-with-ssl-meson">
2477-
<term><option>-Dssl=<replaceable>LIBRARY</replaceable></option>
2477+
<term><option>-Dssl={ auto | <replaceable>LIBRARY</replaceable> }</option>
24782478
<indexterm>
24792479
<primary>OpenSSL</primary>
24802480
<seealso>SSL</seealso>
@@ -2488,7 +2488,7 @@ ninja install
24882488
<productname>OpenSSL</productname> package to be installed. Building
24892489
with this will check for the required header files and libraries to
24902490
make sure that your <productname>OpenSSL</productname> installation is
2491-
sufficient before proceeding. The default for this option is none.
2491+
sufficient before proceeding. The default for this option is auto.
24922492
</para>
24932493
</listitem>
24942494
</varlistentry>

meson.build

Lines changed: 70 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ cc = meson.get_compiler('c')
4343

4444
not_found_dep = dependency('', required: false)
4545
thread_dep = dependency('threads')
46+
auto_features = get_option('auto_features')
4647

4748

4849

@@ -1171,7 +1172,16 @@ cdata.set('USE_SYSTEMD', systemd.found() ? 1 : false)
11711172
# Library: SSL
11721173
###############################################################
11731174

1174-
if get_option('ssl') == 'openssl'
1175+
ssl = not_found_dep
1176+
ssl_library = 'none'
1177+
sslopt = get_option('ssl')
1178+
1179+
if sslopt == 'auto' and auto_features.disabled()
1180+
sslopt = 'none'
1181+
endif
1182+
1183+
if sslopt in ['auto', 'openssl']
1184+
openssl_required = (sslopt == 'openssl')
11751185

11761186
# Try to find openssl via pkg-config et al, if that doesn't work
11771187
# (e.g. because it's provided as part of the OS, like on FreeBSD), look for
@@ -1193,58 +1203,70 @@ if get_option('ssl') == 'openssl'
11931203

11941204
ssl = declare_dependency(dependencies: ssl_int,
11951205
include_directories: postgres_inc)
1196-
else
1197-
cc.has_header('openssl/ssl.h', args: test_c_args, dependencies: ssl, required: true)
1198-
cc.has_header('openssl/err.h', args: test_c_args, dependencies: ssl, required: true)
1199-
1206+
elif cc.has_header('openssl/ssl.h', args: test_c_args, dependencies: ssl, required: openssl_required) and \
1207+
cc.has_header('openssl/err.h', args: test_c_args, dependencies: ssl, required: openssl_required)
12001208
ssl_int = [ssl]
12011209
endif
12021210

1203-
check_funcs = [
1204-
['CRYPTO_new_ex_data', {'required': true}],
1205-
['SSL_new', {'required': true}],
1206-
1207-
# Function introduced in OpenSSL 1.0.2.
1208-
['X509_get_signature_nid'],
1209-
1210-
# Functions introduced in OpenSSL 1.1.0. We used to check for
1211-
# OPENSSL_VERSION_NUMBER, but that didn't work with 1.1.0, because LibreSSL
1212-
# defines OPENSSL_VERSION_NUMBER to claim version 2.0.0, even though it
1213-
# doesn't have these OpenSSL 1.1.0 functions. So check for individual
1214-
# functions.
1215-
['OPENSSL_init_ssl'],
1216-
['BIO_get_data'],
1217-
['BIO_meth_new'],
1218-
['ASN1_STRING_get0_data'],
1219-
['HMAC_CTX_new'],
1220-
['HMAC_CTX_free'],
1221-
1222-
# OpenSSL versions before 1.1.0 required setting callback functions, for
1223-
# thread-safety. In 1.1.0, it's no longer required, and CRYPTO_lock()
1224-
# function was removed.
1225-
['CRYPTO_lock'],
1226-
1227-
# Function introduced in OpenSSL 1.1.1
1228-
['X509_get_signature_info'],
1229-
]
1211+
if ssl.found()
1212+
check_funcs = [
1213+
['CRYPTO_new_ex_data', {'required': true}],
1214+
['SSL_new', {'required': true}],
1215+
1216+
# Function introduced in OpenSSL 1.0.2.
1217+
['X509_get_signature_nid'],
1218+
1219+
# Functions introduced in OpenSSL 1.1.0. We used to check for
1220+
# OPENSSL_VERSION_NUMBER, but that didn't work with 1.1.0, because LibreSSL
1221+
# defines OPENSSL_VERSION_NUMBER to claim version 2.0.0, even though it
1222+
# doesn't have these OpenSSL 1.1.0 functions. So check for individual
1223+
# functions.
1224+
['OPENSSL_init_ssl'],
1225+
['BIO_get_data'],
1226+
['BIO_meth_new'],
1227+
['ASN1_STRING_get0_data'],
1228+
['HMAC_CTX_new'],
1229+
['HMAC_CTX_free'],
1230+
1231+
# OpenSSL versions before 1.1.0 required setting callback functions, for
1232+
# thread-safety. In 1.1.0, it's no longer required, and CRYPTO_lock()
1233+
# function was removed.
1234+
['CRYPTO_lock'],
1235+
1236+
# Function introduced in OpenSSL 1.1.1
1237+
['X509_get_signature_info'],
1238+
]
1239+
1240+
are_openssl_funcs_complete = true
1241+
foreach c : check_funcs
1242+
func = c.get(0)
1243+
val = cc.has_function(func, args: test_c_args, dependencies: ssl_int)
1244+
required = c.get(1, {}).get('required', false)
1245+
if required and not val
1246+
are_openssl_funcs_complete = false
1247+
if openssl_required
1248+
error('openssl function @0@ is required'.format(func))
1249+
endif
1250+
break
1251+
elif not required
1252+
cdata.set('HAVE_' + func.to_upper(), val ? 1 : false)
1253+
endif
1254+
endforeach
12301255

1231-
foreach c : check_funcs
1232-
func = c.get(0)
1233-
val = cc.has_function(func, args: test_c_args, dependencies: ssl_int)
1234-
required = c.get(1, {}).get('required', false)
1235-
if required and not val
1236-
error('openssl function @0@ is required'.format(func))
1237-
elif not required
1238-
cdata.set('HAVE_' + func.to_upper(), val ? 1 : false)
1256+
if are_openssl_funcs_complete
1257+
cdata.set('USE_OPENSSL', 1,
1258+
description: 'Define to 1 to build with OpenSSL support. (-Dssl=openssl)')
1259+
cdata.set('OPENSSL_API_COMPAT', '0x10001000L',
1260+
description: '''Define to the OpenSSL API version in use. This avoids deprecation warnings from newer OpenSSL versions.''')
1261+
ssl_library = 'openssl'
1262+
else
1263+
ssl = not_found_dep
12391264
endif
1240-
endforeach
1265+
endif
1266+
endif
12411267

1242-
cdata.set('USE_OPENSSL', 1,
1243-
description: 'Define to 1 to build with OpenSSL support. (-Dssl=openssl)')
1244-
cdata.set('OPENSSL_API_COMPAT', '0x10001000L',
1245-
description: '''Define to the OpenSSL API version in use. This avoids deprecation warnings from newer OpenSSL versions.''')
1246-
else
1247-
ssl = not_found_dep
1268+
if sslopt == 'auto' and auto_features.enabled() and not ssl.found()
1269+
error('no SSL library found')
12481270
endif
12491271

12501272

@@ -3266,13 +3288,13 @@ if meson.version().version_compare('>=0.57')
32663288
'llvm': llvm,
32673289
'lz4': lz4,
32683290
'nls': libintl,
3291+
'openssl': ssl,
32693292
'pam': pam,
32703293
'plperl': perl_dep,
32713294
'plpython': python3_dep,
32723295
'pltcl': tcl_dep,
32733296
'readline': readline,
32743297
'selinux': selinux,
3275-
'ssl': ssl,
32763298
'systemd': systemd,
32773299
'uuid': uuid,
32783300
'zlib': zlib,

meson_options.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ option('readline', type : 'feature', value : 'auto',
130130
option('selinux', type : 'feature', value : 'disabled',
131131
description: 'build with SELinux support')
132132

133-
option('ssl', type : 'combo', choices : ['none', 'openssl'],
134-
value : 'none',
133+
option('ssl', type : 'combo', choices : ['auto', 'none', 'openssl'],
134+
value : 'auto',
135135
description: 'use LIB for SSL/TLS support (openssl)')
136136

137137
option('systemd', type : 'feature', value: 'auto',

src/interfaces/libpq/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ tests += {
117117
't/001_uri.pl',
118118
't/002_api.pl',
119119
],
120-
'env': {'with_ssl': get_option('ssl')},
120+
'env': {'with_ssl': ssl_library},
121121
},
122122
}
123123

src/makefiles/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pgxs_kv = {
6666
'SUN_STUDIO_CC': 'no', # not supported so far
6767

6868
# want the chosen option, rather than the library
69-
'with_ssl' : get_option('ssl'),
69+
'with_ssl' : ssl_library,
7070
'with_uuid': uuidopt,
7171

7272
'default_port': get_option('pgport'),

src/test/ssl/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ tests += {
66
'bd': meson.current_build_dir(),
77
'tap': {
88
'env': {
9-
'with_ssl': get_option('ssl'),
9+
'with_ssl': ssl_library,
1010
'OPENSSL': openssl.path(),
1111
},
1212
'tests': [

0 commit comments

Comments
 (0)