meson: support building redict-tls as a module

Signed-off-by: Drew DeVault <sir@cmpwn.com>
This commit is contained in:
Drew DeVault 2024-09-18 11:24:06 +02:00
parent 273be0790f
commit bb11922d93
5 changed files with 105 additions and 74 deletions

View File

@ -8,7 +8,7 @@ project(
version: '255.255.255',
license: 'LGPL-3.0-only',
meson_version: '>=1.4.0',
default_options: ['c_std=c11'],
default_options: ['warning_level=3'],
)
cc = meson.get_compiler('c')
@ -16,7 +16,6 @@ add_project_arguments(cc.get_supported_arguments([
'-fno-omit-frame-pointer',
'-pedantic',
'-Wall',
'-Wno-missing-field-initializers',
'-Werror=deprecated-declarations',
'-Wstrict-prototypes',
@ -31,11 +30,10 @@ threads = dependency('threads')
openssl = dependency('openssl', required: get_option('tls'))
systemd = dependency('systemd', required: get_option('systemd'))
if openssl.found()
# TODO: s/USE_OPENSSL/HAVE_OPENSSL/
# TODO: Drop support for TLS as an external Redict module
if openssl.found() and get_option('tls-module')
add_project_arguments(['-DUSE_OPENSSL=2'], language: 'c')
elif openssl.found() and not get_option('tls-module')
add_project_arguments(['-DUSE_OPENSSL=1'], language: 'c')
add_project_arguments(['-DBUILD_TLS_MODULE=0'], language: 'c')
endif
if systemd.found()
@ -163,10 +161,7 @@ redict_server_src = [
'src/zmalloc.c',
]
redict_server = executable('redict-server',
redict_server_src,
include_directories: inc,
dependencies: [
redict_server_deps = [
atomic,
fpconv,
hdr_histogram,
@ -175,9 +170,28 @@ redict_server = executable('redict-server',
math,
openssl,
threads,
],
]
redict_server = executable('redict-server',
redict_server_src,
include_directories: inc,
dependencies: redict_server_deps,
export_dynamic: true,
)
if openssl.found() and get_option('tls-module')
redict_tls = shared_module('redict-tls',
sources: [
release_h,
'src/tls.c',
],
name_prefix: '',
include_directories: inc,
dependencies: redict_server_deps,
c_args: '-DBUILD_TLS_MODULE=2',
)
endif
redict_server_links = [
'redict-sentinel',
'redict-check-rdb',
@ -300,6 +314,16 @@ if tclsh.found()
test_environ.set('REDICT_CLI', redict_cli.full_path())
test_environ.set('REDICT_BENCHMARK', redict_benchmark.full_path())
tls_args = []
tls_depends = []
if openssl.found() and get_option('tls-module')
tls_args += ['--tls-module']
tls_depends += redict_tls
test_environ.set('REDICT_TLS', redict_tls.full_path())
elif openssl.found()
tls_args += ['--tls']
endif
test_suites = {
'redict': {
'exec': runtest,
@ -321,10 +345,10 @@ if tclsh.found()
foreach name, info : test_suites
test(name, tclsh,
args: [info['exec']],
args: [info['exec']] + tls_args,
workdir: meson.current_source_dir(),
is_parallel: false,
depends: info['depends'],
depends: info['depends'] + tls_depends,
timeout: -1,
env: test_environ,
protocol: 'tap')

View File

@ -8,6 +8,12 @@ option('tls',
description: 'Enable TLS support (requires OpenSSL)'
)
option('tls-module',
type: 'boolean',
value: false,
description: 'Build TLS support as a Redict module (requires OpenSSL)'
)
option('systemd',
type: 'feature',
value: 'auto',

View File

@ -85,7 +85,7 @@ proc spawn_instance {type base_port count {conf {}} {base_conf_file ""}} {
if {$::tls} {
if {$::tls_module} {
puts $cfg [format "loadmodule %s/../../../src/redict-tls.so" [pwd]]
puts $cfg "loadmodule $::env(REDICT_TLS)"
}
puts $cfg "tls-port $port"

View File

@ -486,7 +486,7 @@ proc start_server {options {code undefined}} {
set config {}
if {$::tls} {
if {$::tls_module} {
lappend config_lines [list "loadmodule" [format "%s/src/redict-tls.so" [pwd]]]
lappend config_lines "loadmodule $::env(REDICT_TLS)"
}
dict set config "tls-cert-file" [format "%s/tests/tls/server.crt" [pwd]]
dict set config "tls-key-file" [format "%s/tests/tls/server.key" [pwd]]

View File

@ -8,3 +8,4 @@ export REDICT_SERVER=src/redict-server
export REDICT_BENCHMARK=src/redict-benchmark
export REDICT_CHECK_AOF=src/redict-server
export REDICT_CLI=src/redict-server
export REDICT_TLS=src/redict-tls.so