diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9023bd8734..dfc74858c2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -84,6 +84,7 @@ jobs: --bazel="$HOME/bazel-dist/bazel" \ --bazelUserRoot="$BAZEL_USER_ROOT" \ build \ + --disableParallelSwiftmoduleGeneration \ --configurationPath="$HOME/telegram-configuration" \ --buildNumber=$BUILD_NUMBER \ --configuration=release_universal diff --git a/Telegram/BUILD b/Telegram/BUILD index 3c25026565..5893fd8821 100644 --- a/Telegram/BUILD +++ b/Telegram/BUILD @@ -30,6 +30,9 @@ load( "telegram_bundle_id", "telegram_aps_environment", "telegram_team_id", + "telegram_enable_icloud", + "telegram_enable_siri", + "telegram_enable_watch", ) load("@build_bazel_rules_apple//apple:resources.bzl", @@ -287,7 +290,7 @@ apple_pay_merchants_fragment = "" if apple_pay_merchants == [] else """ com.apple.developer.in-app-payments """ + "\n".join([ -" {}".format(merchant_id) for merchant_id in apple_pay_merchants +" {merchant_id}".format(merchant_id=merchant_id) for merchant_id in apple_pay_merchants ]) + "\n" + """ """ @@ -304,44 +307,65 @@ official_carplay_fragment = """ """ carplay_fragment = official_carplay_fragment if telegram_bundle_id in official_bundle_ids else "" -telegram_entitlements_template = """ - com.apple.developer.icloud-services - - CloudKit - CloudDocuments - - com.apple.developer.icloud-container-identifiers - - iCloud.{telegram_bundle_id} - - aps-environment - {telegram_aps_environment} - com.apple.developer.associated-domains - - applinks:telegram.me - applinks:t.me - - com.apple.developer.siri - +icloud_fragment = "" if not telegram_enable_icloud else """ +com.apple.developer.icloud-services + + CloudKit + CloudDocuments + +com.apple.developer.icloud-container-identifiers + + iCloud.{telegram_bundle_id} + +com.apple.developer.icloud-container-environment +{telegram_icloud_environment} +""".format( + telegram_bundle_id=telegram_bundle_id, + telegram_icloud_environment="Production" if telegram_aps_environment == "production" else "Development" +) + +associated_domains_fragment = "" if telegram_bundle_id not in official_bundle_ids else """ +com.apple.developer.associated-domains + + applinks:telegram.me + applinks:t.me + +""" + +siri_fragment = "" if not telegram_enable_siri else """ +com.apple.developer.siri + +""" + +aps_fragment = "" if telegram_aps_environment == "" else """ +aps-environment +{telegram_aps_environment} +""".format(telegram_aps_environment=telegram_aps_environment) + +app_groups_fragment = """ com.apple.security.application-groups group.{telegram_bundle_id} application-identifier {telegram_team_id}.{telegram_bundle_id} - com.apple.developer.icloud-container-environment - {telegram_icloud_environment} -""" + apple_pay_merchants_fragment + unrestricted_voip_fragment + carplay_fragment +""".format( + telegram_team_id=telegram_team_id, + telegram_bundle_id=telegram_bundle_id +) plist_fragment( name = "TelegramEntitlements", extension = "entitlements", - template = telegram_entitlements_template.format( - telegram_bundle_id = telegram_bundle_id, - telegram_team_id = telegram_team_id, - telegram_aps_environment = telegram_aps_environment, - telegram_icloud_environment = "Production" if telegram_aps_environment == "production" else "Development", - ) + template = "".join([ + app_groups_fragment, + siri_fragment, + associated_domains_fragment, + icloud_fragment, + apple_pay_merchants_fragment, + unrestricted_voip_fragment, + carplay_fragment + ]) ) filegroup( @@ -530,7 +554,6 @@ watchos_extension( watchos_application( name = "TelegramWatchApp", - #app_icons = , bundle_id = "{telegram_bundle_id}.watchkitapp".format( telegram_bundle_id = telegram_bundle_id, ), @@ -1112,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( @@ -1127,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", @@ -1194,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( @@ -1209,7 +1271,8 @@ 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, @@ -1296,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( @@ -1311,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", @@ -1350,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( @@ -1365,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", @@ -1598,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 03be983151..fab57433f9 100644 --- a/Telegram/WidgetKitWidget/TodayViewController.swift +++ b/Telegram/WidgetKitWidget/TodayViewController.swift @@ -1,3 +1,5 @@ +#if arch(arm64) || arch(x86_64) + import UIKit import NotificationCenter import BuildConfig @@ -63,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 @@ -221,6 +224,7 @@ struct Provider: IntentTimelineProvider { } } +@available(iOSApplicationExtension 14.0, iOS 14.0, *) struct AvatarsProvider: IntentTimelineProvider { public typealias Entry = SimpleEntry @@ -379,6 +383,7 @@ struct AvatarsProvider: IntentTimelineProvider { } } +@available(iOSApplicationExtension 14.0, iOS 14.0, *) struct SimpleEntry: TimelineEntry { enum Contents { case recent @@ -396,6 +401,7 @@ enum PeersWidgetData { case peers(ParsedPeers) } +@available(iOSApplicationExtension 14.0, iOS 14.0, *) struct AvatarItemView: View { var peer: ParsedPeer? var itemSize: CGFloat @@ -415,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 @@ -853,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 @@ -952,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: @@ -963,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" @@ -978,6 +988,7 @@ struct Static_Widget: Widget { } } +@available(iOSApplicationExtension 14.0, iOS 14.0, *) struct Static_AvatarsWidget: Widget { private let kind: String = "Static_AvatarsWidget" @@ -994,9 +1005,31 @@ 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() Static_AvatarsWidget() } } + +#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 6e9bb42c24..fb4a62fd50 100644 --- a/build-system/Make/Make.py +++ b/build-system/Make/Make.py @@ -27,6 +27,7 @@ class BazelCommandLine: self.build_number = None self.configuration_args = None self.configuration_path = None + self.split_submodules = False self.common_args = [ # https://docs.bazel.build/versions/master/command-line-reference.html @@ -49,12 +50,6 @@ class BazelCommandLine: ] self.common_build_args = [ - # https://github.com/bazelbuild/rules_swift - # If enabled and whole module optimisation is being used, the `*.swiftdoc`, - # `*.swiftmodule` and `*-Swift.h` are generated with a separate action - # rather than as part of the compilation. - '--features=swift.split_derived_files_generation', - # https://github.com/bazelbuild/rules_swift # If enabled the skip function bodies frontend flag is passed when using derived # files generation. @@ -112,11 +107,25 @@ class BazelCommandLine: def set_build_number(self, build_number): self.build_number = build_number + def set_split_swiftmodules(self, value): + self.split_submodules = value + def set_configuration_path(self, path): 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', @@ -151,6 +160,23 @@ class BazelCommandLine: # Generate DSYM files when building. '--apple_generate_dsym', + # Require DSYM files as build output. + '--output_groups=+dsyms' + ] + self.common_release_args + elif configuration == 'release_armv7': + self.configuration_args = [ + # bazel optimized build configuration + '-c', 'opt', + + # Build single-architecture binaries. It is almost 2 times faster is 32-bit support is not required. + '--ios_multi_cpus=armv7', + + # Always build universal Watch binaries. + '--watchos_cpus=armv7k,arm64_32', + + # Generate DSYM files when building. + '--apple_generate_dsym', + # Require DSYM files as build output. '--output_groups=+dsyms' ] + self.common_release_args @@ -217,6 +243,19 @@ class BazelCommandLine: return combined_arguments + def get_additional_build_arguments(self): + combined_arguments = [] + if self.split_submodules: + combined_arguments += [ + # https://github.com/bazelbuild/rules_swift + # If enabled and whole module optimisation is being used, the `*.swiftdoc`, + # `*.swiftmodule` and `*-Swift.h` are generated with a separate action + # rather than as part of the compilation. + '--features=swift.split_derived_files_generation', + ] + + return combined_arguments + def invoke_build(self): combined_arguments = [ self.build_environment.bazel_path @@ -237,6 +276,7 @@ class BazelCommandLine: combined_arguments += self.common_args combined_arguments += self.common_build_args combined_arguments += self.get_define_arguments() + combined_arguments += self.get_additional_build_arguments() if self.remote_cache is not None: combined_arguments += [ @@ -355,6 +395,8 @@ def build(arguments): bazel_command_line.set_configuration(arguments.configuration) bazel_command_line.set_build_number(arguments.buildNumber) + bazel_command_line.set_split_swiftmodules(not arguments.disableParallelSwiftmoduleGeneration) + bazel_command_line.invoke_build() @@ -497,14 +539,22 @@ if __name__ == '__main__': buildParser.add_argument( '--configuration', choices=[ + 'debug_universal', 'debug_arm64', 'debug_armv7', 'release_arm64', + 'release_armv7', 'release_universal' ], required=True, help='Build configuration' ) + buildParser.add_argument( + '--disableParallelSwiftmoduleGeneration', + action='store_true', + default=False, + help='Generate .swiftmodule files in parallel to building modules, can speed up compilation on multi-core systems.' + ) if len(sys.argv) < 2: parser.print_help() diff --git a/build-system/example-configuration/variables.bzl b/build-system/example-configuration/variables.bzl index 489bcd5fde..5403ae8176 100644 --- a/build-system/example-configuration/variables.bzl +++ b/build-system/example-configuration/variables.bzl @@ -9,3 +9,6 @@ telegram_is_appstore_build = "true" telegram_appstore_id = "686449807" 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 diff --git a/submodules/TelegramUI/Sources/WidgetDataContext.swift b/submodules/TelegramUI/Sources/WidgetDataContext.swift index d5dc002d32..d4c99d73f7 100644 --- a/submodules/TelegramUI/Sources/WidgetDataContext.swift +++ b/submodules/TelegramUI/Sources/WidgetDataContext.swift @@ -104,7 +104,7 @@ final class WidgetDataContext { let queue = Queue() let updatedAdditionalPeerIds: Signal<[AccountRecordId: Set], NoError> = Signal { subscriber in if #available(iOSApplicationExtension 14.0, iOS 14.0, *) { - #if arch(arm64) || arch(i386) || arch(x86_64) + #if arch(arm64) || arch(x86_64) WidgetCenter.shared.getCurrentConfigurations { result in var peerIds: [AccountRecordId: Set] = [:] diff --git a/third-party/webrtc/BUILD b/third-party/webrtc/BUILD index 8d122018de..21d6eca221 100644 --- a/third-party/webrtc/BUILD +++ b/third-party/webrtc/BUILD @@ -3174,6 +3174,7 @@ common_arm_specific_sources = [webrtc_source_dir + "/" + path for path in [ armv7_specific_sources = [webrtc_source_dir + "/" + path for path in [ "common_audio/signal_processing/filter_ar_fast_q12.c", "common_audio/signal_processing/complex_bit_reverse.c", + "common_audio/third_party/ooura/fft_size_128/ooura_fft_neon.cc", ]] arm64_specific_sources = [webrtc_source_dir + "/" + path for path in [