Skip to content
This repository was archived by the owner on Oct 28, 2024. It is now read-only.

Commit 4fef46c

Browse files
committed
Disable this library for Swift 5.9 and above.
Swift 5.9 has a new built-in backtrace-on-crash facility, which supersedes this library. rdar://111109405
1 parent 2cfddd6 commit 4fef46c

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ When this gap is closed at the language runtime level, this library will become
77

88
## Usage
99

10-
When building web-services and daemons, direct usage of this library is discouraged.
11-
Instead, use [swift-service-lifecycle](https://github.com/swift-server/swift-service-lifecycle) which helps manage the application lifecycle including setting up backtraces hooks when needed.
10+
**Note**: You do not need this library on Linux as of Swift 5.9, which has
11+
built-in backtracing support.
1212

1313
Add `https://github.com/swift-server/swift-backtrace.git` as a dependency in your `Package.swift`.
1414

Sources/Backtrace/Backtrace.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,20 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
#if os(Linux)
15+
// Swift 5.9 has its own built-in backtracing support in the runtime;
16+
// we don't want to activate this library if we're using 5.9 or above.
17+
#if swift(>=5.9) && !os(Windows)
18+
public enum Backtrace {
19+
@available(*, deprecated, message: "This is no longer needed in Swift 5.9")
20+
public static func install() {}
21+
22+
@available(*, deprecated, message: "This is no longer needed in Swift 5.9")
23+
public static func install(signals: [CInt]) {}
24+
25+
@available(*, deprecated, message: "This method will be removed in the next major version.")
26+
public static func print() {}
27+
}
28+
#elseif os(Linux)
1629
import CBacktrace
1730
import Glibc
1831

Sources/Sample/main.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ import Darwin
1919
import Glibc
2020
#endif
2121

22+
#if swift(<5.9) || os(Windows)
2223
Backtrace.install()
24+
#endif
2325

2426
func raiseSignal(_ signal: Int32) {
2527
raise(signal)

Tests/BacktraceTests/BacktraceTests.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ public final class BacktraceTests: XCTestCase {
2020
try XCTSkipIf(true, "test is only supported on Linux")
2121
#endif
2222

23+
#if swift(>=5.9)
24+
try XCTSkipIf(true, "test is not supported on Swift 5.9")
25+
#endif
26+
2327
let expectedError = UUID().uuidString
2428
let stderr = try runSample(reason: expectedError)
2529
print(stderr)
@@ -34,6 +38,10 @@ public final class BacktraceTests: XCTestCase {
3438
try XCTSkipIf(true, "test is only supported on Linux")
3539
#endif
3640

41+
#if swift(>=5.9)
42+
try XCTSkipIf(true, "test is not supported on Swift 5.9")
43+
#endif
44+
3745
let stderr = try runSample(reason: "SIGILL")
3846
print(stderr)
3947

@@ -46,6 +54,10 @@ public final class BacktraceTests: XCTestCase {
4654
try XCTSkipIf(true, "test is only supported on Linux")
4755
#endif
4856

57+
#if swift(>=5.9)
58+
try XCTSkipIf(true, "test is not supported on Swift 5.9")
59+
#endif
60+
4961
let stderr = try runSample(reason: "SIGSEGV")
5062
print(stderr)
5163

@@ -58,6 +70,10 @@ public final class BacktraceTests: XCTestCase {
5870
try XCTSkipIf(true, "test is only supported on Linux")
5971
#endif
6072

73+
#if swift(>=5.9)
74+
try XCTSkipIf(true, "test is not supported on Swift 5.9")
75+
#endif
76+
6177
let stderr = try runSample(reason: "SIGBUS")
6278
print(stderr)
6379

@@ -70,6 +86,10 @@ public final class BacktraceTests: XCTestCase {
7086
try XCTSkipIf(true, "test is only supported on Linux")
7187
#endif
7288

89+
#if swift(>=5.9)
90+
try XCTSkipIf(true, "test is not supported on Swift 5.9")
91+
#endif
92+
7393
let stderr = try runSample(reason: "SIGFPE")
7494
print(stderr)
7595

0 commit comments

Comments
 (0)