Skip to content

Commit c7c081f

Browse files
committed
Use the new #available(Android <API>, *) 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.
1 parent 00c0b1b commit c7c081f

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

.github/workflows/pull_request.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ jobs:
2525
ios_host_exclude_xcode_versions: '[{"xcode_version": "16.2"}, {"xcode_version": "16.3"}, {"xcode_version": "16.4"}]'
2626
enable_wasm_sdk_build: true
2727
enable_android_sdk_build: true
28+
android_ndk_version: '["r28c"]'
29+
android_sdk_triples: '["aarch64-unknown-linux-android33", "x86_64-unknown-linux-android28"]'
2830
soundness:
2931
name: Soundness
3032
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main

Sources/Testing/SourceAttribution/Backtrace.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public struct Backtrace: Sendable {
4040
self.addresses = addresses.map { Address(UInt(bitPattern: $0)) }
4141
}
4242

43-
#if os(Android) && !SWT_NO_DYNAMIC_LINKING
43+
#if compiler(<6.3) && os(Android)
4444
/// The `backtrace()` function.
4545
///
4646
/// This function was added to Android with API level 33, which is higher than
@@ -76,7 +76,13 @@ public struct Backtrace: Sendable {
7676
initializedCount = .init(clamping: backtrace(addresses.baseAddress!, .init(clamping: addresses.count)))
7777
}
7878
#elseif os(Android)
79-
#if !SWT_NO_DYNAMIC_LINKING
79+
#if compiler(>=6.3)
80+
if #available(Android 33, *) {
81+
initializedCount = addresses.withMemoryRebound(to: UnsafeMutableRawPointer.self) { addresses in
82+
.init(clamping: backtrace(addresses.baseAddress!, .init(clamping: addresses.count)))
83+
}
84+
}
85+
#else
8086
if let _backtrace {
8187
initializedCount = .init(clamping: _backtrace(addresses.baseAddress!, .init(clamping: addresses.count)))
8288
}

0 commit comments

Comments
 (0)