-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from Emurgo/evgenii/build_ios
Change ios build script
- Loading branch information
Showing
2 changed files
with
55 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,71 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
HAS_CARGO_IN_PATH=`which cargo; echo $?` | ||
MAC_OS_VERSION=`sw_vers -productVersion | cut -d '.' -f 1` | ||
MAC_CURRENT_ARCH=`uname -m` | ||
|
||
if [ "${HAS_CARGO_IN_PATH}" -ne "0" ]; then | ||
source $HOME/.cargo/env | ||
fi | ||
set -x | ||
|
||
if [ -z "${PODS_TARGET_SRCROOT}" ]; then | ||
ROOT_DIR="${SRCROOT}/../rust" | ||
else | ||
ROOT_DIR="${PODS_TARGET_SRCROOT}/rust" | ||
fi | ||
|
||
CONFIG_PATH=$(echo $CONFIGURATION | sed 's/^[^.]*\.//') | ||
OUTPUT_DIR=`echo "${CONFIG_PATH}" | tr '[:upper:]' '[:lower:]'` | ||
LIPO_BIN_TARGET_DIR="universal" | ||
# | ||
# Figure out the correct Rust target from the ARCHS and PLATFORM. | ||
# This script expects just one element in ARCHS. | ||
#collect all lib paths into array | ||
LIB_LIST=() | ||
ARCH_LIST=$(echo $ARCHS | tr ";" "\n") | ||
for CURRENT_ARCH in $ARCH_LIST; do | ||
case "$CURRENT_ARCH" in | ||
"arm64") rust_arch="aarch64" ;; | ||
"x86_64") rust_arch="x86_64" ;; | ||
*) echo "error: unsupported architecture: $ARCHS" ;; | ||
esac | ||
if [[ "$PLATFORM_NAME" == "macosx" ]]; then | ||
rust_platform="apple-darwin" | ||
else | ||
rust_platform="apple-ios" | ||
fi | ||
if [[ "$PLATFORM_NAME" == "iphonesimulator" ]]; then | ||
if [[ "${rust_arch}" == "aarch64" ]]; then | ||
rust_abi="-sim" | ||
else | ||
rust_abi="" | ||
fi | ||
else | ||
rust_abi="" | ||
fi | ||
rust_target="${rust_arch}-${rust_platform}${rust_abi}" | ||
# | ||
# Build library in debug or release | ||
build_args=(--manifest-path "${ROOT_DIR}/Cargo.toml" --target "${rust_target}") | ||
if [[ "$CONFIGURATION" == "Release" ]]; then | ||
rust_config="release" | ||
cmd="cargo build --release ${build_args[@]}" | ||
bash -l -c "${cmd}" | ||
elif [[ "$CONFIGURATION" == "Debug" ]]; then | ||
rust_config="debug" | ||
cmd="cargo build ${build_args[@]}" | ||
bash -l -c "${cmd}" | ||
else | ||
echo "error: Unexpected build configuration: $CONFIGURATION" | ||
fi | ||
LIB_LIST+=("${ROOT_DIR}"/target/"${rust_target}"/"${rust_config}"/*.a) | ||
done | ||
# | ||
|
||
cd "${ROOT_DIR}" | ||
|
||
if [[ "$TARGET_DEVICE_PLATFORM_NAME" == "iphonesimulator" ]] && [[ "$MAC_CURRENT_ARCH" == "arm64" ]]; then | ||
# If we're building for the arm simulator on an M1 Mac, we need to use the x86_64-apple-ios-sim target. | ||
# Otherwise, lipo will compile for arm64 iphone that can't run on the simulator. | ||
ACTUAL_SDK_PATH=$(xcrun --sdk iphonesimulator --show-sdk-path) | ||
export LIBRARY_PATH="${ACTUAL_SDK_PATH}/usr/lib:${LIBRARY_PATH:-}" | ||
cargo lipo --targets="aarch64-apple-ios-sim" | ||
LIPO_BIN_TARGET_DIR="aarch64-apple-ios-sim" | ||
if [ ${#LIB_LIST[@]} -gt 1 ]; then | ||
TMP_DIR="${ROOT_DIR}"/target/tmp | ||
LIB_NAME=$(basename "${LIB_LIST[0]}") | ||
mkdir -p "${TMP_DIR}" | ||
lipo -create "${LIB_LIST[@]}" -output "${TMP_DIR}/${LIB_NAME}" | ||
cp -f "${TMP_DIR}/${LIB_NAME}" "${CONFIGURATION_BUILD_DIR}"/ | ||
rm -rf "${TMP_DIR}" | ||
else | ||
ACTUAL_SDK_PATH=$(xcrun --sdk iphoneos --show-sdk-path) | ||
export LIBRARY_PATH="${ACTUAL_SDK_PATH}/usr/lib:${LIBRARY_PATH:-}" | ||
cargo lipo --xcode-integ | ||
cp -f "${LIB_LIST[0]}" "${CONFIGURATION_BUILD_DIR}"/ | ||
fi | ||
|
||
mkdir -p "${CONFIGURATION_BUILD_DIR}" | ||
|
||
cp -f "${ROOT_DIR}"/target/"${LIPO_BIN_TARGET_DIR}"/"${OUTPUT_DIR}"/*.a "${CONFIGURATION_BUILD_DIR}"/ | ||
cp -f "${ROOT_DIR}"/include/*.h "${CONFIGURATION_BUILD_DIR}"/ | ||
|
||
exit 0 | ||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters