Skip to content

Commit 86686ff

Browse files
authored
Merge pull request #441 from mirgee/hotfix/ios-build
Fix iOS build
2 parents 50061a4 + 53a7c00 commit 86686ff

File tree

1 file changed

+125
-67
lines changed

1 file changed

+125
-67
lines changed
Lines changed: 125 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,139 @@
11
#!/bin/sh
2+
set -xev
3+
4+
export PKG_CONFIG_ALLOW_CROSS=1
5+
export CARGO_INCREMENTAL=1
6+
export RUST_LOG=indy=trace
7+
export RUST_TEST_THREADS=1
8+
export INDY_VERSION=v1.16.0
9+
export IOS_TARGETS="aarch64-apple-ios x86_64-apple-ios"
10+
export WORK_DIR="${PWD}/../../../.macosbuild"
11+
export LIBSOV_DIR="${PWD}/../../.."
12+
export INDY_SDK_DIR=$WORK_DIR/sovtoken-indy-sdk
13+
export LIBS_DIR=$WORK_DIR/libs
214

3-
set -xv
4-
function extract_target() {
15+
mkdir -p ${WORK_DIR}
16+
mkdir -p ${LIBS_DIR}
17+
18+
prepare_openssl_dir() {
19+
OPENSSL_BASE_DIR=$(brew --cellar openssl)
20+
for f in $(ls -t "$OPENSSL_BASE_DIR"); do
21+
local ABSOLUTE_FILE_PATH="${OPENSSL_BASE_DIR}/${f}"
22+
if [ -d "$ABSOLUTE_FILE_PATH" ] && [ -d "$ABSOLUTE_FILE_PATH/lib" ]; then
23+
export OPENSSL_VERSION=$f
24+
export OPENSSL_DIR=$ABSOLUTE_FILE_PATH
25+
break
26+
fi
27+
done
28+
if [ -z "$OPENSSL_VERSION" ]; then
29+
echo >&2 "Error: Failed to find an OpenSSL installation in $OPENSSL_BASE_DIR"
30+
exit 1
31+
else
32+
echo "Found OpenSSL version $OPENSSL_VERSION"
33+
fi
34+
}
35+
36+
extract_arch() {
537
case $1 in
638
aarch64-apple-ios) echo "arm64" ;;
739
x86_64-apple-ios) echo "x86_64" ;;
840
\?) exit 1
941
esac
1042
}
1143

12-
source ./shared.functions.sh
13-
14-
START_DIR=${PWD}
15-
WORK_DIR=$(get_work_dir)
16-
mkdir -p ${WORK_DIR}
44+
build_crypto() {
45+
if [ ! -d $WORK_DIR/OpenSSL-for-iPhone ]; then
46+
git clone https://github.com/x2on/OpenSSL-for-iPhone.git $WORK_DIR/OpenSSL-for-iPhone
47+
fi
1748

18-
source ./mac.02.libindy.env.sh
49+
if [ ! -d $WORK_DIR/OpenSSL-for-iPhone/lib ]; then
50+
pushd $WORK_DIR/OpenSSL-for-iPhone
51+
./build-libssl.sh --version=$OPENSSL_VERSION
52+
export OPENSSL_LOCAL_CONFIG_DIR="$PWD/config"
53+
popd
54+
fi
55+
}
1956

20-
mkdir -p ${WORK_DIR}/sovtoken-indy-sdk
57+
extract_architectures() {
58+
FILE_PATH=$1
59+
LIB_FILE_NAME=$2
60+
LIB_NAME=$3
61+
62+
pushd $LIBS_DIR
63+
for TARGET in ${IOS_TARGETS[*]}; do
64+
ARCH=$(extract_arch $TARGET)
65+
DESTINATION=${LIB_NAME}/${ARCH}
66+
67+
mkdir -p $DESTINATION
68+
lipo -extract ${ARCH} $FILE_PATH -o $DESTINATION/$LIB_FILE_NAME-fat.a
69+
lipo $DESTINATION/$LIB_FILE_NAME-fat.a -thin $ARCH -output $DESTINATION/$LIB_FILE_NAME.a
70+
rm $DESTINATION/$LIB_FILE_NAME-fat.a
71+
done
72+
popd
73+
}
2174

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

