Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
ef6a718
cmake build Framework for iOS
sunmou99 Sep 11, 2020
9ab04a5
remove log messages
sunmou99 Sep 16, 2020
c012cb6
Update CMakeLists.txt
sunmou99 Sep 25, 2020
283af3a
Update CMakeLists.txt
sunmou99 Sep 25, 2020
93235d7
script to build iOS framework
sunmou99 Sep 16, 2020
a18b8d3
Update build script & add iOS GHA workflow
sunmou99 Sep 16, 2020
099b6d6
add flag -g[generate Makefiles] -c[CMake build]
sunmou99 Sep 26, 2020
70233c0
build arch in parallel
sunmou99 Oct 5, 2020
04708d7
Update build.sh
sunmou99 Oct 5, 2020
d5f000b
remove useless ""
sunmou99 Oct 5, 2020
9b1e307
Update CMakeLists.txt
sunmou99 Oct 6, 2020
b673801
cmake build Framework for iOS
sunmou99 Sep 11, 2020
d4a00fc
remove log messages
sunmou99 Sep 16, 2020
73f3f3a
Update CMakeLists.txt
sunmou99 Sep 25, 2020
89aee7a
Update CMakeLists.txt
sunmou99 Sep 25, 2020
1ed0d3c
remove useless ""
sunmou99 Oct 5, 2020
a3ed148
Update CMakeLists.txt
sunmou99 Oct 6, 2020
bdfa427
Merge branch 'feature/cmake-ios-framework' of https://github.com/fire…
sunmou99 Oct 6, 2020
10c6e9f
script to build iOS framework
sunmou99 Sep 16, 2020
e9481f5
Update build script & add iOS GHA workflow
sunmou99 Sep 16, 2020
35c7dd7
add flag -g[generate Makefiles] -c[CMake build]
sunmou99 Sep 26, 2020
8bcabed
build arch in parallel
sunmou99 Oct 5, 2020
c26dc51
Update build.sh
sunmou99 Oct 5, 2020
401ec13
Merge branch 'feature/package-ios-frameworks' of https://github.com/f…
sunmou99 Oct 6, 2020
d74929a
build framework in parallel
sunmou99 Oct 6, 2020
351f258
cmake build Framework for iOS
sunmou99 Sep 11, 2020
7669f0c
Update CMakeLists.txt
sunmou99 Sep 25, 2020
657ff7b
remove useless ""
sunmou99 Oct 5, 2020
6543212
Update CMakeLists.txt
sunmou99 Oct 6, 2020
64bedf4
remove useless ""
sunmou99 Oct 5, 2020
058a72a
Update CMakeLists.txt
sunmou99 Oct 6, 2020
4691812
script to build iOS framework
sunmou99 Sep 16, 2020
bf9ce06
Update build script & add iOS GHA workflow
sunmou99 Sep 16, 2020
840b81c
add flag -g[generate Makefiles] -c[CMake build]
sunmou99 Sep 26, 2020
2874a72
build arch in parallel
sunmou99 Oct 5, 2020
16846b3
Update build.sh
sunmou99 Oct 5, 2020
a4dce22
script to build iOS framework
sunmou99 Sep 16, 2020
1304fe5
build framework in parallel
sunmou99 Oct 6, 2020
ff7f380
Merge branch 'feature/package-ios-frameworks' of https://github.com/f…
sunmou99 Oct 6, 2020
a7b9e44
Merge branch 'dev' into feature/package-ios-frameworks
sunmou99 Oct 9, 2020
2e0089b
Merge branch 'dev' into feature/package-ios-frameworks
sunmou99 Oct 10, 2020
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/ios.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: iOS Builds

on:
pull_request:
types: [opened, reopened, synchronize]

jobs:
build:
name: ios-macos-latest
runs-on: macos-latest
strategy:
fail-fast: false

steps:
- uses: actions/checkout@v2
with:
submodules: true

- name: Setup python
uses: actions/setup-python@v2
with:
python-version: 3.7
architecture: "x64"

- name: Install prerequisites
run: |
build_scripts/ios/install_prereqs.sh

