Skip to content

Commit 770accf

Browse files
authored
Fix iOS build multiple platform and architecture (#213)
1 parent b4baf76 commit 770accf

File tree

5 files changed

+171
-87
lines changed

5 files changed

+171
-87
lines changed

.github/workflows/ios.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jobs:
2828
LC_ALL: en_US.UTF-8
2929
LANG: en_US.UTF-8
3030
U3D_PASSWORD: ""
31+
xcodeVersion: "12.4"
3132

3233
steps:
3334
- name: Checkout Unity Repo
@@ -49,6 +50,9 @@ jobs:
4950
with:
5051
python-version: '3.7'
5152

53+
- name: setup Xcode version
54+
run: sudo xcode-select -s /Applications/Xcode_${{ env.xcodeVersion }}.app/Contents/Developer
55+
5256
- name: Install prerequisites
5357
shell: bash
5458
run: |

build_ios.sh

Lines changed: 131 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#
1717
# Builds and runs the tests, meant to be used on a bash environment.
1818

19-
usage(){
19+
usage() {
2020
echo "Usage: $0 [options]
2121
options:
2222
-b, build path default: ios_unity
@@ -30,15 +30,20 @@ usage(){
3030

3131
set -e
3232

33-
readonly SUPPORTED_PLATFORMS=(device) # simulator) only support device arch for now
34-
readonly SUPPORTED_ARCHITECTURES="arm64;armv7" #;x86_64;i386" only support device arch for now
35-
#readonly DEVICE_ARCHITECTURES="arm64;armv7" only support device arch for now
36-
#readonly SIMULATOR_ARCHITECTURES="arm64;x86_64;i386" only support device arch for now
33+
readonly SUPPORTED_PLATFORMS=(device simulator)
34+
readonly SUPPORTED_ARCHITECTURES=(arm64 armv7 x86_64 i386)
35+
readonly DEVICE_ARCHITECTURES=(arm64 armv7)
36+
readonly SIMULATOR_ARCHITECTURES=(arm64 x86_64 i386)
37+
readonly DEVICE_IOS_PLATFORM_LOCATION="iPhoneOS.platform"
38+
readonly SIMULATOR_IOS_PLATFORM_LOCATION="iPhoneSimulator.platform"
39+
readonly DEVICE_OSX_SYSROOT="iphoneos"
40+
readonly SIMULATOR_OSX_SYSROOT="iphonesimulator"
3741

3842
# build default value
3943
buildpath="ios_unity"
4044
sourcepath="."
4145
platforms=("${SUPPORTED_PLATFORMS[@]}")
46+
architectures=("${SUPPORTED_ARCHITECTURES[@]}")
4247
cmake_extra=""
4348

4449
# Enable utf8 output
@@ -48,57 +53,117 @@ export LANG=en_US.UTF-8
4853
IFS=',' # split options on ',' characters
4954
while getopts "hb:s:p:a:c:" opt; do
5055
case $opt in
51-
h)
52-
usage
53-
exit 0
54-
;;
55-
b)
56-
buildpath=$OPTARG
57-
;;
58-
s)
59-
sourcepath=$OPTARG
60-
if [[ ! -d "${sourcepath}" ]]; then
61-
echo "Source path ${sourcepath} not found."
56+
h)
57+
usage
58+
exit 0
59+
;;
60+
b)
61+
buildpath=$OPTARG
62+
;;
63+
s)
64+
sourcepath=$OPTARG
65+
if [[ ! -d "${sourcepath}" ]]; then
66+
echo "Source path ${sourcepath} not found."
67+
exit 2
68+
fi
69+
;;
70+
p)
71+
platforms=($OPTARG)
72+
for platform in ${platforms[@]}; do
73+
if [[ ! " ${SUPPORTED_PLATFORMS[@]} " =~ " ${platform} " ]]; then
74+
echo "invalid platform: ${platform}"
75+
echo "Supported platforms are: ${SUPPORTED_PLATFORMS[@]}"
6276
exit 2
6377
fi
64-
;;
65-
p)
66-
platforms=($OPTARG)
67-
for platform in ${platforms[@]}; do
68-
if [[ ! " ${SUPPORTED_PLATFORMS[@]} " =~ " ${platform} " ]]; then
69-
echo "invalid platform: ${platform}"
70-
echo "Supported platforms are: ${SUPPORTED_PLATFORMS[@]}"
71-
exit 2
72-
fi
73-
done
74-
;;
75-
a)
76-
architectures=($OPTARG)
77-
for arch in ${architectures[@]}; do
78-
if [[ ! " ${SUPPORTED_ARCHITECTURES[@]} " =~ " ${arch} " ]]; then
79-
echo "invalid architecture: ${arch}"
80-
echo "Supported architectures are: ${SUPPORTED_ARCHITECTURES[@]}"
81-
exit 2
82-
fi
83-
done
84-
;;
85-
c)
86-
cmake_extra=$OPTARG
87-
;;
88-
*)
89-
echo "unknown parameter"
90-
exit 2
91-
;;
78+
done
79+
;;
80+
a)
81+
architectures=($OPTARG)
82+
for arch in ${architectures[@]}; do
83+
if [[ ! " ${SUPPORTED_ARCHITECTURES[@]} " =~ " ${arch} " ]]; then
84+
echo "invalid architecture: ${arch}"
85+
echo "Supported architectures are: ${SUPPORTED_ARCHITECTURES[@]}"
86+
exit 2
87+
fi
88+
done
89+
;;
90+
c)
91+
cmake_extra=$OPTARG
92+
;;
93+
*)
94+
echo "unknown parameter"
95+
exit 2
96+
;;
9297
esac
9398
done
9499
echo "*********************** Build Unity iOS SDK *******************************"
95100
echo "build path: ${buildpath}"
96101
echo "source path: ${sourcepath}"
97102
echo "build platforms: ${platforms[@]}"
103+
echo "architectures: ${architectures[@]}"
98104
echo "cmake extras: ${cmake_extra}"
99105
echo "***************************************************************************"
100-
sourcepath=$(cd ${sourcepath} && pwd) #full path
101-
buildpath=$(mkdir -p ${buildpath} && cd ${buildpath} && pwd) #full path
106+
sourcepath=$(cd ${sourcepath} && pwd) #full path
107+
buildpath=$(mkdir -p ${buildpath} && cd ${buildpath} && pwd) #full path
108+
109+
ios_location=""
110+
osx_sysroot=""
111+
xcode_platforms=""
112+
cmake_archs=""
113+
# build necessary cmake args
114+
if [[ " ${platforms[@]} " =~ " device " ]]; then
115+
echo "Build cmake args for device"
116+
ios_location=${DEVICE_IOS_PLATFORM_LOCATION}
117+
osx_sysroot=${DEVICE_OSX_SYSROOT}
118+
xcode_platforms="-${DEVICE_OSX_SYSROOT}"
119+
for arch in ${architectures[@]}; do
120+
if [[ " ${DEVICE_ARCHITECTURES[@]} " =~ " ${arch} " ]]; then
121+
if [ "$cmake_archs" == "" ]; then
122+
cmake_archs=${arch}
123+
else
124+
cmake_archs="${cmake_archs};${arch}"
125+
fi
126+
fi
127+
done
128+
fi
129+
130+
if [[ " ${platforms[@]} " =~ " simulator " ]]; then
131+
echo "Build cmake args for simulator"
132+
if [ "$ios_location" == "" ]; then
133+
ios_location=${SIMULATOR_IOS_PLATFORM_LOCATION}
134+
else
135+
ios_location="${ios_location};${SIMULATOR_IOS_PLATFORM_LOCATION}"
136+
fi
137+
if [ "$osx_sysroot" == "" ]; then
138+
osx_sysroot=${SIMULATOR_OSX_SYSROOT}
139+
else
140+
osx_sysroot="${osx_sysroot};${SIMULATOR_OSX_SYSROOT}"
141+
fi
142+
if [ "$xcode_platforms" == "" ]; then
143+
xcode_platforms="-${SIMULATOR_OSX_SYSROOT}"
144+
else
145+
xcode_platforms="${xcode_platforms};-${SIMULATOR_OSX_SYSROOT}"
146+
fi
147+
148+
for arch in ${architectures[@]}; do
149+
if [[ " ${SIMULATOR_ARCHITECTURES[@]} " =~ " ${arch} " ]]; then
150+
if [ "$cmake_archs" == "" ]; then
151+
cmake_archs=${arch}
152+
else
153+
if [[ ! " ${DEVICE_ARCHITECTURES[@]} " =~ " ${arch} " ]]; then
154+
cmake_archs="${cmake_archs};${arch}"
155+
fi
156+
fi
157+
fi
158+
done
159+
fi
160+
161+
echo "*********************** CMake Args *******************************"
162+
echo "ios_location: ${ios_location}"
163+
echo "osx_sysroot: ${osx_sysroot}"
164+
echo "xcode_platforms: ${xcode_platforms}"
165+
echo "cmake_archs: ${cmake_archs}"
166+
echo "***************************************************************************"
102167

