Skip to content

Commit

Permalink
Ensure full bitcode for iOS framework (#2174)
Browse files Browse the repository at this point in the history
* Add script to check full bitcode inclusion in iOS binaries

* Enable full bitcode generation for Release iOS builds

* iOS snapshot builds use Release mode and run bitcode check

* iOS tagged release builds run bitcode check
  • Loading branch information
matteblair authored Jul 7, 2020
1 parent 804a7a9 commit 0235946
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
11 changes: 8 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,17 @@ jobs:
# Install dependencies.
- run: sudo gem install jazzy --no-document --version 0.10.0
- run: brew install cmake
# Build the framework in debug mode and package it into pod.zip
- run: make ios-framework-universal BUILD_TYPE=Debug
# Build the framework and package it into pod.zip.
- run: make ios-framework-universal BUILD_TYPE=Release
# Check that bitcode is included for required archs.
- run: source scripts/check_bitcode.sh build/ios/Release-universal/TangramMap.framework/TangramMap armv7 arm64
# Build the docs and package them into docs.zip.
- run: make ios-docs
- run: cd build/ios-docs && zip -r ~/docs.zip .
- store_artifacts:
path: ~/docs.zip
# To produce the intended structure within the zip archive, we must cd to each file's location.
- run: cd build/ios/Debug-universal && zip -r ~/pod.zip TangramMap.framework
- run: cd build/ios/Release-universal && zip -r ~/pod.zip TangramMap.framework
# Add the readme and license files.
- run: cd platforms/ios/framework && zip ~/pod.zip README.md
- run: zip ~/pod.zip LICENSE
Expand Down Expand Up @@ -102,6 +105,8 @@ jobs:
- run: brew install cmake jfrog-cli-go
# Build the framework in release mode and package it into pod.zip
- run: make ios-framework-universal BUILD_TYPE=Release
# Check that bitcode is included for required archs.
- run: source scripts/check_bitcode.sh build/ios/Release-universal/TangramMap.framework/TangramMap armv7 arm64
- run: make ios-docs
- run: cd build/ios-docs && zip -r ~/docs.zip .
- store_artifacts:
Expand Down
3 changes: 3 additions & 0 deletions platforms/ios/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ set(TANGRAM_BUNDLE_IDENTIFIER "com.mapzen.TangramMap")
set(CMAKE_OSX_DEPLOYMENT_TARGET "9.3") # Applies to iOS even though the variable name says OSX.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden")
execute_process(COMMAND xcrun --sdk iphoneos --show-sdk-version OUTPUT_VARIABLE IOS_SDK_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
# Set the global BITCODE_GENERATION_MODE value to 'bitcode' for Release builds.
# This is for generating full bitcode outside of the "archive" command.
set(CMAKE_XCODE_ATTRIBUTE_BITCODE_GENERATION_MODE "$<$<CONFIG:Release>:bitcode>")

# Copy necessary workspace settings into a user-specific location in the iOS workspace.
# See platforms/ios/DEVELOPING.md for details.
Expand Down
32 changes: 32 additions & 0 deletions scripts/check_bitcode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash -eo pipefail
# USAGE
# check_bitcode.sh input_file [archs]
#
if [[ ${2} ]]; then
# Take all args after input_file as archs.
archs=${@:2}
else
# If archs not given in args, use lipo to list all archs in file.
archs=$(lipo -archs ${1})
fi

echo "Checking bitcode in file=${1} archs=${archs}"

missing_bitcode=0

for arch in ${archs}; do
# The otool command prints object file data for the given arch in the input file.
# The awk command prints the 'size' value following a 'segname' value equal to '__LLVM' (the bitcode segment).
bitcode_size=$(otool -l -arch ${arch} ${1} | awk '/ segname/ { SEGNAME = $2 }; / size/ { if(SEGNAME == "__LLVM") print $2 }')
echo "arch=${arch} bitcode_size=${bitcode_size}"
# Sometimes bitcode exists but is just a stub, so check for segments that are too small.
# This check also covers bitcode_size being empty.
if [[ ${bitcode_size} -lt 0x10 ]]; then
((missing_bitcode++))
fi
done

if [[ $missing_bitcode -gt 0 ]]; then
echo "Some archs are missing bitcode."
exit 1
fi

0 comments on commit 0235946

Please sign in to comment.