Skip to content

Commit 2c1dd81

Browse files
committed
meson: link tests and benches against shared library, not static library
This makes the tests, and especially benches, more realistic, since xkbcommon is almost always used as a shared library. Also significantly reduces the build time with LTO enabled (for me, from 90s to 30s). Signed-off-by: Ran Benita <[email protected]>
1 parent 3c78edd commit 2c1dd81

File tree

13 files changed

+77
-54
lines changed

13 files changed

+77
-54
lines changed

meson.build

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -450,18 +450,12 @@ icu_dep = dependency('icu-uc', required: false)
450450
build_tools = get_option('enable-tools') and cc.has_header_symbol('getopt.h', 'getopt_long', prefix: '#define _GNU_SOURCE')
451451
if build_tools
452452
# Common resources
453-
libxkbcommon_tools_internal_sources = [
454-
'tools/tools-common.h',
455-
'tools/tools-common.c',
456-
]
457-
libxkbcommon_tools_internal = static_library(
458-
'tools-internal',
459-
libxkbcommon_tools_internal_sources,
460-
dependencies: dep_libxkbcommon,
461-
)
462453
tools_dep = declare_dependency(
454+
sources: [
455+
'tools/tools-common.h',
456+
'tools/tools-common.c',
457+
],
463458
include_directories: [include_directories('tools', 'include')],
464-
link_with: libxkbcommon_tools_internal,
465459
dependencies: dep_libxkbcommon,
466460
)
467461
configh_data.set10('HAVE_TOOLS', true)
@@ -553,8 +547,6 @@ if build_tools
553547
# The same tool again, but with access to some private APIs.
554548
executable('interactive-evdev',
555549
'tools/interactive-evdev.c',
556-
libxkbcommon_sources,
557-
libxkbcommon_tools_internal_sources,
558550
dependencies: [tools_dep],
559551
c_args: ['-DENABLE_PRIVATE_APIS'],
560552
include_directories: [include_directories('src', 'include')],
@@ -687,30 +679,34 @@ configure_file(output: 'test-config.h', configuration: test_configh_data)
687679
m_dep = cc.find_library('m', required : false)
688680
# Some tests need to use unexported symbols, so we link them against
689681
# an internal copy of libxkbcommon with all symbols exposed.
690-
libxkbcommon_test_internal = static_library(
682+
libxkbcommon_test_internal = library(
691683
'xkbcommon-test-internal',
692-
'test/common.c',
693-
'test/test.h',
694-
'test/evdev-scancodes.h',
695-
'bench/bench.c',
696-
'bench/bench.h',
697684
libxkbcommon_sources,
698685
include_directories: include_directories('src', 'include'),
699686
c_args: ['-DENABLE_PRIVATE_APIS'],
700-
dependencies: [m_dep],
687+
gnu_symbol_visibility: 'hidden',
701688
)
702689
test_dep = declare_dependency(
690+
sources: [
691+
'bench/bench.c',
692+
'bench/bench.h',
693+
'test/common.c',
694+
'test/evdev-scancodes.h',
695+
'test/test.h',
696+
'tools/tools-common.c',
697+
'tools/tools-common.h',
698+
],
703699
include_directories: include_directories('src', 'include'),
704700
link_with: libxkbcommon_test_internal,
705-
dependencies: [tools_dep],
701+
dependencies: [m_dep],
706702
)
707703
if get_option('enable-x11')
708-
libxkbcommon_x11_test_internal = static_library(
704+
libxkbcommon_x11_test_internal = library(
709705
'xkbcommon-x11-internal',
710706
libxkbcommon_x11_sources,
711-
'test/xvfb-wrapper.c',
712-
'test/xvfb-wrapper.h',
713707
include_directories: include_directories('src', 'include'),
708+
c_args: ['-DENABLE_PRIVATE_APIS'],
709+
gnu_symbol_visibility: 'hidden',
714710
link_with: libxkbcommon_test_internal,
715711
dependencies: [
716712
xcb_dep,
@@ -722,9 +718,15 @@ if get_option('enable-x11')
722718
dependencies: [
723719
test_dep,
724720
xcb_dep,
725-
xcb_xkb_dep,
726721
],
727722
)
723+
x11_xvfb_test_dep = declare_dependency(
724+
sources: [
725+
'test/xvfb-wrapper.c',
726+
'test/xvfb-wrapper.h',
727+
],
728+
dependencies: [x11_test_dep],
729+
)
728730
endif
729731
# TODO: version range?
730732
keysyms_test_dep = [test_dep]
@@ -889,13 +891,13 @@ if get_option('enable-x11')
889891
endif
890892
test(
891893
'x11',
892-
executable('test-x11', 'test/x11.c', dependencies: x11_test_dep),
894+
executable('test-x11', 'test/x11.c', dependencies: x11_xvfb_test_dep),
893895
env: test_env,
894896
is_parallel : false,
895897
)
896898
test(
897899
'x11comp',
898-
executable('test-x11comp', 'test/x11comp.c', dependencies: x11_test_dep),
900+
executable('test-x11comp', 'test/x11comp.c', dependencies: x11_xvfb_test_dep),
899901
env: test_env,
900902
is_parallel : false,
901903
)

src/atom.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,24 @@
1010
#include <stdint.h>
1111
#include <stdbool.h>
1212

13+
#include "utils.h"
14+
1315
typedef uint32_t xkb_atom_t;
1416

1517
#define XKB_ATOM_NONE 0
1618

1719
struct atom_table;
1820

19-
struct atom_table *
21+
XKB_EXPORT_PRIVATE struct atom_table *
2022
atom_table_new(void);
2123

22-
void
24+
XKB_EXPORT_PRIVATE void
2325
atom_table_free(struct atom_table *table);
2426

25-
xkb_atom_t
27+
XKB_EXPORT_PRIVATE xkb_atom_t
2628
atom_intern(struct atom_table *table, const char *string, size_t len, bool add);
2729

28-
const char *
30+
XKB_EXPORT_PRIVATE const char *
2931
atom_text(struct atom_table *table, xkb_atom_t atom);
3032

3133
#endif /* ATOM_H */

src/compose/dump.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "escape.h"
1717
#include "dump.h"
1818
#include "src/keysym.h"
19-
#include "src/utils.h"
2019

2120
bool
2221
print_compose_table_entry(FILE *file, struct xkb_compose_table_entry *entry)

src/compose/parser.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@
1313
#include "xkbcommon/xkbcommon.h"
1414
#include "xkbcommon/xkbcommon-compose.h"
1515

16+
#include "src/utils.h"
17+
1618
#define MAX_LHS_LEN 10
1719
#define MAX_INCLUDE_DEPTH 5
1820
/** Maximum size of the string returned by xkb_compose_state_get_utf8() */
1921
#define XKB_COMPOSE_MAX_STRING_SIZE 256
2022

21-
char *
23+
XKB_EXPORT_PRIVATE char *
2224
parse_string_literal(struct xkb_context *ctx, const char *string);
2325

2426
bool

src/context.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ xkb_context_include_path_get_system_path(struct xkb_context *ctx);
6767
xkb_atom_t
6868
xkb_atom_lookup(struct xkb_context *ctx, const char *string);
6969

70-
xkb_atom_t
70+
XKB_EXPORT_PRIVATE xkb_atom_t
7171
xkb_atom_intern(struct xkb_context *ctx, const char *string, size_t len);
7272

7373
#define xkb_atom_intern_literal(ctx, literal) \
@@ -82,13 +82,13 @@ xkb_atom_intern(struct xkb_context *ctx, const char *string, size_t len);
8282
xkb_atom_t
8383
xkb_atom_steal(struct xkb_context *ctx, char *string);
8484

85-
const char *
85+
XKB_EXPORT_PRIVATE const char *
8686
xkb_atom_text(struct xkb_context *ctx, xkb_atom_t atom);
8787

8888
char *
8989
xkb_context_get_buffer(struct xkb_context *ctx, size_t size);
9090

91-
ATTR_PRINTF(4, 5) void
91+
XKB_EXPORT_PRIVATE ATTR_PRINTF(4, 5) void
9292
xkb_log(struct xkb_context *ctx, enum xkb_log_level level, int verbosity,
9393
const char *fmt, ...);
9494

src/keysym.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include <stdbool.h>
1515
#include "xkbcommon/xkbcommon.h"
16+
#include "utils.h"
1617

1718
/*
1819
* NOTE: this is not defined in xkbcommon.h, because if we did, it may add
@@ -49,31 +50,31 @@
4950
* 4 bytes + NULL-terminating byte */
5051
#define XKB_KEYSYM_UTF8_MAX_SIZE 5
5152

52-
bool
53+
XKB_EXPORT_PRIVATE bool
5354
xkb_keysym_is_assigned(xkb_keysym_t ks);
5455

5556
struct xkb_keysym_iterator;
5657

57-
struct xkb_keysym_iterator*
58+
XKB_EXPORT_PRIVATE struct xkb_keysym_iterator*
5859
xkb_keysym_iterator_new(bool explicit);
5960

60-
struct xkb_keysym_iterator*
61+
XKB_EXPORT_PRIVATE struct xkb_keysym_iterator*
6162
xkb_keysym_iterator_unref(struct xkb_keysym_iterator *iter);
6263

63-
bool
64+
XKB_EXPORT_PRIVATE bool
6465
xkb_keysym_iterator_next(struct xkb_keysym_iterator *iter);
6566

66-
xkb_keysym_t
67+
XKB_EXPORT_PRIVATE xkb_keysym_t
6768
xkb_keysym_iterator_get_keysym(struct xkb_keysym_iterator *iter);
6869

69-
int
70+
XKB_EXPORT_PRIVATE int
7071
xkb_keysym_iterator_get_name(struct xkb_keysym_iterator *iter,
7172
char *buffer, size_t size);
7273

73-
bool
74+
XKB_EXPORT_PRIVATE bool
7475
xkb_keysym_iterator_is_explicitly_named(struct xkb_keysym_iterator *iter);
7576

76-
bool
77+
XKB_EXPORT_PRIVATE bool
7778
xkb_keysym_is_deprecated(xkb_keysym_t keysym,
7879
const char *name,
7980
const char **reference_name);
@@ -94,16 +95,16 @@ xkb_keysym_is_deprecated(xkb_keysym_t keysym,
9495
} \
9596
}
9697

97-
bool
98+
XKB_EXPORT_PRIVATE bool
9899
xkb_keysym_is_lower(xkb_keysym_t keysym);
99100

100-
bool
101+
XKB_EXPORT_PRIVATE bool
101102
xkb_keysym_is_upper_or_title(xkb_keysym_t keysym);
102103

103-
bool
104+
XKB_EXPORT_PRIVATE bool
104105
xkb_keysym_is_keypad(xkb_keysym_t keysym);
105106

106-
bool
107+
XKB_EXPORT_PRIVATE bool
107108
xkb_keysym_is_modifier(xkb_keysym_t keysym);
108109

109110
#endif

src/utf8.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "config.h"
1010

11+
#include "utils.h"
1112
#include "utf8.h"
1213

1314
/* Conformant encoding form conversion from UTF-32 to UTF-8.

src/utf8.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
#include <stddef.h>
1414
#include <stdint.h>
1515

16-
int
16+
#include "utils.h"
17+
18+
XKB_EXPORT_PRIVATE int
1719
utf32_to_utf8(uint32_t unichar, char *buffer);
1820

19-
bool
21+
XKB_EXPORT_PRIVATE bool
2022
is_valid_utf8(const char *ss, size_t len);
2123

2224
#endif

src/utils-paths.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#define is_path_separator(s) ((s) == PATH_SEPARATOR)
1919
#endif
2020

21-
bool
21+
XKB_EXPORT_PRIVATE bool
2222
is_absolute(const char *path);
2323

2424
#endif

src/utils.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,19 @@ open_file(const char *path);
267267

268268
/* Compiler Attributes */
269269

270+
/* Private functions only exposed in tests. */
271+
#ifdef ENABLE_PRIVATE_APIS
272+
# if defined(__GNUC__) && !defined(__CYGWIN__)
273+
# define XKB_EXPORT_PRIVATE __attribute__((visibility("default")))
274+
# elif defined(_WIN32)
275+
# define XKB_EXPORT_PRIVATE __declspec(dllexport)
276+
# else
277+
# define XKB_EXPORT_PRIVATE
278+
# endif
279+
#else
280+
# define XKB_EXPORT_PRIVATE
281+
#endif
282+
270283
#if defined(__MINGW32__)
271284
# define ATTR_PRINTF(x,y) __attribute__((__format__(__MINGW_PRINTF_FORMAT, x, y)))
272285
#elif defined(__GNUC__)
@@ -300,10 +313,10 @@ open_file(const char *path);
300313
#endif
301314

302315
#if !(defined(HAVE_ASPRINTF) && HAVE_ASPRINTF)
303-
int asprintf(char **strp, const char *fmt, ...) ATTR_PRINTF(2, 3);
316+
XKB_EXPORT_PRIVATE int asprintf(char **strp, const char *fmt, ...) ATTR_PRINTF(2, 3);
304317
# if !(defined(HAVE_VASPRINTF) && HAVE_VASPRINTF)
305318
# include <stdarg.h>
306-
int vasprintf(char **strp, const char *fmt, va_list ap);
319+
XKB_EXPORT_PRIVATE int vasprintf(char **strp, const char *fmt, va_list ap);
307320
# endif /* !HAVE_VASPRINTF */
308321
#endif /* !HAVE_ASPRINTF */
309322

src/xkbcomp/rules.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#include "xkbcomp-priv.h"
1212

13-
bool
13+
XKB_EXPORT_PRIVATE bool
1414
xkb_components_from_rules(struct xkb_context *ctx,
1515
const struct xkb_rule_names *rmlvo,
1616
struct xkb_component_names *out,

test/symbols-leak-test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def symbols_from_map(path):
1919

2020

2121
def symbols_from_src(path):
22-
return re.findall(r"XKB_EXPORT.*\n(xkb_.*)\(", path.read_text("utf-8"))
22+
return re.findall(r"\bXKB_EXPORT\b.*\n(xkb_.*)\(", path.read_text("utf-8"))
2323

2424

2525
def diff(map_path, src_paths):

test/test.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#define TEST_H
1010

1111
#include <assert.h>
12+
#include <stdbool.h>
1213

1314
/* Don't use compat names in internal code. */
1415
#define _XKBCOMMON_COMPAT_H

0 commit comments

Comments
 (0)