From 6d8f366bc76e099c81f2e09519f1db7cddd82961 Mon Sep 17 00:00:00 2001 From: nmcc24 <4029254+nmcc24@users.noreply.github.com> Date: Sun, 8 Nov 2026 09:47:54 +0000 Subject: [PATCH] Prefer FoundationEssentials when it's available Import FoundationEssentials instead of Foundation where the toolchain provides it, and fall back to Foundation elsewhere. The Date and DateComponents support is guarded by either module being available. --- Sources/TOMLDecoder/DateTime.swift | 6 +++++- Sources/TOMLDecoder/Parsing/TOMLDocument.swift | 4 ++++ Sources/TOMLDecoder/TOMLDecoder.swift | 4 ++++ Sources/TOMLDecoder/TOMLKeyedDecodingContainer.swift | 8 ++++++-- .../TOMLSingleValueDecodingContainer.Generated.swift | 4 ++++ Sources/TOMLDecoder/TOMLUnkeyedDecodingContainer.swift | 8 ++++++-- .../gyb/TOMLSingleValueDecodingContainer.swift.gyb | 4 ++++ 7 files changed, 33 insertions(+), 5 deletions(-) diff --git a/Sources/TOMLDecoder/DateTime.swift b/Sources/TOMLDecoder/DateTime.swift index e38b5daa..8f3b09fa 100644 --- a/Sources/TOMLDecoder/DateTime.swift +++ b/Sources/TOMLDecoder/DateTime.swift @@ -431,8 +431,12 @@ extension String { } } -#if canImport(Foundation) +#if canImport(FoundationEssentials) || canImport(Foundation) +#if canImport(FoundationEssentials) +public import FoundationEssentials +#else public import Foundation +#endif extension DateComponents { /// Create a new `Foundation.DateComponents` from an offset date-time. diff --git a/Sources/TOMLDecoder/Parsing/TOMLDocument.swift b/Sources/TOMLDecoder/Parsing/TOMLDocument.swift index 189b94c4..90ec91ae 100644 --- a/Sources/TOMLDecoder/Parsing/TOMLDocument.swift +++ b/Sources/TOMLDecoder/Parsing/TOMLDocument.swift @@ -1,4 +1,8 @@ +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif struct TOMLDocument: Equatable, @unchecked Sendable { let tables: [InternalTOMLTable] diff --git a/Sources/TOMLDecoder/TOMLDecoder.swift b/Sources/TOMLDecoder/TOMLDecoder.swift index 68d570c9..be013445 100644 --- a/Sources/TOMLDecoder/TOMLDecoder.swift +++ b/Sources/TOMLDecoder/TOMLDecoder.swift @@ -1,4 +1,8 @@ +#if canImport(FoundationEssentials) +public import FoundationEssentials +#else public import Foundation +#endif /// Convert data for a TOML document into `Codable` types. /// diff --git a/Sources/TOMLDecoder/TOMLKeyedDecodingContainer.swift b/Sources/TOMLDecoder/TOMLKeyedDecodingContainer.swift index d6d5e54b..c0c0a62f 100644 --- a/Sources/TOMLDecoder/TOMLKeyedDecodingContainer.swift +++ b/Sources/TOMLDecoder/TOMLKeyedDecodingContainer.swift @@ -1,6 +1,10 @@ -#if canImport(Foundation) +#if canImport(FoundationEssentials) || canImport(Foundation) +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation #endif +#endif struct TOMLKeyedDecodingContainer: KeyedDecodingContainerProtocol { private let decoder: _TOMLDecoder private let table: TOMLTable @@ -74,7 +78,7 @@ struct TOMLKeyedDecodingContainer: KeyedDecodingContainerProtoco decoder.codingPath.removeLast() } decoder.token = token - #if canImport(Foundation) + #if canImport(FoundationEssentials) || canImport(Foundation) // have to intercept these here otherwise Foundation will try to decode it as a float if type == Date.self { return try decoder.decode(Date.self) as! T diff --git a/Sources/TOMLDecoder/TOMLSingleValueDecodingContainer.Generated.swift b/Sources/TOMLDecoder/TOMLSingleValueDecodingContainer.Generated.swift index 9b0e765a..3aaab815 100644 --- a/Sources/TOMLDecoder/TOMLSingleValueDecodingContainer.Generated.swift +++ b/Sources/TOMLDecoder/TOMLSingleValueDecodingContainer.Generated.swift @@ -1,7 +1,11 @@ // WARNING: This file is generated from TOMLSingleValueDecodingContainer.swift.gyb // Do not edit TOMLSingleValueDecodingContainer.swift directly. +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension _TOMLDecoder: SingleValueDecodingContainer { var context: TOMLKey { diff --git a/Sources/TOMLDecoder/TOMLUnkeyedDecodingContainer.swift b/Sources/TOMLDecoder/TOMLUnkeyedDecodingContainer.swift index f71c9ac3..c997d29c 100644 --- a/Sources/TOMLDecoder/TOMLUnkeyedDecodingContainer.swift +++ b/Sources/TOMLDecoder/TOMLUnkeyedDecodingContainer.swift @@ -1,6 +1,10 @@ -#if canImport(Foundation) +#if canImport(FoundationEssentials) || canImport(Foundation) +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation #endif +#endif struct TOMLUnkeyedDecodingContainer: UnkeyedDecodingContainer { private let decoder: _TOMLDecoder @@ -89,7 +93,7 @@ struct TOMLUnkeyedDecodingContainer: UnkeyedDecodingContainer { decoder.token = token // have to intercept these here otherwise Foundation will try to decode it as a float - #if canImport(Foundation) + #if canImport(FoundationEssentials) || canImport(Foundation) if type == Date.self { return try decoder.decode(Date.self) as! T } else if type == DateComponents.self { diff --git a/Sources/TOMLDecoder/gyb/TOMLSingleValueDecodingContainer.swift.gyb b/Sources/TOMLDecoder/gyb/TOMLSingleValueDecodingContainer.swift.gyb index 88010b7a..d99e71e9 100644 --- a/Sources/TOMLDecoder/gyb/TOMLSingleValueDecodingContainer.swift.gyb +++ b/Sources/TOMLDecoder/gyb/TOMLSingleValueDecodingContainer.swift.gyb @@ -13,7 +13,11 @@ native_types = [ // WARNING: This file is generated from ${template_name} // Do not edit ${generated_file} directly. +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension _TOMLDecoder: SingleValueDecodingContainer { var context: TOMLKey {