Skip to content

Commit

Permalink
[mono] Fix iOS/tvOS build with Xcode 14 (#76447)
Browse files Browse the repository at this point in the history
Before Xcode 14 the `objc_super` struct definition in the SDK headers looked like this:

```
#if !defined(__cplusplus)  &&  !__OBJC2__
    /* For compatibility with old objc-runtime.h header */
    __unsafe_unretained _Nonnull Class class;
#else
    __unsafe_unretained _Nonnull Class super_class;
#endif
```

With Xcode 14 however the iOS/tvOS SDK header was changed to only define `super_class`, but the MacOSX SDK stayed the same.

Added CMake detection of this case so we can compile both on older and newer Xcode SDKs across platforms.

Co-authored-by: Alexander Köplinger <alex.koeplinger@outlook.com>
  • Loading branch information
github-actions[bot] and akoeplinger committed Sep 30, 2022
1 parent f29fd6f commit 54bf306
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/mono/cmake/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,9 @@
/* Define to 1 if `st_atimespec' is a member of `struct stat'. */
#cmakedefine HAVE_STRUCT_STAT_ST_ATIMESPEC 1

/* Define to 1 if `super_class' is a member of `struct objc_super'. */
#cmakedefine HAVE_OBJC_SUPER_SUPER_CLASS 1

/* Define to 1 if you have the <sys/time.h> header file. */
#cmakedefine HAVE_SYS_TIME_H 1

Expand Down
4 changes: 4 additions & 0 deletions src/mono/cmake/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ check_struct_has_member("struct sockaddr_in6" sin6_len "netinet/in.h" HAVE_SOCKA
check_struct_has_member("struct stat" st_atim "sys/types.h;sys/stat.h;unistd.h" HAVE_STRUCT_STAT_ST_ATIM)
check_struct_has_member("struct stat" st_atimespec "sys/types.h;sys/stat.h;unistd.h" HAVE_STRUCT_STAT_ST_ATIMESPEC)

if (HOST_DARWIN)
check_struct_has_member("struct objc_super" super_class "objc/runtime.h;objc/message.h" HAVE_OBJC_SUPER_SUPER_CLASS)
endif()

check_type_size("int" SIZEOF_INT)
check_type_size("void*" SIZEOF_VOID_P)
check_type_size("long" SIZEOF_LONG)
Expand Down
6 changes: 3 additions & 3 deletions src/mono/mono/utils/mono-threads-mach-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ mono_dead_letter_dealloc (id self, SEL _cmd)
{
struct objc_super super;
super.receiver = self;
#if !defined(__cplusplus) && !__OBJC2__
super.class = nsobject;
#else
#if defined(__cplusplus) || defined(HAVE_OBJC_SUPER_SUPER_CLASS)
super.super_class = nsobject;
#else
super.class = nsobject;
#endif
void (*objc_msgSendSuper_op)(struct objc_super *, SEL) = (void (*)(struct objc_super *, SEL)) objc_msgSendSuper;
objc_msgSendSuper_op (&super, dealloc);
Expand Down

0 comments on commit 54bf306

Please sign in to comment.