Skip to content

Commit

Permalink
Support Meson as an alternative build system
Browse files Browse the repository at this point in the history
This adds a basic support for building and installing the provider
with Meson.  To test:

```console
meson setup build
meson compile -C build
meson test -C build --num-processes 1
```

Note that parallel execution of tests are currently not working, as
the same port number is used in multiple tests.

Signed-off-by: Daiki Ueno <[email protected]>
  • Loading branch information
ueno committed Nov 6, 2023
1 parent f706b05 commit dd4d9a9
Show file tree
Hide file tree
Showing 5 changed files with 241 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
install_man('provider-pkcs11.7')
115 changes: 115 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
project('pkcs11-provider', 'c',
version: '0.2',
meson_version: '>= 0.57')

version_arr = meson.project_version().split('.')
major_version = version_arr[0].to_int()
minor_version = version_arr[1].to_int()

cc = meson.get_compiler('c')

warning_c_args = [
'-Wwrite-strings',
'-Wpointer-arith',
'-Wno-missing-field-initializers',
'-Wformat',
'-Wshadow',
# Temporarily disable unused parameter until the implementation is complete
'-Wno-unused-parameter',
# These should be always errors
'-Werror=implicit-function-declaration',
'-Werror=missing-prototypes',
'-Werror=format-security',
'-Werror=parentheses',
'-Werror=implicit',
'-Werror=strict-prototypes',
]

extra_c_args = [
'-fno-strict-aliasing',
'-fno-delete-null-pointer-checks',
'-fdiagnostics-show-option',
]

add_project_arguments(cc.get_supported_arguments(warning_c_args + extra_c_args),
language: 'c')

configinc = include_directories('.')

conf = configuration_data()

conf.set_quoted('PACKAGE_NAME', meson.project_name())
conf.set('PACKAGE_MAJOR', major_version)
conf.set('PACKAGE_MINOR', minor_version)

libcrypto = dependency('libcrypto', version: '>= 3.0.7')
provider_path = libcrypto.get_variable(pkgconfig: 'modulesdir')
libssl = dependency('libssl', version: '>= 3.0.7')

host_system = host_machine.system()
if host_system == 'windows'
shlext = '.dll'
else
shlext = '.so'
endif

if host_machine.endian() == 'big'
conf.set('WORDS_BIGENDIAN', 1)
endif

p11_kit = dependency('p11-kit-1', required: false)
if p11_kit.found()
default_pkcs11_module = p11_kit.get_variable(pkgconfig: 'proxy_module')
conf.set_quoted('DEFAULT_PKCS11_MODULE', default_pkcs11_module)

# p11-kit-client module doesn't support Windows, so hard-coding .so is fine
p11_module_path = p11_kit.get_variable(pkgconfig: 'p11_module_path')
p11_client_path = p11_module_path / 'p11-kit-client.so'
endif

nss_softokn = dependency('nss-softokn', required: false)
if not nss_softokn.found()
nss_softokn = dependency('nss', required: false)
endif
softokendir = ''
softokensubdir = ''
if nss_softokn.found()
fs = import('fs')
softokendir = nss_softokn.get_variable(pkgconfig: 'libdir')
if fs.exists(softokendir / 'libsoftokn3@0@'.format(shlext))
softokensubdir = ''
elif fs.exists(softokendir / 'nss' / 'libsoftokn3@0@'.format(shlext))
softokensubdir = 'nss'
else
warning('Softoken library missing, tests will fail!')
endif
endif

headers = [
'string.h',
'dlfcn.h',
'stdbool.h',
]

foreach h : headers
if cc.has_header(h)
conf.set('HAVE_' + h.underscorify().to_upper(), 1)
endif
endforeach

functions = [
'strpbrk',
]

foreach f : functions
if cc.has_function(f)
conf.set('HAVE_' + f.underscorify().to_upper(), 1)
endif
endforeach

configure_file(output: 'config.h', configuration: conf)

subdir('src')
subdir('docs')
subdir('tests')

35 changes: 35 additions & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
pkcs11_provider_sources = [
'asymmetric_cipher.c',
'debug.c',
'encoder.c',
'digests.c',
'exchange.c',
'kdf.c',
'keymgmt.c',
'interface.c',
'objects.c',
'provider.h',
'provider.c',
'random.c',
'session.c',
'signature.c',
'slot.c',
'store.c',
'tls.c',
'util.c',
]

pkcs11_provider_map = meson.current_source_dir() / 'provider.map'
pkcs11_provider_ldflags = cc.get_supported_link_arguments([
'-Wl,--version-script,' + pkcs11_provider_map
])

pkcs11_provider = shared_module(
'pkcs11',
pkcs11_provider_sources,
name_prefix: '',
dependencies: [libcrypto],
include_directories: [configinc],
link_depends: [pkcs11_provider_map],
link_args: pkcs11_provider_ldflags,
)
6 changes: 6 additions & 0 deletions src/provider.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
global:
OSSL_provider_init;
local:
*;
};
84 changes: 84 additions & 0 deletions tests/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
test_programs = [
'tsession',
'tgenkey',
'tlsctx',
'tdigests',
'treadkeys',
'tcmpkeys',
'tfork',
'pincache',
]

foreach t : test_programs
executable(t, '@[email protected]'.format(t),
include_directories: [configinc],
dependencies: [libcrypto, libssl])
endforeach

conf_env = environment({
'LIBSPATH': meson.project_build_root() / 'src',
'TESTSSRCDIR': meson.current_source_dir(),
'TESTBLDDIR': meson.current_build_dir(),
'SHARED_EXT': shlext,
'SOFTOKNPATH': softokendir / softokensubdir,
'P11KITCLIENTPATH': p11_client_path,
})

softoken_conf = custom_target(
'generate softoken configuration',
output: 'tmp.softokn.log',
env: conf_env,
command: [
find_program('setup-softokn.sh'),
],
capture: true,
)

softhsm_conf = custom_target(
'generate softhsm configuration',
output: 'tmp.softhsm.log',
env: conf_env,
command: [
find_program('setup-softhsm.sh'),
],
capture: true,
)

test_env = environment({
'TEST_PATH': meson.current_source_dir(),
'TESTBLDDIR': meson.current_build_dir(),
})

tests = [
'basic-softokn.t', 'basic-softhsm.t',
'pubkey-softokn.t', 'pubkey-softhsm.t',
'certs-softokn.t', 'certs-softhsm.t',
'ecc-softokn.t', 'ecc-softhsm.t',
'edwards-softhsm.t',
'ecdh-softokn.t',
'democa-softokn.t', 'democa-softhsm.t',
'digest-softokn.t', 'digest-softhsm.t',
'fork-softokn.t', 'fork-softhsm.t',
'oaepsha2-softokn.t',
'hkdf-softokn.t',
'rsapss-softokn.t',
'genkey-softokn.t', 'genkey-softhsm.t',
'session-softokn.t', 'session-softhsm.t',
'rand-softokn.t', 'rand-softhsm.t',
'readkeys-softokn.t', 'readkeys-softhsm.t',
'tls-softokn.t', 'tls-softhsm.t',
'uri-softokn.t', 'uri-softhsm.t',
'ecxc-softhsm.t',
'cms-softokn.t',
]

test_wrapper = find_program('test-wrapper')
foreach t : tests
test(
t,
test_wrapper,
args: t,
depends: [softoken_conf, softhsm_conf],
env: test_env,
)
endforeach

0 comments on commit dd4d9a9

Please sign in to comment.