Skip to content

Commit 55a439e

Browse files
committed
qb: skip Metal/Vulkan force-on for pre-10.7 macOS targets
The Darwin branch of config.libs.sh unconditionally forces HAVE_METAL and HAVE_VULKAN on unless the user explicitly disabled them. This cascades into HAVE_COCOA_METAL being defined via the COCOA/COCOA_METAL check that follows, which pulls in code such as: ui/drivers/cocoa/apple_platform.h:51: cannot find protocol declaration for 'NSWindowDelegate' NSWindowDelegate as a formal @protocol is a 10.6+ addition. Metal itself requires 10.11+ and Vulkan via MoltenVK requires 10.11+. None of these are available on Tiger/Leopard/PowerPC, so forcing them on there is actively harmful. Factor the pre-10.7 detection that was added for microphone auto- disable (c11279c) into a macos_target_pre_10_7 flag computed once, then use it to also skip the Metal/Vulkan force-on. That keeps the later check on the plain HAVE_COCOA branch and avoids the 10.6+ code paths entirely. Modern macOS builds see no change — they continue to force Metal and Vulkan on and take the HAVE_COCOA_METAL branch. Explicit --enable- metal / --enable-vulkan still work on any target.
1 parent a619a17 commit 55a439e

2 files changed

Lines changed: 46 additions & 27 deletions

File tree

libretro-common/features/features_cpu.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ retro_time_t cpu_features_get_time_usec(void)
244244
return osGetTime() * 1000;
245245
#elif defined(_POSIX_MONOTONIC_CLOCK) || defined(__QNX__) || defined(ANDROID) || defined(__MACH__)
246246
struct timespec tv;
247+
tv.tv_sec = 0;
248+
tv.tv_nec = 0;
247249
if (ra_clock_gettime(CLOCK_MONOTONIC, &tv) < 0)
248250
return 0;
249251
return tv.tv_sec * INT64_C(1000000) + (tv.tv_nsec + 500) / 1000;

qb/config.libs.sh

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,32 @@ check_platform Linux RPILED 'The RPI led driver is' true
244244
check_platform Darwin METAL 'Metal is' true
245245

246246
if [ "$OS" = 'Darwin' ]; then
247+
# Detect whether we're building against a pre-10.7 (Lion) macOS target.
248+
# Many modern Apple APIs used by RetroArch require 10.7 or later
249+
# (Metal, Vulkan/MoltenVK, GCD, NSWindowDelegate protocol, C11
250+
# <stdatomic.h>, AVFoundation, @available). On Tiger/Leopard /
251+
# PowerPC / Xcode 3.1 those APIs are absent and builds fail.
252+
#
253+
# MACOSX_DEPLOYMENT_TARGET (set by the invoker or the toolchain)
254+
# takes priority over sw_vers, because on a cross-build the host
255+
# OS version may be newer than the target.
256+
macos_target_pre_10_7=no
257+
macos_target_ver="${MACOSX_DEPLOYMENT_TARGET:-}"
258+
if [ -z "$macos_target_ver" ] && command -v sw_vers >/dev/null 2>&1; then
259+
macos_target_ver="$(sw_vers -productVersion 2>/dev/null)"
260+
fi
261+
if [ -n "$macos_target_ver" ]; then
262+
mt_major=$(printf %s "$macos_target_ver" | cut -d. -f1)
263+
mt_minor=$(printf %s "$macos_target_ver" | cut -d. -f2)
264+
[ -z "$mt_major" ] && mt_major=0
265+
[ -z "$mt_minor" ] && mt_minor=0
266+
if [ "$mt_major" -lt 10 ] || \
267+
{ [ "$mt_major" -eq 10 ] && [ "$mt_minor" -lt 7 ]; }; then
268+
macos_target_pre_10_7=yes
269+
fi
270+
unset mt_major mt_minor
271+
fi
272+
247273
# macOS: the Metal and Vulkan (MoltenVK) defaults differ from what the
248274
# generic qb logic produces.
249275
# * HAVE_METAL defaults to 'no' in config.params.sh so check_platform
@@ -254,8 +280,16 @@ if [ "$OS" = 'Darwin' ]; then
254280
# whether Metal/Vulkan is in play. Link-time libvulkan is not
255281
# required on Darwin; MoltenVK is loaded dynamically at runtime
256282
# by gfx/common/vulkan_common.c.
257-
[ "${USER_METAL:-}" != 'no' ] && HAVE_METAL=yes
258-
[ "${USER_VULKAN:-}" != 'no' ] && HAVE_VULKAN=yes
283+
# Skip the force-on on pre-10.7 targets — Metal is 10.11+ and
284+
# MoltenVK is 10.11+, so neither is buildable on Tiger/Leopard.
285+
# That also keeps HAVE_COCOA_METAL off, which in turn avoids code
286+
# paths that use the 10.6+ NSWindowDelegate protocol.
287+
if [ "$macos_target_pre_10_7" = 'no' ]; then
288+
[ "${USER_METAL:-}" != 'no' ] && HAVE_METAL=yes
289+
[ "${USER_VULKAN:-}" != 'no' ] && HAVE_VULKAN=yes
290+
else
291+
die : "Notice: macOS target $macos_target_ver is pre-10.7; Metal/Vulkan not forced on (neither is available before 10.11)."
292+
fi
259293