103168
# Stop display commands being run.
104169
set +x
@@ -107,17 +172,17 @@ set +x
107172
FIRST_FAILED_EXITCODE=0
108173

109174
function check_exit_code {
110-
if [ "$1" -ne "0" ] && [ "$FIRST_FAILED_EXITCODE" -eq 0 ]; then
111-
FIRST_FAILED_EXITCODE=$1
112-
fi
175+
if [ "$1" -ne "0" ] && [ "$FIRST_FAILED_EXITCODE" -eq 0 ]; then
176+
FIRST_FAILED_EXITCODE=$1
177+
fi
113178
}
114179

115180
CMAKE_OPTIONS="-DFIREBASE_UNITY_BUILD_TESTS=ON"
116181
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DFIREBASE_CPP_BUILD_STUB_TESTS=ON" # enable a stub gtest target to get abseil-cpp working.
117182

118183
if [ -d "../firebase-cpp-sdk" ]; then
119-
REAL_PATH=`python -c "import os; print(os.path.realpath('../firebase-cpp-sdk'))"`
120-
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DFIREBASE_CPP_SDK_DIR=$REAL_PATH"
184+
REAL_PATH=$(python -c "import os; print(os.path.realpath('../firebase-cpp-sdk'))")
185+
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DFIREBASE_CPP_SDK_DIR=$REAL_PATH"
121186
fi
122187

