Skip to content

Commit 86c04f3

Browse files
committed
Firestore instructions and convinience script
1 parent 7419575 commit 86c04f3

File tree

5 files changed

+197
-4
lines changed

5 files changed

+197
-4
lines changed

.gitignore

+46
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,49 @@ vcpkg
3030

3131
# Visual Studio Code
3232
.vscode/
33+
34+
# Firestore testapp
35+
firestore/testapp/**/*.dll
36+
firestore/testapp/**/*.pdb
37+
firestore/testapp/**/*.bundle
38+
firestore/testapp/**/*.meta
39+
40+
firestore/testapp/Assets/Plugins
41+
firestore/testapp/Assets/StreamingAssets
42+
firestore/testapp/Assets/Editor Default Resources
43+
firestore/testapp/Assets/ExternalDependencyManager
44+
firestore/testapp/Assets/Firebase/Editor/*.xml
45+
firestore/testapp/Assets/Firebase/Editor/*.txt
46+
firestore/testapp/Assets/Firebase/Editor/*.exe
47+
firestore/testapp/Assets/Firebase/Editor/*.py
48+
firestore/testapp/Assets/Firebase/Sample/AutomatedTestRunner.cs
49+
firestore/testapp/Assets/Firebase/Sample/ftl_testapp_files
50+
firestore/testapp/Assets/Firebase/m2repository
51+
52+
firestore/testapp/Library
53+
firestore/testapp/Logs
54+
firestore/testapp/Packages
55+
firestore/testapp/Temp
56+
firestore/testapp/UserSettings
57+
firestore/testapp/android_BackUpThisFolder_ButDontShipItWithYourGame
58+
firestore/testapp/ios
59+
firestore/testapp/macos.app/Contents
60+
firestore/testapp/obj/Debug
61+
firestore/testapp/Assembly-CSharp-Editor.csproj
62+
firestore/testapp/Assembly-CSharp-firstpass.csproj
63+
firestore/testapp/Assembly-CSharp.csproj
64+
firestore/testapp/Tests.csproj
65+
firestore/testapp/android.apk
66+
firestore/testapp/android_mapping.txt
67+
firestore/testapp/testapp.sln
68+
69+
firestore/testapp/ProjectSettings/AndroidResolverDependencies.xml
70+
firestore/testapp/ProjectSettings/GvhProjectSettings.xml
71+
firestore/testapp/ProjectSettings/MemorySettings.asset
72+
firestore/testapp/ProjectSettings/PackageManagerSettings.asset
73+
firestore/testapp/ProjectSettings/PresetManager.asset
74+
firestore/testapp/ProjectSettings/TimelineSettings.asset
75+
firestore/testapp/ProjectSettings/VFXManager.asset
76+
firestore/testapp/ProjectSettings/VersionControlSettings.asset
77+
firestore/testapp/ProjectSettings/XRSettings.asset
78+
firestore/testapp/ProjectSettings/boot.config

firestore/CONTRIBUTING.md

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Overview
2+
3+
This describes how Firestore Unity SDK works, and how to develop and test
4+
the SDK, targeting desktop/Android/iOS.
5+
6+
# Prerequisites
7+
8+
Building the Unity SDK requires building the underlying C++ SDK. Refer to
9+
[][this doc] for what the prerequisites are.
10+
11+
On top of above, you also need Unity installed (obviously). If you use an
12+
apple silicon machine as host, be sure to install the right version of
13+
Unity!
14+
15+
# Building Firestore Unity SDK
16+
17+
Building Firestore into Unity Packages is a very involved process, mixed with
18+
multiple build tools working together. Therefore, we will rely on Python scripts
19+
to automate the process. The scripts live under `$REPO_ROOT/scripts/build_scripts`.
20+
21+
```zsh
22+
# all scripts are run from the repo root.
23+
24+
# Building for Mac. The build tools will try to find Unity automatically
25+
python scripts/build_scripts/build_zips.py -platform=macos -targets=auth -targets=firestore -use_boringssl
26+
27+
# If above does not work, try specify Unity path direcly
28+
python scripts/build_scripts/build_zips.py -platform=macos -unity_root=<PATH_TO_UNITY> -targets=auth -targets=firestore -use_boringssl
29+
30+
# Building for Android
31+
python scripts/build_scripts/build_zips.py -platform=android -targets=auth -targets=firestore -use_boringssl
32+
33+
# Building for iOS. Incremental build for iOS is broken, so we use clean_build here.
34+
python scripts/build_scripts/build_zips.py -platform=android -targets=auth -targets=firestore -use_boringssl -clean_build
35+
36+
# Other supported platforms are tvos,linux,windows
37+
```
38+
39+
After running above commands, some zip files for each platform are created under
40+
`$PLATFORM_unity` directories. Run below to put all of them into Unity packages:
41+
42+
```zsh
43+
# Built Unity packages for all platforms are stored under ./package_dir
44+
python scripts/build_scripts/zips_to_packages.py --output package_dir
45+
```
46+
47+
# Running Firestore Desktop TestApp
48+
49+
Test app for Firestore is under `firestore/testapp`, we need to copy a
50+
`google-services.json` or `GoogleServices-Info.plist` to `firestore/testapp/Assets/Firebase/Sample/Firestore`
51+
before we can run the test app.
52+
53+
The testapp depends on a custom test runner, which is needs to be copied over unfortunately:
54+
55+
```zsh
56+
cp ./scripts/gha/integration_testing/automated_testapp/AutomatedTestRunner.cs firestore/testapp/Assets/Firebase/Sample/
57+
cp -r ./scripts/gha/integration_testing/automated_testapp/ftl_testapp_files firestore/testapp/Assets/Firebase/Sample/
58+
```
59+
60+
To run the test app, open `firestore/testapp` from Unity Editor, and load the Unity packages we built above.
61+
Then open up `firestore/testapp/Assets/Firebase/Sample/Firestore/MainSceneAutomated.unity`, you should be
62+
able to run this scene which in turn runs all integration tests for Firestore.
63+
64+
# Running Firestore Android TestApp
65+
66+
You *probably* need to use `IL2CPP` as scripting backend instead of `Mono` for Android. To do this,
67+
you can go to `Edit->Project Setting->Player->Android->Scripting Backend` and select `IL2CPP`.
68+
69+
You also need to turn on `minification` under on the same setting page, by turning on `R8` under `publish
70+
settings`.
71+
72+
To run the Android testapp, go to `File->Build Settings`, select `Android` then click `Switch Platform`. After
73+
assets are loaded, click `Build and Run`.
74+
75+
# Running Firestore iOS TestApp
76+
77+
Similarly for iOS, go to `File-Build Settings` and select `iOS`. After you click `Build and Run`, it will prompt
78+
you to select a directory to save generated code and XCode project.
79+
80+
After the code generation is done, go under the directory, and run `pod install` to generate
81+
a `xcworkspace`, then open it via `XCode`. From `XCode` you should be able to sign the testapp, build and run/debug
82+
the app with an actual iOS device, or as an iPad App on an Apple Silicon mac.

firestore/testapp/Assets/Firebase/Editor/Builder.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public static void BuildTvos() {
5151
options.locationPathName = "tvos-build";
5252
options.target = BuildTarget.tvOS;
5353
// Firebase Unity plugins don't seem to work on a simulator.
54-
PlayerSettings.tvOS.sdkVersion = tvOSSdkVersion.DeviceSDK;
54+
PlayerSettings.tvOS.sdkVersion = tvOSSdkVersion.Device;
5555

5656
// AcceptExternalModificationsToPlayer corresponds to "Append" in the Unity
5757
// UI -- it allows doing incremental builds.

scripts/build_scripts/build_zips.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ def make_macos_arch(arch, cmake_args):
466466
build_dir = os.path.join(os.getcwd(), arch)
467467
cmake_args.append('-DCMAKE_OSX_ARCHITECTURES='+arch)
468468
subprocess.call(cmake_args, cwd=build_dir)
469-
subprocess.call('make', cwd=build_dir)
469+
subprocess.call(['make', '-j'], cwd=build_dir)
470470
subprocess.call(['cpack', '.'], cwd=build_dir)
471471

472472
def make_macos_multi_arch_build(cmake_args):
@@ -565,7 +565,7 @@ def make_tvos_target(device, arch, cmake_args):
565565
os.makedirs(arch)
566566
build_dir = os.path.join(os.getcwd(), arch)
567567
subprocess.call(build_args, cwd=build_dir)
568-
subprocess.call('make', cwd=build_dir)
568+
subprocess.call(['make', '-j'], cwd=build_dir)
569569
subprocess.call(['cpack', '.'], cwd=build_dir)
570570

571571
def make_tvos_multi_arch_build(cmake_args):
@@ -795,7 +795,7 @@ def main(argv):
795795
# no make command in windows. TODO make config passable
796796
subprocess.call("cmake --build . --config Release")
797797
else:
798-
subprocess.call("make")
798+
subprocess.call(["make", "-j"])
799799

800800
cmake_pack_args = [
801801
"cpack",
+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/python
2+
#
3+
# Copyright 2022 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
"""Collects built zips(built by build_zips.py) under current directory
18+
and packages them into Unity Packages using build_packages.py.
19+
20+
Example usage:
21+
python zips_to_packages.py --ouput unity_packages
22+
"""
23+
import glob
24+
import os
25+
import shutil
26+
import subprocess
27+
import zipfile
28+
import tempfile
29+
import threading
30+
import sys
31+
32+
from absl import app, flags, logging
33+
34+
FLAGS = flags.FLAGS
35+
flags.DEFINE_string(
36+
'output', 'unity_packages',
37+
'Relative directory to save the generated unity packages')
38+
39+
def main(argv):
40+
if len(argv) > 1:
41+
raise app.UsageError('Too many command-line arguments.')
42+
output = FLAGS.output
43+
44+
if os.path.exists(output):
45+
shutil.rmtree(output)
46+
if not os.path.exists(output):
47+
os.makedirs(output)
48+
logging.info("Ready to build Unity packages to {}".format(output))
49+
50+
zip_temp_dir = tempfile.mkdtemp()
51+
52+
try:
53+
candidates = glob.glob('./*_unity/firebase_unity*.zip')
54+
for candidate in candidates:
55+
shutil.copy(candidate, zip_temp_dir)
56+
57+
if len(candidates) > 0:
58+
logging.info("Found zip files:\n {}".format("\n".join(candidates)))
59+
subprocess.call(["python", "scripts/build_scripts/build_package.py",
60+
"--zip_dir", zip_temp_dir, "-output", output])
61+
finally:
62+
shutil.rmtree(zip_temp_dir)
63+
64+
if __name__ == '__main__':
65+
app.run(main)

0 commit comments

Comments
 (0)