From 9350d3f78cee508f98bbae8d31a3a47007cb0322 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Thu, 3 Dec 2015 16:03:00 -0800 Subject: [ios] Converted iOS SDK into dynamic framework make iproj now produces a target that pulls together static libraries like core and platform-ios into a real dynamic framework. iosapp is pretty much just a regular iOS application that links Mapbox.framework (except for the inclusion of default_styles.hpp). iosapp runs fine in the Simulator and on a device, and the same is true for any application linking against Mapbox.framework. The ipackage target produces both a Bitcode-disabled static framework and a Bitcode-enabled dynamic framework, eliminating the need for a separate framework.sh. It disables code signing, since that happens on copy when the framework is embedded inside the application bundle. It also merges the device and simulator builds into a single fat framework. Also bumped itest minimum deployment target to iOS 8.0, the first version that supports linking frameworks. Fixes #828. --- platform/ios/scripts/package.sh | 112 ++++++++++++++++++++++++++++------------ 1 file changed, 79 insertions(+), 33 deletions(-) (limited to 'platform/ios/scripts/package.sh') diff --git a/platform/ios/scripts/package.sh b/platform/ios/scripts/package.sh index 8faebb60e8..0d5808aea3 100755 --- a/platform/ios/scripts/package.sh +++ b/platform/ios/scripts/package.sh @@ -7,17 +7,11 @@ set -u NAME=Mapbox OUTPUT=build/ios/pkg LIBUV_VERSION=1.7.5 -ENABLE_BITCODE=YES if [[ ${#} -eq 0 ]]; then # e.g. "make ipackage" BUILDTYPE="Release" BUILD_FOR_DEVICE=true GCC_GENERATE_DEBUGGING_SYMBOLS="YES" -elif [[ ${1} == "no-bitcode" ]]; then # e.g. "make ipackage-no-bitcode" - BUILDTYPE="Release" - BUILD_FOR_DEVICE=true - GCC_GENERATE_DEBUGGING_SYMBOLS="YES" - ENABLE_BITCODE=NO elif [[ ${1} == "sim" ]]; then # e.g. "make ipackage-sim" BUILDTYPE="Debug" BUILD_FOR_DEVICE=false @@ -41,10 +35,11 @@ trap finish EXIT rm -rf ${OUTPUT} mkdir -p "${OUTPUT}"/static +mkdir -p "${OUTPUT}"/dynamic -step "Recording library version..." -VERSION="${OUTPUT}"/static/version.txt +step "Recording library version…" +VERSION="${OUTPUT}"/version.txt echo -n "https://github.com/mapbox/mapbox-gl-native/commit/" > ${VERSION} HASH=`git log | head -1 | awk '{ print $2 }' | cut -c 1-10` && true echo -n "mapbox-gl-native " @@ -52,27 +47,44 @@ echo ${HASH} echo ${HASH} >> ${VERSION} -step "Creating build files..." +step "Creating build files…" export MASON_PLATFORM=ios export BUILDTYPE=${BUILDTYPE:-Release} export HOST=ios make Xcode/ios +PROJ_VERSION=${TRAVIS_JOB_NUMBER:-${BITRISE_BUILD_NUMBER:-0}} + if [[ "${BUILD_FOR_DEVICE}" == true ]]; then - step "Building iOS device targets..." + step "Building intermediate static libraries for iOS devices (build ${PROJ_VERSION})…" xcodebuild -sdk iphoneos${IOS_SDK_VERSION} \ ARCHS="arm64 armv7 armv7s" \ ONLY_ACTIVE_ARCH=NO \ GCC_GENERATE_DEBUGGING_SYMBOLS=${GCC_GENERATE_DEBUGGING_SYMBOLS} \ - ENABLE_BITCODE=${ENABLE_BITCODE} \ + ENABLE_BITCODE=NO \ DEPLOYMENT_POSTPROCESSING=YES \ -project ./build/ios-all/gyp/mbgl.xcodeproj \ -configuration ${BUILDTYPE} \ -target everything \ -jobs ${JOBS} + + step "Building dynamic framework for iOS devices (build ${PROJ_VERSION})…" + xcodebuild -sdk iphoneos${IOS_SDK_VERSION} \ + ARCHS="arm64 armv7 armv7s" \ + ONLY_ACTIVE_ARCH=NO \ + GCC_GENERATE_DEBUGGING_SYMBOLS=${GCC_GENERATE_DEBUGGING_SYMBOLS} \ + ENABLE_BITCODE=YES \ + DEPLOYMENT_POSTPROCESSING=YES \ + CURRENT_PROJECT_VERSION=${PROJ_VERSION} \ + CODE_SIGNING_REQUIRED=NO \ + CODE_SIGN_IDENTITY= \ + -project ./build/ios-all/gyp/ios.xcodeproj \ + -configuration ${BUILDTYPE} \ + -target iossdk \ + -jobs ${JOBS} fi -step "Building iOS Simulator targets..." +step "Building intermediate static libraries for iOS Simulator (build ${PROJ_VERSION})…" xcodebuild -sdk iphonesimulator${IOS_SDK_VERSION} \ ARCHS="x86_64 i386" \ ONLY_ACTIVE_ARCH=NO \ @@ -82,54 +94,88 @@ xcodebuild -sdk iphonesimulator${IOS_SDK_VERSION} \ -target everything \ -jobs ${JOBS} +step "Building dynamic framework for iOS Simulator (build ${PROJ_VERSION})…" +xcodebuild -sdk iphonesimulator${IOS_SDK_VERSION} \ + ARCHS="x86_64 i386" \ + ONLY_ACTIVE_ARCH=NO \ + GCC_GENERATE_DEBUGGING_SYMBOLS=${GCC_GENERATE_DEBUGGING_SYMBOLS} \ + ENABLE_BITCODE=YES \ + CURRENT_PROJECT_VERSION=${PROJ_VERSION} \ + -project ./build/ios-all/gyp/ios.xcodeproj \ + -configuration ${BUILDTYPE} \ + -target iossdk \ + -jobs ${JOBS} -step "Building static library..." LIBS=(core.a platform-ios.a asset-fs.a http-nsurl.a) + +# https://medium.com/@syshen/create-an-ios-universal-framework-148eb130a46c if [[ "${BUILD_FOR_DEVICE}" == true ]]; then + step "Assembling static framework for iOS Simulator and devices…" + mkdir -p ${OUTPUT}/static/${NAME}.framework libtool -static -no_warning_for_no_symbols \ `find mason_packages/ios-${IOS_SDK_VERSION} -type f -name libuv.a` \ `find mason_packages/ios-${IOS_SDK_VERSION} -type f -name libgeojsonvt.a` \ - -o ${OUTPUT}/static/lib${NAME}.a \ + -o ${OUTPUT}/static/${NAME}.framework/${NAME} \ ${LIBS[@]/#/gyp/build/${BUILDTYPE}-iphoneos/libmbgl-} \ ${LIBS[@]/#/gyp/build/${BUILDTYPE}-iphonesimulator/libmbgl-} + + step "Copying dynamic framework into place for iOS devices" + cp -r \ + gyp/build/${BUILDTYPE}-iphoneos/${NAME}.framework \ + ${OUTPUT}/dynamic/ + + step "Merging simulator dynamic library into device dynamic library…" + lipo \ + gyp/build/${BUILDTYPE}-iphoneos/${NAME}.framework/${NAME} \ + gyp/build/${BUILDTYPE}-iphonesimulator/${NAME}.framework/${NAME} \ + -create -output ${OUTPUT}/dynamic/${NAME}.framework/${NAME} | echo else + step "Assembling static library for iOS Simulator…" + mkdir -p ${OUTPUT}/static/${NAME}.framework libtool -static -no_warning_for_no_symbols \ `find mason_packages/ios-${IOS_SDK_VERSION} -type f -name libuv.a` \ `find mason_packages/ios-${IOS_SDK_VERSION} -type f -name libgeojsonvt.a` \ -o ${OUTPUT}/static/lib${NAME}.a \ ${LIBS[@]/#/gyp/build/${BUILDTYPE}-iphonesimulator/libmbgl-} + + step "Copying dynamic framework into place for iOS Simulator…" + cp -r \ + gyp/build/${BUILDTYPE}-iphonesimulator/${NAME}.framework \ + ${OUTPUT}/dynamic/${NAME}.framework fi -echo "Created ${OUTPUT}/static/lib${NAME}.a" +if [[ "${GCC_GENERATE_DEBUGGING_SYMBOLS}" == false ]]; then + step "Stripping binaries…" + strip -Sx "${OUTPUT}/static/${NAME}.framework/${NAME}" + strip -Sx "${OUTPUT}/dynamic/${NAME}.framework/${NAME}" +fi -step "Copying Headers..." -mkdir -p "${OUTPUT}/static/Headers" -for i in `ls -R include/mbgl/darwin | grep -vi private`; do - cp -pv include/mbgl/darwin/$i "${OUTPUT}/static/Headers" -done -for i in `ls -R include/mbgl/ios | grep -vi private`; do - cp -pv include/mbgl/ios/$i "${OUTPUT}/static/Headers" -done +stat "${OUTPUT}/static/${NAME}.framework" +stat "${OUTPUT}/dynamic/${NAME}.framework" +step "Copying static library headers…" +mkdir -p "${OUTPUT}/static/${NAME}.framework/Headers" +cp -pv include/mbgl/{darwin,ios}/*.h "${OUTPUT}/static/${NAME}.framework/Headers" -# Manually create resource bundle. We don't use a GYP target here because of -# complications between faked GYP bundles-as-executables, device build -# dependencies, and code signing. -step "Copying Resources..." -cp -pv LICENSE.md "${OUTPUT}/static" -mkdir -p "${OUTPUT}/static/${NAME}.bundle" -cp -pv platform/ios/resources/* "${OUTPUT}/static/${NAME}.bundle" +step "Copying library resources…" +cp -pv LICENSE.md "${OUTPUT}" +cp -rv ios/app/Settings.bundle "${OUTPUT}" +cp -pv platform/ios/resources/* "${OUTPUT}/static/${NAME}.framework" +cp -pv ios/framework/Info.plist "${OUTPUT}/static/${NAME}.framework/Info.plist" +perl -pi -e "s/(?<=)0(?=<\/string>)/${PROJ_VERSION}/g" "${OUTPUT}/static/${NAME}.framework/Info.plist" +mkdir "${OUTPUT}/static/${NAME}.framework/Modules" +cp -pv ios/framework/modulemap "${OUTPUT}/static/${NAME}.framework/Modules/module.modulemap" -step "Creating API Docs..." +step "Generating API documentation…" if [ -z `which jazzy` ]; then - step "Installing jazzy..." + step "Installing jazzy…" gem install jazzy if [ -z `which jazzy` ]; then echo "Unable to install jazzy. See https://github.com/mapbox/mapbox-gl-native/blob/master/platform/ios/INSTALL.md" exit 1 fi fi -DOCS_OUTPUT="${OUTPUT}/static/Docs" +DOCS_OUTPUT="${OUTPUT}/documentation" DOCS_VERSION=$( git tag | grep ^ios | sed 's/^ios-//' | sort -r | grep -v '\-rc.' | grep -v '\-pre.' | sed -n '1p' | sed 's/^v//' ) rm -rf /tmp/mbgl mkdir -p /tmp/mbgl/ -- cgit v1.2.1