JitsiMeetSDK-xcframeworks.sh 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #!/bin/sh
  2. set -e
  3. set -u
  4. set -o pipefail
  5. function on_error {
  6. echo "$(realpath -mq "${0}"):$1: error: Unexpected failure"
  7. }
  8. trap 'on_error $LINENO' ERR
  9. # This protects against multiple targets copying the same framework dependency at the same time. The solution
  10. # was originally proposed here: https://lists.samba.org/archive/rsync/2008-February/020158.html
  11. RSYNC_PROTECT_TMP_FILES=(--filter "P .*.??????")
  12. variant_for_slice()
  13. {
  14. case "$1" in
  15. "JitsiMeetSDK.xcframework/ios-arm64")
  16. echo ""
  17. ;;
  18. "JitsiMeetSDK.xcframework/ios-arm64_x86_64-simulator")
  19. echo "simulator"
  20. ;;
  21. "hermes.xcframework/ios-arm64")
  22. echo ""
  23. ;;
  24. "hermes.xcframework/ios-arm64_x86_64-maccatalyst")
  25. echo "maccatalyst"
  26. ;;
  27. "hermes.xcframework/ios-arm64_x86_64-simulator")
  28. echo "simulator"
  29. ;;
  30. "hermes.xcframework/xros-arm64")
  31. echo ""
  32. ;;
  33. "hermes.xcframework/xros-arm64_x86_64-simulator")
  34. echo "simulator"
  35. ;;
  36. esac
  37. }
  38. archs_for_slice()
  39. {
  40. case "$1" in
  41. "JitsiMeetSDK.xcframework/ios-arm64")
  42. echo "arm64"
  43. ;;
  44. "JitsiMeetSDK.xcframework/ios-arm64_x86_64-simulator")
  45. echo "arm64 x86_64"
  46. ;;
  47. "hermes.xcframework/ios-arm64")
  48. echo "arm64"
  49. ;;
  50. "hermes.xcframework/ios-arm64_x86_64-maccatalyst")
  51. echo "arm64 x86_64"
  52. ;;
  53. "hermes.xcframework/ios-arm64_x86_64-simulator")
  54. echo "arm64 x86_64"
  55. ;;
  56. "hermes.xcframework/xros-arm64")
  57. echo "arm64"
  58. ;;
  59. "hermes.xcframework/xros-arm64_x86_64-simulator")
  60. echo "arm64 x86_64"
  61. ;;
  62. esac
  63. }
  64. copy_dir()
  65. {
  66. local source="$1"
  67. local destination="$2"
  68. # Use filter instead of exclude so missing patterns don't throw errors.
  69. echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --links --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" \"${source}*\" \"${destination}\""
  70. rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --links --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" "${source}"/* "${destination}"
  71. }
  72. SELECT_SLICE_RETVAL=""
  73. select_slice() {
  74. local xcframework_name="$1"
  75. xcframework_name="${xcframework_name##*/}"
  76. local paths=("${@:2}")
  77. # Locate the correct slice of the .xcframework for the current architectures
  78. local target_path=""
  79. # Split archs on space so we can find a slice that has all the needed archs
  80. local target_archs=$(echo $ARCHS | tr " " "\n")
  81. local target_variant=""
  82. if [[ "$PLATFORM_NAME" == *"simulator" ]]; then
  83. target_variant="simulator"
  84. fi
  85. if [[ ! -z ${EFFECTIVE_PLATFORM_NAME+x} && "$EFFECTIVE_PLATFORM_NAME" == *"maccatalyst" ]]; then
  86. target_variant="maccatalyst"
  87. fi
  88. for i in ${!paths[@]}; do
  89. local matched_all_archs="1"
  90. local slice_archs="$(archs_for_slice "${xcframework_name}/${paths[$i]}")"
  91. local slice_variant="$(variant_for_slice "${xcframework_name}/${paths[$i]}")"
  92. for target_arch in $target_archs; do
  93. if ! [[ "${slice_variant}" == "$target_variant" ]]; then
  94. matched_all_archs="0"
  95. break
  96. fi
  97. if ! echo "${slice_archs}" | tr " " "\n" | grep -F -q -x "$target_arch"; then
  98. matched_all_archs="0"
  99. break
  100. fi
  101. done
  102. if [[ "$matched_all_archs" == "1" ]]; then
  103. # Found a matching slice
  104. echo "Selected xcframework slice ${paths[$i]}"
  105. SELECT_SLICE_RETVAL=${paths[$i]}
  106. break
  107. fi
  108. done
  109. }
  110. install_xcframework() {
  111. local basepath="$1"
  112. local name="$2"
  113. local package_type="$3"
  114. local paths=("${@:4}")
  115. # Locate the correct slice of the .xcframework for the current architectures
  116. select_slice "${basepath}" "${paths[@]}"
  117. local target_path="$SELECT_SLICE_RETVAL"
  118. if [[ -z "$target_path" ]]; then
  119. echo "warning: [CP] $(basename ${basepath}): Unable to find matching slice in '${paths[@]}' for the current build architectures ($ARCHS) and platform (${EFFECTIVE_PLATFORM_NAME-${PLATFORM_NAME}})."
  120. return
  121. fi
  122. local source="$basepath/$target_path"
  123. local destination="${PODS_XCFRAMEWORKS_BUILD_DIR}/${name}"
  124. if [ ! -d "$destination" ]; then
  125. mkdir -p "$destination"
  126. fi
  127. copy_dir "$source/" "$destination"
  128. echo "Copied $source to $destination"
  129. }
  130. install_xcframework "${PODS_ROOT}/JitsiMeetSDK/Frameworks/JitsiMeetSDK.xcframework" "JitsiMeetSDK" "framework" "ios-arm64" "ios-arm64_x86_64-simulator"
  131. install_xcframework "${PODS_ROOT}/JitsiMeetSDK/Frameworks/hermes.xcframework" "JitsiMeetSDK" "framework" "ios-arm64" "ios-arm64_x86_64-maccatalyst" "ios-arm64_x86_64-simulator"