swiftkube / client

Swift client for Kubernetes
Apache License 2.0
129 stars 20 forks source link

Explicit dependency on NIO #12

Closed t089 closed 2 years ago

t089 commented 2 years ago

Motivation

When compiling with Swift 5.5 on linux I get the following errors

$ docker run -it --rm -v (pwd):/app -w /app  swift:5.5.2-focal swift build -c release --static-swift-stdlib
/app/.build/checkouts/client/Sources/SwiftkubeClient/Client/GenericKubernetesClient.swift:335:14: error: no exact matches in call to initializer 
                let data = Data(buffer: byteBuffer)
                           ^
/app/.build/checkouts/client/Sources/SwiftkubeClient/Client/GenericKubernetesClient.swift:335:14: note: found candidate with type '(UnsafeBufferPointer<_>) -> Data'
                let data = Data(buffer: byteBuffer)
                           ^
/app/.build/checkouts/client/Sources/SwiftkubeClient/Client/GenericKubernetesClient.swift:335:14: note: found candidate with type '(UnsafeMutableBufferPointer<_>) -> Data'
                let data = Data(buffer: byteBuffer)
                           ^
/app/.build/checkouts/client/Sources/SwiftkubeClient/Discovery/KubernetesClient+Discovery.swift:153:14: error: no exact matches in call to initializer 
                let data = Data(buffer: byteBuffer)
                           ^
/app/.build/checkouts/client/Sources/SwiftkubeClient/Discovery/KubernetesClient+Discovery.swift:153:14: note: found candidate with type '(UnsafeBufferPointer<_>) -> Data'
                let data = Data(buffer: byteBuffer)
                           ^
/app/.build/checkouts/client/Sources/SwiftkubeClient/Discovery/KubernetesClient+Discovery.swift:153:14: note: found candidate with type '(UnsafeMutableBufferPointer<_>) -> Data'
                let data = Data(buffer: byteBuffer)
                           ^
/app/.build/checkouts/client/Sources/SwiftkubeClient/Watch/StreamingDelegate.swift:74:31: error: value of type 'ByteBuffer' has no member 'readData'
                        let data = streamingBuffer.readData(length: readableLine + 1)

In StreamingDelegate.swift we are importing and using methods from NIO and we are using API from NIOFoundationCompat without explicitly importing this package.

Neither NIO, nor NIOFoundationCompat are explicitly declared dependencies in Package.swift. Adding those fixes the compilation.

Changes

Add explicit dependency on NIO and NIOFoundationCompat.

Result

Compilation completes successfully on linux with Swift 5.5.2.

I remember vaguely that there was a recent change on how transitive dependencies are handled in Swift but I could not find any reference anymore.

iabudiab commented 2 years ago

Yes, I remember this from the Swift forums. I guess you may be referring to this one: https://forums.swift.org/t/semantic-versioning-should-removing-a-dependency-be-a-semver-major/51179

Thanks for the PR 👍

I think, I'll have to update the workflows for Swift v5.5