Skip to content

Commit 3a01415

Browse files
committed
docs(firestore): Add docs on Firestore x SPM integration
1 parent 8314558 commit 3a01415

File tree

1 file changed

+152
-0
lines changed

1 file changed

+152
-0
lines changed

docs/FirestoreSPM.md

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
# Firestore Swift Package Manager Target Hierarchy
2+
3+
This document outlines the hierarchy of the Firestore-related targets in the
4+
`Package.swift` manifest. The setup is designed to support two different build
5+
options for Firestore: from source or from a pre-compiled binary. This choice is
6+
controlled by the `FIREBASE_SOURCE_FIRESTORE` environment variable.
7+
8+
## Main Product
9+
10+
The main entry point for integrating Firestore via Swift Package Manager is the
11+
`FirebaseFirestore` library product.
12+
13+
```swift
14+
.library(
15+
name: "FirebaseFirestore",
16+
targets: ["FirebaseFirestoreTarget"]
17+
)
18+
```
19+
20+
This product points to a wrapper target, `FirebaseFirestoreTarget`, which then
21+
depends on the appropriate Firestore targets based on the chosen build option.
22+
23+
---
24+
25+
## Wrapper Target
26+
27+
The `FirebaseFirestoreTarget` is a thin wrapper that exists to work around a
28+
limitation in Swift Package Manager where a single target cannot conditionally
29+
depend on different sets of targets (source vs. binary).
30+
31+
By having clients depend on the wrapper, the `Package.swift` can internally
32+
manage the complexity of switching between source and binary builds based on the
33+
`FIREBASE_SOURCE_FIRESTORE` environment variable. This provides a stable entry
34+
point for all clients and avoids pushing conditional logic into their own
35+
package manifests.
36+
37+
---
38+
39+
## 1. Binary-Based Build
40+
41+
When the `FIREBASE_SOURCE_FIRESTORE` environment variable is **not** set (which is
42+
the default), Swift Package Manager will use pre-compiled binaries for Firestore
43+
and its heavy dependencies.
44+
45+
### Dependency Hierarchy
46+
47+
The dependency tree for a binary-based build is as follows:
48+
49+
```
50+
FirebaseFirestore (Library Product)
51+
└── FirebaseFirestoreTarget (Wrapper Target)
52+
└── FirebaseFirestore (Swift Target)
53+
├── FirebaseAppCheckInterop
54+
├── FirebaseCore
55+
├── FirebaseCoreExtension
56+
├── FirebaseSharedSwift
57+
├── leveldb
58+
├── nanopb
59+
├── abseil (binary) (from https://github.com/google/abseil-cpp-binary.git)
60+
├── gRPC-C++ (binary) (from https://github.com/google/grpc-binary.git)
61+
└── FirebaseFirestoreInternalWrapper (Wrapper Target)
62+
└── FirebaseFirestoreInternal (Binary Target)
63+
```
64+
65+
### Target Breakdown
66+
67+
* **`FirebaseFirestoreTarget`**: A wrapper target, same as in the source-based
68+
build.
69+
* **`FirebaseFirestore`**: The Swift target containing the public API. In this
70+
configuration, it depends on the binary versions of abseil and gRPC, as
71+
well as the `FirebaseFirestoreInternalWrapper`.
72+
* **`FirebaseFirestoreInternalWrapper`**: A thin wrapper target that exists to
73+
expose the headers from the underlying binary target.
74+
* **`FirebaseFirestoreInternal`**: This is a `binaryTarget` that downloads and
75+
links the pre-compiled `FirebaseFirestoreInternal.xcframework`. This
76+
framework contains the compiled C++ core of Firestore.
77+
78+
---
79+
80+
## 2. Source-Based Build
81+
82+
When the `FIREBASE_SOURCE_FIRESTORE` environment variable is set, Firestore and
83+
its dependencies (like abseil and gRPC) are compiled from source.
84+
85+
### Dependency Hierarchy
86+
87+
The dependency tree for a source-based build looks like this:
88+
89+
```
90+
FirebaseFirestore (Library Product)
91+
└── FirebaseFirestoreTarget (Wrapper Target)
92+
└── FirebaseFirestore (Swift Target)
93+
├── FirebaseCore
94+
├── FirebaseCoreExtension
95+
├── FirebaseSharedSwift
96+
└── FirebaseFirestoreInternalWrapper (C++ Target)
97+
├── FirebaseAppCheckInterop
98+
├── FirebaseCore
99+
├── leveldb
100+
├── nanopb
101+
├── abseil (source) (from https://github.com/firebase/abseil-cpp-SwiftPM.git)
102+
├── gRPC-cpp (source) (from https://github.com/grpc/grpc-ios.git)
103+
└── BoringSSL (source) (from https://github.com/firebase/boringSSL-SwiftPM.git)
104+
```
105+
106+
### Target Breakdown
107+
108+
* **`FirebaseFirestoreTarget`**: A wrapper target that conditionally depends on
109+
the main `FirebaseFirestore` target.
110+
* **`FirebaseFirestore`**: The main Swift target containing the public Swift
111+
API for Firestore. It acts as a bridge to the underlying C++
112+
implementation.
113+
* **`FirebaseFirestoreInternalWrapper`**: This target compiles the core C++
114+
source code of Firestore. It depends on other low-level libraries and C++
115+
dependencies, which are also built from source.
116+
117+
---
118+
119+
## 3. Local Binary Build (CI Only)
120+
121+
A third, less common build option is available for CI environments. When the
122+
`FIREBASECI_USE_LOCAL_FIRESTORE_ZIP` environment variable is set, the build
123+
system will use a local `FirebaseFirestoreInternal.xcframework` instead of
124+
downloading the pre-compiled binary. This option assumes the xcframework is
125+
located at the root of the repository.
126+
127+
This option is primarily used by internal scripts, such as
128+
`scripts/check_firestore_symbols.sh`, to perform validation against a locally
129+
built version of the Firestore binary. It is not intended for general consumer
130+
use.
131+
132+
---
133+
134+
## 4. Test Targets
135+
136+
The testing infrastructure for Firestore in Swift Package Manager is designed to
137+
be independent of the build choice (source vs. binary).
138+
139+
* **`FirebaseFirestoreTestingSupport`**: This is a library target, not a test
140+
target. It provides public testing utilities that consumers can use to write
141+
unit tests for their Firestore-dependent code. It has a dependency on
142+
`FirebaseFirestoreTarget`, which means it will link against whichever
143+
version of Firestore (source or binary) is being used in the build.
144+
145+
* **`FirestoreTestingSupportTests`**: This is a test target that contains the
146+
unit tests for the `FirebaseFirestoreTestingSupport` library itself. Its
147+
purpose is to validate the testing utilities.
148+
149+
Because both of these targets depend on the `FirebaseFirestoreTarget` wrapper,
150+
they seamlessly adapt to either the source-based or binary-based build path
151+
without any conditional logic.
152+

0 commit comments

Comments
 (0)