Commit ddbe4d94 authored by Yannick Heinrich's avatar Yannick Heinrich Committed by Xianwen Chen

Add a script to build static fat binary lib. (#341)

* Add a script to build static fat  binary lib.

Based on the platform file provided by the
[ios-cmake](https://github.com/leetal/ios-cmake) repository,
the script generates a fat static library based on the architectures
specified by the `BUILD_ARCHITECTURES` variable.

* Update according to the discussion

- Rename the name of the script
- Clarify what does the script

* Move the build script.

* Move script to support lib directory
parent e675e319
...@@ -492,6 +492,21 @@ java -jar $DJINNI_JAR_DIR/djinni-assembly-0.1-SNAPSHOT.jar \ ...@@ -492,6 +492,21 @@ java -jar $DJINNI_JAR_DIR/djinni-assembly-0.1-SNAPSHOT.jar \
*Note*: The `all` target of the main `Makefile` includes the `djinni_jar` target. *Note*: The `all` target of the main `Makefile` includes the `djinni_jar` target.
## Generate an iOS universal binary of the support library.
The `ios-build-support-lib.sh` helps you to build an universal static library for iOS platforms.
It uses the platform file of the [ios-cmake](https://github.com/leetal/ios-cmake) repository.
It basically creates one universal static library per `IOS_PLATFORM` variable and uses `lipo`
to merge all the files in one.
There is basically two variables you would like to modify:
- `BUILD_APPLE_ARCHITECTURES`: Specifies which `IOS_PLATFORM` to build.
For more informations, take a look at https://github.com/leetal/ios-cmake.
- `ENABLE_BITCODE`: enable/disable the bitcode generation.
## Community Links ## Community Links
* Join the discussion with other developers at the [Mobile C++ Slack Community](https://mobilecpp.herokuapp.com/) * Join the discussion with other developers at the [Mobile C++ Slack Community](https://mobilecpp.herokuapp.com/)
......
This diff is collapsed.
#!/bin/sh
# This script helps you to build apple fat binaries.
# This uses the excellent https://github.com/leetal/ios-cmake cmake platform file.
BASEDIR=$(cd "$(dirname "$0")"; pwd)
# The directory used for building
BUILD_DIR=${BASEDIR}/build
# The directory where library will be generated
OUTPUT_DIR=${BASEDIR}/out/apple
# The architecture to build for apple
# See https://github.com/leetal/ios-cmake for more informations
BUILD_APPLE_ARCHITECTURES=(OS SIMULATOR64)
# Enable disable bitcode
ENABLE_BITCODE=true
# Helper functions for building one arhcitecture
function build_apple_native_static_arch {
echo "Building Native $1"
cd ${BUILD_DIR}
BUILD_PATH=build_$1
if [ -d ${BUILD_PATH} ]; then
rm -f ${BUILD_PATH}/*
rmdir ${BUILD_PATH}
fi
mkdir -p ${BUILD_PATH}
cd ${BUILD_PATH}
cmake ${BASEDIR}/.. -DDJINNI_WITH_OBJC=ON -DDJINNI_WITH_JNI=OFF -DDJINNI_STATIC_LIB=ON -DCMAKE_TOOLCHAIN_FILE=${BASEDIR}/../cmake/ios.toolchain.cmake -DIOS_PLATFORM=$1 -DENABLE_BITCODE=${ENABLE_BITCODE} -DCMAKE_INSTALL_PREFIX=${BUILD_PATH}
make -j 4
cp ${BUILD_DIR}/${BUILD_PATH}/libdjinni_support_lib.a ${OUTPUT_DIR}/libdjinni_support_lib_$1.a
cd ${BUILD_DIR}
rm -rf ${BUILD_PATH}
}
# Start of the script
echo "Checking build directory..."
if [ -d ${BUILD_DIR} ]; then
rm -rf ${BUILD_DIR}/*
rmdir ${BUILD_DIR}
fi
mkdir -p ${BUILD_DIR}
echo "Checking output directory..."
if [ -d ${OUTPUT_DIR} ]; then
rm -rf ${OUTPUT_DIR}/*
rmdir ${OUTPUT_DIR}
fi
mkdir -p ${OUTPUT_DIR}
# Build elements
for arch in ${BUILD_APPLE_ARCHITECTURES[@]}
do
build_apple_native_static_arch ${arch}
done
# Lipo creates a fat binary
lipo -create ${OUTPUT_DIR}/*.a -output ${OUTPUT_DIR}/libdjinni_support_lib_UNIVERSAL.a
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment