Skip to content

Commit

Permalink
iOS,macOS: Add Obj-C cflags to all Obj-C targets (flutter#56386)
Browse files Browse the repository at this point in the history
Ensure that all Objective-C code in the codebase is being built with the standard set of Flutter Objective-C compiler flags with ARC enabled.

Also bumps the cflags config up to the top of the first block within each target in which Objective-C sources appear, so that the location is consistent.

Migrates The following targets to ARC, which had been missed in previous passes since they didn't declare the standard Flutter Obj-C[++] cflags:
* `//flutter/fml:fml_unittests`
* `//flutter/impeller/golden_tests:metal_screenshot`
* `//flutter/impeller/playground:playground`
* `//flutter/impeller/backend/metal:metal`
* `//flutter/impeller/backend/metal:metal_unittests`
* `//shell/gpu:gpu_surface_metal_unittests`
* `//flutter/shell/platform/embedder:embedder_unittests`

This patch includes no semantic changes.

Issue: flutter/flutter#137801

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
  • Loading branch information
cbracken authored Nov 6, 2024
1 parent 4950bb4 commit 3df1546
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 41 deletions.
18 changes: 9 additions & 9 deletions fml/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,13 @@ source_set("fml") {
libs = []

if (is_ios || is_mac) {
sources += [ "platform/darwin/concurrent_message_loop_factory.mm" ]
} else {
sources += [ "concurrent_message_loop_factory.cc" ]
}

if (is_ios || is_mac) {
cflags_objc = flutter_cflags_objc
cflags_objcc = flutter_cflags_objcc
cflags_objc = flutter_cflags_objc_arc
cflags_objcc = flutter_cflags_objcc_arc

sources += [
"platform/darwin/cf_utils.cc",
"platform/darwin/cf_utils.h",
"platform/darwin/concurrent_message_loop_factory.mm",
"platform/darwin/message_loop_darwin.h",
"platform/darwin/message_loop_darwin.mm",
"platform/darwin/paths_darwin.mm",
Expand All @@ -163,6 +158,8 @@ source_set("fml") {
]

frameworks = [ "Foundation.framework" ]
} else {
sources += [ "concurrent_message_loop_factory.cc" ]
}

if (is_android) {
Expand Down Expand Up @@ -365,7 +362,10 @@ if (enable_unittests) {
"time/time_unittest.cc",
]

if (is_mac) {
if (is_mac || is_ios) {
cflags_objc = flutter_cflags_objc_arc
cflags_objcc = flutter_cflags_objcc_arc

sources += [
"platform/darwin/cf_utils_unittests.mm",
"platform/darwin/string_range_sanitization_unittests.mm",
Expand Down
5 changes: 4 additions & 1 deletion impeller/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ impeller_component("impeller_unittests") {
"core:allocator_unittests",
"display_list:skia_conversions_unittests",
"geometry:geometry_unittests",
"renderer/backend/metal:metal_unittests",
"runtime_stage:runtime_stage_unittests",
"shader_archive:shader_archive_unittests",
"tessellator:tessellator_unittests",
Expand All @@ -80,6 +79,10 @@ impeller_component("impeller_unittests") {
]
}

if (impeller_enable_metal) {
deps += [ "//flutter/impeller/renderer/backend/metal:metal_unittests" ]
}

if (impeller_enable_vulkan) {
deps += [ "//flutter/impeller/renderer/backend/vulkan:vulkan_unittests" ]
}
Expand Down
6 changes: 3 additions & 3 deletions shell/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,14 @@ if (enable_unittests) {
}

if (test_enable_metal) {
cflags_objc = flutter_cflags_objc_arc
cflags_objcc = flutter_cflags_objcc_arc

sources += [
"shell_test_platform_view_metal.h",
"shell_test_platform_view_metal.mm",
]

cflags_objc = flutter_cflags_objc_arc
cflags_objcc = flutter_cflags_objcc_arc

public_deps += [ "//flutter/shell/platform/darwin/graphics" ]
}
}
Expand Down
9 changes: 6 additions & 3 deletions shell/gpu/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ source_set("gpu_surface_vulkan") {

if (shell_enable_metal) {
source_set("gpu_surface_metal") {
cflags_objc = flutter_cflags_objc_arc
cflags_objcc = flutter_cflags_objcc_arc

sources = [
"gpu_surface_metal_delegate.cc",
"gpu_surface_metal_delegate.h",
Expand All @@ -80,9 +83,6 @@ if (shell_enable_metal) {
"gpu_surface_noop.mm",
]

cflags_objc = flutter_cflags_objc_arc
cflags_objcc = flutter_cflags_objcc_arc

public_deps = gpu_common_deps

if (impeller_enable_metal) {
Expand All @@ -99,6 +99,9 @@ if (shell_enable_metal) {
if (is_mac) {
impeller_component("gpu_surface_metal_unittests") {
testonly = true
cflags_objc = flutter_cflags_objc_arc
cflags_objcc = flutter_cflags_objcc_arc

target_type = "executable"
sources = [
"gpu_surface_metal_impeller_unittests.mm",
Expand Down
7 changes: 3 additions & 4 deletions shell/platform/darwin/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ test_fixtures("framework_common_fixtures") {
# Unit tests for channels.
executable("framework_common_unittests") {
testonly = true
cflags_objc = flutter_cflags_objc_arc
cflags_objcc = flutter_cflags_objcc_arc
ldflags = [ "-ObjC" ]

sources = [
"framework/Source/FlutterBinaryMessengerRelayTest.mm",
Expand All @@ -119,10 +122,6 @@ executable("framework_common_unittests") {
"framework/Source/flutter_standard_codec_unittest.mm",
]

cflags_objcc = flutter_cflags_objcc_arc

ldflags = [ "-ObjC" ]

deps = [
":framework_common",
":framework_common_fixtures",
Expand Down
11 changes: 5 additions & 6 deletions shell/platform/darwin/macos/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ _flutter_framework_headers_copy_dir =

source_set("flutter_framework_source") {
visibility = [ ":*" ]
cflags_objc = flutter_cflags_objc_arc
cflags_objcc = flutter_cflags_objcc_arc

sources = [
"framework/Source/AccessibilityBridgeMac.h",
Expand Down Expand Up @@ -141,8 +143,6 @@ source_set("flutter_framework_source") {
"FLUTTER_ENGINE_NO_PROTOTYPES",
]

cflags_objcc = flutter_cflags_objcc_arc

frameworks = [
"Carbon.framework",
"Cocoa.framework",
Expand Down Expand Up @@ -173,6 +173,9 @@ test_fixtures("flutter_desktop_darwin_fixtures") {

executable("flutter_desktop_darwin_unittests") {
testonly = true
cflags_objc = flutter_cflags_objc_arc
cflags_objcc = flutter_cflags_objcc_arc
ldflags = [ "-ObjC" ]

sources = [
"framework/Source/AccessibilityBridgeMacTest.mm",
Expand Down Expand Up @@ -205,10 +208,6 @@ executable("flutter_desktop_darwin_unittests") {
"framework/Source/TestFlutterPlatformView.mm",
]

cflags_objcc = flutter_cflags_objcc_arc

ldflags = [ "-ObjC" ]

deps = [
":flutter_desktop_darwin_fixtures",
":flutter_framework_source",
Expand Down
9 changes: 6 additions & 3 deletions shell/platform/embedder/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ template("embedder_source_set") {
}

if (embedder_enable_metal) {
cflags_objc = flutter_cflags_objc_arc
cflags_objcc = flutter_cflags_objcc_arc

sources += [
"embedder_external_texture_metal.h",
"embedder_external_texture_metal.mm",
Expand All @@ -159,9 +162,6 @@ template("embedder_source_set") {
deps += [ "//flutter/impeller/renderer/backend/metal" ]
}

cflags_objc = flutter_cflags_objc_arc
cflags_objcc = flutter_cflags_objcc_arc

deps += [ "//flutter/shell/platform/darwin/graphics" ]
}

Expand Down Expand Up @@ -375,6 +375,9 @@ if (enable_unittests) {
}

if (test_enable_metal) {
cflags_objc = flutter_cflags_objc_arc
cflags_objcc = flutter_cflags_objcc_arc

sources += [ "tests/embedder_metal_unittests.mm" ]
}

Expand Down
2 changes: 1 addition & 1 deletion shell/platform/embedder/tests/embedder_metal_unittests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
SkISize texture_size,
void* texture) {
GrMtlTextureInfo info;
info.fTexture.reset([(id<MTLTexture>)texture retain]);
info.fTexture.retain(texture);
GrBackendTexture backend_texture = GrBackendTextures::MakeMtl(
texture_size.width(), texture_size.height(), skgpu::Mipmapped::kNo, info);

Expand Down
10 changes: 5 additions & 5 deletions testing/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,12 @@ if (enable_unittests) {
# On iOS, this is enabled to allow for Metal tests to run within a test app
if (is_mac || is_ios) {
source_set("metal") {
testonly = true

if (shell_enable_metal) {
cflags_objc = flutter_cflags_objc_arc
cflags_objcc = flutter_cflags_objcc_arc

sources = [
"test_metal_context.h",
"test_metal_context.mm",
Expand All @@ -210,11 +215,6 @@ if (is_mac || is_ios) {
deps += [ "//flutter/vulkan" ]
}
}

cflags_objc = flutter_cflags_objc_arc
cflags_objcc = flutter_cflags_objcc_arc

testonly = true
}
}

Expand Down
8 changes: 4 additions & 4 deletions third_party/accessibility/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ if (enable_unittests) {
]

if (is_mac) {
cflags_objc = flutter_cflags_objc_arc
cflags_objcc = flutter_cflags_objcc_arc
ldflags = [ "-ObjC" ]

sources += [ "ax/platform/ax_platform_node_mac_unittest.mm" ]
frameworks = [
"AppKit.framework",
Expand All @@ -84,10 +88,6 @@ if (enable_unittests) {
"CoreText.framework",
"IOSurface.framework",
]

cflags_objc = flutter_cflags_objc_arc
cflags_objcc = flutter_cflags_objcc_arc
ldflags = [ "-ObjC" ]
}
if (is_win) {
sources += [
Expand Down
5 changes: 3 additions & 2 deletions third_party/accessibility/ax/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,13 @@ source_set("ax") {
]

if (is_mac) {
cflags_objc = flutter_cflags_objc_arc
cflags_objcc = flutter_cflags_objcc_arc

sources += [
"platform/ax_platform_node_mac.h",
"platform/ax_platform_node_mac.mm",
]
cflags_objc = flutter_cflags_objc_arc
cflags_objcc = flutter_cflags_objcc_arc
} else if (is_win) {
sources += [
"platform/ax_fragment_root_delegate_win.h",
Expand Down

0 comments on commit 3df1546

Please sign in to comment.