From af4e4fed44ae5a48353970c5ae3ad6e0cd39939e Mon Sep 17 00:00:00 2001 From: der richter Date: Mon, 8 Sep 2025 12:29:01 +0200 Subject: [PATCH] meson: disable swift when cocoa not available or disabled it doesn't make sense to build the swift parts without cocoa because the swift bridge would be missing and it's impossible to interact with the swift parts from obj-c, swift depends on cocoa/appkit/etc, and the cocoa main function/main loop is missing making anything cocoa/appkit/GUI crash on use. like this it is possible to build mpv on macOS without cocoa, it will fallback to the unix main function and mpv can run in 'headless' mode, eg you can use it from CLI, it won't spawn any App icon/menu/etc, and you can use everything that isn't related to cocoa/appkit/GUI like audio playback. anything other will make mpv segfault, for example sdl2 and its vo, since it tries to spawn a window. --- meson.build | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index fc82cfe6d2..b5b6c2ca50 100644 --- a/meson.build +++ b/meson.build @@ -1526,7 +1526,11 @@ if macos_sdk_version != '0.0' add_project_link_arguments(objc_link_flags, language: ['c', 'objc']) endif -xcrun = find_program('xcrun', required: get_option('swift-build').require(darwin)) +swift = get_option('swift-build').require( + darwin and features['cocoa'], + error_message: 'cocoa was not found', +) +xcrun = find_program('xcrun', required: swift) swift_ver = '0.0' if xcrun.found() swift_prog = find_program(run_command(xcrun, '-find', 'swiftc', check: true).stdout().strip()) @@ -1544,7 +1548,7 @@ sys.stdout.write(swift_ver) endif swift = get_option('swift-build').require( - darwin and macos_sdk_version.version_compare('>= 10.15') and swift_ver.version_compare('>= 4.1'), + swift.allowed() and macos_sdk_version.version_compare('>= 10.15') and swift_ver.version_compare('>= 4.1'), error_message: 'A suitable macos sdk version or swift version could not be found!', ) features += {'swift': swift.allowed()}