diff --git a/.bazelrc b/.bazelrc index fc6d0486d1..53cb710dc1 100644 --- a/.bazelrc +++ b/.bazelrc @@ -6,26 +6,11 @@ build --apple_crosstool_top=@local_config_apple_cc//:toolchain build --crosstool_top=@local_config_apple_cc//:toolchain build --host_crosstool_top=@local_config_apple_cc//:toolchain -build --cxxopt='-std=c++17' -build --per_file_copt="third-party/webrtc/.*\.cpp$","@-std=c++17" -build --per_file_copt="third-party/webrtc/.*\.cc$","@-std=c++17" -build --per_file_copt="third-party/webrtc/.*\.mm$","@-std=c++17" -build --per_file_copt="submodules/LottieMeshSwift/LottieMeshBinding/Sources/.*\.mm$","@-std=c++17" -build --per_file_copt="submodules/LottieCpp/lottiecpp/Sources/.*\.mm$","@-std=c++17" -build --per_file_copt="submodules/LottieCpp/lottiecpp/Sources/.*\.cpp$","@-std=c++17" -build --per_file_copt="submodules/LottieCpp/lottiecpp/PlatformSpecific/Darwin/Sources/.*\.mm$","@-std=c++17" -build --per_file_copt="submodules/LottieCpp/lottiecpp/PlatformSpecific/Darwin/Sources/.*\.cpp$","@-std=c++17" -build --per_file_copt="Tests/LottieMetalTest/SoftwareLottieRenderer/Sources/.*\.cpp$","@-std=c++17" -build --per_file_copt="Tests/LottieMetalTest/SoftwareLottieRenderer/Sources/.*\.mm$","@-std=c++17" -build --per_file_copt="third-party/td/TdBinding/Sources/.*\.mm$","@-std=c++17" - #build --swiftcopt=-whole-module-optimization build --per_file_copt=".*\.m$","@-fno-objc-msgsend-selector-stubs" build --per_file_copt=".*\.mm$","@-fno-objc-msgsend-selector-stubs" -#build --linkopt="-ld_classic" - build --features=debug_prefix_map_pwd_is_dot build --features=swift.cacheable_swiftmodules build --features=swift.debug_prefix_map diff --git a/Telegram/BUILD b/Telegram/BUILD index 6ed4339a42..6cbd6e4e77 100644 --- a/Telegram/BUILD +++ b/Telegram/BUILD @@ -1779,16 +1779,13 @@ ios_application( ":UrlTypesInfoPlist", ], deps = [ - #"//submodules/MtProtoKit", - #"//submodules/SSignalKit/SwiftSignalKit", - #"//submodules/Postbox", - #"//submodules/TelegramApi", - #"//submodules/TelegramCore", - #"//submodules/FFMpegBinding", - #"//submodules/Display", - #"//third-party/webrtc", + "//submodules/Display", + "//submodules/TelegramCore", + "//submodules/FFMpegBinding", + "//third-party/webrtc", "//submodules/AsyncDisplayKit", "//submodules/ObjCRuntimeUtils", + ], ) diff --git a/Tests/LottieMetalTest/SoftwareLottieRenderer/BUILD b/Tests/LottieMetalTest/SoftwareLottieRenderer/BUILD index 041c8eda84..9909820b33 100644 --- a/Tests/LottieMetalTest/SoftwareLottieRenderer/BUILD +++ b/Tests/LottieMetalTest/SoftwareLottieRenderer/BUILD @@ -16,6 +16,11 @@ objc_library( "-Werror", "-I{}/Sources".format(package_name()), ], + cxxopts = [ + "-Werror", + "-std=c++17", + "-I{}/Sources".format(package_name()), + ], hdrs = glob([ "PublicHeaders/**/*.h", ]), diff --git a/build-system/bazel-utils/spm.bzl b/build-system/bazel-utils/spm.bzl index 7cd7038a13..4dd33b196a 100644 --- a/build-system/bazel-utils/spm.bzl +++ b/build-system/bazel-utils/spm.bzl @@ -54,10 +54,14 @@ _IGNORE_CC_LIBRARY_EMPTY_ATTRS = [ "include_prefix", "strip_include_prefix", "local_defines", + "conlyopts", + "module_interfaces", + "package_metadata", ] _CC_LIBRARY_ATTRS = { "copts": [], + "cxxopts": [], "defines": [], "deps": [], "hdrs": [], @@ -108,11 +112,11 @@ _IGNORE_OBJC_LIBRARY_EMPTY_ATTRS = [ "textual_hdrs", "sdk_includes", "conlyopts", - "cxxopts", ] _OBJC_LIBRARY_ATTRS = { "copts": [], + "cxxopts": [], "defines": [], "deps": [], "hdrs": [], @@ -351,6 +355,7 @@ def _collect_spm_modules_impl(target, ctx): "sources": sorted(sources + headers), "module_name": module_name, "copts": result_attrs["copts"], + "cxxopts": result_attrs["cxxopts"], "sdk_frameworks": result_attrs["sdk_frameworks"], "sdk_dylibs": result_attrs["sdk_dylibs"], "weak_sdk_frameworks": result_attrs["weak_sdk_frameworks"], @@ -366,6 +371,7 @@ def _collect_spm_modules_impl(target, ctx): "sources": sorted(sources + headers), "module_name": module_name, "copts": result_attrs["copts"], + "cxxopts": result_attrs["cxxopts"], "includes": result_attrs["includes"], } elif module_type == "swift_library": @@ -373,6 +379,7 @@ def _collect_spm_modules_impl(target, ctx): "name": result_attrs["name"], "type": module_type, "path": module_path, + "defines": result_attrs["defines"], "deps": dep_names, "sources": sorted(sources), "module_name": module_name, diff --git a/build-system/generate_spm.py b/build-system/generate_spm.py index fea5dbf31c..a6579dafbd 100644 --- a/build-system/generate_spm.py +++ b/build-system/generate_spm.py @@ -19,6 +19,24 @@ if os.path.exists(spm_files_dir): if not os.path.exists(spm_files_dir): os.makedirs(spm_files_dir) +def escape_swift_string_literal_component(text: str) -> str: + return text.replace('\\', '\\\\').replace('"', '\\"') + +parsed_modules = {} +for name, module in sorted(modules.items()): + is_empty = False + all_source_files = [] + for source in module.get("hdrs", []) + module["sources"]: + if source.endswith(('.a')): + continue + all_source_files.append(source) + if module["type"] == "objc_library" or module["type"] == "swift_library" or module["type"] == "cc_library": + if all_source_files == []: + is_empty = True + parsed_modules[name] = { + "is_empty": is_empty, + } + combined_lines = [] combined_lines.append("// swift-tools-version: 6.0") combined_lines.append("// The swift-tools-version declares the minimum version of Swift required to build this package.") @@ -28,11 +46,14 @@ combined_lines.append("") combined_lines.append("let package = Package(") combined_lines.append(" name: \"Telegram\",") combined_lines.append(" platforms: [") -combined_lines.append(" .iOS(.v13)") +combined_lines.append(" .iOS(.v12)") combined_lines.append(" ],") combined_lines.append(" products: [") for name, module in sorted(modules.items()): + if parsed_modules[name]["is_empty"]: + continue + if module["type"] == "objc_library" or module["type"] == "swift_library" or module["type"] == "cc_library": combined_lines.append(" .library(name: \"%s\", targets: [\"%s\"])," % (module["name"], module["name"])) @@ -40,6 +61,9 @@ combined_lines.append(" ],") combined_lines.append(" targets: [") for name, module in sorted(modules.items()): + if parsed_modules[name]["is_empty"]: + continue + module_type = module["type"] if module_type == "objc_library" or module_type == "cc_library" or module_type == "swift_library": combined_lines.append(" .target(") @@ -47,7 +71,7 @@ for name, module in sorted(modules.items()): linked_directory = None has_non_linked_sources = False - for source in module["sources"]: + for source in module["sources"] + module.get("hdrs", []): if source.startswith("bazel-out/"): linked_directory = "spm-files/" + name else: @@ -60,7 +84,8 @@ for name, module in sorted(modules.items()): combined_lines.append(" dependencies: [") for dep in module["deps"]: - combined_lines.append(" .target(name: \"%s\")," % dep) + if not parsed_modules[dep]["is_empty"]: + combined_lines.append(" .target(name: \"%s\")," % dep) combined_lines.append(" ],") if linked_directory: @@ -85,7 +110,7 @@ for name, module in sorted(modules.items()): continue # Check if any source file is under this directory has_source = False - for source in module["sources"]: + for source in module["sources"] + module.get("hdrs", []): rel_source = source[len(module["path"]) + 1:] if rel_source.startswith(dir_path + "/"): has_source = True @@ -98,16 +123,14 @@ for name, module in sorted(modules.items()): file_path = os.path.join(rel_path, f) if any(component.startswith('.') for component in file_path.split('/')): continue - if file_path not in [source[len(module["path"]) + 1:] for source in module["sources"]]: + if file_path not in [source[len(module["path"]) + 1:] for source in module["sources"] + module.get("hdrs", [])]: exclude_files_and_dirs.append(file_path) for item in exclude_files_and_dirs: combined_lines.append(" \"%s\"," % item) combined_lines.append(" ],") combined_lines.append(" sources: [") - for source in module["sources"]: - if source.endswith(('.h', '.hpp')): - continue + for source in module["sources"] + module.get("hdrs", []): linked_source_file_names = [] if not source.startswith(module["path"]): if source.startswith("bazel-out/"): @@ -138,7 +161,8 @@ for name, module in sorted(modules.items()): os.symlink(symlink_target, symlink_location) relative_source = source_file_name - combined_lines.append(" \"%s\"," % relative_source) + if not source.endswith(('.h', '.hpp', '.a')): + combined_lines.append(" \"%s\"," % relative_source) else: print("Source {} is not inside module path {}".format(source, module["path"])) sys.exit(1) @@ -152,16 +176,53 @@ for name, module in sorted(modules.items()): elif len(module["includes"]) == 1: combined_lines.append(" publicHeadersPath: \"%s\"," % module["includes"][0]) else: - print("Multiple includes are not supported yet: {}".format(module["includes"])) + print("{}: Multiple includes are not yet supported: {}".format(name, module["includes"])) sys.exit(1) - combined_lines.append(" cSettings: [") - combined_lines.append(" .unsafeFlags([") - for flag in module["copts"]: - # Escape C-string entities in flag - escaped_flag = flag.replace('\\', '\\\\').replace('"', '\\"') - combined_lines.append(" \"%s\"," % escaped_flag) - combined_lines.append(" ])") - combined_lines.append(" ],") + + defines = module.get("defines", []) + copts = module.get("copts", []) + cxxopts = module.get("cxxopts", []) + + if defines or copts: + combined_lines.append(" cSettings: [") + if defines: + for define in defines: + if "=" in define: + print("{}: Defines with = are not yet supported: {}".format(name, define)) + sys.exit(1) + else: + combined_lines.append(f' .define("{define}"),') + if copts: + combined_lines.append(" .unsafeFlags([") + for flag in copts: + escaped_flag = escape_swift_string_literal_component(flag) + combined_lines.append(f' "{escaped_flag}",') + combined_lines.append(" ])") + combined_lines.append(" ],") + + if defines or cxxopts: # Check for defines OR cxxopts + combined_lines.append(" cxxSettings: [") + if defines: # Add defines again if present, for C++ context + for define in defines: + if "=" in define: + print("{}: Defines with = are not yet supported: {}".format(name, define)) + sys.exit(1) + else: + combined_lines.append(f' .define("{define}"),') + if cxxopts: + combined_lines.append(" .unsafeFlags([") + for flag in cxxopts: + if flag.startswith("-std="): + if flag != "-std=c++17": + print("{}: Unsupported C++ standard: {}".format(name, flag)) + sys.exit(1) + else: + continue + escaped_flag = escape_swift_string_literal_component(flag) + combined_lines.append(f' "{escaped_flag}",') + combined_lines.append(" ])") + combined_lines.append(" ],") + combined_lines.append(" linkerSettings: [") if module_type == "objc_library": for framework in module["sdk_frameworks"]: @@ -171,12 +232,33 @@ for name, module in sorted(modules.items()): combined_lines.append(" ]") elif module_type == "swift_library": + defines = module.get("defines", []) + swift_copts = module.get("copts", []) # These are actual swiftc flags + + # Handle cSettings for defines if they exist + if defines: + combined_lines.append(" cSettings: [") + for define in defines: + combined_lines.append(f' .define("{define}"),') + combined_lines.append(" ],") + + # Handle swiftSettings combined_lines.append(" swiftSettings: [") combined_lines.append(" .swiftLanguageMode(.v5),") - combined_lines.append(" .unsafeFlags([") - for flag in module["copts"]: - combined_lines.append(" \"%s\"," % flag) - combined_lines.append(" ])") + # Add defines to swiftSettings as simple .define("STRING") flags + if defines: + for define in defines: + # For Swift settings, the define is passed as a single string, e.g., "KEY=VALUE" or "FLAG" + escaped_define = escape_swift_string_literal_component(define) # Escape the whole define string + combined_lines.append(f' .define("{escaped_define}"),') + + # Add copts (swiftc flags) to unsafeFlags in swiftSettings + if swift_copts: + combined_lines.append(" .unsafeFlags([") + for flag in swift_copts: + escaped_flag = escape_swift_string_literal_component(flag) + combined_lines.append(f' "{escaped_flag}",') + combined_lines.append(" ])") combined_lines.append(" ]") combined_lines.append(" ),") elif module["type"] == "root": @@ -185,7 +267,8 @@ for name, module in sorted(modules.items()): print("Unknown module type: {}".format(module["type"])) sys.exit(1) -combined_lines.append(" ]") +combined_lines.append(" ],") +combined_lines.append(" cxxLanguageStandard: .cxx17") combined_lines.append(")") combined_lines.append("") diff --git a/submodules/AsyncDisplayKit/BUILD b/submodules/AsyncDisplayKit/BUILD index 856b29e81d..f713d1184c 100644 --- a/submodules/AsyncDisplayKit/BUILD +++ b/submodules/AsyncDisplayKit/BUILD @@ -17,6 +17,10 @@ objc_library( copts = [ "-Werror", ], + cxxopts = [ + "-Werror", + "-std=c++17", + ], hdrs = public_headers, defines = [ "MINIMAL_ASDK", diff --git a/submodules/AsyncDisplayKit/Source/PublicHeaders/AsyncDisplayKit/AsyncDisplayKit.h b/submodules/AsyncDisplayKit/Source/PublicHeaders/AsyncDisplayKit/AsyncDisplayKit.h index dc00ed8339..265a9fe343 100644 --- a/submodules/AsyncDisplayKit/Source/PublicHeaders/AsyncDisplayKit/AsyncDisplayKit.h +++ b/submodules/AsyncDisplayKit/Source/PublicHeaders/AsyncDisplayKit/AsyncDisplayKit.h @@ -63,3 +63,9 @@ #import #import + +#import +#import +#import +#import +#import diff --git a/submodules/LottieCpp/BUILD b/submodules/LottieCpp/BUILD index 686f35669a..7569482041 100644 --- a/submodules/LottieCpp/BUILD +++ b/submodules/LottieCpp/BUILD @@ -22,6 +22,11 @@ objc_library( "-Werror", "-I{}/lottiecpp/Sources".format(package_name()), ], + cxxopts = [ + "-Werror", + "-std=c++17", + "-I{}/lottiecpp/Sources".format(package_name()), + ], hdrs = glob([ "lottiecpp/PublicHeaders/**/*.h", ]), @@ -49,6 +54,9 @@ cc_library( "PublicHeaders", ], copts = [], + cxxopts = [ + "-std=c++17", + ], visibility = ["//visibility:public"], linkstatic = 1, ) diff --git a/submodules/ShareItems/Impl/Sources/TGItemProviderSignals.m b/submodules/ShareItems/Impl/Sources/TGItemProviderSignals.m index 35f8ec5068..92aeb2c25e 100644 --- a/submodules/ShareItems/Impl/Sources/TGItemProviderSignals.m +++ b/submodules/ShareItems/Impl/Sources/TGItemProviderSignals.m @@ -46,7 +46,7 @@ } } - NSInteger providerIndex = -1; + __unused NSInteger providerIndex = -1; for (NSItemProvider *provider in providers) { providerIndex++; @@ -140,7 +140,7 @@ }]; } -static UIImage *TGScaleImageToPixelSize(UIImage *image, CGSize size) { +__unused static UIImage *TGScaleImageToPixelSize(UIImage *image, CGSize size) { UIGraphicsBeginImageContextWithOptions(size, true, 1.0f); [image drawInRect:CGRectMake(0, 0, size.width, size.height) blendMode:kCGBlendModeCopy alpha:1.0f]; UIImage *result = UIGraphicsGetImageFromCurrentImageContext(); @@ -149,7 +149,7 @@ static UIImage *TGScaleImageToPixelSize(UIImage *image, CGSize size) { return result; } -static CGSize TGFitSize(CGSize size, CGSize maxSize) { +__unused static CGSize TGFitSize(CGSize size, CGSize maxSize) { if (size.width < 1) size.width = 1; if (size.height < 1) diff --git a/submodules/ShareItems/Impl/Sources/TGShareLocationSignals.m b/submodules/ShareItems/Impl/Sources/TGShareLocationSignals.m index 58387a1d92..f90521a186 100644 --- a/submodules/ShareItems/Impl/Sources/TGShareLocationSignals.m +++ b/submodules/ShareItems/Impl/Sources/TGShareLocationSignals.m @@ -64,12 +64,15 @@ NSString *const TGShareGoogleProvider = @"google"; NSString * TGURLEncodedStringFromStringWithEncoding(NSString *string, NSStringEncoding encoding) { static NSString * const kAFLegalCharactersToBeEscaped = @"?!@#$^&%*+=,:;'\"`<>()[]{}/\\|~ "; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" NSString *unescapedString = [string stringByReplacingPercentEscapesUsingEncoding:encoding]; if (unescapedString) { string = unescapedString; } return (__bridge NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (__bridge CFStringRef)string, NULL, (__bridge CFStringRef)kAFLegalCharactersToBeEscaped, CFStringConvertNSStringEncodingToEncoding(encoding)); +#pragma clang diagnostic pop } @implementation TGQueryStringComponent diff --git a/submodules/ffmpeg/BUILD b/submodules/ffmpeg/BUILD index f17be250cb..e60ed3ec8d 100644 --- a/submodules/ffmpeg/BUILD +++ b/submodules/ffmpeg/BUILD @@ -286,11 +286,15 @@ genrule( PATH="$$PATH:$$YASM_DIR" "$$SOURCE_PATH/build-ffmpeg-bazel.sh" "$$VARIANT" "$$BUILD_ARCH" "$$BUILD_DIR" "$$SOURCE_PATH" "$$FFMPEG_VERSION" """ + "\n" + "\n".join([ "cp \"$$BUILD_DIR/FFmpeg-iOS/include/{header_path}\" \"$(location Public/third_party/ffmpeg/{header_path})\"".format(header_path = header_path) for header_path in ffmpeg_header_paths + ]) + "\n" + "\n".join([ + "cp \"$$BUILD_DIR/FFmpeg-iOS/include/{header_path}\" \"$(location Public/{header_path})\"".format(header_path = header_path) for header_path in ffmpeg_header_paths ]) + "\n" + "\n".join([ "cp \"$$BUILD_DIR/FFmpeg-iOS/lib/{lib}\" \"$(location {lib})\"".format(lib = lib) for lib in ffmpeg_libs ]), outs = [ "Public/third_party/ffmpeg/{}".format(header_path) for header_path in ffmpeg_header_paths + ] + [ + "Public/{}".format(header_path) for header_path in ffmpeg_header_paths ] + ffmpeg_libs, tools = [ "//third-party/yasm:yasm.tar", @@ -312,10 +316,9 @@ objc_library( name = "ffmpeg", module_name = "ffmpeg", enable_modules = True, - hdrs = ["Public/third_party/ffmpeg/" + x for x in ffmpeg_header_paths], + hdrs = ["Public/third_party/ffmpeg/" + x for x in ffmpeg_header_paths] + ["Public/" + x for x in ffmpeg_header_paths], includes = [ "Public", - "Public/third_party/ffmpeg", ], sdk_dylibs = [ "libbz2", diff --git a/submodules/openssl/BUILD b/submodules/openssl/BUILD index 2770f12648..88e867860f 100644 --- a/submodules/openssl/BUILD +++ b/submodules/openssl/BUILD @@ -162,6 +162,9 @@ genrule( cc_library( name = "openssl_lib", srcs = [":" + x for x in openssl_libs], + cxxopts = [ + "-std=c++17", + ], ) objc_library( diff --git a/submodules/sqlcipher/BUILD b/submodules/sqlcipher/BUILD index 85e0a5f8c0..266e1d9bf5 100644 --- a/submodules/sqlcipher/BUILD +++ b/submodules/sqlcipher/BUILD @@ -29,6 +29,7 @@ objc_library( "-DNDEBUG=1", "-DSQLITE_MAX_MMAP_SIZE=0", "-Wno-all", + "-Wno-#warnings", ], sdk_frameworks = [ "Foundation", diff --git a/third-party/td/BUILD b/third-party/td/BUILD index 85a5e2d97d..396dde13bb 100644 --- a/third-party/td/BUILD +++ b/third-party/td/BUILD @@ -135,6 +135,10 @@ objc_library( copts = [ "-Werror", ], + cxxopts = [ + "-Werror", + "-std=c++17", + ], includes = [ "TdBinding/Public", ], diff --git a/third-party/webrtc/BUILD b/third-party/webrtc/BUILD index 91498518d5..d76f237543 100644 --- a/third-party/webrtc/BUILD +++ b/third-party/webrtc/BUILD @@ -3473,6 +3473,9 @@ cc_library( "-DWEBRTC_HAVE_DCSCTP", "-DWEBRTC_HAVE_SCTP", ] + arch_specific_cflags + optimization_flags, + cxxopts = [ + "-std=c++17", + ], deps = [ "//third-party/boringssl:crypto", "//third-party/boringssl:ssl", @@ -3602,6 +3605,9 @@ objc_library( "-DRTC_DISABLE_TRACE_EVENTS", "-DRTC_DISABLE_METRICS", ] + arch_specific_cflags + optimization_flags, + cxxopts = [ + "-std=c++17", + ], deps = [ "//third-party/boringssl:crypto", "//third-party/boringssl:ssl",