123188
# Display commands being run.
@@ -128,25 +193,28 @@ mkdir -p "$buildpath"
128193

129194
pushd "$buildpath"
130195

131-
# Configure cmake with option value
132-
cmake $sourcepath \
196+
# Configure cmake with option value
197+
cmake $sourcepath \
133198
-DCMAKE_TOOLCHAIN_FILE=$sourcepath/cmake/unity_ios.cmake \
134-
-DCMAKE_OSX_ARCHITECTURES=$SUPPORTED_ARCHITECTURES \
199+
-DCMAKE_OSX_ARCHITECTURES=$cmake_archs \
200+
-DCMAKE_OSX_SYSROOT=$osx_sysroot \
201+
-DCMAKE_XCODE_EFFECTIVE_PLATFORMS=$xcode_platforms \
202+
-DIOS_PLATFORM_LOCATION=$ios_location \
135203
-DUNITY_ROOT_DIR=${UNITY_ROOT_DIR} \
136204
$CMAKE_OPTIONS \
137205
$cmake_extra
138-
check_exit_code $?
206+
check_exit_code $?
139207

140-
# Build the SDK
141-
make
142-
check_exit_code $?
208+
# Build the SDK
209+
make
210+
check_exit_code $?
143211

144-
# Package build output into zip
145-
cpack .
146-
check_exit_code $?
212+
# Package build output into zip
213+
cpack .
214+
check_exit_code $?
147215

148-
# Stop display commands being run.
149-
set +x
216+
# Stop display commands being run.
217+
set +x
150218

151219
popd
152220

cmake/unity_ios.cmake

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,17 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
# Locate gcc
16-
execute_process(COMMAND /usr/bin/xcrun -sdk iphoneos -find clang
17-
OUTPUT_VARIABLE CMAKE_C_COMPILER
18-
OUTPUT_STRIP_TRAILING_WHITESPACE)
19-
20-
# Locate g++
21-
execute_process(COMMAND /usr/bin/xcrun -sdk iphoneos -find clang++
22-
OUTPUT_VARIABLE CMAKE_CXX_COMPILER
23-
OUTPUT_STRIP_TRAILING_WHITESPACE)
24-
25-
# Set the CMAKE_OSX_SYSROOT to the latest SDK found
26-
execute_process(COMMAND /usr/bin/xcrun -sdk iphoneos --show-sdk-path
27-
OUTPUT_VARIABLE CMAKE_OSX_SYSROOT
28-
OUTPUT_STRIP_TRAILING_WHITESPACE)
29-
3015
message(STATUS "gcc found at: ${CMAKE_C_COMPILER}")
3116
message(STATUS "g++ found at: ${CMAKE_CXX_COMPILER}")
3217
message(STATUS "Using iOS SDK: ${CMAKE_OSX_SYSROOT}")
3318

