Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions Sources/Compatibility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,28 @@
// Created by Ben Ku on 7/5/24.
//

#if compiler(>=6.0) && canImport(Synchronization)
import Synchronization
private let colorLoggingState = Mutex(false)
#endif

public extension DebugLevel {
/// Set this to `true` to log failed color parsing notices when returning `nil`
@MainActor
/// Set this to `true` to log failed color parsing notices when returning `nil`.
///
/// Swift 6 uses `Synchronization.Mutex` so synchronous color parsing can read this
/// configuration from any actor without making the parsing APIs MainActor-isolated.
#if compiler(>=6.0) && canImport(Synchronization)
static var colorLogging: Bool {
get { colorLoggingState.withLock { $0 } }
set { colorLoggingState.withLock { $0 = newValue } }
}
#elseif compiler(>=6.0)
// Compatibility fallback for Swift 6 toolchains that do not ship Synchronization.
// Current supported Swift 6 toolchains use the mutex-backed implementation above.
nonisolated(unsafe) static var colorLogging = false
#else
static var colorLogging = false
#endif

// TODO: Change this to generic type matching protocol instead of boxed any type?
@available(iOS 13, tvOS 13, watchOS 6, *)
Expand Down