Skip to content

Commit

Permalink
meson: link tests and benches against shared library, not static library
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
bluetech committed Feb 5, 2025
1 parent 3c78edd commit 2c1dd81
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 54 deletions.
54 changes: 28 additions & 26 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -450,18 +450,12 @@ icu_dep = dependency('icu-uc', required: false)
build_tools = get_option('enable-tools') and cc.has_header_symbol('getopt.h', 'getopt_long', prefix: '#define _GNU_SOURCE')
if build_tools
# Common resources
libxkbcommon_tools_internal_sources = [
'tools/tools-common.h',
'tools/tools-common.c',
]
libxkbcommon_tools_internal = static_library(
'tools-internal',
libxkbcommon_tools_internal_sources,
dependencies: dep_libxkbcommon,
)
tools_dep = declare_dependency(
sources: [
'tools/tools-common.h',
'tools/tools-common.c',
],
include_directories: [include_directories('tools', 'include')],
link_with: libxkbcommon_tools_internal,
dependencies: dep_libxkbcommon,
)
configh_data.set10('HAVE_TOOLS', true)
Expand Down Expand Up @@ -553,8 +547,6 @@ if build_tools
# The same tool again, but with access to some private APIs.
executable('interactive-evdev',
'tools/interactive-evdev.c',
libxkbcommon_sources,
libxkbcommon_tools_internal_sources,
dependencies: [tools_dep],
c_args: ['-DENABLE_PRIVATE_APIS'],
include_directories: [include_directories('src', 'include')],
Expand Down Expand Up @@ -687,30 +679,34 @@ configure_file(output: 'test-config.h', configuration: test_configh_data)
m_dep = cc.find_library('m', required : false)
# Some tests need to use unexported symbols, so we link them against
# an internal copy of libxkbcommon with all symbols exposed.
libxkbcommon_test_internal = static_library(
libxkbcommon_test_internal = library(
'xkbcommon-test-internal',
'test/common.c',
'test/test.h',
'test/evdev-scancodes.h',
'bench/bench.c',
'bench/bench.h',
libxkbcommon_sources,
include_directories: include_directories('src', 'include'),
c_args: ['-DENABLE_PRIVATE_APIS'],
dependencies: [m_dep],
gnu_symbol_visibility: 'hidden',
)
test_dep = declare_dependency(
sources: [
'bench/bench.c',
'bench/bench.h',
'test/common.c',
'test/evdev-scancodes.h',
'test/test.h',
'tools/tools-common.c',
'tools/tools-common.h',
],
include_directories: include_directories('src', 'include'),
link_with: libxkbcommon_test_internal,
dependencies: [tools_dep],
dependencies: [m_dep],
)
if get_option('enable-x11')
libxkbcommon_x11_test_internal = static_library(
libxkbcommon_x11_test_internal = library(
'xkbcommon-x11-internal',
libxkbcommon_x11_sources,
'test/xvfb-wrapper.c',
'test/xvfb-wrapper.h',
include_directories: include_directories('src', 'include'),
c_args: ['-DENABLE_PRIVATE_APIS'],
gnu_symbol_visibility: 'hidden',
link_with: libxkbcommon_test_internal,
dependencies: [
xcb_dep,
Expand All @@ -722,9 +718,15 @@ if get_option('enable-x11')
dependencies: [
test_dep,
xcb_dep,
xcb_xkb_dep,
],
)
x11_xvfb_test_dep = declare_dependency(
sources: [
'test/xvfb-wrapper.c',
'test/xvfb-wrapper.h',
],
dependencies: [x11_test_dep],
)
endif
# TODO: version range?
keysyms_test_dep = [test_dep]
Expand Down Expand Up @@ -889,13 +891,13 @@ if get_option('enable-x11')
endif
test(
'x11',
executable('test-x11', 'test/x11.c', dependencies: x11_test_dep),
executable('test-x11', 'test/x11.c', dependencies: x11_xvfb_test_dep),
env: test_env,
is_parallel : false,
)
test(
'x11comp',
executable('test-x11comp', 'test/x11comp.c', dependencies: x11_test_dep),
executable('test-x11comp', 'test/x11comp.c', dependencies: x11_xvfb_test_dep),
env: test_env,
is_parallel : false,
)
Expand Down
10 changes: 6 additions & 4 deletions src/atom.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,24 @@
#include <stdint.h>
#include <stdbool.h>

#include "utils.h"

typedef uint32_t xkb_atom_t;

#define XKB_ATOM_NONE 0

struct atom_table;

struct atom_table *
XKB_EXPORT_PRIVATE struct atom_table *
atom_table_new(void);

void
XKB_EXPORT_PRIVATE void
atom_table_free(struct atom_table *table);

xkb_atom_t
XKB_EXPORT_PRIVATE xkb_atom_t
atom_intern(struct atom_table *table, const char *string, size_t len, bool add);

const char *
XKB_EXPORT_PRIVATE const char *
atom_text(struct atom_table *table, xkb_atom_t atom);

#endif /* ATOM_H */
1 change: 0 additions & 1 deletion src/compose/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "escape.h"
#include "dump.h"
#include "src/keysym.h"
#include "src/utils.h"

bool
print_compose_table_entry(FILE *file, struct xkb_compose_table_entry *entry)
Expand Down
4 changes: 3 additions & 1 deletion src/compose/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
#include "xkbcommon/xkbcommon.h"
#include "xkbcommon/xkbcommon-compose.h"

#include "src/utils.h"

#define MAX_LHS_LEN 10
#define MAX_INCLUDE_DEPTH 5
/** Maximum size of the string returned by xkb_compose_state_get_utf8() */
#define XKB_COMPOSE_MAX_STRING_SIZE 256

char *
XKB_EXPORT_PRIVATE char *
parse_string_literal(struct xkb_context *ctx, const char *string);

bool
Expand Down
6 changes: 3 additions & 3 deletions src/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ xkb_context_include_path_get_system_path(struct xkb_context *ctx);
xkb_atom_t
xkb_atom_lookup(struct xkb_context *ctx, const char *string);

xkb_atom_t
XKB_EXPORT_PRIVATE xkb_atom_t
xkb_atom_intern(struct xkb_context *ctx, const char *string, size_t len);

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

const char *
XKB_EXPORT_PRIVATE const char *
xkb_atom_text(struct xkb_context *ctx, xkb_atom_t atom);

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

ATTR_PRINTF(4, 5) void
XKB_EXPORT_PRIVATE ATTR_PRINTF(4, 5) void
xkb_log(struct xkb_context *ctx, enum xkb_log_level level, int verbosity,
const char *fmt, ...);

Expand Down
25 changes: 13 additions & 12 deletions src/keysym.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <stdbool.h>
#include "xkbcommon/xkbcommon.h"
#include "utils.h"

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

bool
XKB_EXPORT_PRIVATE bool
xkb_keysym_is_assigned(xkb_keysym_t ks);

struct xkb_keysym_iterator;

struct xkb_keysym_iterator*
XKB_EXPORT_PRIVATE struct xkb_keysym_iterator*
xkb_keysym_iterator_new(bool explicit);

struct xkb_keysym_iterator*
XKB_EXPORT_PRIVATE struct xkb_keysym_iterator*
xkb_keysym_iterator_unref(struct xkb_keysym_iterator *iter);

bool
XKB_EXPORT_PRIVATE bool
xkb_keysym_iterator_next(struct xkb_keysym_iterator *iter);

xkb_keysym_t
XKB_EXPORT_PRIVATE xkb_keysym_t
xkb_keysym_iterator_get_keysym(struct xkb_keysym_iterator *iter);

int
XKB_EXPORT_PRIVATE int
xkb_keysym_iterator_get_name(struct xkb_keysym_iterator *iter,
char *buffer, size_t size);

bool
XKB_EXPORT_PRIVATE bool
xkb_keysym_iterator_is_explicitly_named(struct xkb_keysym_iterator *iter);

bool
XKB_EXPORT_PRIVATE bool
xkb_keysym_is_deprecated(xkb_keysym_t keysym,
const char *name,
const char **reference_name);
Expand All @@ -94,16 +95,16 @@ xkb_keysym_is_deprecated(xkb_keysym_t keysym,
} \
}

bool
XKB_EXPORT_PRIVATE bool
xkb_keysym_is_lower(xkb_keysym_t keysym);

bool
XKB_EXPORT_PRIVATE bool
xkb_keysym_is_upper_or_title(xkb_keysym_t keysym);

bool
XKB_EXPORT_PRIVATE bool
xkb_keysym_is_keypad(xkb_keysym_t keysym);

bool
XKB_EXPORT_PRIVATE bool
xkb_keysym_is_modifier(xkb_keysym_t keysym);

#endif
1 change: 1 addition & 0 deletions src/utf8.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "config.h"

#include "utils.h"
#include "utf8.h"

/* Conformant encoding form conversion from UTF-32 to UTF-8.
Expand Down
6 changes: 4 additions & 2 deletions src/utf8.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
#include <stddef.h>
#include <stdint.h>

int
#include "utils.h"

XKB_EXPORT_PRIVATE int
utf32_to_utf8(uint32_t unichar, char *buffer);

bool
XKB_EXPORT_PRIVATE bool
is_valid_utf8(const char *ss, size_t len);

#endif
2 changes: 1 addition & 1 deletion src/utils-paths.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#define is_path_separator(s) ((s) == PATH_SEPARATOR)
#endif

bool
XKB_EXPORT_PRIVATE bool
is_absolute(const char *path);

#endif
17 changes: 15 additions & 2 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,19 @@ open_file(const char *path);

/* Compiler Attributes */

/* Private functions only exposed in tests. */
#ifdef ENABLE_PRIVATE_APIS
# if defined(__GNUC__) && !defined(__CYGWIN__)
# define XKB_EXPORT_PRIVATE __attribute__((visibility("default")))
# elif defined(_WIN32)
# define XKB_EXPORT_PRIVATE __declspec(dllexport)
# else
# define XKB_EXPORT_PRIVATE
# endif
#else
# define XKB_EXPORT_PRIVATE
#endif

#if defined(__MINGW32__)
# define ATTR_PRINTF(x,y) __attribute__((__format__(__MINGW_PRINTF_FORMAT, x, y)))
#elif defined(__GNUC__)
Expand Down Expand Up @@ -300,10 +313,10 @@ open_file(const char *path);
#endif

#if !(defined(HAVE_ASPRINTF) && HAVE_ASPRINTF)
int asprintf(char **strp, const char *fmt, ...) ATTR_PRINTF(2, 3);
XKB_EXPORT_PRIVATE int asprintf(char **strp, const char *fmt, ...) ATTR_PRINTF(2, 3);
# if !(defined(HAVE_VASPRINTF) && HAVE_VASPRINTF)
# include <stdarg.h>
int vasprintf(char **strp, const char *fmt, va_list ap);
XKB_EXPORT_PRIVATE int vasprintf(char **strp, const char *fmt, va_list ap);
# endif /* !HAVE_VASPRINTF */
#endif /* !HAVE_ASPRINTF */

Expand Down
2 changes: 1 addition & 1 deletion src/xkbcomp/rules.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include "xkbcomp-priv.h"

bool
XKB_EXPORT_PRIVATE bool
xkb_components_from_rules(struct xkb_context *ctx,
const struct xkb_rule_names *rmlvo,
struct xkb_component_names *out,
Expand Down
2 changes: 1 addition & 1 deletion test/symbols-leak-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def symbols_from_map(path):


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


def diff(map_path, src_paths):
Expand Down
1 change: 1 addition & 0 deletions test/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define TEST_H

#include <assert.h>
#include <stdbool.h>

/* Don't use compat names in internal code. */
#define _XKBCOMMON_COMPAT_H
Expand Down

0 comments on commit 2c1dd81

Please sign in to comment.