260294
check_platform Darwin COCOA 'Cocoa is' true
261295
check_lib '' COREAUDIO "-framework AudioUnit" AudioUnitInitialize
@@ -265,32 +299,15 @@ if [ "$OS" = 'Darwin' ]; then
265299
# The microphone driver (audio/drivers/coreaudio_mic_macos.m) uses
266300
# C11 <stdatomic.h>, which requires a 10.6/10.7-era SDK or newer.
267301
# On Xcode 3.1 / 10.4-10.5 / PowerPC the header doesn't exist and
268-
# the driver cannot be compiled. Detect pre-10.7 targets and
269-
# auto-disable microphone support unless the user passed
270-
# --enable-microphone explicitly.
271-
#
272-
# MACOSX_DEPLOYMENT_TARGET (set by the invoker or the toolchain)
273-
# takes priority over sw_vers, because on a cross-build the host
274-
# OS version may be newer than the target.
275-
if [ "${USER_MICROPHONE:-}" != 'yes' ] && [ "$HAVE_MICROPHONE" != 'no' ]; then
276-
macos_target_ver="${MACOSX_DEPLOYMENT_TARGET:-}"
277-
if [ -z "$macos_target_ver" ] && command -v sw_vers >/dev/null 2>&1; then
278-
macos_target_ver="$(sw_vers -productVersion 2>/dev/null)"
279-
fi
280-
if [ -n "$macos_target_ver" ]; then
281-
mt_major=$(printf %s "$macos_target_ver" | cut -d. -f1)
282-
mt_minor=$(printf %s "$macos_target_ver" | cut -d. -f2)
283-
[ -z "$mt_major" ] && mt_major=0
284-
[ -z "$mt_minor" ] && mt_minor=0
285-
if [ "$mt_major" -lt 10 ] || \
286-
{ [ "$mt_major" -eq 10 ] && [ "$mt_minor" -lt 7 ]; }; then
287-
HAVE_MICROPHONE=no
288-
die : "Notice: macOS target $macos_target_ver is pre-10.7; disabling microphone (requires C11 <stdatomic.h>). Override with --enable-microphone."
289-
fi
290-
unset mt_major mt_minor
291-
fi
292-
unset macos_target_ver
302+
# the driver cannot be compiled. Auto-disable microphone support
303+
# on pre-10.7 targets unless the user passed --enable-microphone.
304+
if [ "$macos_target_pre_10_7" = 'yes' ] && \
305+
[ "${USER_MICROPHONE:-}" != 'yes' ] && \
306+
[ "$HAVE_MICROPHONE" != 'no' ]; then
307+
HAVE_MICROPHONE=no
308+
die : "Notice: macOS target $macos_target_ver is pre-10.7; disabling microphone (requires C11 <stdatomic.h>). Override with --enable-microphone."
293309
fi
310+
unset macos_target_ver macos_target_pre_10_7
294311

295312
if [ "$HAVE_METAL" = yes ] || [ "$HAVE_VULKAN" = yes ]; then
296313
check_lib '' COCOA_METAL "-framework AppKit" NSApplicationMain

0 commit comments

Comments
 (0)