Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix iOS build #441

Merged
merged 2 commits into from
Jun 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
192 changes: 125 additions & 67 deletions libsovtoken/build_scripts/ios/mac/mac.14.libsovtoken.build.sh
Original file line number Diff line number Diff line change
@@ -1,81 +1,139 @@
#!/bin/sh
set -xev

export PKG_CONFIG_ALLOW_CROSS=1
export CARGO_INCREMENTAL=1
export RUST_LOG=indy=trace
export RUST_TEST_THREADS=1
export INDY_VERSION=v1.16.0
export IOS_TARGETS="aarch64-apple-ios x86_64-apple-ios"
export WORK_DIR="${PWD}/../../../.macosbuild"
export LIBSOV_DIR="${PWD}/../../.."
export INDY_SDK_DIR=$WORK_DIR/sovtoken-indy-sdk
export LIBS_DIR=$WORK_DIR/libs

set -xv
function extract_target() {
mkdir -p ${WORK_DIR}
mkdir -p ${LIBS_DIR}

prepare_openssl_dir() {
OPENSSL_BASE_DIR=$(brew --cellar openssl)
for f in $(ls -t "$OPENSSL_BASE_DIR"); do
local ABSOLUTE_FILE_PATH="${OPENSSL_BASE_DIR}/${f}"
if [ -d "$ABSOLUTE_FILE_PATH" ] && [ -d "$ABSOLUTE_FILE_PATH/lib" ]; then
export OPENSSL_VERSION=$f
export OPENSSL_DIR=$ABSOLUTE_FILE_PATH
break
fi
done
if [ -z "$OPENSSL_VERSION" ]; then
echo >&2 "Error: Failed to find an OpenSSL installation in $OPENSSL_BASE_DIR"
exit 1
else
echo "Found OpenSSL version $OPENSSL_VERSION"
fi
}

extract_arch() {
case $1 in
aarch64-apple-ios) echo "arm64" ;;
x86_64-apple-ios) echo "x86_64" ;;
\?) exit 1
esac
}

source ./shared.functions.sh

START_DIR=${PWD}
WORK_DIR=$(get_work_dir)
mkdir -p ${WORK_DIR}
build_crypto() {
if [ ! -d $WORK_DIR/OpenSSL-for-iPhone ]; then
git clone https://github.com/x2on/OpenSSL-for-iPhone.git $WORK_DIR/OpenSSL-for-iPhone
fi

source ./mac.02.libindy.env.sh
if [ ! -d $WORK_DIR/OpenSSL-for-iPhone/lib ]; then
pushd $WORK_DIR/OpenSSL-for-iPhone
./build-libssl.sh --version=$OPENSSL_VERSION
export OPENSSL_LOCAL_CONFIG_DIR="$PWD/config"
popd
fi
}

mkdir -p ${WORK_DIR}/sovtoken-indy-sdk
extract_architectures() {
FILE_PATH=$1
LIB_FILE_NAME=$2
LIB_NAME=$3

pushd $LIBS_DIR
for TARGET in ${IOS_TARGETS[*]}; do
ARCH=$(extract_arch $TARGET)
DESTINATION=${LIB_NAME}/${ARCH}

mkdir -p $DESTINATION
lipo -extract ${ARCH} $FILE_PATH -o $DESTINATION/$LIB_FILE_NAME-fat.a
lipo $DESTINATION/$LIB_FILE_NAME-fat.a -thin $ARCH -output $DESTINATION/$LIB_FILE_NAME.a
rm $DESTINATION/$LIB_FILE_NAME-fat.a
done
popd
}

