From c7c081f6e09ebe46032dd23021ef771d36e18cf9 Mon Sep 17 00:00:00 2001 From: Finagolfin Date: Thu, 6 Nov 2025 04:30:57 +0530 Subject: [PATCH] Use the new `#available(Android , *)` instead from Swift 6.3 to look for `backtrace()` Mads added this compiler feature for Android in swiftlang/swift#84574 before the 6.3 branch, so update the Android triples and NDK version to test it, as it requires NDK 28 or later. --- .github/workflows/pull_request.yml | 2 ++ Sources/Testing/SourceAttribution/Backtrace.swift | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 086b2226e..df9627de8 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -25,6 +25,8 @@ jobs: ios_host_exclude_xcode_versions: '[{"xcode_version": "16.2"}, {"xcode_version": "16.3"}, {"xcode_version": "16.4"}]' enable_wasm_sdk_build: true enable_android_sdk_build: true + android_ndk_version: '["r28c"]' + android_sdk_triples: '["aarch64-unknown-linux-android33", "x86_64-unknown-linux-android28"]' soundness: name: Soundness uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main diff --git a/Sources/Testing/SourceAttribution/Backtrace.swift b/Sources/Testing/SourceAttribution/Backtrace.swift index 552e16d68..e9f53816e 100644 --- a/Sources/Testing/SourceAttribution/Backtrace.swift +++ b/Sources/Testing/SourceAttribution/Backtrace.swift @@ -40,7 +40,7 @@ public struct Backtrace: Sendable { self.addresses = addresses.map { Address(UInt(bitPattern: $0)) } } -#if os(Android) && !SWT_NO_DYNAMIC_LINKING +#if compiler(<6.3) && os(Android) /// The `backtrace()` function. /// /// This function was added to Android with API level 33, which is higher than @@ -76,7 +76,13 @@ public struct Backtrace: Sendable { initializedCount = .init(clamping: backtrace(addresses.baseAddress!, .init(clamping: addresses.count))) } #elseif os(Android) -#if !SWT_NO_DYNAMIC_LINKING +#if compiler(>=6.3) + if #available(Android 33, *) { + initializedCount = addresses.withMemoryRebound(to: UnsafeMutableRawPointer.self) { addresses in + .init(clamping: backtrace(addresses.baseAddress!, .init(clamping: addresses.count))) + } + } +#else if let _backtrace { initializedCount = .init(clamping: _backtrace(addresses.baseAddress!, .init(clamping: addresses.count))) }