diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml
index ed6da015b..1838c8661 100644
--- a/.github/workflows/unit-tests.yml
+++ b/.github/workflows/unit-tests.yml
@@ -9,18 +9,42 @@ concurrency:
jobs:
unit-tests:
- runs-on: macos-latest
- timeout-minutes: 10
+ runs-on: "macos-${{ matrix.macos-version || 'latest' }}"
strategy:
fail-fast: false
matrix:
- platform:
- - iOS
- - macOS
- - watchOS
- - tvOS
- - mac-catalyst
- - visionOS
+ include:
+ - platform: iOS
+ - platform: iOS
+ os-version: ~12.4.0
+ runtime: "12.4"
+ macos-version: "12"
+ xcode-version: "13.4.1"
+
+ - platform: watchOS
+ - platform: watchOS
+ os-version: ~7.4.0
+ runtime: "7.4"
+ macos-version: "12"
+ xcode-version: "13.4.1"
+ # TODO: Test with an older watchOS version if possible
+
+ - platform: tvOS
+ - platform: tvOS
+ os-version: ~12.4.0
+ runtime: "12.4"
+ macos-version: "12"
+ xcode-version: "13.4.1"
+
+ - platform: visionOS
+
+ - platform: macOS
+ - platform: macOS
+ macos-version: "11"
+
+ - platform: mac-catalyst
+ - platform: mac-catalyst
+ macos-version: "11"
steps:
- name: Checkout Code
uses: actions/checkout@v4
@@ -28,11 +52,28 @@ jobs:
- name: Use Latest Stable Xcode
uses: maxim-lobanov/setup-xcode@v1
with:
- xcode-version: latest-stable
+ xcode-version: ${{ matrix.xcode-version || 'latest-stable' }}
+
+ - name: Cache
+ if: ${{ matrix.runtime }}
+ uses: actions/cache@v3
+ with:
+ path: "~/Downloads"
+ key: ${{ runner.os }}-runtimes-downloads-${{ matrix.platform }}-${{ matrix.runtime }}
+
+ - name: Install Simulator
+ if: ${{ matrix.runtime }}
+ uses: nick-fields/retry@v2
+ with:
+ timeout_minutes: 20
+ max_attempts: 3
+ command: sudo xcodes runtimes install --keep-archive '${{ matrix.platform }} ${{ matrix.runtime }}'
- name: Run Unit Tests
- uses: bamx23/xcodebuild@vision-os
+ uses: bamx23/xcodebuild@os-version
+ timeout-minutes: 10
with:
workspace: ".swiftpm/xcode/package.xcworkspace"
scheme: "KSCrash-Package"
platform: ${{ matrix.platform }}
+ os-version: ${{ matrix.os-version }}
diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/KSCrash-Package.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/KSCrash-Package.xcscheme
index 42930a35b..d51337c14 100644
--- a/.swiftpm/xcode/xcshareddata/xcschemes/KSCrash-Package.xcscheme
+++ b/.swiftpm/xcode/xcshareddata/xcschemes/KSCrash-Package.xcscheme
@@ -140,6 +140,15 @@
+
+
+
+
+
+
#import
#include
-#include
#import "KSCrashReportFields.h"
#import "KSJSONCodecObjC.h"
+#import "KSCPU.h"
#if defined(__LP64__)
#define FMT_LONG_DIGITS "16"
@@ -267,26 +267,11 @@ - (NSString*) CPUArchForMajor:(cpu_type_t) majorCode minor:(cpu_subtype_t) minor
{
#if KSCRASH_HOST_APPLE
// In Apple platforms we can use this function to get the name of a particular architecture
-#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 char *archName = kscpu_archForCPU(majorCode, minorCode);
+ if(archName)
{
- const NXArchInfo* info = NXGetArchInfoFromCpuType(majorCode, minorCode);
- if (info && info->name)
- {
- return [[NSString alloc] initWithUTF8String:info->name];
- }
+ return [[NSString alloc] initWithUTF8String:archName];
}
-#endif
#endif
switch(majorCode)
diff --git a/Sources/KSCrashRecordingCore/KSCPU.c b/Sources/KSCrashRecordingCore/KSCPU.c
index 1a787b76f..113e4e41d 100644
--- a/Sources/KSCrashRecordingCore/KSCPU.c
+++ b/Sources/KSCrashRecordingCore/KSCPU.c
@@ -31,14 +31,34 @@
#include
#include
+
+#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 160000 // Xcode 14
#include
+#define _HAS_MACH_O_UTILS 1
+#else
+#define _HAS_MACH_O_UTILS 0
+#endif
//#define KSLogger_LocalLevel TRACE
#include "KSLogger.h"
+#if !_HAS_MACH_O_UTILS || !KSCRASH_HOST_VISION
+static inline const char* currentArch_nx(void)
+{
+ const NXArchInfo* archInfo = NXGetLocalArchInfo();
+ return archInfo == NULL ? NULL : archInfo->name;
+}
+
+static inline const char* archForCPU_nx(cpu_type_t majorCode, cpu_subtype_t minorCode)
+{
+ const NXArchInfo* info = NXGetArchInfoFromCpuType(majorCode, minorCode);
+ return info == NULL ? NULL : info->name;
+}
+#endif
const char* kscpu_currentArch(void)
{
+#if _HAS_MACH_O_UTILS
#if !KSCRASH_HOST_VISION
if(__builtin_available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 8.0, *))
#endif
@@ -48,10 +68,32 @@ const char* kscpu_currentArch(void)
#if !KSCRASH_HOST_VISION
else
{
- const NXArchInfo* archInfo = NXGetLocalArchInfo();
- return archInfo == NULL ? NULL : archInfo->name;
+ return currentArch_nx();
+ }
+#endif
+#else // _HAS_MACH_O_UTILS
+ return currentArch_nx();
+#endif // _HAS_MACH_O_UTILS
+}
+
+const char* kscpu_archForCPU(cpu_type_t majorCode, cpu_subtype_t minorCode)
+{
+#if _HAS_MACH_O_UTILS
+#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_cpu_type(majorCode, minorCode);
+ }
+#if !KSCRASH_HOST_VISION
+ else
+ {
+ return archForCPU_nx(majorCode, minorCode);
}
#endif
+#else // _HAS_MACH_O_UTILS
+ return archForCPU_nx(majorCode, minorCode);
+#endif // _HAS_MACH_O_UTILS
}
#if KSCRASH_HAS_THREADS_API
diff --git a/Sources/KSCrashRecordingCore/include/KSCPU.h b/Sources/KSCrashRecordingCore/include/KSCPU.h
index 1023670fe..4166e836d 100644
--- a/Sources/KSCrashRecordingCore/include/KSCPU.h
+++ b/Sources/KSCrashRecordingCore/include/KSCPU.h
@@ -42,6 +42,15 @@ extern "C" {
*/
const char* kscpu_currentArch(void);
+/** Get the CPU architecture for given major and minor codes.
+ *
+ * @param majorCode The major code as defined in kernel.
+ * @param minorCode The minor code as defined in kernel.
+ *
+ * @return The architecture name.
+ */
+const char* kscpu_archForCPU(cpu_type_t majorCode, cpu_subtype_t minorCode);
+
/** Get the frame pointer for a machine context.
* The frame pointer marks the top of the call stack.
*