diff --git a/engine/src/build/config/apple/BUILD.gn b/engine/src/build/config/apple/BUILD.gn new file mode 100644 index 00000000000..aa1129e9ea9 --- /dev/null +++ b/engine/src/build/config/apple/BUILD.gn @@ -0,0 +1,76 @@ +# Copyright 2013 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +assert(is_mac || is_ios) + +import("//build/config/apple/apple_sdk.gni") + +config("compiler") { + # swiftc -sdk flag. + if (is_ios) { + _sdk_root = ios_sdk_path + if (create_xcode_symlinks) { + _sdk_root = rebase_path(ios_sdk_path, root_build_dir) + } + } else if (is_mac) { + _sdk_root = mac_sdk_path + if (create_xcode_symlinks) { + _sdk_root = rebase_path(mac_sdk_path, root_build_dir) + } + } else { + assert(false, "unsupported platform") + } + + # swiftc -target flag (target triplet). + # CPU architecture. + if (current_cpu == "x64") { + _triplet_cpu = "x86_64" + } else if (current_cpu == "arm64") { + _triplet_cpu = "arm64" + } else { + # x86, arm, armv7, etc. + assert(false, "unsupported cpu: $current_cpu") + } + # Environment. + if (use_ios_simulator) { + _triplet_environment = "-simulator" + } else { + _triplet_environment = "" + } + # OS. + if (is_ios) { + _triplet_os = "apple-ios" + } else if (is_mac) { + _triplet_os = "apple-macos" + } else { + assert(false, "unsupported Apple os") + } + _target_triplet = "$_triplet_cpu-$_triplet_os$mac_deployment_target$_triplet_environment" + + # swiftc -swift-version flag. + # + # Swift 6 transition: As of April 2025, no public Flutter framework API is + # authored in Swift. Swift 6 is ABI-compatible with Swift 5, but not + # source-compatible. If any public API *is* written in Swift, it's possible + # we may need to prepare concurrent Swift 5 and 6 builds during a transition + # period. + _swift_version = "5" + + # TODO(cbracken): https://github.com/flutter/flutter/issues/167592 + # Look up xcode_version in apple_sdk.gni + # + # This is here so that all files get recompiled after an Xcode update. + # (defines are passed via the command line, and build system rebuild things + # when their commandline changes). Nothing should ever read this define. + #defines = [ "CR_XCODE_VERSION=$xcode_version" ] + + swiftflags = [ + "-sdk", + _sdk_root, + "-target", + _target_triplet, + "-swift-version", + _swift_version + ] +} diff --git a/engine/src/build/config/compiler/BUILD.gn b/engine/src/build/config/compiler/BUILD.gn index 266e22885fb..b657abe4145 100644 --- a/engine/src/build/config/compiler/BUILD.gn +++ b/engine/src/build/config/compiler/BUILD.gn @@ -72,10 +72,8 @@ config("compiler") { configs = [] # Platform-specific configs. - if (is_ios) { - configs += [ "//build/config/ios:compiler" ] - } else if (is_mac) { - configs += [ "//build/config/mac:compiler" ] + if (is_ios || is_mac) { + configs += [ "//build/config/apple:compiler" ] } # In general, Windows is totally different, but all the other builds share diff --git a/engine/src/build/config/ios/BUILD.gn b/engine/src/build/config/ios/BUILD.gn index 079abb60d63..774e4def775 100644 --- a/engine/src/build/config/ios/BUILD.gn +++ b/engine/src/build/config/ios/BUILD.gn @@ -6,66 +6,6 @@ config("sdk") { cflags_cc = [ "-stdlib=libc++" ] } -config("compiler") { - # swiftc -sdk flag. - _sdk_root = ios_sdk_path - if (create_xcode_symlinks) { - _sdk_root = rebase_path(ios_sdk_path, root_build_dir) - } - - # swiftc -target flag (target triplet). - # CPU architecture. - if (current_cpu == "x64") { - _triplet_cpu = "x86_64" - } else if (current_cpu == "arm64") { - _triplet_cpu = "arm64" - } else { - # x86, arm, armv7, etc. - assert(false, "unsupported cpu: $current_cpu") - } - # Environment. - if (use_ios_simulator) { - _triplet_environment = "-simulator" - } else { - _triplet_environment = "" - } - # OS. - if (is_ios) { - _triplet_os = "apple-ios" - } else if (is_mac) { - _triplet_os = "apple-macos" - } else { - assert(false, "unsupported Apple os") - } - _target_triplet = "$_triplet_cpu-$_triplet_os$ios_deployment_target$_triplet_environment" - - # swiftc -swift-version flag. - # - # Swift 6 transition: As of April 2025, no public Flutter framework API is - # authored in Swift. Swift 6 is ABI-compatible with Swift 5, but not - # source-compatible. If any public API *is* written in Swift, it's possible - # we may need to prepare concurrent Swift 5 and 6 builds during a transition - # period. - _swift_version = "5" - - # TODO(cbracken): https://github.com/flutter/flutter/issues/167592 - # Look up xcode_version in apple_sdk.gni - # - # This is here so that all files get recompiled after an Xcode update. - # (defines are passed via the command line, and build system rebuild things - # when their commandline changes). Nothing should ever read this define. - #defines = [ "CR_XCODE_VERSION=$xcode_version" ] - - swiftflags = [ - "-sdk", - _sdk_root, - "-target", - _target_triplet, - "-swift-version", - _swift_version - ] -} - config("ios_application_extension") { cflags_objc = [ "-fapplication-extension" ] cflags_objcc = [ "-fapplication-extension" ] diff --git a/engine/src/build/config/mac/BUILD.gn b/engine/src/build/config/mac/BUILD.gn index ef8b1ada90d..b679282ec4c 100644 --- a/engine/src/build/config/mac/BUILD.gn +++ b/engine/src/build/config/mac/BUILD.gn @@ -28,53 +28,3 @@ config("mac_dynamic_flags") { config("mac_executable_flags") { ldflags = [ "-Wl,-pie" ] # Position independent. } - -config("compiler") { - # swiftc -sdk flag. - _sdk_root = mac_sdk_path - if (create_xcode_symlinks) { - _sdk_root = rebase_path(mac_sdk_path, root_build_dir) - } - - # swiftc -target flag (target triplet). - # CPU architecture. - if (current_cpu == "x64") { - _triplet_cpu = "x86_64" - } else if (current_cpu == "arm64") { - _triplet_cpu = "arm64" - } else { - # x86, arm, armv7, etc. - assert(false, "unsupported cpu: $current_cpu") - } - # Environment. - _triplet_environment = "" - # OS. - _triplet_os = "apple-macos" - _target_triplet = "$_triplet_cpu-$_triplet_os$mac_deployment_target$_triplet_environment" - - # swiftc -swift-version flag. - # - # Swift 6 transition: As of April 2025, no public Flutter framework API is - # authored in Swift. Swift 6 is ABI-compatible with Swift 5, but not - # source-compatible. If any public API *is* written in Swift, it's possible - # we may need to prepare concurrent Swift 5 and 6 builds during a transition - # period. - _swift_version = "5" - - # TODO(cbracken): https://github.com/flutter/flutter/issues/167592 - # Look up xcode_version in apple_sdk.gni - # - # This is here so that all files get recompiled after an Xcode update. - # (defines are passed via the command line, and build system rebuild things - # when their commandline changes). Nothing should ever read this define. - #defines = [ "CR_XCODE_VERSION=$xcode_version" ] - - swiftflags = [ - "-sdk", - _sdk_root, - "-target", - _target_triplet, - "-swift-version", - _swift_version - ] -} diff --git a/engine/src/flutter/shell/platform/darwin/common/BUILD.gn b/engine/src/flutter/shell/platform/darwin/common/BUILD.gn index 3881e6df3f2..89cbfd292ac 100644 --- a/engine/src/flutter/shell/platform/darwin/common/BUILD.gn +++ b/engine/src/flutter/shell/platform/darwin/common/BUILD.gn @@ -4,10 +4,44 @@ assert(is_mac || is_ios) +import("//build/config/apple/apple_sdk.gni") import("//flutter/common/config.gni") import("//flutter/testing/testing.gni") import("framework_common.gni") +config("config") { + include_dirs = [ target_gen_dir ] + if (is_ios) { + lib_dirs = ios_swift_lib_paths + } else if (is_mac) { + lib_dirs = mac_swift_lib_paths + } + + # Allow use of @testable imports in debug builds and when tests are enabled. + if ((is_ios && enable_ios_unittests) || (is_mac && enable_unittests)) { + swiftflags = [ "-enable-testing" ] + } +} + +config("test_config") { + configs = [ ":config" ] + + # Add platform frameworks directory to search path for test frameworks. + # Add platform lib to search path for test libraries/Swift modules. + cflags = [ "-fvisibility=default" ] + + if (is_ios) { + _platform_path = ios_platform_path + } else if (is_mac) { + _platform_path = mac_platform_path + } + cflags += [ "-F$_platform_path/Developer/Library/Frameworks" ] + swiftflags = [ "-F$_platform_path/Developer/Library/Frameworks" ] + include_dirs = [ "$_platform_path/Developer/usr/lib" ] + framework_dirs = [ "$_platform_path/Developer/Library/Frameworks" ] + lib_dirs = [ "$_platform_path/Developer/usr/lib" ] +} + source_set("common") { cflags_objc = flutter_cflags_objc cflags_objcc = flutter_cflags_objcc diff --git a/engine/src/flutter/shell/platform/darwin/ios/BUILD.gn b/engine/src/flutter/shell/platform/darwin/ios/BUILD.gn index e0b1a1c3976..6a499179bfb 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/BUILD.gn +++ b/engine/src/flutter/shell/platform/darwin/ios/BUILD.gn @@ -22,31 +22,6 @@ shell_gpu_configuration("ios_gpu_configuration") { enable_metal = true } -config("config_ios") { - include_dirs = [ target_gen_dir ] - lib_dirs = ios_swift_lib_paths - - # Allow use of @testable imports in debug builds and when tests are enabled. - if (enable_ios_unittests) { - swiftflags = [ "-enable-testing" ] - } -} - -config("config_ios_test") { - configs = [ ":config_ios" ] - - # Add platform frameworks directory to search path for test frameworks. - # Add platform lib to search path for test libraries/Swift modules. - cflags = [ - "-fvisibility=default", - "-F$ios_platform_path/Developer/Library/Frameworks", - ] - swiftflags = [ "-F$ios_platform_path/Developer/Library/Frameworks" ] - include_dirs = [ "$ios_platform_path/Developer/usr/lib" ] - framework_dirs = [ "$ios_platform_path/Developer/Library/Frameworks" ] - lib_dirs = [ "$ios_platform_path/Developer/usr/lib" ] -} - # The headers that will be copied to the Flutter.framework and be accessed # from outside the Flutter engine source root. _flutter_framework_headers = [ @@ -66,7 +41,7 @@ _flutter_framework_headers_copy_dir = "$_flutter_framework_dir/Headers" source_set("InternalFlutterSwift") { visibility = [ ":*" ] - configs += [ ":config_ios" ] + configs += [ "//flutter/shell/platform/darwin/common:config" ] sources = [ "framework/Source/ConnectionCollection.swift", @@ -85,7 +60,7 @@ source_set("flutter_framework_source") { "//flutter:config", ] configs += [ - ":config_ios", + "//flutter/shell/platform/darwin/common:config", "//build/config/ios:ios_application_extension", ] @@ -224,7 +199,7 @@ if (enable_ios_unittests) { source_set("ios_test_flutter_swift") { testonly = true visibility = [ ":*" ] - configs += [ ":config_ios_test" ] + configs += [ "//flutter/shell/platform/darwin/common:test_config" ] sources = [ "framework/Source/ConnectionCollectionTest.swift", "framework/Source/FakeUIPressProxy.swift", @@ -247,11 +222,14 @@ if (enable_ios_unittests) { ldflags = [ "-Wl,-install_name,@rpath/Frameworks/libios_test_flutter.dylib" ] frameworks = [ "XCTest.framework" ] - configs += [ ":config_ios_test" ] + include_dirs = [ target_gen_dir ] + + configs += [ "//flutter/shell/platform/darwin/common:test_config" ] configs -= [ "//build/config/gcc:symbol_visibility_hidden", "//build/config:symbol_visibility_hidden", ] + sources = [ "framework/Source/FlutterAppDelegateTest.mm", "framework/Source/FlutterChannelKeyResponderTest.mm", diff --git a/engine/src/flutter/shell/platform/darwin/macos/BUILD.gn b/engine/src/flutter/shell/platform/darwin/macos/BUILD.gn index ad77009a1c1..06557229e22 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/BUILD.gn +++ b/engine/src/flutter/shell/platform/darwin/macos/BUILD.gn @@ -18,31 +18,6 @@ shell_gpu_configuration("macos_gpu_configuration") { enable_metal = true } -config("config_macos") { - include_dirs = [ target_gen_dir ] - lib_dirs = mac_swift_lib_paths - - # Allow use of @testable imports in debug builds and when tests are enabled. - if (enable_unittests) { - swiftflags = [ "-enable-testing" ] - } -} - -config("config_macos_test") { - configs = [ ":config_macos" ] - - # Add platform frameworks directory to search path for test frameworks. - # Add platform lib to search path for test libraries/Swift modules. - cflags = [ - "-fvisibility=default", - "-F$mac_platform_path/Developer/Library/Frameworks", - ] - swiftflags = [ "-F$mac_platform_path/Developer/Library/Frameworks" ] - include_dirs = [ "$mac_platform_path/Developer/usr/lib" ] - framework_dirs = [ "$mac_platform_path/Developer/Library/Frameworks" ] - lib_dirs = [ "$mac_platform_path/Developer/usr/lib" ] -} - group("macos") { deps = [ ":flutter_framework" ] if (build_glfw_shell) { @@ -77,7 +52,7 @@ _flutter_framework_headers_copy_dir = source_set("InternalFlutterSwift") { visibility = [ ":*" ] - configs += [ ":config_macos" ] + configs += [ "//flutter/shell/platform/darwin/common:config" ] sources = [ "framework/Source/FlutterRunLoop.swift" ] }