Skip to content

Commit de786c6

Browse files
committed
build: fix llvm 17 and older + Apple SDK 14.4 and newer
Fixup faulty target macro initialization in Apple SDK since v14.4 (as of 15.0 beta). The SDK target detection in `TargetConditionals.h` correctly detects macOS, but fails to set the macro's old name `TARGET_OS_OSX`, then continues to set it to a default value of 0. Other parts of the SDK still rely on the old name, and with this inconsistency our builds fail due to missing declarations. It happens when using mainline llvm older than v18. Later versions fixed it by predefining these target macros, avoiding the faulty dynamic detection. gcc is not affected (for now) because it lacks the necessary dynamic detection features, so the SDK falls back to a codepath that sets both the old and new macro to 1. Also move the `TargetConditionals.h` include to the top of to make sure including it also for c-ares builds, combined with SecureTransport or other curl features that may call use the Apple SDK. Before this patch, affected build combinations (e.g. llvm@15 + Xcode 15.3, 15.4, 16.0 with their default SDKs + SecureTransport) fail with: error: use of undeclared identifier 'noErr' / 'SecCertificateCopyLongDescription' / 'SecItemImportExportKeyParameters' / 'SecExternalFormat' / 'SecExternalItemType' / 'SEC_KEY_IMPORT_EXPORT_PARAMS_VERSION' Example: ``` curl/lib/vtls/sectransp.c:311:18: error: use of undeclared identifier 'noErr' OSStatus rtn = noErr; ^ curl/lib/vtls/sectransp.c:379:7: error: use of undeclared identifier 'SecCertificateCopyLongDescription' if(&SecCertificateCopyLongDescription) ^ curl/lib/vtls/sectransp.c:381:7: error: call to undeclared function 'SecCertificateCopyLongDescription'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration] SecCertificateCopyLongDescription(NULL, cert, NULL); ^ curl/lib/vtls/sectransp.c:380:25: error: incompatible integer to pointer conversion assigning to 'CFStringRef' (aka 'const struct __CFString *') from 'int' [-Wint-conversion] server_cert_summary = ^ [...] ``` Ref: https://github.com/curl/curl/actions/runs/9893867519/job/27330135969#step:10:22 llvm v18 patches implementing the predefined macros: llvm/llvm-project#74676 llvm/llvm-project@6e1f191 llvm/llvm-project#82833 llvm/llvm-project@e5ed7b6 Cherry-picked from curl#14097 Closes #xxxxx
1 parent 16f5658 commit de786c6

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

lib/curl_setup.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,26 @@
4040
#include <_mingw.h>
4141
#endif
4242

43+
#if defined(__APPLE__)
44+
#include <sys/types.h>
45+
#include <TargetConditionals.h>
46+
/* Fixup faulty target macro initialization in Apple SDK since v14.4 (as of
47+
15.0 beta). The SDK target detection in `TargetConditionals.h` correctly
48+
detects macOS, but fails to set the macro's old name `TARGET_OS_OSX`, then
49+
continues to set it to a default value of 0. Other parts of the SDK still
50+
rely on the old name, and with this inconsistency our builds fail due to
51+
missing declarations. It happens when using mainline llvm older than v18.
52+
Later versions fixed it by predefining these target macros, avoiding the
53+
faulty dynamic detection. gcc is not affected (for now) because it lacks
54+
the necessary dynamic detection features, so the SDK falls back to
55+
a codepath that sets both the old and new macro to 1. */
56+
#if defined(TARGET_OS_MAC) && TARGET_OS_MAC && \
57+
defined(TARGET_OS_OSX) && !TARGET_OS_OSX
58+
#undef TARGET_OS_OSX
59+
#define TARGET_OS_OSX TARGET_OS_MAC
60+
#endif
61+
#endif
62+
4363
/*
4464
* Disable Visual Studio warnings:
4565
* 4127 "conditional expression is constant"
@@ -325,7 +345,6 @@
325345
* performing this task will result in a synthesized IPv6 address.
326346
*/
327347
#if defined(__APPLE__) && !defined(USE_ARES)
328-
#include <TargetConditionals.h>
329348
#define USE_RESOLVE_ON_IPS 1
330349
# if TARGET_OS_MAC && !(defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) && \
331350
defined(USE_IPV6)

0 commit comments

Comments
 (0)