Build boringssl for iOS

Feb 16, 2019 • 预计阅读时间 2 分钟

Clone boringssl

git clone https://github.com/google/boringssl.git boringssl

Build boringssl

cd boringssl
mkdir build && cd build
./build.ios

build.ios is my build script

#!/bin/bash
set -e

export IPHONEOS_DEPLOYMENT_TARGET="9.0" # for -miphoneos-version-min

arch=arm64
mkdir ${arch} && cd ${arch}
cmake -DCMAKE_OSX_SYSROOT=iphoneos -DCMAKE_OSX_ARCHITECTURES=${arch} -GNinja ../..
ninja
cd ..

arch=armv7
mkdir ${arch} && cd ${arch}
cmake -DCMAKE_OSX_SYSROOT=iphoneos -DCMAKE_OSX_ARCHITECTURES=${arch} -GNinja ../..
ninja
cd ..

arch=x86_64
mkdir ${arch} && cd ${arch}
cmake -DCMAKE_OSX_SYSROOT=iphonesimulator -DCMAKE_OSX_ARCHITECTURES=${arch} -GNinja ../..
ninja
cd ..

crypto=crypto/libcrypto.a
ssl=ssl/libssl.a

lipo -create arm64/${crypto} armv7/${crypto} x86_64/${crypto} -o libcrypto.a

lipo -create arm64/${ssl} armv7/${ssl} x86_64/${ssl} -o libssl.a

Merge libcrypto & libssl

If you want a standalone lib (name like libboringssl.a), you can use below shell script

#!/bin/bash
set -e

export IPHONEOS_DEPLOYMENT_TARGET="9.0"

function merge_crypto_ssl_lib () {
  cd crypto && ar x libcrypto.a
  cd ../ssl && ar x libssl.a && cd ..
  ar r libboringssl.a ./crypto/*.o ./ssl/*.o
}

arch=arm64
mkdir ${arch} && cd ${arch}
cmake -DCMAKE_OSX_SYSROOT=iphoneos -DCMAKE_OSX_ARCHITECTURES=${arch} -GNinja ../..
ninja
merge_crypto_ssl_lib
cd ..

arch=armv7
mkdir ${arch} && cd ${arch}
cmake -DCMAKE_OSX_SYSROOT=iphoneos -DCMAKE_OSX_ARCHITECTURES=${arch} -GNinja ../..
ninja
merge_crypto_ssl_lib
cd ..

arch=x86_64
mkdir ${arch} && cd ${arch}
cmake -DCMAKE_OSX_SYSROOT=iphonesimulator -DCMAKE_OSX_ARCHITECTURES=${arch} -GNinja ../..
ninja
merge_crypto_ssl_lib
cd ..

lipo -create arm64/libboringssl.a armv7/libboringssl.a x86_64/libboringssl.a -o libboringssl.a

Create OpenSSL.framework

After build libboringssl.a, if you want using it in swift, you will need a modulemap, so we create a framework.

the framework must be named OpenSSL.framework

mkdir OpenSSL.framework
cp libboringssl.a OpenSSL.framework/OpenSSL
mkdir OpenSSL.framework/Headers
cp ../include/openssl/* OpenSSL.framework/Headers/
mkdir OpenSSL.framework/Modules
modulemap_file=OpenSSL.framework/Modules/module.modulemap
echo "framework module OpenSSL {" > ${modulemap_file}
echo "  export *" >> ${modulemap_file}
echo "}" >> ${modulemap_file}

You can download my Pre-Built on github

Pre-Built of BoringSSL

版权声明:如果转发请带上本文链接和注明来源。

lvv.me

iOS/macOS Developer

Build LLVM for macOS

Build extern version of hugo