29-
if [ ! -d "${WORK_DIR}/sovtoken-indy-sdk" ]; then
30-
echo STDERR "Unable to find ${WORK_DIR}/sovtoken-indy-sdk directory"
31-
exit 1
32-
fi
33-
34-
IOS_TARGETS="aarch64-apple-ios,x86_64-apple-ios"
35-
if [ ! -z "$2" ]; then
36-
IOS_TARGETS=$2
37-
fi
38-
39-
#########################################################################################################################
40-
# Now build libsovtoken
41-
#########################################################################################################################
42-
cd $(get_sovtoken_dir)
43-
44-
if [ "$DEBUG_SYMBOLS" = "debuginfo" ]; then
45-
cat $START_DIR/cargo.toml.add.debug.txt >> Cargo.toml
46-
fi
47-
48-
bkpIFS="$IFS"
49-
IFS=',()][' read -r -a targets <<<"${IOS_TARGETS}"
50-
echo "Building targets: ${targets[@]}"
51-
IFS="$bkpIFS"
52-
53-
to_combine=""
54-
for target in ${targets[*]}
55-
do
56-
LIBINDY=${WORK_DIR}/sovtoken-indy-sdk
57-
export LIBINDY_DIR=${LIBINDY}/${target}
58-
mkdir -p ${LIBINDY_DIR}
59-
etarget=$(extract_target $target)
60-
61-
echo "LIBINDY_DIR=${LIBINDY_DIR}"
62-
lipo -thin $etarget $LIBINDY/libindy.a -o $LIBINDY_DIR/libindy.a
63-
cargo lipo --release --verbose --targets="${target}"
64-
mv ./target/$target/release/libsovtoken.a ./target/$target/libsovtoken-unstripped.a
65-
strip -S -x -o ./target/$target/libsovtoken.a -r ./target/$target/libsovtoken-unstripped.a
66-
67-
to_combine="${to_combine} ./target/${target}/libsovtoken.a"
68-
69-
done
70-
71-
mkdir -p ./target/universal/release
72-
lipo -create $to_combine -o ./target/universal/release/libsovtoken.a
73-
cp ./target/universal/release/libsovtoken.a ./target/universal/libsovtoken-unstripped.a
74-
strip -S -x -o ./target/universal/libsovtoken.a -r ./target/universal/libsovtoken-unstripped.a
75-
76-
BUILD_TIME=$(date -u "+%Y%m%d%H%M")
77-
GIT_REV=$(git rev-parse --short HEAD)
78-
LIBSOVTOKEN_VER=$(grep ^version Cargo.toml | head -n 1 | cut -d '"' -f 2)
79-
mv target libsovtoken
80-
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'`
81-
mv libsovtoken target
80+
pushd $INDY_SDK_DIR
81+
git fetch --all
82+
git checkout $INDY_VERSION
83+
popd
84+
}
85+
86+
build_libindy() {
87+
pushd $INDY_SDK_DIR/libindy
88+
cargo lipo --release --targets="aarch64-apple-ios,x86_64-apple-ios"
89+
popd
90+
}
91+
92+
copy_libindy_architectures() {
93+
for TARGET in ${IOS_TARGETS[*]}; do
94+
ARCH=$(extract_arch $TARGET)
95+
96+
mkdir -p $LIBS_DIR/indy/$ARCH
97+
cp -v $INDY_SDK_DIR/libindy/target/$TARGET/release/libindy.a $LIBS_DIR/indy/$ARCH/libindy.a
98+
done
99+
}
100+
101+
build_libsovtoken() {
102+
pushd $LIBSOV_DIR
103+
to_combine=""
104+
for TARGET in ${IOS_TARGETS[*]}
105+
do
106+
export LIBINDY_DIR=${LIBS_DIR}/indy/$(extract_arch $TARGET)
107+
cargo lipo --release --verbose --targets="${TARGET}"
108+
109+
mv ./target/$TARGET/release/libsovtoken.a ./target/$TARGET/libsovtoken-unstripped.a
110+
strip -S -x -o ./target/$TARGET/libsovtoken.a -r ./target/$TARGET/libsovtoken-unstripped.a
111+
112+
to_combine="${to_combine} ./target/${TARGET}/libsovtoken.a"
113+
114+
mkdir -p ./target/universal/release
115+
lipo -create $to_combine -o ./target/universal/release/libsovtoken.a
116+
cp ./target/universal/release/libsovtoken.a ./target/universal/libsovtoken-unstripped.a
117+
strip -S -x -o ./target/universal/libsovtoken.a -r ./target/universal/libsovtoken-unstripped.a
118+
119+
BUILD_TIME=$(date -u "+%Y%m%d%H%M")
120+
GIT_REV=$(git rev-parse --short HEAD)
121+
LIBSOVTOKEN_VER=$(grep ^version Cargo.toml | head -n 1 | cut -d '"' -f 2)
122+
mv target libsovtoken
123+
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'`
124+
mv libsovtoken target
125+
done
126+
popd
127+
}
128+
129+
prepare_openssl_dir
130+
build_crypto
131+
132+
extract_architectures $WORK_DIR/OpenSSL-for-iPhone/lib/libssl.a libssl openssl
133+
extract_architectures $WORK_DIR/OpenSSL-for-iPhone/lib/libcrypto.a libcrypto openssl
134+
135+
checkout_indy_sdk
136+
build_libindy
137+
copy_libindy_architectures
138+
139+
build_libsovtoken

0 commit comments

Comments
 (0)