From 6e53be2cd3b5de96032d226534ab2d4bd613e99f Mon Sep 17 00:00:00 2001 From: Nikolay Volosatov Date: Sun, 12 Nov 2023 20:54:19 +0000 Subject: [PATCH 1/4] Add visionOS support --- KSCrash.podspec | 1 + .../include/KSSystemCapabilities.h | 21 ++++++++++--------- Sources/KSCrashRecordingCore/KSCPU.c | 8 +++++++ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/KSCrash.podspec b/KSCrash.podspec index 1a2ad7c60..d2a332a07 100644 --- a/KSCrash.podspec +++ b/KSCrash.podspec @@ -10,6 +10,7 @@ Pod::Spec.new do |s| s.osx.deployment_target = '10.13' s.tvos.deployment_target = '11.0' s.watchos.deployment_target = '4.0' + s.visionos.deployment_target = '1.0' s.source = { :git => "https://github.com/kstenerud/KSCrash.git", :tag=>s.version.to_s } s.frameworks = 'Foundation' s.libraries = 'c++', 'z' diff --git a/Sources/KSCrashCore/include/KSSystemCapabilities.h b/Sources/KSCrashCore/include/KSSystemCapabilities.h index 0ba0afae9..e1dd03bef 100644 --- a/Sources/KSCrashCore/include/KSSystemCapabilities.h +++ b/Sources/KSCrashCore/include/KSSystemCapabilities.h @@ -38,7 +38,8 @@ #define KSCRASH_HOST_IOS (KSCRASH_HOST_APPLE && TARGET_OS_IOS) #define KSCRASH_HOST_TV (KSCRASH_HOST_APPLE && TARGET_OS_TV) #define KSCRASH_HOST_WATCH (KSCRASH_HOST_APPLE && TARGET_OS_WATCH) -#define KSCRASH_HOST_MAC (KSCRASH_HOST_APPLE && TARGET_OS_MAC && !(TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_WATCH)) +#define KSCRASH_HOST_VISION (KSCRASH_HOST_APPLE && TARGET_OS_VISION) +#define KSCRASH_HOST_MAC (KSCRASH_HOST_APPLE && TARGET_OS_MAC && !(TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_WATCH || TARGET_OS_VISION)) #if KSCRASH_HOST_APPLE #define KSCRASH_CAN_GET_MAC_ADDRESS 1 @@ -66,13 +67,13 @@ #define KSCRASH_HAS_STRNSTR 0 #endif -#if KSCRASH_HOST_IOS || KSCRASH_HOST_TV || KSCRASH_HOST_WATCH +#if KSCRASH_HOST_IOS || KSCRASH_HOST_TV || KSCRASH_HOST_WATCH || KSCRASH_HOST_VISION #define KSCRASH_HAS_UIKIT 1 #else #define KSCRASH_HAS_UIKIT 0 #endif -#if KSCRASH_HOST_IOS || KSCRASH_HOST_TV +#if KSCRASH_HOST_IOS || KSCRASH_HOST_TV || KSCRASH_HOST_VISION #define KSCRASH_HAS_UIAPPLICATION 1 #else #define KSCRASH_HAS_UIAPPLICATION 0 @@ -90,13 +91,13 @@ #define KSCRASH_HAS_MESSAGEUI 0 #endif -#if KSCRASH_HOST_IOS || KSCRASH_HOST_TV +#if KSCRASH_HOST_IOS || KSCRASH_HOST_TV || KSCRASH_HOST_VISION #define KSCRASH_HAS_UIDEVICE 1 #else #define KSCRASH_HAS_UIDEVICE 0 #endif -#if KSCRASH_HOST_IOS || KSCRASH_HOST_MAC || KSCRASH_HOST_TV +#if KSCRASH_HOST_IOS || KSCRASH_HOST_MAC || KSCRASH_HOST_TV || KSCRASH_HOST_VISION #define KSCRASH_HAS_ALERTVIEW 1 #else #define KSCRASH_HAS_ALERTVIEW 0 @@ -114,32 +115,32 @@ #define KSCRASH_HAS_NSALERT 0 #endif -#if KSCRASH_HOST_IOS || KSCRASH_HOST_MAC +#if KSCRASH_HOST_IOS || KSCRASH_HOST_MAC || KSCRASH_HOST_VISION #define KSCRASH_HAS_MACH 1 #else #define KSCRASH_HAS_MACH 0 #endif // WatchOS signal is broken as of 3.1 -#if KSCRASH_HOST_ANDROID || KSCRASH_HOST_IOS || KSCRASH_HOST_MAC || KSCRASH_HOST_TV +#if KSCRASH_HOST_ANDROID || KSCRASH_HOST_IOS || KSCRASH_HOST_MAC || KSCRASH_HOST_TV || KSCRASH_HOST_VISION #define KSCRASH_HAS_SIGNAL 1 #else #define KSCRASH_HAS_SIGNAL 0 #endif -#if KSCRASH_HOST_ANDROID || KSCRASH_HOST_MAC || KSCRASH_HOST_IOS +#if KSCRASH_HOST_ANDROID || KSCRASH_HOST_MAC || KSCRASH_HOST_IOS || KSCRASH_HOST_VISION #define KSCRASH_HAS_SIGNAL_STACK 1 #else #define KSCRASH_HAS_SIGNAL_STACK 0 #endif -#if KSCRASH_HOST_MAC || KSCRASH_HOST_IOS || KSCRASH_HOST_TV +#if KSCRASH_HOST_MAC || KSCRASH_HOST_IOS || KSCRASH_HOST_TV || KSCRASH_HOST_VISION #define KSCRASH_HAS_THREADS_API 1 #else #define KSCRASH_HAS_THREADS_API 0 #endif -#if KSCRASH_HOST_MAC || KSCRASH_HOST_IOS || KSCRASH_HOST_TV +#if KSCRASH_HOST_MAC || KSCRASH_HOST_IOS || KSCRASH_HOST_TV || KSCRASH_HOST_VISION #define KSCRASH_HAS_REACHABILITY 1 #else #define KSCRASH_HAS_REACHABILITY 0 diff --git a/Sources/KSCrashRecordingCore/KSCPU.c b/Sources/KSCrashRecordingCore/KSCPU.c index f67c45bbf..6cce664a6 100644 --- a/Sources/KSCrashRecordingCore/KSCPU.c +++ b/Sources/KSCrashRecordingCore/KSCPU.c @@ -32,14 +32,22 @@ #include #include +#if KSCRASH_HOST_VISION +#include +#endif + //#define KSLogger_LocalLevel TRACE #include "KSLogger.h" const char* kscpu_currentArch(void) { +#if KSCRASH_HOST_VISION + return macho_arch_name_for_mach_header(NULL); +#else const NXArchInfo* archInfo = NXGetLocalArchInfo(); return archInfo == NULL ? NULL : archInfo->name; +#endif } #if KSCRASH_HAS_THREADS_API From 34f50c212da5ef5c1dc755b7218b0a20bc3d38dd Mon Sep 17 00:00:00 2001 From: Nikolay Volosatov Date: Sat, 16 Mar 2024 12:24:20 +0000 Subject: [PATCH 2/4] Fix compilation warning for older Xcodes --- Sources/KSCrashCore/include/KSSystemCapabilities.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sources/KSCrashCore/include/KSSystemCapabilities.h b/Sources/KSCrashCore/include/KSSystemCapabilities.h index e1dd03bef..c39e84b88 100644 --- a/Sources/KSCrashCore/include/KSSystemCapabilities.h +++ b/Sources/KSCrashCore/include/KSSystemCapabilities.h @@ -35,10 +35,15 @@ #define KSCRASH_HOST_ANDROID 1 #endif +#if defined(TARGET_OS_VISION) && TARGET_OS_VISION +#define KSCRASH_HOST_VISION 1 +#else +#define KSCRASH_HOST_VISION 0 +#endif + #define KSCRASH_HOST_IOS (KSCRASH_HOST_APPLE && TARGET_OS_IOS) #define KSCRASH_HOST_TV (KSCRASH_HOST_APPLE && TARGET_OS_TV) #define KSCRASH_HOST_WATCH (KSCRASH_HOST_APPLE && TARGET_OS_WATCH) -#define KSCRASH_HOST_VISION (KSCRASH_HOST_APPLE && TARGET_OS_VISION) #define KSCRASH_HOST_MAC (KSCRASH_HOST_APPLE && TARGET_OS_MAC && !(TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_WATCH || TARGET_OS_VISION)) #if KSCRASH_HOST_APPLE From 5d45a2fac8cae62d60ce72e602eb54a0f8d9301b Mon Sep 17 00:00:00 2001 From: Nikolay Volosatov Date: Sat, 16 Mar 2024 13:05:18 +0000 Subject: [PATCH 3/4] Use mach utils when available --- .../KSCrashReportFilterAppleFmt.m | 27 +++++++++++++++---- Sources/KSCrashRecordingCore/KSCPU.c | 20 ++++++++------ 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/Sources/KSCrashFilters/KSCrashReportFilterAppleFmt.m b/Sources/KSCrashFilters/KSCrashReportFilterAppleFmt.m index cf57dca79..292cc418f 100644 --- a/Sources/KSCrashFilters/KSCrashReportFilterAppleFmt.m +++ b/Sources/KSCrashFilters/KSCrashReportFilterAppleFmt.m @@ -26,11 +26,12 @@ #import "KSCrashReportFilterAppleFmt.h" - +#import "KSSystemCapabilities.h" #import #import #include +#include #import "KSCrashReportFields.h" #import "KSJSONCodecObjC.h" @@ -264,12 +265,28 @@ - (NSString*) CPUType:(NSString*) CPUArch isSystemInfoHeader:(BOOL) isSystemInfo - (NSString*) CPUArchForMajor:(cpu_type_t) majorCode minor:(cpu_subtype_t) minorCode { -#ifdef __APPLE__ +#if KSCRASH_HOST_APPLE // In Apple platforms we can use this function to get the name of a particular architecture - const NXArchInfo* info = NXGetArchInfoFromCpuType(majorCode, minorCode); - if (info && info->name) { - return [[NSString alloc] initWithUTF8String: info->name]; +#if !KSCRASH_HOST_VISION + if(@available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 8.0, *)) +#endif + { + const char *archName = macho_arch_name_for_cpu_type(majorCode, minorCode); + if(archName) + { + return [[NSString alloc] initWithUTF8String:archName]; + } } +#if !KSCRASH_HOST_VISION + else + { + const NXArchInfo* info = NXGetArchInfoFromCpuType(majorCode, minorCode); + if (info && info->name) + { + return [[NSString alloc] initWithUTF8String:info->name]; + } + } +#endif #endif switch(majorCode) diff --git a/Sources/KSCrashRecordingCore/KSCPU.c b/Sources/KSCrashRecordingCore/KSCPU.c index 6cce664a6..1a787b76f 100644 --- a/Sources/KSCrashRecordingCore/KSCPU.c +++ b/Sources/KSCrashRecordingCore/KSCPU.c @@ -31,10 +31,7 @@ #include #include - -#if KSCRASH_HOST_VISION #include -#endif //#define KSLogger_LocalLevel TRACE #include "KSLogger.h" @@ -42,11 +39,18 @@ const char* kscpu_currentArch(void) { -#if KSCRASH_HOST_VISION - return macho_arch_name_for_mach_header(NULL); -#else - const NXArchInfo* archInfo = NXGetLocalArchInfo(); - return archInfo == NULL ? NULL : archInfo->name; +#if !KSCRASH_HOST_VISION + if(__builtin_available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 8.0, *)) +#endif + { + return macho_arch_name_for_mach_header(NULL); + } +#if !KSCRASH_HOST_VISION + else + { + const NXArchInfo* archInfo = NXGetLocalArchInfo(); + return archInfo == NULL ? NULL : archInfo->name; + } #endif } From f37aa3c379acde8034abbc164adf7d5a42074fff Mon Sep 17 00:00:00 2001 From: Nikolay Volosatov Date: Mon, 6 May 2024 14:35:25 +0100 Subject: [PATCH 4/4] Add visionOS to CI jobs --- .github/workflows/cocoapods-lint.yml | 16 ++++++++++++++++ .github/workflows/unit-tests.yml | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cocoapods-lint.yml b/.github/workflows/cocoapods-lint.yml index 095b07107..9918e3723 100644 --- a/.github/workflows/cocoapods-lint.yml +++ b/.github/workflows/cocoapods-lint.yml @@ -29,6 +29,8 @@ jobs: config: "" - platform: watchOS config: "" + - platform: visionOS + config: "" steps: - name: Checkout Code uses: actions/checkout@v4 @@ -41,6 +43,20 @@ jobs: - name: Install CocoaPods run: sudo gem install cocoapods + - name: Use Latest Stable Xcode + uses: maxim-lobanov/setup-xcode@v1 + with: + xcode-version: latest-stable + + - name: Install visionOS Platform + if: matrix.platform == 'visionOS' + shell: bash + run: | + # See https://github.com/actions/runner-images/issues/8144#issuecomment-1902072070 + defaults write com.apple.dt.Xcode AllowUnsupportedVisionOSHost -bool YES + defaults write com.apple.CoreSimulator AllowUnsupportedVisionOSHost -bool YES + xcodebuild -downloadPlatform visionOS + - name: Lint Podspec id: lint run: | diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 52ddbe762..ed6da015b 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -20,6 +20,7 @@ jobs: - watchOS - tvOS - mac-catalyst + - visionOS steps: - name: Checkout Code uses: actions/checkout@v4 @@ -30,7 +31,7 @@ jobs: xcode-version: latest-stable - name: Run Unit Tests - uses: bamx23/xcodebuild@node20 + uses: bamx23/xcodebuild@vision-os with: workspace: ".swiftpm/xcode/package.xcworkspace" scheme: "KSCrash-Package"