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,21 +161,37 @@ redict_server_src = [
'src/zmalloc.c',
]
redict_server_deps = [
atomic,
fpconv,
hdr_histogram,
hiredict,
lua,
math,
openssl,
threads,
]
redict_server = executable('redict-server',
redict_server_src,
include_directories: inc,
dependencies: [
atomic,
fpconv,
hdr_histogram,
hiredict,
lua,
math,
openssl,
threads,
],
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',
@ -265,68 +279,78 @@ tclsh = find_program(
# TODO: Implement TAP output for test suite
if tclsh.found()
subdir('tests/modules')
subdir('tests/modules')
runtest = join_paths(srcdir, 'tests', 'test_helper.tcl')
runtest_cluster = join_paths(srcdir, 'tests', 'cluster', 'run.tcl')
runtest_sentinel = join_paths(srcdir, 'tests', 'sentinel', 'run.tcl')
runtest_modules = join_paths(srcdir, 'tests', 'modules', 'run.tcl')
runtest = join_paths(srcdir, 'tests', 'test_helper.tcl')
runtest_cluster = join_paths(srcdir, 'tests', 'cluster', 'run.tcl')
runtest_sentinel = join_paths(srcdir, 'tests', 'sentinel', 'run.tcl')
runtest_modules = join_paths(srcdir, 'tests', 'modules', 'run.tcl')
test_environ = environment()
test_environ.set('MODULES_PATH',
test_environ = environment()
test_environ.set('MODULES_PATH',
join_paths(meson.current_build_dir(), 'tests', 'modules'))
bins = [
redict_server,
redict_cli,
redict_benchmark,
]
bins = [
redict_server,
redict_cli,
redict_benchmark,
]
# Make symlinks to redict-server in the build directory, which is required for
# the test suite to execute redict-server aliases
foreach link : redict_server_links
target = custom_target(
link,
output: link,
input: redict_server,
command: ['ln', '-sf', '@INPUT@', '@OUTPUT@'],
)
bins += target
# Make symlinks to redict-server in the build directory, which is required for
# the test suite to execute redict-server aliases
foreach link : redict_server_links
target = custom_target(
link,
output: link,
input: redict_server,
command: ['ln', '-sf', '@INPUT@', '@OUTPUT@'],
)
bins += target
test_environ.set(link.to_upper().replace('-', '_'), target.full_path())
endforeach
test_environ.set(link.to_upper().replace('-', '_'), target.full_path())
endforeach
test_environ.set('REDICT_SERVER', redict_server.full_path())
test_environ.set('REDICT_CLI', redict_cli.full_path())
test_environ.set('REDICT_BENCHMARK', redict_benchmark.full_path())
test_environ.set('REDICT_SERVER', redict_server.full_path())
test_environ.set('REDICT_CLI', redict_cli.full_path())
test_environ.set('REDICT_BENCHMARK', redict_benchmark.full_path())
test_suites = {
'redict': {
'exec': runtest,
'depends': bins,
},
'redict-cluster': {
'exec': runtest_cluster,
'depends': bins,
},
'redict-sentinel': {
'exec': runtest_sentinel,
'depends': bins,
},
'redict-modules': {
'exec': runtest_modules,
'depends': [bins, test_modules],
},
}
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
foreach name, info : test_suites
test(name, tclsh,
args: [info['exec']],
workdir: meson.current_source_dir(),
is_parallel: false,
depends: info['depends'],
timeout: -1,
env: test_environ,
protocol: 'tap')
endforeach
endif
test_suites = {
'redict': {
'exec': runtest,
'depends': bins,
},
'redict-cluster': {
'exec': runtest_cluster,
'depends': bins,
},
'redict-sentinel': {
'exec': runtest_sentinel,
'depends': bins,
},
'redict-modules': {
'exec': runtest_modules,
'depends': [bins, test_modules],
},
}
foreach name, info : test_suites
test(name, tclsh,
args: [info['exec']] + tls_args,
workdir: meson.current_source_dir(),
is_parallel: false,
depends: info['depends'] + tls_depends,
timeout: -1,
env: test_environ,
protocol: 'tap')
endforeach
endif

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