Skip to content

Commit

Permalink
Merge pull request #104 from Emurgo/evgenii/build_ios
Browse files Browse the repository at this point in the history
Change ios build script
  • Loading branch information
lisicky authored Nov 1, 2023
2 parents 96321c1 + d006376 commit 95ddeae
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 27 deletions.
80 changes: 54 additions & 26 deletions ios/build.sh
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@emurgo/csl-mobile-bridge",
"title": "CSL mobile bridge",
"version": "5.1.2",
"version": "5.1.3",
"description": "React-native bindings for Emurgo's cardano-serialization-lib (Cardano haskell Shelley)",
"main": "index.js",
"files": [
Expand Down

0 comments on commit 95ddeae

Please sign in to comment.