Twift icon indicating copy to clipboard operation
Twift copied to clipboard

Linux Support

Open abdulajet opened this issue 2 years ago • 2 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

abdulajet avatar Mar 29 '22 20:03 abdulajet

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.

daneden avatar Mar 31 '22 10:03 daneden

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)

abdulajet avatar Apr 02 '22 04:04 abdulajet