|
| 1 | +# Overview |
| 2 | + |
| 3 | +This describes how to Firestore CPP SDK works on supported platforms, and how to |
| 4 | +contribute this Firestore CPP SDK. |
| 5 | + |
| 6 | +Please read `README.md` and `CONTRIBUTING.md` from the repository root first. |
| 7 | + |
| 8 | +# Prerequisites |
| 9 | + |
| 10 | +There is no specific prerequisites for Firestore, `README.md` from the root directory |
| 11 | +should have everything you need. |
| 12 | + |
| 13 | +One slight enhancement is to use [https://github.com/pyenv/pyenv][pyenv] to manage |
| 14 | +your python versions, if you work on multiple projects with different python |
| 15 | +requirements. |
| 16 | + |
| 17 | +For CPP SDK to compile, you generally need your `pyenv which python` to point to |
| 18 | +a Python3 installation. |
| 19 | + |
| 20 | +# Architecture |
| 21 | + |
| 22 | +It is easier to work this Firestore CPP SDK by keeping a high level archetecture in mind: |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | +To summarize, the C++ Code in this directory is an adapting layer on top of the underlying |
| 27 | +SDKs: Firestore Android SDK for Android, and C++ Core SDK for everything else. |
| 28 | + |
| 29 | +These dependencies live within different github repos, so understanding where and which versions |
| 30 | +of the dependencies being used is critical to troubleshooting, should the issues stem from |
| 31 | +those dependencies or the interop layer. |
| 32 | + |
| 33 | +# Desktop building and testing |
| 34 | + |
| 35 | +Desktop builds of the Firestore SDK uses `CMAKE` to build and test. The complete set |
| 36 | +of tests lives under `${REPO_ROOT}/firestore/integration_test_internal`. To build |
| 37 | +the Firestore CPP SDK and its test suites: |
| 38 | + |
| 39 | +```shell |
| 40 | +# from ${REPO_ROOT}/firestore/integration_test_internal |
| 41 | +mkdir cmake-build-debug |
| 42 | +cd cmake-build-debug |
| 43 | + |
| 44 | +# Generate build files |
| 45 | +cmake .. # Or OPENSSL_ROOT_DIR=${PATH_TO_OPENSSL} cmake .. |
| 46 | +# Build SDK and tests |
| 47 | +cmake --build . -j |
| 48 | +``` |
| 49 | + |
| 50 | +Once above steps are successful, there should be a `integration_test` under the current directory: |
| 51 | +```shell |
| 52 | +./integration_test # Run all tests against Firestore Prod Backend |
| 53 | + |
| 54 | +USE_FIRESTORE_EMULATOR=yes ./integration_test # Run all tests against Firestore Emulator |
| 55 | + |
| 56 | +# Run all tests against Firestore Emulator on a custom port |
| 57 | +USE_FIRESTORE_EMULATOR=yes FIRESTORE_EMULATOR_PORT=9999 ./integration_test |
| 58 | + |
| 59 | +./integration_test --gtest_filter="*Query*" # Run a subset of tests |
| 60 | +``` |
| 61 | + |
| 62 | +It is also possible to change where we get the underlying C++ Core SDK living under |
| 63 | +`firebase-ios-sdk` by providing a custom cmake flag `FIRESTORE_DEP_SOURCE`: |
| 64 | +```shell |
| 65 | +# Default behavior when not specified, getting the Core SDK the last C++ SDK release |
| 66 | +# was released with. |
| 67 | +cmake -DFIRESTORE_DEP_SOURCE=RELEASED .. |
| 68 | + |
| 69 | +# Clones the origin/master branch of `firebase-ios-sdk` to get the Core SDK. |
| 70 | +cmake -DFIRESTORE_DEP_SOURCE=TIP .. |
| 71 | + |
| 72 | +# Clones the origin/master branch of `firebase-ios-sdk` to get the Core SDK. |
| 73 | +cmake -DFIRESTORE_DEP_SOURCE=origin/master .. |
| 74 | + |
| 75 | +# Clones commit '555555' of `firebase-ios-sdk`. |
| 76 | +cmake -DFIRESTORE_DEP_SOURCE=555555 .. |
| 77 | +``` |
| 78 | + |
| 79 | +## IDE Integration |
| 80 | + |
| 81 | +Open up the repo root directory from `CLion` should load all symbols for the SDK itself. |
| 82 | +Once loaded, you can right click on `firestore/integration_test_internal/CMakeLists.txt` |
| 83 | +and `load project` to load the tests into the IDE. |
| 84 | + |
| 85 | +# Android building and testing |
| 86 | + |
| 87 | +Once Android NDK is installed and added to `local.properties` (should be same as the one |
| 88 | +you use for Android SDK development), and `google-services.json`, |
| 89 | +is added to `integration_test_internal`, it should be possible to build the testing |
| 90 | +Android App directly with `gradlew`: |
| 91 | + |
| 92 | +```shell |
| 93 | +# from within integration_test_internal, build and install the testapp to an emulator or |
| 94 | +# device |
| 95 | +./gradlew installDebug |
| 96 | + |
| 97 | +# Start the testapp |
| 98 | +adb shell am start com.google.firebase.cpp.firestore.testapp/android.app.NativeActivity |
| 99 | +``` |
| 100 | + |
| 101 | +**Note Firestore Emulator support is currently broken, it falls back to using Production Backend for now.** |
| 102 | +It is also possible to run the testapp against Firestore emulator, as long as the testapp |
| 103 | +is run from an Android Emulator and the Firestore emulator is running from the same |
| 104 | +host OS: |
| 105 | + |
| 106 | +```shell |
| 107 | +# Start the testapp, but run against Firestore emulator |
| 108 | +adb shell am start com.google.firebase.cpp.firestore.testapp/android.app.NativeActivity -e USE_FIRESTORE_EMULATOR true |
| 109 | +``` |
| 110 | + |
| 111 | +## IDE Integration |
| 112 | + |
| 113 | +It is possible to simply open up the `integration_test_internal` directory from `Android Studio` |
| 114 | +directly, Android Studio will configure gradle and load all the tasks. Once configured, there |
| 115 | +should be a `integration_test_internal` testapp you can start/debug from Android Studio. |
| 116 | + |
| 117 | +In case when you cannot start the testapp from Android Studio, you can start it via `adb`: |
| 118 | + |
| 119 | +```shell |
| 120 | +# Start the testapp but wait for a debug to attach |
| 121 | +adb shell am start -D -N com.google.firebase.cpp.firestore.testapp/android.app.NativeActivity |
| 122 | +``` |
| 123 | + |
| 124 | +Then attach the debugger from Android Studio to unblock the testapp. |
| 125 | + |
| 126 | + |
| 127 | +# iOS building and testing |
| 128 | + |
| 129 | +When targting iOS, the SDK gets its dependency from Cocoapods, as opposed to from `cmake/external/firestore.cmake`. |
| 130 | +The dependencies are specified with `ios_pod/Podfile`. Running cmake for iOS will download the pods |
| 131 | +listed in this file, and add the C++ headers from the downloaded pods to include directories. |
| 132 | + |
| 133 | +To build Firestore for iOS/tvOS: |
| 134 | +```shell |
| 135 | +# Build xcframeworks from this REPO, install pod dependencies and prepare xcworkspace |
| 136 | +./prepare_xcworkspace.sh |
| 137 | + |
| 138 | +# Open up the workspace |
| 139 | +open integration_test.xcworkspace |
| 140 | +``` |
| 141 | + |
| 142 | +NOTE: `prepare_xcworkspace.sh` changes `integration_test.xcodeproj/project.pbxproj`, to add the |
| 143 | +build xcframeworks, these changes are not meant to be checked in, otherwise CI jobs will fail. |
| 144 | + |
| 145 | +It should now be possible to run iOS tests in a simulator or a device from XCode. |
| 146 | + |
| 147 | +To run the tests against a Firestore Emulator from an iOS simulator, set environment |
| 148 | +variable `USE_FIRESTORE_EMULATOR` from XCode by: |
| 149 | + |
| 150 | +1. Go to `Edit Scheme...` for target `integration_test`. |
| 151 | +2. Add the environment variable like below: |
| 152 | + |
| 153 | + |
| 154 | + |
| 155 | + |
| 156 | +## IDE Integration |
| 157 | + |
| 158 | +IDE integration for iOS unfortunately is splitted between CLion and XCode. You can |
| 159 | +do most of the development from CLion, with the same setup as desktop testing, and |
| 160 | +use XCode for debugging only. |
0 commit comments