- name: Build SDK
run: |
build_scripts/ios/build.sh -b ios_build -s .
197 changes: 168 additions & 29 deletions build_scripts/ios/build.sh
Original file line number Diff line number Diff line change
@@ -1,37 +1,176 @@
#!/bin/bash -ex
#!/bin/bash
#
# Script to build iOS Frameworks
# If built for all architectures (arm64 armv7 x86_64 i386),
# it will build universal framework as well
#
# Usage: ./build.sh [options]
# options:
# -b, build path default: ios_build
# -s, source path default: .
# -a, framework architecture default: SUPPORTED_ARCHITECTURES
# -t, CMake target default: SUPPORTED_TARGETS
# -g, generate Makefiles default: true
# -c, CMake build default: true
# example:
# build_scripts/ios/build.sh -b ios_build -s . -a arm64,x86_64 -t firebase_admob,firebase_auth -c false

buildpath=$1
sourcepath=$2
arch=$3
set -e

if [[ -z "${buildpath}" || -z "${sourcepath}" || -z "${arch}" ]]; then
echo "Usage: $0 <build path> <source path> <arm64|x86_64>"
exit 1
fi
readonly SUPPORTED_ARCHITECTURES=(arm64 armv7 x86_64 i386)
readonly SUPPORTED_TARGETS=(firebase_admob firebase_analytics firebase_auth firebase_database firebase_dynamic_links firebase_firestore firebase_functions firebase_instance_id firebase_messaging firebase_remote_config firebase_storage)

if [[ "${arch}" == "x86_64" ]]; then
toolchain="cmake/toolchains/ios_simulator.cmake"
elif [[ "${arch}" == "arm64" ]]; then
toolchain="cmake/toolchains/ios.cmake"
else
echo "Invalid architecture: '${arch}'"
exit 2
fi
# build default value
buildpath="ios_build"
sourcepath="."
architectures=("${SUPPORTED_ARCHITECTURES[@]}")
targets=("${SUPPORTED_TARGETS[@]}")
generateMakefiles=true
cmakeBuild=true

if [[ ! -d "${sourcepath}" ]]; then
echo "Source path '${sourcepath}' not found."
exit 2
fi
# check options
IFS=',' # split options on ',' characters
while getopts ":b:s:a:t:g:c" opt; do
case $opt in
b)
buildpath=$OPTARG
;;
s)
sourcepath=$OPTARG
if [[ ! -d "${sourcepath}" ]]; then
echo "Source path ${sourcepath} not found."
exit 2
fi
;;
a)
architectures=($OPTARG)
for arch in ${architectures[@]}; do
if [[ ! " ${SUPPORTED_ARCHITECTURES[@]} " =~ " ${arch} " ]]; then
echo "invalid architecture: ${arch}"
echo "Supported architectures are: ${SUPPORTED_ARCHITECTURES[@]}"
exit 2
fi
done
;;
t)
targets=($OPTARG)
for t in ${targets[@]}; do
if [[ ! " ${SUPPORTED_TARGETS[@]} " =~ " ${t} " ]]; then
echo "invalid target: ${t}"
echo "Supported targets are: ${SUPPORTED_TARGETS[@]}"
exit 2
fi
done
;;
g)
if [[ $OPTARG == true ]]; then
generateMakefiles=true
else
generateMakefiles=false
fi
;;
c)
if [[ $OPTARG == true ]]; then
cmakeBuild=true
else
cmakeBuild=false
fi
;;
*)
echo "unknow parameter"
exit 2
;;
esac
done
echo "build path: ${buildpath}"
echo "source path: ${sourcepath}"
echo "build architectures: ${architectures[@]}"
echo "build targets: ${targets[@]}"
echo "generate Makefiles: ${generateMakefiles}"
echo "CMake Build: ${cmakeBuild}"
sourcepath=$(cd ${sourcepath} && pwd) #full path
buildpath=$(mkdir -p ${buildpath} && cd ${buildpath} && pwd) #full path