if [ ! -f "${WORK_DIR}/sovtoken-indy-sdk/libindy.a" ] ; then
command pushd ${WORK_DIR}/sovtoken-indy-sdk > /dev/null
curl -sSLO ${LIBINDY_IOS_BUILD_URL}
tar -xf ${LIBINDY_FILE}
command popd > /dev/null
checkout_indy_sdk() {
if [ ! -d $INDY_SDK_DIR ]; then
git clone https://github.com/hyperledger/indy-sdk $INDY_SDK_DIR
fi

if [ ! -d "${WORK_DIR}/sovtoken-indy-sdk" ]; then
echo STDERR "Unable to find ${WORK_DIR}/sovtoken-indy-sdk directory"
exit 1
fi

IOS_TARGETS="aarch64-apple-ios,x86_64-apple-ios"
if [ ! -z "$2" ]; then
IOS_TARGETS=$2
fi

#########################################################################################################################
# Now build libsovtoken
#########################################################################################################################
cd $(get_sovtoken_dir)

if [ "$DEBUG_SYMBOLS" = "debuginfo" ]; then
cat $START_DIR/cargo.toml.add.debug.txt >> Cargo.toml
fi

bkpIFS="$IFS"
IFS=',()][' read -r -a targets <<<"${IOS_TARGETS}"
echo "Building targets: ${targets[@]}"
IFS="$bkpIFS"

to_combine=""
for target in ${targets[*]}
do
LIBINDY=${WORK_DIR}/sovtoken-indy-sdk
export LIBINDY_DIR=${LIBINDY}/${target}
mkdir -p ${LIBINDY_DIR}
etarget=$(extract_target $target)

echo "LIBINDY_DIR=${LIBINDY_DIR}"
lipo -thin $etarget $LIBINDY/libindy.a -o $LIBINDY_DIR/libindy.a
cargo lipo --release --verbose --targets="${target}"
mv ./target/$target/release/libsovtoken.a ./target/$target/libsovtoken-unstripped.a
strip -S -x -o ./target/$target/libsovtoken.a -r ./target/$target/libsovtoken-unstripped.a

to_combine="${to_combine} ./target/${target}/libsovtoken.a"

done

mkdir -p ./target/universal/release
lipo -create $to_combine -o ./target/universal/release/libsovtoken.a
cp ./target/universal/release/libsovtoken.a ./target/universal/libsovtoken-unstripped.a
strip -S -x -o ./target/universal/libsovtoken.a -r ./target/universal/libsovtoken-unstripped.a

BUILD_TIME=$(date -u "+%Y%m%d%H%M")
GIT_REV=$(git rev-parse --short HEAD)
LIBSOVTOKEN_VER=$(grep ^version Cargo.toml | head -n 1 | cut -d '"' -f 2)
mv target libsovtoken
zip -qq "libsovtoken_${LIBSOVTOKEN_VER}-${BUILD_TIME}-${GIT_REV}_all.zip" `find libsovtoken -type f -name "libsovtoken.a" | egrep '(ios|universal)' | egrep -v 'deps|debug|release'`
mv libsovtoken target
pushd $INDY_SDK_DIR
git fetch --all
git checkout $INDY_VERSION
popd
}

build_libindy() {
pushd $INDY_SDK_DIR/libindy
cargo lipo --release --targets="aarch64-apple-ios,x86_64-apple-ios"
popd
}

copy_libindy_architectures() {
for TARGET in ${IOS_TARGETS[*]}; do
ARCH=$(extract_arch $TARGET)

mkdir -p $LIBS_DIR/indy/$ARCH
cp -v $INDY_SDK_DIR/libindy/target/$TARGET/release/libindy.a $LIBS_DIR/indy/$ARCH/libindy.a
done
}

build_libsovtoken() {
pushd $LIBSOV_DIR
to_combine=""
for TARGET in ${IOS_TARGETS[*]}
do
export LIBINDY_DIR=${LIBS_DIR}/indy/$(extract_arch $TARGET)
cargo lipo --release --verbose --targets="${TARGET}"

mv ./target/$TARGET/release/libsovtoken.a ./target/$TARGET/libsovtoken-unstripped.a
strip -S -x -o ./target/$TARGET/libsovtoken.a -r ./target/$TARGET/libsovtoken-unstripped.a

to_combine="${to_combine} ./target/${TARGET}/libsovtoken.a"

mkdir -p ./target/universal/release
lipo -create $to_combine -o ./target/universal/release/libsovtoken.a
cp ./target/universal/release/libsovtoken.a ./target/universal/libsovtoken-unstripped.a
strip -S -x -o ./target/universal/libsovtoken.a -r ./target/universal/libsovtoken-unstripped.a

BUILD_TIME=$(date -u "+%Y%m%d%H%M")
GIT_REV=$(git rev-parse --short HEAD)
LIBSOVTOKEN_VER=$(grep ^version Cargo.toml | head -n 1 | cut -d '"' -f 2)
mv target libsovtoken
zip -qq "libsovtoken_${LIBSOVTOKEN_VER}-${BUILD_TIME}-${GIT_REV}_all.zip" `find libsovtoken -type f -name "libsovtoken.a" | egrep '(ios|universal)' | egrep -v 'deps|debug|release'`
mv libsovtoken target
done
popd
}

prepare_openssl_dir
build_crypto

extract_architectures $WORK_DIR/OpenSSL-for-iPhone/lib/libssl.a libssl openssl
extract_architectures $WORK_DIR/OpenSSL-for-iPhone/lib/libcrypto.a libcrypto openssl

checkout_indy_sdk
build_libindy
copy_libindy_architectures

build_libsovtoken