0

Make tvOS imply iOS in GN and C++/Objective-C++

Following recent conversations with relevant Chromium on iOS folks, it
was decided that it made more sense for now to reverse one of the
decisions from https://crrev.com/c/6197019 and stop making the tvOS and
iOS builds be completely independent of each other: having them be
completely separate would require too many changes in GN, .grd, .py and
C++/Objective-C++ files in the tree (and even more so if we started
renaming the _ios.{mm,cc,h} files to something more generic).

More succinctly, this means that IS_IOS_TVOS in C++ and
`target_platform` in GN are set if and only if IS_IOS and is_ios are set
too, and iOS files and code paths are built on tvOS by default (rather
than being opt-in).

This CL implements this reversal while also making a few more
adjustments:

* The `is_tvos` GN flag is now called `target_platform` and takes
  "iphoneos" (default), "tvos" or "watchos" as values at the moment. As
  mentioned, it is set only if `is_ios` is also true (i.e. the target
  toolchain is being used). Files used by multiple toolchains may need
  to check for `is_ios` as well before referencing it.
* The GN flag is no longer being set in the main BUILDCONFIG.gn file,
  but rather in one of the files in //build/config/apple. Build system
  files that need to check this variable need to explicitly import this
  file.
* `BUILDFLAG(IS_TVOS)` is now `BUILDFLAG(IS_IOS_TVOS)` in C++.

Bug: 391990604, 391914246, 397889862
Change-Id: I7862cf63074b8ff75b4b58c911212d4652cae113
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6306066
Reviewed-by: Nico Weber <thakis@chromium.org>
Reviewed-by: Dave Tapuska <dtapuska@chromium.org>
Commit-Queue: Raphael Kubo da Costa <kubo@igalia.com>
Reviewed-by: Colin Blundell <blundell@chromium.org>
Reviewed-by: Sylvain Defresne <sdefresne@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1426638}
This commit is contained in:
Raphael Kubo da Costa
2025-02-28 16:51:43 -08:00
committed by Chromium LUCI CQ
parent 9902c0cd1e
commit c57d2df361
11 changed files with 87 additions and 51 deletions

