Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server Side Swift Support #85

Open
richardpiazza opened this issue Sep 26, 2023 · 1 comment
Open

Server Side Swift Support #85

richardpiazza opened this issue Sep 26, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@richardpiazza
Copy link

Summary

Although the repository specially called out Apple platforms (This is Amplitude's latest version of the iOS SDK, covering iOS/tvOS/macOS/watchOS.), Swift as a language is growing beyond those specific usages. With a few modifications, this library can be adapted to run on other Swift native environments (like Linux and Windows).

Motivations

I had a PR that started this work, but recent changes has made it difficult to stay on top keeping it merge-ready. When library developers aren't trained to think about multiple platform support, it's easy to make decisions that directly make that support hard to achieve.

Here are some of the areas identified that would need to be addressed to make this library compatible with non-apple platforms:

Isolate OSLog usage by checking for #if canImport(os.log)

  • Preferably use a cross-platform solution like swift-log

Add conditional imports for FoundationNetworking where required. (#if canImport(FoundationNetworking))

  • On non-apple platforms, networking classes like URL, URLRequest, URLSession are part of the FoundationNetworking package.

Setup a CSQLite map for linux systems

      .systemLibrary(
           name: "CSQLite",
           pkgConfig: "sqlite3",
           providers: [
               .apt(["sqlite3", "libsqlite3-dev"])
           ]
       ),
       .target(
           name: "AmplitudeSwift",
           dependencies: [
               .target(name: "CSQLite", condition: .when(platforms: [.linux]))
           ],
           path: "Sources/Amplitude",
           exclude: ["../../Examples/", "../../Tests/"]
       ),

Beware of DispatchQueue.main

This may not exist or function differently on other platforms. In a server-side environment, using this queue often does nothing.

@richardpiazza richardpiazza added the enhancement New feature or request label Sep 26, 2023
@Mercy811
Copy link
Collaborator

Hi @richardpiazza, thanks for supporting and contributing to Amplitude. Swift is close to GA and I will pass this to our team to see if we can support non Apple platforms in GA version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants