macos: undo `availability` macro enabled by Homebrew gcc

Homebrew gcc builds starting with 12.4.0, 13.3.0 and 14.1.0 enabled
the `availability` attribute.

This broke builds because the way the Apple SDK uses attributes (when
available) are incompatible with how gcc accepts them. Causing these
errors:
```
  error: attributes should be specified before the declarator in a function definition
  error: expected ',' or '}' before
```

Upstream commits implementing the `availability` macro:
gcc-12: fd5530b7cb
gcc-13: cb7e4eca68
gcc-14: ff62a10886

The project above is a Darwin gcc compatibility pack, that is applied
to Homebrew gcc builds.

This patch works by redefining the `availability` macro to an invalid
value, making `__has_attribute(availability)` checks fail, stopping
Apple SDK from inserting the incompatible attributes.

It also replaces the previous, local workaround for `lib/macos.c`.

Example with gcc 12.4.0 with macOS SDK 14.0 (Xcode 15.0.1):
```
In file included from <path-to-sdk>/MacOSX14.0.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h:54,
                 from <path-to-sdk>/MacOSX14.0.sdk/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCDynamicStoreCopySpecific.h:30,
                 from /Users/runner/work/curl/curl/lib/macos.c:33,
                 from /Users/runner/work/curl/curl/build/lib/CMakeFiles/libcurl_shared.dir/Unity/unity_0_c.c:244:
<path-to-sdk>/MacOSX14.0.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFUserNotification.h:126:1: error: attributes should be specified before the declarator in a function definition
  126 | CF_INLINE CFOptionFlags CFUserNotificationCheckBoxChecked(CFIndex i) API_AVAILABLE(macos(10.0)) API_UNAVAILABLE(ios, watchos, tvos) {return ((CFOptionFlags)(1UL << (8 + i)));}
      | ^~~~~~~~~
```
Ref: https://github.com/curl/curl/actions/runs/9787982387/job/27025351601?pr=14096#step:7:18

The gcc vs. llvm/clang incompatibility possibly tracked here upstream:
  https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108796
More info:
  https://github.com/llvm/llvm-project/issues/81767
  8433baadec
  https://discourse.llvm.org/t/changing-attribute-ast-printing-location-for-gcc-compatibility/73215
  https://reviews.llvm.org/D159362

Follow-up to db135f8d72 #14119
Ref: https://github.com/curl/curl/pull/14091#issuecomment-2222703468
Fixes #13700
Cherry-picked from #14097
Closes #14155
This commit is contained in:
Viktor Szakats 2024-07-09 20:48:11 +02:00
Родитель 682c357f7f
Коммит e91fcbac7d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5ABD165E2AEF201
2 изменённых файлов: 17 добавлений и 10 удалений

Просмотреть файл

@ -40,6 +40,23 @@
#include <_mingw.h>
#endif
/* Workaround for Homebrew gcc 12.4.0, 13.3.0, 14.1.0 and newer (as of 14.1.0)
that started advertising the `availability` attribute, which then gets used
by Apple SDK, but, in a way incompatible with gcc, resulting in a misc
errors inside SDK headers, e.g.:
error: attributes should be specified before the declarator in a function
definition
error: expected ',' or '}' before
Followed by missing declarations.
Fix it by overriding the built-in feature-check macro used by the headers
to enable the problematic attributes. This makes the feature check fail. */
#if defined(__APPLE__) && \
!defined(__clang__) && \
defined(__GNUC__) && __GNUC__ >= 12 && \
defined(__has_attribute)
#define availability curl_pp_attribute_disabled
#endif
/*
* Disable Visual Studio warnings:
* 4127 "conditional expression is constant"

Просмотреть файл

@ -30,17 +30,7 @@
#include "macos.h"
/* Certain Apple SDK v13.0+ headers are incompatible with the GCC compiler.
As a workaround, use a minimal header and define the function we need,
to avoid hitting those incompatibilities when compiling with GCC. */
#if defined(__clang__)
#include <SystemConfiguration/SCDynamicStoreCopySpecific.h>
#else
#include <CoreFoundation/CFDictionary.h>
typedef const struct CF_BRIDGED_TYPE(id) __SCDynamicStore * SCDynamicStoreRef;
CFDictionaryRef __nullable
SCDynamicStoreCopyProxies(SCDynamicStoreRef __nullable store);
#endif
CURLcode Curl_macos_init(void)
{