From 28f220cbab4e2a7484fe102da7905fe926ea8c74 Mon Sep 17 00:00:00 2001 From: Ali <> Date: Wed, 17 Feb 2021 23:43:48 +0400 Subject: [PATCH] Experimental min OS version patching --- Telegram/BUILD | 108 +++++++++++++++--- .../Sources/NotificationService.swift | 2 +- Telegram/PatchMinOSVersion.source.sh | 15 +++ .../WidgetKitWidget/TodayViewController.swift | 29 +++++ build-system/Make/Make.py | 14 ++- .../example-configuration/variables.bzl | 1 + 6 files changed, 148 insertions(+), 21 deletions(-) create mode 100644 Telegram/PatchMinOSVersion.source.sh diff --git a/Telegram/BUILD b/Telegram/BUILD index 485c8a854c..5893fd8821 100644 --- a/Telegram/BUILD +++ b/Telegram/BUILD @@ -32,6 +32,7 @@ load( "telegram_team_id", "telegram_enable_icloud", "telegram_enable_siri", + "telegram_enable_watch", ) load("@build_bazel_rules_apple//apple:resources.bzl", @@ -1134,6 +1135,25 @@ swift_library( ], ) +genrule( + name = "SetMinOsVersionNotificationContentExtension", + cmd_bash = +""" + name=NotificationContentExtension.appex + cat $(location PatchMinOSVersion.source.sh) | sed -e "s/<<>>/10\\.0/g" | sed -e "s/<<>>/$$name/g" > $(location SetMinOsVersionNotificationContentExtension.sh) +""", + srcs = [ + "PatchMinOSVersion.source.sh", + ], + outs = [ + "SetMinOsVersionNotificationContentExtension.sh", + ], + executable = True, + visibility = [ + "//visibility:public", + ] +) + ios_extension( name = "NotificationContentExtension", bundle_id = "{telegram_bundle_id}.NotificationContent".format( @@ -1149,7 +1169,8 @@ ios_extension( ":BuildNumberInfoPlist", ":AppNameInfoPlist", ], - minimum_os_version = "10.0", + minimum_os_version = "9.0", # maintain the same minimum OS version across extensions + ipa_post_processor = ":SetMinOsVersionNotificationContentExtension", provisioning_profile = select({ ":disableProvisioningProfilesSetting": None, "//conditions:default": "@build_configuration//provisioning:NotificationContent.mobileprovision", @@ -1216,6 +1237,25 @@ swift_library( ], ) +genrule( + name = "SetMinOsVersionWidgetExtension", + cmd_bash = +""" + name=WidgetExtension.appex + cat $(location PatchMinOSVersion.source.sh) | sed -e "s/<<>>/14\\.0/g" | sed -e "s/<<>>/$$name/g" > $(location SetMinOsVersionWidgetExtension.sh) +""", + srcs = [ + "PatchMinOSVersion.source.sh", + ], + outs = [ + "SetMinOsVersionWidgetExtension.sh", + ], + executable = True, + visibility = [ + "//visibility:public", + ] +) + ios_extension( name = "WidgetExtension", bundle_id = "{telegram_bundle_id}.Widget".format( @@ -1231,26 +1271,16 @@ ios_extension( ":BuildNumberInfoPlist", ":AppNameInfoPlist", ], - minimum_os_version = "14.0", + minimum_os_version = "9.0", # maintain the same minimum OS version across extensions + ipa_post_processor = ":SetMinOsVersionWidgetExtension", provides_main = True, provisioning_profile = select({ ":disableProvisioningProfilesSetting": None, "//conditions:default": "@build_configuration//provisioning:Widget.mobileprovision", }), - deps = select({ - "@build_bazel_rules_apple//apple:ios_arm64": [ - ":WidgetExtensionLib", - ], - "//build-system:ios_sim_arm64": [ - ":WidgetExtensionLib", - ], - "@build_bazel_rules_apple//apple:ios_x86_64": [ - ":WidgetExtensionLib", - ], - "@build_bazel_rules_apple//apple:ios_armv7": [ - ":WidgetExtensionLib", - ], - }), + deps = [ + ":WidgetExtensionLib", + ], frameworks = [ ":SwiftSignalKitFramework", ":PostboxFramework", @@ -1329,6 +1359,25 @@ swift_library( ], ) +genrule( + name = "SetMinOsVersionIntentsExtension", + cmd_bash = +""" + name=IntentsExtension.appex + cat $(location PatchMinOSVersion.source.sh) | sed -e "s/<<>>/10\\.0/g" | sed -e "s/<<>>/$$name/g" > $(location SetMinOsVersionIntentsExtension.sh) +""", + srcs = [ + "PatchMinOSVersion.source.sh", + ], + outs = [ + "SetMinOsVersionIntentsExtension.sh", + ], + executable = True, + visibility = [ + "//visibility:public", + ] +) + ios_extension( name = "IntentsExtension", bundle_id = "{telegram_bundle_id}.SiriIntents".format( @@ -1344,7 +1393,8 @@ ios_extension( ":BuildNumberInfoPlist", ":AppNameInfoPlist", ], - minimum_os_version = "10.0", + minimum_os_version = "9.0", # maintain the same minimum OS version across extensions + ipa_post_processor = ":SetMinOsVersionIntentsExtension", provisioning_profile = select({ ":disableProvisioningProfilesSetting": None, "//conditions:default": "@build_configuration//provisioning:Intents.mobileprovision", @@ -1383,6 +1433,25 @@ plist_fragment( ) ) +genrule( + name = "SetMinOsVersionNotificationServiceExtension", + cmd_bash = +""" + name=NotificationServiceExtension.appex + cat $(location PatchMinOSVersion.source.sh) | sed -e "s/<<>>/10\\.0/g" | sed -e "s/<<>>/$$name/g" > $(location SetMinOsVersionNotificationServiceExtension.sh) +""", + srcs = [ + "PatchMinOSVersion.source.sh", + ], + outs = [ + "SetMinOsVersionNotificationServiceExtension.sh", + ], + executable = True, + visibility = [ + "//visibility:public", + ] +) + ios_extension( name = "NotificationServiceExtension", bundle_id = "{telegram_bundle_id}.NotificationService".format( @@ -1398,7 +1467,8 @@ ios_extension( ":BuildNumberInfoPlist", ":AppNameInfoPlist", ], - minimum_os_version = "10.0", + minimum_os_version = "9.0", # maintain the same minimum OS version across extensions + ipa_post_processor = ":SetMinOsVersionNotificationServiceExtension", provisioning_profile = select({ ":disableProvisioningProfilesSetting": None, "//conditions:default": "@build_configuration//provisioning:NotificationService.mobileprovision", @@ -1631,7 +1701,7 @@ ios_application( watch_application = select({ ":disableExtensionsSetting": None, "//conditions:default": ":TelegramWatchApp", - }), + }) if telegram_enable_watch else None, deps = [ ":Main", ":Lib", diff --git a/Telegram/NotificationService/Sources/NotificationService.swift b/Telegram/NotificationService/Sources/NotificationService.swift index 606c0a7482..ed38bb5585 100644 --- a/Telegram/NotificationService/Sources/NotificationService.swift +++ b/Telegram/NotificationService/Sources/NotificationService.swift @@ -5,7 +5,7 @@ import NotificationServiceObjC private let queue = Queue() -@available(iOSApplicationExtension 10.0, *) +@available(iOSApplicationExtension 10.0, iOS 10.0, *) @objc(NotificationService) final class NotificationService: UNNotificationServiceExtension { private let impl: QueueLocalObject diff --git a/Telegram/PatchMinOSVersion.source.sh b/Telegram/PatchMinOSVersion.source.sh new file mode 100644 index 0000000000..dd0607c784 --- /dev/null +++ b/Telegram/PatchMinOSVersion.source.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +set -e + +name=<<>> +version=<<>> + +f="$1/$name" + +plist_path="$f/Info.plist" +plutil -replace MinimumOSVersion -string $version "$plist_path" +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 diff --git a/Telegram/WidgetKitWidget/TodayViewController.swift b/Telegram/WidgetKitWidget/TodayViewController.swift index 0df1f073a9..fab57433f9 100644 --- a/Telegram/WidgetKitWidget/TodayViewController.swift +++ b/Telegram/WidgetKitWidget/TodayViewController.swift @@ -65,6 +65,7 @@ private func rootPathForBasePath(_ appGroupPath: String) -> String { return appGroupPath + "/telegram-data" } +@available(iOSApplicationExtension 14.0, iOS 14.0, *) struct Provider: IntentTimelineProvider { public typealias Entry = SimpleEntry @@ -223,6 +224,7 @@ struct Provider: IntentTimelineProvider { } } +@available(iOSApplicationExtension 14.0, iOS 14.0, *) struct AvatarsProvider: IntentTimelineProvider { public typealias Entry = SimpleEntry @@ -381,6 +383,7 @@ struct AvatarsProvider: IntentTimelineProvider { } } +@available(iOSApplicationExtension 14.0, iOS 14.0, *) struct SimpleEntry: TimelineEntry { enum Contents { case recent @@ -398,6 +401,7 @@ enum PeersWidgetData { case peers(ParsedPeers) } +@available(iOSApplicationExtension 14.0, iOS 14.0, *) struct AvatarItemView: View { var peer: ParsedPeer? var itemSize: CGFloat @@ -417,6 +421,7 @@ struct AvatarItemView: View { } } +@available(iOSApplicationExtension 14.0, iOS 14.0, *) struct WidgetView: View { @Environment(\.widgetFamily) private var widgetFamily @Environment(\.colorScheme) private var colorScheme @@ -855,6 +860,7 @@ struct WidgetView: View { } } +@available(iOSApplicationExtension 14.0, iOS 14.0, *) struct AvatarsWidgetView: View { @Environment(\.widgetFamily) private var widgetFamily @Environment(\.colorScheme) private var colorScheme @@ -954,6 +960,7 @@ private let buildConfig: BuildConfig = { return buildConfig }() +@available(iOSApplicationExtension 14.0, iOS 14.0, *) func getWidgetData(contents: SimpleEntry.Contents) -> PeersWidgetData { switch contents { case .recent: @@ -965,6 +972,7 @@ func getWidgetData(contents: SimpleEntry.Contents) -> PeersWidgetData { } } +@available(iOSApplicationExtension 14.0, iOS 14.0, *) struct Static_Widget: Widget { private let kind: String = "Static_Widget" @@ -980,6 +988,7 @@ struct Static_Widget: Widget { } } +@available(iOSApplicationExtension 14.0, iOS 14.0, *) struct Static_AvatarsWidget: Widget { private let kind: String = "Static_AvatarsWidget" @@ -996,6 +1005,17 @@ struct Static_AvatarsWidget: Widget { } @main +struct AllWidgetsEntryPoint { + static func main() { + if #available(iOS 14.0, *) { + AllWidgets.main() + } else { + preconditionFailure() + } + } +} + +@available(iOSApplicationExtension 14.0, iOS 14.0, *) struct AllWidgets: WidgetBundle { var body: some Widget { Static_Widget() @@ -1003,4 +1023,13 @@ struct AllWidgets: WidgetBundle { } } +#else + +@main +class MyApp { + static func main() { + preconditionFailure("Not supported") + } +} + #endif diff --git a/build-system/Make/Make.py b/build-system/Make/Make.py index 0b34bf4bbe..fb4a62fd50 100644 --- a/build-system/Make/Make.py +++ b/build-system/Make/Make.py @@ -114,7 +114,18 @@ class BazelCommandLine: self.configuration_path = path def set_configuration(self, configuration): - if configuration == 'debug_arm64': + if configuration == 'debug_universal': + self.configuration_args = [ + # bazel debug build configuration + '-c', 'dbg', + + # Build universal binaries. + '--ios_multi_cpus=armv7,arm64', + + # Always build universal Watch binaries. + '--watchos_cpus=armv7k,arm64_32' + ] + self.common_debug_args + elif configuration == 'debug_arm64': self.configuration_args = [ # bazel debug build configuration '-c', 'dbg', @@ -528,6 +539,7 @@ if __name__ == '__main__': buildParser.add_argument( '--configuration', choices=[ + 'debug_universal', 'debug_arm64', 'debug_armv7', 'release_arm64', diff --git a/build-system/example-configuration/variables.bzl b/build-system/example-configuration/variables.bzl index 4014bba028..5403ae8176 100644 --- a/build-system/example-configuration/variables.bzl +++ b/build-system/example-configuration/variables.bzl @@ -11,3 +11,4 @@ telegram_app_specific_url_scheme = "tg" telegram_aps_environment = "production" telegram_enable_siri = True telegram_enable_icloud = True +telegram_enable_watch = True \ No newline at end of file