diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..8ae616b --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,34 @@ +{ + "name": "Swift", + "image": "swift:6.0", + "features": { + "ghcr.io/devcontainers/features/common-utils:2": {}, + "ghcr.io/devcontainers/features/git:1": {}, + "ghcr.io/devcontainers/features/go:1": {} + }, + "runArgs": [ + "--cap-add=SYS_PTRACE", + "--security-opt", + "seccomp=unconfined" + ], + // Configure tool-specific properties. + "customizations": { + // Configure properties specific to VS Code. + "vscode": { + // Set *default* container specific settings.json values on container create. + "settings": { + "lldb.library": "/usr/lib/liblldb.so" + }, + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "sswg.swift-lang" + ] + } + }, + "postCreateCommand": "sudo apt-get update && sudo apt-get install libsodium-dev -y", + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Set `remoteUser` to `root` to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. + "remoteUser": "vscode" +} diff --git a/Package.swift b/Package.swift index 1f253cb..bc2e6b3 100644 --- a/Package.swift +++ b/Package.swift @@ -16,9 +16,10 @@ let package = Package( dependencies: [ .package(url: "https://github.com/apple/swift-nio.git", from: "2.0.0"), .package(url: "https://github.com/apple/swift-log.git", from: "1.4.2"), - .package(url: "https://github.com/nats-io/nkeys.swift.git", from: "0.1.2"), + .package(url: "https://github.com/nats-io/nkeys.swift.git", from: "0.2.0"), .package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.0.0"), - .package(url: "https://github.com/Jarema/swift-nuid.git", from: "0.2.0"), + .package(url: "https://github.com/Jarema/swift-nuid.git", from: "0.3.0"), + .package(url: "https://github.com/apple/swift-crypto.git", "1.0.0" ..< "4.0.0"), ], targets: [ .target( @@ -38,6 +39,7 @@ let package = Package( dependencies: [ "Nats", .product(name: "Logging", package: "swift-log"), + .product(name: "Crypto", package: "swift-crypto", condition: .when(platforms: [.linux])), ]), .target( name: "NatsServer", diff --git a/Sources/BenchmarkPubSub/main.swift b/Sources/BenchmarkPubSub/main.swift index e4da998..6a13a2b 100644 --- a/Sources/BenchmarkPubSub/main.swift +++ b/Sources/BenchmarkPubSub/main.swift @@ -36,7 +36,7 @@ try await withThrowingTaskGroup(of: Void.self) { group in hm.append(try! NatsHeaderName("foo"), NatsHeaderValue("baz")) hm.insert(try! NatsHeaderName("another"), NatsHeaderValue("one")) var i = 0 - for try await msg in sub { + for try await msg in await sub { let payload = msg.payload! if String(data: payload, encoding: .utf8) != "\(i)" { let emptyString = "" diff --git a/Sources/JetStream/Consumer.swift b/Sources/JetStream/Consumer.swift index 3e13bc5..dd2e346 100644 --- a/Sources/JetStream/Consumer.swift +++ b/Sources/JetStream/Consumer.swift @@ -11,10 +11,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -import CryptoKit import Foundation import Nuid +#if canImport(CryptoKit) + import CryptoKit +#else + import Crypto +#endif + public class Consumer { private static var rdigits: [UInt8] = Array( diff --git a/Sources/JetStream/JetStreamContext.swift b/Sources/JetStream/JetStreamContext.swift index fd3ba78..ea8d655 100644 --- a/Sources/JetStream/JetStreamContext.swift +++ b/Sources/JetStream/JetStreamContext.swift @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -import Combine import Foundation import Nats import Nuid diff --git a/Sources/Nats/NatsConnection.swift b/Sources/Nats/NatsConnection.swift index a12be50..7a38a22 100644 --- a/Sources/Nats/NatsConnection.swift +++ b/Sources/Nats/NatsConnection.swift @@ -22,6 +22,11 @@ import NIOSSL import NIOWebSocket import NKeys +// URLSession is implemented in FoundationNetworking on Linux OS +#if canImport(FoundationNetworking) + import FoundationNetworking +#endif + class ConnectionHandler: ChannelInboundHandler { let lang = "Swift" let version = "0.0.1" diff --git a/Tests/NatsTests/Unit/JwtTests.swift b/Tests/NatsTests/Unit/JwtTests.swift index a2f5ffa..af30b2c 100644 --- a/Tests/NatsTests/Unit/JwtTests.swift +++ b/Tests/NatsTests/Unit/JwtTests.swift @@ -16,6 +16,11 @@ import XCTest @testable import Nats +// URLSession is implemented in FoundationNetworking on Linux OS +#if canImport(FoundationNetworking) + import FoundationNetworking +#endif + class JwtTests: XCTestCase { static var allTests = [