daneden / Twift

🐦 An async Swift library for the Twitter v2 API 🚧 WIP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Linux Support

abdulajet opened this issue · comments

Swift Server folks might want to use this package, and most likely will be deploying via linux. Swift linux does not have the Foundation and CryptoKit frameworks. But there are implementations for linux called FoundationNetworking and Crypto which have the same API.

Adding support should be as easy as adding

#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

and

Importing Crypto over CryptoKit

Thanks for the pointers @abdulajet! If I wanted to test whether this package runs/compiles on Linux distros, do you know how I’d do that in Xcode on macOS?

Do you happen to know how to conditionally import packages for Linux distros? I know how to do compiler conditions based on OS like so:

#if os(macOS)
typealias NativeColor = NSColor
#else
typealias NativeColor = UIColor
#endif

I figure we’ll need to do something similar for importing Foundation vs FoundationNetworking and CryptoKit vs Crypto but not sure how we’d switch over Linux specifically.

Im not sure about testing on Xcode on macOS, I only ran into issues in my project when I tried to deploy via docker. So maybe you can create a Vapor test project and try run it on docker locally.

You can conditionally check for linux but using:

#if os(Linux)