Skip to content

Commit

Permalink
Add visionOS support (#452)
Browse files Browse the repository at this point in the history
  • Loading branch information
bamx23 committed May 7, 2024
1 parent 842dc9c commit cc4eff4
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 18 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/cocoapods-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ jobs:
config: ""
- platform: watchOS
config: ""
- platform: visionOS
config: ""
steps:
- name: Checkout Code
uses: actions/checkout@v4
Expand All @@ -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: |
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
- watchOS
- tvOS
- mac-catalyst
- visionOS
steps:
- name: Checkout Code
uses: actions/checkout@v4
Expand All @@ -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"
Expand Down
1 change: 1 addition & 0 deletions KSCrash.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
26 changes: 16 additions & 10 deletions Sources/KSCrashCore/include/KSSystemCapabilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,16 @@
#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_MAC (KSCRASH_HOST_APPLE && TARGET_OS_MAC && !(TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_WATCH))
#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
Expand Down Expand Up @@ -66,13 +72,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
Expand All @@ -90,13 +96,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
Expand All @@ -114,32 +120,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
Expand Down
27 changes: 22 additions & 5 deletions Sources/KSCrashFilters/KSCrashReportFilterAppleFmt.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@


#import "KSCrashReportFilterAppleFmt.h"

#import "KSSystemCapabilities.h"

#import <inttypes.h>
#import <mach/machine.h>
#include <mach-o/arch.h>
#include <mach-o/utils.h>

#import "KSCrashReportFields.h"
#import "KSJSONCodecObjC.h"
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 14 additions & 2 deletions Sources/KSCrashRecordingCore/KSCPU.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,27 @@

#include <mach/mach.h>
#include <mach-o/arch.h>
#include <mach-o/utils.h>

//#define KSLogger_LocalLevel TRACE
#include "KSLogger.h"


const char* kscpu_currentArch(void)
{
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
}

#if KSCRASH_HAS_THREADS_API
Expand Down

0 comments on commit cc4eff4

Please sign in to comment.