diff --git a/Examples/BackgroundTasks/Sources/main.swift b/Examples/BackgroundTasks/Sources/main.swift index 929e676a..1985fc34 100644 --- a/Examples/BackgroundTasks/Sources/main.swift +++ b/Examples/BackgroundTasks/Sources/main.swift @@ -13,7 +13,12 @@ //===----------------------------------------------------------------------===// import AWSLambdaRuntime + +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif struct BackgroundProcessingHandler: LambdaWithBackgroundProcessingHandler { struct Input: Decodable { diff --git a/Sources/AWSLambdaRuntime/Context+Foundation.swift b/Sources/AWSLambdaRuntime/Context+Foundation.swift index a83237a7..105b7765 100644 --- a/Sources/AWSLambdaRuntime/Context+Foundation.swift +++ b/Sources/AWSLambdaRuntime/Context+Foundation.swift @@ -14,7 +14,11 @@ import AWSLambdaRuntimeCore +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import struct Foundation.Date +#endif extension LambdaContext { var deadlineDate: Date { diff --git a/Sources/AWSLambdaRuntime/Vendored/ByteBuffer-foundation.swift b/Sources/AWSLambdaRuntime/Vendored/ByteBuffer-foundation.swift index e0b6cf5e..8dbd7326 100644 --- a/Sources/AWSLambdaRuntime/Vendored/ByteBuffer-foundation.swift +++ b/Sources/AWSLambdaRuntime/Vendored/ByteBuffer-foundation.swift @@ -26,9 +26,14 @@ // //===----------------------------------------------------------------------===// -import Foundation import NIOCore +#if canImport(FoundationEssentials) +import FoundationEssentials +#else +import Foundation +#endif + // This is NIO's `NIOFoundationCompat` module which at the moment only adds `ByteBuffer` utility methods // for Foundation's `Data` type. // diff --git a/Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift b/Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift index f10f07b1..317ee7ea 100644 --- a/Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift +++ b/Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift @@ -12,11 +12,16 @@ // //===----------------------------------------------------------------------===// -import Foundation import Logging import NIOConcurrencyHelpers import NIOCore +#if canImport(FoundationEssentials) +import FoundationEssentials +#else +import Foundation +#endif + // We need `@unchecked` Sendable here, as `NIOLockedValueBox` does not understand `sending` today. // We don't want to use `NIOLockedValueBox` here anyway. We would love to use Mutex here, but this // sadly crashes the compiler today. diff --git a/Sources/MockServer/main.swift b/Sources/MockServer/main.swift index 9bed33bd..1b8466f9 100644 --- a/Sources/MockServer/main.swift +++ b/Sources/MockServer/main.swift @@ -12,11 +12,17 @@ // //===----------------------------------------------------------------------===// -import Foundation +import Dispatch import NIOCore import NIOHTTP1 import NIOPosix +#if canImport(FoundationEssentials) +import FoundationEssentials +#else +import Foundation +#endif + struct MockServer { private let group: EventLoopGroup private let host: String diff --git a/Tests/AWSLambdaRuntimeCoreTests/InvocationTests.swift b/Tests/AWSLambdaRuntimeCoreTests/InvocationTests.swift index 86bfaae9..fca58391 100644 --- a/Tests/AWSLambdaRuntimeCoreTests/InvocationTests.swift +++ b/Tests/AWSLambdaRuntimeCoreTests/InvocationTests.swift @@ -12,12 +12,17 @@ // //===----------------------------------------------------------------------===// -import Foundation import NIOHTTP1 import Testing @testable import AWSLambdaRuntimeCore +#if canImport(FoundationEssentials) +import FoundationEssentials +#else +import Foundation +#endif + @Suite struct InvocationTest { @Test diff --git a/Tests/AWSLambdaRuntimeCoreTests/LambdaMockClient.swift b/Tests/AWSLambdaRuntimeCoreTests/LambdaMockClient.swift index 15a30223..613276ed 100644 --- a/Tests/AWSLambdaRuntimeCoreTests/LambdaMockClient.swift +++ b/Tests/AWSLambdaRuntimeCoreTests/LambdaMockClient.swift @@ -13,10 +13,15 @@ //===----------------------------------------------------------------------===// import AWSLambdaRuntimeCore -import Foundation import Logging import NIOCore +#if canImport(FoundationEssentials) +import FoundationEssentials +#else +import Foundation +#endif + struct LambdaMockWriter: LambdaRuntimeClientResponseStreamWriter { var underlying: LambdaMockClient diff --git a/Tests/AWSLambdaRuntimeCoreTests/LambdaRequestIDTests.swift b/Tests/AWSLambdaRuntimeCoreTests/LambdaRequestIDTests.swift index 9e406fdf..45886c64 100644 --- a/Tests/AWSLambdaRuntimeCoreTests/LambdaRequestIDTests.swift +++ b/Tests/AWSLambdaRuntimeCoreTests/LambdaRequestIDTests.swift @@ -12,12 +12,17 @@ // //===----------------------------------------------------------------------===// -import Foundation import NIOCore import Testing @testable import AWSLambdaRuntimeCore +#if canImport(FoundationEssentials) +import FoundationEssentials +#else +import Foundation +#endif + @Suite("LambdaRequestID tests") struct LambdaRequestIDTest { @Test @@ -100,6 +105,7 @@ struct LambdaRequestIDTest { #expect(buffer.readableBytes == readableBeforeRead) } + #if os(macOS) @Test func testInitFromNSStringSuccess() { let nsString = NSMutableString(capacity: 16) @@ -121,6 +127,7 @@ struct LambdaRequestIDTest { #expect(requestID?.uuidString == LambdaRequestID(uuidString: nsString as String)?.uuidString) #expect(requestID?.uppercased == nsString as String) } + #endif @Test func testUnparse() { diff --git a/Tests/AWSLambdaRuntimeCoreTests/LambdaRunLoopTests.swift b/Tests/AWSLambdaRuntimeCoreTests/LambdaRunLoopTests.swift index 741bbf50..f57f051b 100644 --- a/Tests/AWSLambdaRuntimeCoreTests/LambdaRunLoopTests.swift +++ b/Tests/AWSLambdaRuntimeCoreTests/LambdaRunLoopTests.swift @@ -12,13 +12,18 @@ // //===----------------------------------------------------------------------===// -import Foundation import Logging import NIOCore import Testing @testable import AWSLambdaRuntimeCore +#if canImport(FoundationEssentials) +import FoundationEssentials +#else +import Foundation +#endif + @Suite struct LambdaRunLoopTests { struct MockEchoHandler: StreamingLambdaHandler { diff --git a/Tests/AWSLambdaRuntimeCoreTests/MockLambdaServer.swift b/Tests/AWSLambdaRuntimeCoreTests/MockLambdaServer.swift index cc3c4ac2..dc325742 100644 --- a/Tests/AWSLambdaRuntimeCoreTests/MockLambdaServer.swift +++ b/Tests/AWSLambdaRuntimeCoreTests/MockLambdaServer.swift @@ -12,7 +12,6 @@ // //===----------------------------------------------------------------------===// -import Foundation // for JSON import Logging import NIOCore import NIOHTTP1 @@ -20,6 +19,12 @@ import NIOPosix @testable import AWSLambdaRuntimeCore +#if canImport(FoundationEssentials) +import FoundationEssentials +#else +import Foundation +#endif + func withMockServer( behaviour: some LambdaServerBehavior, port: Int = 0, diff --git a/Tests/AWSLambdaRuntimeCoreTests/Utils.swift b/Tests/AWSLambdaRuntimeCoreTests/Utils.swift index cd7730b7..49a3cfbb 100644 --- a/Tests/AWSLambdaRuntimeCoreTests/Utils.swift +++ b/Tests/AWSLambdaRuntimeCoreTests/Utils.swift @@ -12,7 +12,11 @@ // //===----------------------------------------------------------------------===// +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension Date { var millisSinceEpoch: Int64 { diff --git a/readme.md b/readme.md index 7c42587e..0717c3e3 100644 --- a/readme.md +++ b/readme.md @@ -253,7 +253,11 @@ Background tasks allow code to execute asynchronously after the main response ha Here is an example of a minimal function that waits 10 seconds after it returned a response but before the handler returns. ```swift import AWSLambdaRuntime +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif struct BackgroundProcessingHandler: LambdaWithBackgroundProcessingHandler { struct Input: Decodable {