-
Notifications
You must be signed in to change notification settings - Fork 3k
Application Services for the iOS Developer
Application Services (AS, or sometimes A~S) is a dependency (in reality, it provides a set of multiple components that may ship separately soon) that many Mozilla products rely on, including ours. AS allows us to integrate with Firefox Accounts, Sync, Experimentation, etc. The aim of this document is to:
- provide the team with an overview of it
- how we integrate it (currently Carthage, but SPM soon)
- what's available to leverage, and what we do to begin adoption and use of them
- what's left to leverage/adopt
- and limitations that specifically impact this team.
- Application Services Repo. Although there's an Application Services in mozilla-mobile, it's a fork of the official. See ONLY the official.
- Our repo, of course, Firefox-ios.
- The focus repo also utilizes AS, so it's a good reference.
Here's the flow of things.
AS has many components that are all written in Rust. Bindings/wrappers are generated (with Uniffi) or manually written for Kotlin and Swift afterwards. And finally (currently), our product consumes AS via a Carthage binary.
Respective repositories consume those APIs through those wrappers to implement a given feature in the product.
To see a list of all components that are a part of AS, you can look here.
If you navigate into a component, you'll see that some components have a detailed README. You'll also find that some components have a separate Android and iOS directory, but not all do. iOS seems to be missing sometimes, indicating that the given component isn't ready for iOS products to consume yet.
Summaries from READMEs will be most helpful, but you can also look at details of each component here. Each "crate" is a component you can find more details about, albeit some of it might not be directly relevant to us.
Currently, we consume AS through Carthage/binary. A .fat
file is generated that contains all precompiled binaries. Carthage collects all of that into a single directory, and eventually XCode locates and compiles.
Currently, Firefox-ios has issues running on M1 due to the nature of .fat
files. These libraries can only contain binaries for one architecture. With the introduction to M1's we've moved from:
-
x86_64
--> Simulators -
arm64
--> physical devices
To:
-
x86_64
orarm64
--> Simulator Intel or M1 -
arm64
--> physical device
It's been recommended to switch to XCFrameworks, which SPM supports well. There's been much work done for this already on both the AS side, and ours. Here's a PR that converts AS via Carthage to SPM.
To follow progress of this migration, you can look at this wiki here.
There's about 15 components available, but iOS can utilize about 10 of those at the moment:
- RustLog
- Viaduct
- Nimbus
- Glean
- CrashTest
- Logins
- FxAClient
- Push
- Tabs
- Places
- Autofill
More components out of AS are being worked on to be available for iOS, but without being able to use GeckoView, you can expect component availibility to take a bit longer.
To see the official list, and others that get added/removed in the future, you can look at Package.swift here from AS.
Currently, we utilize FxA, Logins, Places, Glean, and Nimbus to name a few. There's quite a few components left to adopt and use, but transitioning to using them may take time. It's possible that a feature was implemented prior to the component being available. If that's the case, then there's a higher level of effort to moving to use it, naturally.
Given the team can't utilize GeckoView (yet?), you can expect components to be available a bit later than Android. However, to maintain feature parity across the two platforms, the iOS team may opt for a custom implementation. This costs more cycles and also makes adoption of the component (when it becomes available) to be slower.
Take Nimbus as an example.
Let's say Nimbus became newly available for the iOS team to consume. It has been added as a component of AS, and you're now using an updated AS version that incliudes this new component. So, where do we start?
Since this component is part of AS, we simply add the import statement for AS, import MozillaAppServices
and start using what you'd like from it. For example, see Experiments.swift
. The alternative importing MzoillaAppServices would be to import that specific module directly, import Nimbus
. To see an example of this, you can have a look at this PR from Focus-iOS. After discussing with the core firefox team, we may follow the same pattern of adoption.
Afterwards, you can Command-Click into it to see the API and what's available to you. You can also go to AS's components directory and drill into the iOS folder. The component's API is viewable there as well.
As both teams work towards supporting this migration, we'll note related PRs and wikis here. Currently, the Firefox-iOS team is working towards moving towards SPM with its current 3rd party dependencies. After an SPM migration, we'll work on removing as many of those as we can.
- This wiki :D
- Modernizing AS for iOS