build: Fix build and tests on macOS

This commit addresses several compatibility issues that prevented Wayland
from building and passing its test suite on macOS

Core and Compatibility changes:
- Emulate Linux behavior by explicitly setting O_NONBLOCK on connections
  (fixes blocking sendmsg issues on macOS).
- Fix compilation on platforms missing SOCK_CLOEXEC and MSG_CMSG_CLOEXEC.
- Implement wl_os_socket_peercred() using LOCAL_PEERPID for macOS.
- Ensure availability of struct itimerspec (required for POSIX Timers API).

Test suite fixes:
- Add socketpair_cloexec() wrapper to handle platforms without atomic
  SOCK_CLOEXEC support.
- Add implementation of memrchr() for platforms that do not provide it.
- Implement is_debugger_attached() for macOS to handle test timeouts.
- Fix tests to handle Mach-O binary format (instead of ELF).
- Update egl-symbols-check to support macOS *.dylib Mach-O libraries.

Build system:
- Add meson option 'xml_catalog' to allow specifying custom catalog paths.

Signed-off-by: Martin Lopatář <lopin@dataplex.cz>
This commit is contained in:
Martin Lopatář 2026-01-10 08:01:57 +01:00 committed by Martin Lopatář
parent 53509f09ba
commit 6ef7947c93
16 changed files with 179 additions and 23 deletions

View file

@ -20,7 +20,9 @@ config_h.set_quoted('PACKAGE', meson.project_name())
config_h.set_quoted('PACKAGE_VERSION', meson.project_version())
cc_args = []
if host_machine.system() not in ['freebsd', 'openbsd']
if host_machine.system() == 'darwin'
cc_args += ['-D_DARWIN_C_SOURCE']
elif host_machine.system() not in ['freebsd', 'openbsd']
cc_args += ['-D_POSIX_C_SOURCE=200809L']
endif
add_project_arguments(cc_args, language: 'c')
@ -73,10 +75,17 @@ if host_machine.system() == 'freebsd'
endif
config_h.set10('HAVE_BROKEN_MSG_CMSG_CLOEXEC', have_broken_msg_cmsg_cloexec)
has_itimerspec = cc.has_type(
'struct itimerspec',
prefix: '#include <time.h>',
args: '-D_POSIX_C_SOURCE=200809L'
)
config_h.set('HAVE_ITIMERSPEC', has_itimerspec)
if get_option('libraries')
if host_machine.system() in ['freebsd', 'openbsd']
# When building for FreeBSD, epoll(7) is provided by a userspace
# wrapper around kqueue(2).
if host_machine.system() in ['freebsd', 'openbsd', 'darwin']
# When building for FreeBSD, OpenBSD or Darwin, epoll(7) is provided
# by a userspace wrapper around kqueue(2).
epoll_dep = dependency('epoll-shim')
else
# Otherwise, assume that epoll(7) is supported natively.
@ -112,6 +121,8 @@ configure_file(
wayland_protocol_xml = files('protocol/wayland.xml')
catalog_path = get_option('xml_catalog')
root_inc = include_directories('.')
protocol_inc = include_directories('protocol')
src_inc = include_directories('src')