connectrpc / connect-swift

The Swift implementation of Connect: Protobuf RPC that works.
https://connectrpc.com/docs/swift/getting-started
Apache License 2.0
103 stars 21 forks source link

connect-swift can't compile for watchOS #226

Closed scottybobandy closed 11 months ago

scottybobandy commented 1 year ago

Hey team πŸ‘‹

We're working on adopting connect-swift and are running into some issues compiling connect-swift for our watchOS app.

For context, we are attempting to perform unary requests from a watchOS app using the URLSessionHTTPClient and grpc-web protocol. However, connect-swift imports CFNetwork (only 1 explicit import here AFAIK) which is unavailable on watchOS, so we can't actually compile for our watchOS target.

In addition, Technote TN3135 describes the 3 specific circumstances when low-level networking is allowed on watchOS. watchOS blocks low-level networking outside of these specific circumstances, impacting aspects of URLSession including URLSessionStreamTask and URLSessionWebSocketTask.

With this limitation on low-level networking, it's likely stream requests will fail even if we can compile and run on watchOS. This is OK for our immediate use-case as we only need to execute unary requests, but a consideration for the future.

Is watchOS support, or at a minimum, the ability to compile and execute unary requests, a reasonable prerequisite for a stable v1.0 release?

scottybobandy commented 1 year ago

Quick update with some additional checks required to compile for watchOS:

rebello95 commented 1 year ago

πŸ‘‹πŸ½ thank you for flagging this. I'm out of town through the first week of December, but can investigate when I'm back if @eseay doesn't get to it before then. Alternatively, feel free to submit a PR in the meantime πŸ™‚

rebello95 commented 11 months ago

Hey @scottybobandy - Thank you for contributing https://github.com/connectrpc/connect-swift/pull/227! I also spent some time investigating this, and I opened a PR to introduce CI validation for watchOS, tvOS, and iOS (rather than only for macOS) as a follow-up: https://github.com/connectrpc/connect-swift/pull/231

In addition, Technote TN3135 describes the 3 specific circumstances when low-level networking is allowed on watchOS. watchOS blocks low-level networking outside of these specific circumstances, impacting aspects of URLSession including URLSessionStreamTask and URLSessionWebSocketTask.

With this limitation on low-level networking, it's likely stream requests will fail even if we can compile and run on watchOS. This is OK for our immediate use-case as we only need to execute unary requests, but a consideration for the future.

I read through the technote you linked, and I think the circumstances in which streaming is allowed by watchOS are tied to application-level features (such as doing networking while streaming audio). That said, there isn't much we can/should do from a networking library perspective, since after your PR Connect will work if it's being used within the boundaries set by watchOS. Relatedly, the tests being run in the PR pass on watchOS because of this detail in the technote:

When writing watchOS networking code, test it on a real device; the simulator always allows low-level networking.

I think between #227 and #231 we should be covered :)