34-
set(CMAKE_OSX_ARCHITECTURES "arm64" CACHE STRING "")
35-
set(CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos")
19+
set(CMAKE_OSX_SYSROOT "iphoneos;iphonesimulator")
20+
set(CMAKE_OSX_ARCHITECTURES "arm64;armv7;x86_64;i386" CACHE STRING "")
21+
set(CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos;-iphonesimulator")
22+
set(IOS_PLATFORM_LOCATION "iPhoneOS.platform;iPhoneSimulator.platform")
23+
24+
set(CMAKE_IOS_INSTALL_UNIVERSAL_LIBS "YES")
25+
set(CMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH "NO")
3626
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO")
3727
set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE "YES")
3828

messaging/testapp/Assets/Firebase/Sample/Messaging/UIHandlerAutomated.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,31 @@ protected override void Start() {
5454
MakeTest(TestGetTokenAsync),
5555
MakeTest(TestDeleteTokenAsync),
5656
};
57+
58+
string[] customTests = {
59+
// Disable these tests on desktop, as desktop never receives a token, and so WaitForToken
60+
// (called by all of these tests) stalls forever.
61+
#if (UNITY_IOS || UNITY_ANDROID)
62+
"TestWaitForToken",
63+
#if !UNITY_IOS
64+
// TODO(b/130674454) This test times out on iOS, disabling until fixed.
65+
"TestSendPlaintextMessageToDevice",
66+
#endif // !UNITY_IOS
67+
"TestSendJsonMessageToDevice",
68+
"TestSendJsonMessageToSubscribedTopic",
69+
#else // (UNITY_IOS || UNITY_ANDROID)
70+
// Run a vacuous test. Should be removed if/when desktop platforms get a real test.
71+
"TestDummy",
72+
#endif // (UNITY_IOS || UNITY_ANDROID)
73+
// TODO(varconst): a more involved test to check that resubscribing works
74+
"TestGetTokenAsync",
75+
"TestDeleteTokenAsync",
76+
};
77+
5778
testRunner = AutomatedTestRunner.CreateTestRunner(
5879
testsToRun: tests,
59-
logFunc: DebugLog
80+
logFunc: DebugLog,
81+
testNames: customTests
6082
);
6183

6284
base.Start();
@@ -151,18 +173,18 @@ IEnumerator TestDummy(TaskCompletionSource<string> tcs) {
151173

152174
// Test GetTokenAsync
153175
IEnumerator TestGetTokenAsync(TaskCompletionSource<string> tcs) {
154-
yield return StartCoroutine(WaitForToken());
155176
FirebaseMessaging.GetTokenAsync().ContinueWithOnMainThread(task => {
156177
tcs.SetResult(task.Result);
178+
DebugLog("GetToken:"+task.Result);
157179
});
158-
180+
yield break;
159181
}
160182
// Test DeleteTokenAsync
161183
IEnumerator TestDeleteTokenAsync(TaskCompletionSource<string> tcs) {
162-
yield return StartCoroutine(WaitForToken());
163184
FirebaseMessaging.DeleteTokenAsync().ContinueWithOnMainThread(task => {
164185
tcs.SetResult("DeleteTokenAsync completed");
165186
});
187+
yield break;
166188
}
167189

168190
// Sends the given message to targetDevice in plaintext format and gives back the message id iff

scripts/gha/print_matrix_configuration.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
"ndk": "https://dl.google.com/android/repository/android-ndk-r19-darwin-x86_64.zip"
110110
},
111111
_LINUX: {
112-
"version": "2019.4.36f1",
112+
"version": "2019.4.37f1",
113113
"packages": {"Default": ["Unity"], "Android": ["Android"], "iOS": ["Ios"], "Windows": ["Windows-mono"], "macOS": ["Mac-mono"], "Linux": None}
114114
}
115115
},
@@ -158,10 +158,10 @@
158158
"emulator_latest": {"platform": "Android", "type": "virtual", "image": "system-images;android-30;google_apis;x86_64"},
159159
"emulator_32bit": {"platform": "Android", "type": "virtual", "image": "system-images;android-30;google_apis;x86"},
160160
"ios_min": {"platform": "iOS", "type": "real", "model": "iphone8", "version": "11.4"},
161-
"ios_target": {"platform": "iOS", "type": "real", "model": "iphone8plus", "version": "12.0"},
161+
"ios_target": {"platform": "iOS", "type": "real", "model": "iphone8", "version": "14.7"},
162162
"ios_latest": {"platform": "iOS", "type": "real", "model": "iphone11", "version": "13.6"},
163163
"simulator_min": {"platform": "iOS", "type": "virtual", "name": "iPhone 6", "version": "11.4"},
164-
"simulator_target": {"platform": "iOS", "type": "virtual", "name": "iPhone 8", "version": "12.0"},
164+
"simulator_target": {"platform": "iOS", "type": "virtual", "name": "iPhone 8", "version": "14.5"},
165165
"simulator_latest": {"platform": "iOS", "type": "virtual", "name": "iPhone 11", "version": "14.4"},
166166
}
167167

0 commit comments

Comments
 (0)