@ -45,7 +45,7 @@ import("//testing/libfuzzer/fuzzer_test.gni")
import("//testing/test.gni")
if (is_ios) {
# Used to access target_environment.
# Used to access target_environment and target_platform.
import("//build/config/apple/mobile_config.gni")
# Used to access ios_is_app_extension variable definition.
@ -2188,13 +2188,20 @@ component("base") {
"process/process_handle_mac.cc",
"process/process_ios.cc",
"process/process_iterator_mac.cc",
"process/process_mac.cc",
"process/process_posix.cc",
"sync_socket_posix.cc",
"synchronization/waitable_event_posix.cc",
"synchronization/waitable_event_watcher_posix.cc",
]
if (target_platform == "tvos") {
# tvOS apps must be single-process. Build a Process version that does
# the bare minimum and does not use Mach ports.
sources += [ "process/process_tvos.cc" ]
} else {
sources += [ "process/process_mac.cc" ]
}
# We include launch_mac on simulator builds so unittests can fork.
if (target_environment == "simulator") {
sources += [
@ -2252,13 +2259,6 @@ component("base") {
]
}
# tvOS.
if (is_tvos) {
sources -= [ "process/process_mac.cc" ]
sources += [ "process/process_tvos.cc" ]
}
# Linux.
if (is_linux || is_chromeos) {
# TODO(brettw) this will need to be parameterized at some point.

@ -222,7 +222,7 @@ class BASE_EXPORT Process {
};
#if (BUILDFLAG(IS_MAC) || (BUILDFLAG(IS_IOS) && BUILDFLAG(USE_BLINK))) && \
!BUILDFLAG(IS_TVOS)
!BUILDFLAG(IS_IOS_TVOS)
// The Mac needs a Mach port in order to manipulate a process's priority,
// and there's no good way to get that from base given the pid. These Mac
// variants of the `GetPriority()` and `SetPriority()` API take a port

@ -16,10 +16,10 @@
//
// Operating System:
// IS_AIX / IS_ANDROID / IS_ASMJS / IS_CHROMEOS / IS_FREEBSD / IS_FUCHSIA /
// IS_IOS / IS_IOS_MACCATALYST / IS_LINUX / IS_MAC / IS_NACL / IS_NETBSD /
// IS_OPENBSD / IS_QNX / IS_SOLARIS / IS_TVOS / IS_WATCHOS / IS_WIN
// IS_IOS / IS_IOS_MACCATALYST / IS_IOS_TVOS / IS_LINUX / IS_MAC / IS_NACL /
// IS_NETBSD / IS_OPENBSD / IS_QNX / IS_SOLARIS / IS_WATCHOS / IS_WIN
// Operating System family:
// IS_APPLE: IOS or MAC or IOS_MACCATALYST or TVOS or WATCHOS
// IS_APPLE: IOS or MAC or IOS_MACCATALYST or IOS_TVOS or WATCHOS
// IS_BSD: FREEBSD or NETBSD or OPENBSD
// IS_POSIX: AIX or ANDROID or ASMJS or CHROMEOS or FREEBSD or IOS or LINUX
// or MAC or NACL or NETBSD or OPENBSD or QNX or SOLARIS
@ -78,7 +78,7 @@
#define OS_IOS_MACCATALYST
#endif // defined(TARGET_OS_MACCATALYST) && TARGET_OS_MACCATALYST
#if defined(TARGET_OS_TV) && TARGET_OS_TV
#define OS_TVOS 1
#define OS_IOS_TVOS 1
#endif // defined(TARGET_OS_TV) && TARGET_OS_TV
#if defined(TARGET_OS_WATCH) && TARGET_OS_WATCH
#define OS_WATCHOS 1
@ -205,6 +205,12 @@
#define BUILDFLAG_INTERNAL_IS_IOS_MACCATALYST() (0)
#endif
#if defined(OS_IOS_TVOS)
#define BUILDFLAG_INTERNAL_IS_IOS_TVOS() (1)
#else
#define BUILDFLAG_INTERNAL_IS_IOS_TVOS() (0)
#endif
#if defined(OS_LINUX)
#define BUILDFLAG_INTERNAL_IS_LINUX() (1)
#else
@ -253,12 +259,6 @@
#define BUILDFLAG_INTERNAL_IS_SOLARIS() (0)
#endif
#if defined(OS_TVOS)
#define BUILDFLAG_INTERNAL_IS_TVOS() (1)
#else
#define BUILDFLAG_INTERNAL_IS_TVOS() (0)
#endif
#if defined(OS_WATCHOS)
#define BUILDFLAG_INTERNAL_IS_WATCHOS() (1)
#else

@ -170,15 +170,13 @@ declare_args() {
#
# For more information see
# https://chromium.googlesource.com/chromium/src/+/main/docs/component_build.md
is_component_build = is_debug && current_os != "ios" &&
current_os != "tvos" && current_os != "watchos"
is_component_build =
is_debug && current_os != "ios" && current_os != "watchos"
}
assert(!(is_debug && is_official_build), "Can't do official debug builds")
assert(!(current_os == "ios" && is_component_build),
"Can't use component build on iOS")
assert(!(current_os == "tvos" && is_component_build),
"Can't use component build on tvOS")
assert(!(current_os == "watchos" && is_component_build),
"Can't use component build on watchOS")
@ -317,11 +315,10 @@ is_ios = current_os == "ios"
is_linux = current_os == "linux"
is_mac = current_os == "mac"
is_nacl = current_os == "nacl"
is_tvos = current_os == "tvos"
is_watchos = current_os == "watchos"
is_win = current_os == "win" || current_os == "winuwp"
is_apple = is_ios || is_mac || is_tvos || is_watchos
is_apple = is_ios || is_mac || is_watchos
is_posix = !is_win && !is_fuchsia
# =============================================================================

@ -2,11 +2,19 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/config/features.gni") # For `use_blink`
declare_args() {
# Configure the environment for which to build. Could be either "device",
# "simulator" or "catalyst". Must be specified.
target_environment = ""
# Valid values: "iphoneos" (default), "tvos", "watchos".
# Indicates the kind of iOS or iOS-based platform that is being targeted.
# Note that this value is available only when is_ios is also true (i.e. it
# cannot be used with the host toolchain).
target_platform = "iphoneos"
# Control whether codesiging is enabled (ignored for simulator builds).
# TODO(crbug.com/378918882): Prefix with apple_mobile_ instead of ios_.
ios_enable_code_signing = true
@ -60,12 +68,28 @@ shared_bundle_id_for_test_apps =
# the variables can only be executed if building for ios or watchos (as they
# either have no meaning or depend on tools that are only available on macOS).
if (is_ios || is_watchos) {
# Check that target_environment is set to a supported value.
# Check that target_platform and target_environment are set to supported
# values.
_target_platforms = []
if (is_ios) {
_target_platforms += [
"iphoneos",
"tvos",
]
} else if (is_watchos) {
_target_platforms += [
"iphoneos",
"watchos",
]
}
assert(filter_include([ target_platform ], _target_platforms) != [],
"target_platform '$target_platform' does not match a target value: " +
"$_target_platforms")
_target_environments = [
"simulator",
"device",
]
if (is_ios) {
if (is_ios && target_platform == "iphoneos") {
_target_environments += [ "catalyst" ]
}
assert(filter_include([ target_environment ], _target_environments) != [],
@ -99,4 +123,13 @@ if (is_ios || is_watchos) {
"trim string")
}
}
# Sanity check: tvOS builds require `use_blink`.
if (target_platform == "tvos") {
assert(use_blink, "tvOS builds require use_blink=true")
}
} else {
# On host toolchains, checking this value does not make sense. Set it to
# something invalid to prevent checks for specific values from passing.
target_platform = ""
}

@ -310,13 +310,12 @@ NO_STACK_PROTECTOR int RunContentProcess(
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
command_line->AppendSwitch(switches::kEnableViewport);
command_line->AppendSwitch(embedder_support::kUseMobileUserAgent);
#endif
#if BUILDFLAG(IS_TVOS)
#if BUILDFLAG(IS_IOS_TVOS)
// Set tvOS to single-process mode by default.
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
command_line->AppendSwitch(switches::kSingleProcess);
#endif
#endif
#if (BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_LINUX)) && !defined(COMPONENT_BUILD)
base::subtle::EnableFDOwnershipEnforcement(true);

@ -49,6 +49,10 @@ if (is_android) {
}
}
if (is_ios) {
import("//build/config/apple/mobile_config.gni") # For `target_platform`
}
source_set("browser") {
# Only the public target should depend on this. All other targets (even
# internal content ones) should depend on the public one.
@ -2812,7 +2816,7 @@ source_set("browser") {
"IOSurface.framework",
"UniformTypeIdentifiers.framework",
]
} else if (is_ios || is_tvos) {
} else if (is_ios) {
sources += [
"date_time_chooser/ios/date_time_chooser_coordinator.h",
"date_time_chooser/ios/date_time_chooser_coordinator.mm",
@ -2847,11 +2851,11 @@ source_set("browser") {
"web_contents/web_contents_view_ios.mm",
]
if (is_tvos) {
sources += [ "child_process_launcher_helper_tvos.mm" ]
} else {
if (target_platform != "tvos") {
sources += [ "child_process_launcher_helper_ios.mm" ]
frameworks += [ "BrowserEngineKit.framework" ]
} else {
sources += [ "child_process_launcher_helper_tvos.mm" ]
}
frameworks += [ "IOSurface.framework" ]

@ -7,9 +7,6 @@
#include "content/browser/child_process_launcher_helper.h"
#include "content/browser/child_process_launcher_helper_posix.h"
static_assert(BUILDFLAG(IS_TVOS),
"child_process_launcher_helper_tvos.mm requires is_tvos");
// TODO(crbug.com/391914246): Implement the ChildProcessLauncherHelper when
// tvOS actually requires the functionality.
namespace content {

@ -15,6 +15,10 @@ if (is_android) {
import("//third_party/jni_zero/jni_zero.gni")
}
if (is_ios) {
import("//build/config/apple/mobile_config.gni") # For `target_platform`
}
# Common configuration for targets in the media/midi directory.
config("midi_config") {
if (use_alsa && use_udev) {
@ -128,7 +132,9 @@ component("midi") {
}
if (is_apple) {
if (!is_tvos) {
if (is_ios && target_platform == "tvos") {
sources += [ "midi_manager_tvos.cc" ]
} else {
sources += [
"midi_manager_mac.cc",
"midi_manager_mac.h",
@ -138,8 +144,6 @@ component("midi") {
"CoreFoundation.framework",
"CoreMIDI.framework",
]
} else {
sources += [ "midi_manager_tvos.cc" ]
}
}

@ -6,8 +6,6 @@
#include "media/midi/midi_manager.h"
#include "media/midi/midi_service.h"
static_assert(BUILDFLAG(IS_TVOS), "midi_manager_tvos.cc requires is_tvos");
namespace midi {
MidiManager* MidiManager::Create(MidiService* service) {

@ -7,6 +7,10 @@ import("//build/config/features.gni")
import("//build/config/ui.gni")
import("//testing/libfuzzer/fuzzer_test.gni")
if (is_ios) {
import("//build/config/apple/mobile_config.gni") # For `target_platform`
}
component("clipboard_types") {
output_name = "ui_base_clipboard_types"
sources = [
@ -128,14 +132,14 @@ component("clipboard") {
}
if (is_ios) {
sources += [
"clipboard_ios.h",
"clipboard_ios.mm",
]
}
if (is_tvos) {
sources += [ "clipboard_tvos.mm" ]
if (target_platform == "tvos") {
sources += [ "clipboard_tvos.mm" ]
} else {
sources += [
"clipboard_ios.h",
"clipboard_ios.mm",
]
}
}
if (is_win) {