Skip to content

Commit beb1279

Browse files
committed
meson: support building without libc
Introduce a new meson option 'nolibc'. Include the headers in src/arch when building liburing. Build the src/syscall.c as seperate library for the tests when building without libc. Signed-off-by: Florian Fischer <[email protected]>
1 parent 019e60d commit beb1279

File tree

4 files changed

+44
-11
lines changed

4 files changed

+44
-11
lines changed

meson.build

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ has_cxx = true
7272
has_ucontext = (cc.has_type('ucontext_t', prefix: '#include <ucontext.h>')
7373
and cc.has_function('makecontext', prefix: '#include <ucontext.h>'))
7474

75+
nolibc = get_option('nolibc')
76+
77+
build_tests = get_option('tests')
78+
7579
conf_data = configuration_data()
7680
conf_data.set('CONFIG_HAVE_KERNEL_RWF_T', has__kernel_rwf_t)
7781
conf_data.set('CONFIG_HAVE_KERNEL_TIMESPEC', has__kernel_timespec)
@@ -80,6 +84,8 @@ conf_data.set('CONFIG_HAVE_STATX', has_statx)
8084
conf_data.set('CONFIG_HAVE_GLIBC_STATX', glibc_statx)
8185
conf_data.set('CONFIG_HAVE_CXX', has_cxx)
8286
conf_data.set('CONFIG_HAVE_UCONTEXT', has_ucontext)
87+
conf_data.set('CONFIG_NOLIBC', nolibc)
88+
conf_data.set('LIBURING_BUILD_TEST', build_tests)
8389
configure_file(output: 'config-host.h',
8490
configuration: conf_data)
8591

@@ -90,7 +96,7 @@ if get_option('examples')
9096
subdir('examples')
9197
endif
9298

93-
if get_option('tests')
99+
if build_tests
94100
if get_option('default_library') != 'both'
95101
error('default_library=both required to build tests')
96102
endif

meson_options.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ option('tests',
77
type : 'boolean',
88
value : false,
99
description : 'Build test programs')
10+
11+
option('nolibc',
12+
type : 'boolean',
13+
value : false,
14+
description : 'Build liburing without libc')

src/meson.build

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
11
subdir('include')
22

3-
inc = include_directories(['include'])
3+
liburing_includes = include_directories(['include'])
4+
liburing_internal_includes = [liburing_includes]
5+
6+
liburing_sources = ['queue.c', 'register.c', 'setup.c']
7+
liburing_c_args = ['-DLIBURING_INTERNAL', '-fno-stack-protector']
8+
liburing_link_args = ['-Wl,--version-script=' + meson.current_source_dir() + '/liburing.map']
9+
10+
if nolibc
11+
liburing_internal_includes += include_directories(['arch'])
12+
13+
liburing_sources += ['nolibc.c']
14+
liburing_c_args += ['-nostdlib', '-nodefaultlibs', '-ffreestanding']
15+
liburing_link_args += ['-nostdlib', '-nodefaultlibs']
16+
else
17+
liburing_sources += ['syscall.c']
18+
endif
419

520
liburing = library('uring',
6-
'queue.c',
7-
'register.c',
8-
'setup.c',
9-
'syscall.c',
10-
include_directories: inc,
11-
c_args: ['-DLIBURING_INTERNAL', '-fno-stack-protector'],
12-
link_args: '-Wl,--version-script=' + meson.current_source_dir() + '/liburing.map',
21+
liburing_sources,
22+
include_directories: liburing_internal_includes,
23+
c_args: liburing_c_args,
24+
link_args: liburing_link_args,
1325
link_depends: 'liburing.map',
1426
version: meson.project_version(),
1527
install: true)
1628

1729
uring = declare_dependency(link_with: liburing,
18-
include_directories: inc)
30+
include_directories: liburing_includes)

test/meson.build

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,16 @@ endif
159159

160160
test_dependencies = [thread_dep]
161161

162+
if nolibc
163+
syscall_lib = static_library('syscall',
164+
'../src/syscall.c',
165+
include_directories: liburing_includes)
166+
167+
syscall_dep = declare_dependency(link_with: syscall_lib,
168+
include_directories: liburing_includes)
169+
test_dependencies += [syscall_dep]
170+
endif
171+
162172
foreach test_source: all_tests
163173
# Tests are not allowed to contain multiple '.' in their name
164174
# using the meson filesystem module would solve this restriction
@@ -168,7 +178,7 @@ foreach test_source: all_tests
168178
[test_source, 'helpers.c'],
169179
c_args: xcflags,
170180
cpp_args: xcflags,
171-
include_directories: inc,
181+
include_directories: liburing_internal_includes,
172182
link_with: liburing.get_static_lib(),
173183
dependencies: test_dependencies,
174184
install: true,

0 commit comments

Comments
 (0)