mkdir -p "${buildpath}"
cd "${buildpath}"
if [[ -n $(ls) ]]; then
echo "Error: build path '${buildpath}' not empty."
exit 2
# generate Makefiles for each architecture and target
frameworkspath="frameworks/ios"
if ${generateMakefiles}; then
for arch in ${architectures[@]}; do
echo "generate Makefiles start"
mkdir -p ${buildpath}/ios_build_file/${arch} && cd ${buildpath}/ios_build_file/${arch}
if [[ "${arch}" == "arm64" || "${arch}" == "armv7" ]]; then
toolchain="cmake/toolchains/ios.cmake"
elif [[ "${arch}" == "x86_64" || "${arch}" == "i386" ]]; then
toolchain="cmake/toolchains/ios_simulator.cmake"
fi
cmake -DCMAKE_TOOLCHAIN_FILE=${sourcepath}/${toolchain} \
-DCMAKE_OSX_ARCHITECTURES=${arch} \
-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=${buildpath}/${frameworkspath}/${arch} \
${sourcepath}
echo "generate Makefiles end"
done
fi
cd -

set -ex
# build framework for each architecture and target
if ${cmakeBuild}; then
for arch in ${architectures[@]}; do
{
cd ${buildpath}/ios_build_file/${arch}
echo "build ${arch} ${targets[@]} framework start"
cmake --build . --target ${targets[@]}
echo "build ${arch} ${targets[@]} framework end"

} &
done
wait
echo "${architectures[@]} frameworks build end"

# arrange the framework
IFS=$'\n' # split $(ls) on \n characters
cd ${buildpath}/${frameworkspath}
for arch in ${architectures[@]}; do
# rename firebase_app to firebase
if [[ ! -d "${arch}/firebase.framework" ]]; then
cp -r ${arch}/firebase_app.framework ${arch}/firebase.framework
mv ${arch}/firebase.framework/firebase_app ${arch}/firebase.framework/firebase
rm ${arch}/firebase.framework/Info.plist
fi

cmake -GXcode "-DCMAKE_TOOLCHAIN_FILE=$toolchain" -S "${sourcepath}" -B "${buildpath}"
cmake --build "${buildpath}"
# delete useless Info.plist
for target in ${targets[@]}; do
if [[ -f "${arch}/${target}.framework/Info.plist" ]]; then
rm ${arch}/${target}.framework/Info.plist
fi
done

# delete non-framework dir
for dir in $(ls ${arch}); do
if [[ ! ${dir} =~ ".framework" ]]; then
rm -rf ${arch}/${dir}
fi
done
done
echo "${architectures[@]} frameworks ready to use"

# if we built for all architectures (arm64 armv7 x86_64 i386)
# build universal framework as well
if [[ ${#architectures[@]} < ${#SUPPORTED_ARCHITECTURES[@]} ]]; then
exit 0
fi

targets+=('firebase')
for target in ${targets[@]}; do
mkdir -p universal/${target}.framework
libsubpath="${target}.framework/${target}"
if [[ -f "${SUPPORTED_ARCHITECTURES[0]}/${libsubpath}" ]]; then
lipo -create "${SUPPORTED_ARCHITECTURES[0]}/${libsubpath}" \
"${SUPPORTED_ARCHITECTURES[1]}/${libsubpath}" \
"${SUPPORTED_ARCHITECTURES[2]}/${libsubpath}" \
"${SUPPORTED_ARCHITECTURES[3]}/${libsubpath}" \
-output "universal/${libsubpath}"
fi
done
if [[ ! -d "universal/firebase.framework/Headers" ]]; then
cp -R ${SUPPORTED_ARCHITECTURES[0]}/firebase.framework/Headers universal/firebase.framework
fi
echo "universal frameworks build end & ready to use"
fi
2 changes: 1 addition & 1 deletion cmake/toolchains/ios_simulator.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

set(CMAKE_OSX_SYSROOT iphonesimulator)
set(CMAKE_OSX_ARCHITECTURES x86_64)
set(CMAKE_OSX_ARCHITECTURES x86_64 CACHE STRING "")
set(CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator")
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO")
set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE "YES")
Expand Down