From 6c5359d23be54d51882305b6c1e3b107b526d699 Mon Sep 17 00:00:00 2001 From: Kylmakalle Date: Mon, 19 May 2025 23:42:53 +0300 Subject: [PATCH] Fix iOS 13-14 concurrency backport --- Swiftgram/FixConcurrencyBackport/BUILD | 37 ++++++++++++++++++++++++++ Telegram/BUILD | 9 ++++++- Telegram/PatchMinOSVersion.source.sh | 8 ++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 Swiftgram/FixConcurrencyBackport/BUILD diff --git a/Swiftgram/FixConcurrencyBackport/BUILD b/Swiftgram/FixConcurrencyBackport/BUILD new file mode 100644 index 0000000000..d910f483e6 --- /dev/null +++ b/Swiftgram/FixConcurrencyBackport/BUILD @@ -0,0 +1,37 @@ +# Something changed in Telegram versions 11.8.1 -> 11.10 +# https://github.com/TelegramMessenger/Telegram-iOS/compare/release-11.8.1...TelegramMessenger:Telegram-iOS:release-11.10 +# +# Since then, all binaries and libs are linked to the /usr/lib/swift/libswift_Concurrency.dylib instead of expected @rpath/libswift_Concurrency.dylib, +# this makes swift-stdlib-tool to ignore libswift_Concurrency.dylib and not copy it to the app bundle. +# This causes crash on every system that expects this backport (iOS 14 and below). +# This script will remap the path to @rpath/libswift_Concurrency.dylib in all binaries of the App, it's only needed for iphoneos target in this project. +# This is a temporary fix until minimum OS version will be bumped to iOS 15+ or Xcode version changed to 16.3 (with Swift 6.1 support) + +# find "$1" -type f \( -perm +111 -o -name "*.dylib" \) | while read -r bin; do +# if otool -L "$bin" | grep -q "/usr/lib/swift/libswift_Concurrency.dylib"; then +# echo "Patching concurrency backport in: $bin" +# install_name_tool -change /usr/lib/swift/libswift_Concurrency.dylib @rpath/libswift_Concurrency.dylib "$bin" +# fi +# done + +# Refs: +# https://stackoverflow.com/questions/79522371/when-building-the-project-with-xcode-16-2-the-app-crashes-due-to-an-incorrect-l +# https://github.com/swiftlang/swift/issues/74303 +# https://github.com/bazelbuild/rules_apple/pull/1393 + +genrule( + name = "CopyConcurrencyDylib", + cmd_bash = +""" + echo 'ditto "$$(xcode-select -p)/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.5/iphoneos/libswift_Concurrency.dylib" "$$1/Payload/Swiftgram.app/Frameworks/libswift_Concurrency.dylib"' > $(location CopyConcurrencyDylib.sh) + echo 'ditto "$$1/Payload/Swiftgram.app/Frameworks/libswift_Concurrency.dylib" "$$1/SwiftSupport/iphoneos/libswift_Concurrency.dylib"' >> $(location CopyConcurrencyDylib.sh) + echo '' >> $(location CopyConcurrencyDylib.sh) +""", + outs = [ + "CopyConcurrencyDylib.sh", + ], + executable = True, + visibility = [ + "//visibility:public", + ] +) \ No newline at end of file diff --git a/Telegram/BUILD b/Telegram/BUILD index 3ca93f37ef..e434e44725 100644 --- a/Telegram/BUILD +++ b/Telegram/BUILD @@ -1001,6 +1001,13 @@ genrule( cmd_bash = """ echo 'for f in $$1/*.framework; do binary_name=`echo $$(basename $$f) | sed -e "s/\\\\.framework//"`; strip -ST $$f/$$binary_name; done;' > $(location StripFramework.sh) + # MARK: Swiftgram + echo 'find "$$1" -type f \\( -perm +111 -o -name "*.dylib" \\) | while read -r bin; do \ + if otool -L "$$bin" | grep -q "/usr/lib/swift/libswift_Concurrency.dylib"; then \ + echo "Patching concurrency backport in: $$bin"; \ + install_name_tool -change /usr/lib/swift/libswift_Concurrency.dylib @rpath/libswift_Concurrency.dylib "$$bin"; \ + fi; \ + done;' >> $(location StripFramework.sh) echo '' >> $(location StripFramework.sh) """, outs = [ @@ -2038,7 +2045,7 @@ ios_application( alternate_icons = [ ":{}".format(name) for name in alternate_icon_folders ], - #ipa_post_processor = ":AddAlternateIcons", + ipa_post_processor = "//Swiftgram/FixConcurrencyBackport:CopyConcurrencyDylib", resources = [ ":LaunchScreen", ":DefaultAppIcon", diff --git a/Telegram/PatchMinOSVersion.source.sh b/Telegram/PatchMinOSVersion.source.sh index dd0607c784..565529e0ef 100644 --- a/Telegram/PatchMinOSVersion.source.sh +++ b/Telegram/PatchMinOSVersion.source.sh @@ -13,3 +13,11 @@ if [ "$version" == "14.0" ]; then binary_path="$f/$(basename $f | sed -e s/\.appex//g)" xcrun lipo "$binary_path" -remove armv7 -o "$binary_path" 2>/dev/null || true fi + +# MARK: Swiftgram +find "$1" -type f \( -perm +111 -o -name "*.dylib" \) | while read -r bin; do + if otool -L "$bin" | grep -q "/usr/lib/swift/libswift_Concurrency.dylib"; then + echo "Patching concurrency backport in: $bin" + install_name_tool -change /usr/lib/swift/libswift_Concurrency.dylib @rpath/libswift_Concurrency.dylib "$bin" + fi +done \ No newline at end of file