From 67b57d4c4b5024175094b97ea27d277a2c96f46d Mon Sep 17 00:00:00 2001
From: Chongyun Lee <licy183@termux.dev>
Date: Wed, 16 Apr 2025 01:49:52 +0800
Subject: [PATCH] reland jumbo 1

Enable jumbo build for the following component(s)/source_set(s):

- //base:base
- //base:i18n
# - //cc/slim:slim # Used in Android

Enable jumbo build for the following template(s):

- //cc/cc.gni -> template("cc_component")
- //components/viz/viz.gni -> template("viz_component")
- //components/viz/viz.gni -> template("viz_static_library")
- //components/viz/viz.gni -> template("viz_source_set")

---
 base/BUILD.gn                                     | 15 +++++++++++++--
 .../poisson_allocation_sampler.cc                 |  9 ++++++++-
 .../sampling_heap_profiler.cc                     |  9 ++++++++-
 base/task/sequenced_task_runner.cc                |  4 ++++
 base/task/single_thread_task_runner.cc            |  4 ++++
 base/threading/platform_thread_metrics_linux.cc   |  4 ++++
 cc/cc.gni                                         |  5 +++--
 .../viz/service/display/occlusion_culler.cc       |  4 ++++
 .../service/display/overlay_candidate_factory.cc  |  4 ++++
 components/viz/service/display/skia_renderer.cc   |  4 ++++
 .../viz/service/display/software_renderer.cc      |  4 ++++
 .../service/frame_sinks/frame_sink_manager_impl.h |  3 +++
 components/viz/viz.gni                            |  7 ++++---
 13 files changed, 67 insertions(+), 9 deletions(-)

diff --git a/base/BUILD.gn b/base/BUILD.gn
index f73ed42f84..f9e71f34c7 100644
--- a/base/BUILD.gn
+++ b/base/BUILD.gn
@@ -28,6 +28,7 @@ import("//build/config/cast.gni")
 import("//build/config/compiler/compiler.gni")
 import("//build/config/cronet/config.gni")
 import("//build/config/dcheck_always_on.gni")
+import("//build/config/jumbo.gni")
 import("//build/config/logging.gni")
 import("//build/config/profiling/profiling.gni")
 import("//build/config/rust.gni")
@@ -173,7 +174,7 @@ use_epoll = is_linux || is_chromeos || is_android
 # base compilation units to be linked in where they wouldn't have otherwise.
 # This does not include test code (test support and anything in the test
 # directory) which should use source_set as is recommended for GN targets).
-component("base") {
+jumbo_component("base") {
   sources = [
     "allocator/allocator_check.cc",
     "allocator/allocator_check.h",
@@ -985,6 +986,10 @@ component("base") {
     ]
   }
 
+  jumbo_excluded_sources = [
+      "logging.cc",
+  ]
+
   if (is_linux || is_chromeos) {
     sources += [
       "debug/proc_maps_linux.cc",
@@ -1004,6 +1009,7 @@ component("base") {
       "threading/thread_type_delegate.cc",
       "threading/thread_type_delegate.h",
     ]
+    jumbo_excluded_sources += [ "process/memory_linux.cc" ]
   }
 
   if (is_chromeos) {
@@ -1944,6 +1950,11 @@ component("base") {
       "win/wrapped_window_proc.h",
     ]
 
+    # winternl.h and NTSecAPI.h have different definitions of UNICODE_STRING.
+    # There's only one client of NTSecAPI.h in base but several of winternl.h,
+    # so exclude the NTSecAPI.h one.
+    jumbo_excluded_sources += [ "rand_util_win.cc" ]
+
     deps += [ "//base/win:base_win_buildflags" ]
 
     if (com_init_check_hook_disabled) {
@@ -2838,7 +2849,7 @@ if (enable_rust_translit) {
   }
 }
 
-component("i18n") {
+jumbo_component("i18n") {
   output_name = "base_i18n"
   sources = [
     "i18n/base_i18n_export.h",
diff --git a/base/sampling_heap_profiler/poisson_allocation_sampler.cc b/base/sampling_heap_profiler/poisson_allocation_sampler.cc
index c093e98ee2..2f5a25fb44 100644
--- a/base/sampling_heap_profiler/poisson_allocation_sampler.cc
+++ b/base/sampling_heap_profiler/poisson_allocation_sampler.cc
@@ -20,6 +20,8 @@
 #include "base/rand_util.h"
 #include "build/build_config.h"
 
+#define ThreadLocalData ThreadLocalData_PoissonAllocationSampler
+
 namespace base {
 
 namespace {
@@ -65,7 +67,7 @@ struct ThreadLocalData {
 // Returns an object storing thread-local state. This does NOT use
 // base::ThreadLocalStorage, so it's safe to call from hooks in the
 // base::ThreadLocalStorage implementation.
-ThreadLocalData* GetThreadLocalData() {
+ThreadLocalData* GetThreadLocalData_PoissonAllocationSampler() {
 #if USE_LOCAL_TLS_EMULATION()
   // If available, use ThreadLocalStorage to bypass dependencies introduced by
   // Clang's implementation of thread_local.
@@ -101,6 +103,8 @@ ThreadLocalData* GetThreadLocalData() {
 
 }  // namespace
 
+#define GetThreadLocalData GetThreadLocalData_PoissonAllocationSampler
+
 PoissonAllocationSamplerStats::PoissonAllocationSamplerStats(
     size_t address_cache_hits,
     size_t address_cache_misses,
@@ -505,3 +509,6 @@ void PoissonAllocationSampler::RemoveSamplesObserver(
 }
 
 }  // namespace base
+
+#undef ThreadLocalData
+#undef GetThreadLocalData
diff --git a/base/sampling_heap_profiler/sampling_heap_profiler.cc b/base/sampling_heap_profiler/sampling_heap_profiler.cc
index 60e96b0081..de29c802f6 100644
--- a/base/sampling_heap_profiler/sampling_heap_profiler.cc
+++ b/base/sampling_heap_profiler/sampling_heap_profiler.cc
@@ -35,6 +35,8 @@
 #include <sys/prctl.h>
 #endif
 
+#define ThreadLocalData ThreadLocalData_SamplingHeapProfiler
+
 namespace base {
 
 constexpr uint32_t kMaxStackEntries = 256;
@@ -45,7 +47,7 @@ struct ThreadLocalData {
   const char* thread_name = nullptr;
 };
 
-ThreadLocalData* GetThreadLocalData() {
+ThreadLocalData* ThreadLocalData_GetThreadLocalData() {
 #if USE_LOCAL_TLS_EMULATION()
   static base::NoDestructor<
       base::allocator::dispatcher::ThreadLocalStorage<ThreadLocalData>>
@@ -57,6 +59,8 @@ ThreadLocalData* GetThreadLocalData() {
 #endif
 }
 
+#define GetThreadLocalData ThreadLocalData_GetThreadLocalData
+
 using StackUnwinder = SamplingHeapProfiler::StackUnwinder;
 using base::allocator::dispatcher::AllocationSubsystem;
 
@@ -334,3 +338,6 @@ SamplingHeapProfiler::MuteHookedSamplesForTesting() {
 }
 
 }  // namespace base
+
+#undef ThreadLocalData
+#undef GetThreadLocalData
diff --git a/base/task/sequenced_task_runner.cc b/base/task/sequenced_task_runner.cc
index 16bd753e47..d6c6178311 100644
--- a/base/task/sequenced_task_runner.cc
+++ b/base/task/sequenced_task_runner.cc
@@ -11,6 +11,8 @@
 #include "base/task/thread_pool/thread_pool_instance.h"
 #include "base/time/time.h"
 
+#define current_default_handle current_default_handle_sequenced_task_runner
+
 namespace base {
 
 namespace {
@@ -144,3 +146,5 @@ OnTaskRunnerDeleter& OnTaskRunnerDeleter::operator=(OnTaskRunnerDeleter&&) =
     default;
 
 }  // namespace base
+
+#undef current_default_handle
diff --git a/base/task/single_thread_task_runner.cc b/base/task/single_thread_task_runner.cc
index 651267a81a..179bdf2010 100644
--- a/base/task/single_thread_task_runner.cc
+++ b/base/task/single_thread_task_runner.cc
@@ -15,6 +15,8 @@
 #include "base/lazy_instance.h"
 #include "base/run_loop.h"
 
+#define current_default_handle current_default_handle_single_thread_task_runner
+
 namespace base {
 
 namespace {
@@ -100,3 +102,5 @@ SingleThreadTaskRunner::CurrentHandleOverrideForTesting::
     ~CurrentHandleOverrideForTesting() = default;
 
 }  // namespace base
+
+#undef current_default_handle
diff --git a/base/threading/platform_thread_metrics_linux.cc b/base/threading/platform_thread_metrics_linux.cc
index 13f0eb30a8..3935f876c5 100644
--- a/base/threading/platform_thread_metrics_linux.cc
+++ b/base/threading/platform_thread_metrics_linux.cc
@@ -18,6 +18,8 @@
 #include "base/time/time.h"
 #include "base/trace_event/trace_event.h"
 
+#define ParseTotalCPUTimeFromStats ParseTotalCPUTimeFromStats_PlatformThreadMetricsLinux
+
 namespace base {
 
 namespace {
@@ -61,3 +63,5 @@ std::optional<TimeDelta> PlatformThreadMetrics::GetCumulativeCPUUsage() {
 }
 
 }  // namespace base
+
+#undef ParseTotalCPUTimeFromStats
diff --git a/cc/cc.gni b/cc/cc.gni
index 090420c902..6b0e76bf21 100644
--- a/cc/cc.gni
+++ b/cc/cc.gni
@@ -2,6 +2,7 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
+import("//build/config/jumbo.gni")
 import("//testing/test.gni")
 
 cc_remove_configs = []
@@ -16,7 +17,7 @@ if (!is_debug) {
 }
 
 template("cc_component") {
-  component(target_name) {
+  jumbo_component(target_name) {
     forward_variables_from(invoker, "*", [ "configs" ])
     if (defined(invoker.configs)) {
       configs += invoker.configs
@@ -27,7 +28,7 @@ template("cc_component") {
 }
 
 template("cc_test_static_library") {
-  static_library(target_name) {
+  jumbo_static_library(target_name) {
     forward_variables_from(invoker, "*", [ "configs" ])
     if (defined(invoker.configs)) {
       configs += invoker.configs
diff --git a/components/viz/service/display/occlusion_culler.cc b/components/viz/service/display/occlusion_culler.cc
index 10d1bba2ce..b895d3a63f 100644
--- a/components/viz/service/display/occlusion_culler.cc
+++ b/components/viz/service/display/occlusion_culler.cc
@@ -26,6 +26,8 @@
 #include "ui/gfx/geometry/rect_conversions.h"
 #include "ui/gfx/geometry/rect_f.h"
 
+#define kEpsilon kEpsilon_OcclusionCuller
+
 namespace viz {
 namespace {
 
@@ -536,3 +538,5 @@ bool OcclusionCuller::CanSplitDrawQuad(
 }
 
 }  // namespace viz
+
+#undef kEpsilon
diff --git a/components/viz/service/display/overlay_candidate_factory.cc b/components/viz/service/display/overlay_candidate_factory.cc
index 898652d4d8..696a784ff1 100644
--- a/components/viz/service/display/overlay_candidate_factory.cc
+++ b/components/viz/service/display/overlay_candidate_factory.cc
@@ -95,6 +95,8 @@ gfx::OverlayTransform GetOverlayTransform(const gfx::Transform& quad_transform,
   }
 }
 
+#define kEpsilon kEpsilon_OverlayCandidate
+
 constexpr double kEpsilon = 0.0001;
 
 // Determine why the transformation isn't axis aligned. A transform with z
@@ -834,3 +836,5 @@ gfx::RectF OverlayCandidateFactory::GetDamageRect(const DrawQuad* quad) const {
 }
 
 }  // namespace viz
+
+#undef kEpsilon
diff --git a/components/viz/service/display/skia_renderer.cc b/components/viz/service/display/skia_renderer.cc
index 16de85a38b..2e699dd26e 100644
--- a/components/viz/service/display/skia_renderer.cc
+++ b/components/viz/service/display/skia_renderer.cc
@@ -110,6 +110,8 @@
 #include "components/viz/service/display/overlay_processor_surface_control.h"
 #endif
 
+#define MakeOpacityFilter MakeOpacityFilter_SkiaRenderer
+
 namespace viz {
 
 namespace {
@@ -4500,3 +4502,5 @@ bool SkiaRenderer::OverlayLockKeyEqual::operator()(
 #endif
 
 }  // namespace viz
+
+#undef MakeOpacityFilter
diff --git a/components/viz/service/display/software_renderer.cc b/components/viz/service/display/software_renderer.cc
index 2d952f903f..fab2724532 100644
--- a/components/viz/service/display/software_renderer.cc
+++ b/components/viz/service/display/software_renderer.cc
@@ -53,6 +53,8 @@
 #include "ui/gfx/geometry/skia_conversions.h"
 #include "ui/gfx/geometry/transform.h"
 
+#define MakeOpacityFilter MakeOpacityFilter_SoftwareRenderer
+
 namespace viz {
 namespace {
 
@@ -1087,3 +1089,5 @@ gfx::Rect SoftwareRenderer::GetRenderPassBackingDrawnRect(
 }
 
 }  // namespace viz
+
+#undef MakeOpacityFilter
diff --git a/components/viz/service/frame_sinks/frame_sink_manager_impl.h b/components/viz/service/frame_sinks/frame_sink_manager_impl.h
index 3ebefa4b63..1350f5c75f 100644
--- a/components/viz/service/frame_sinks/frame_sink_manager_impl.h
+++ b/components/viz/service/frame_sinks/frame_sink_manager_impl.h
@@ -5,6 +5,9 @@
 #ifndef COMPONENTS_VIZ_SERVICE_FRAME_SINKS_FRAME_SINK_MANAGER_IMPL_H_
 #define COMPONENTS_VIZ_SERVICE_FRAME_SINKS_FRAME_SINK_MANAGER_IMPL_H_
 
+// Macro 'Status' from X11/Xlib.h will cause confliction
+#undef Status
+
 #include <stdint.h>
 
 #include <list>
diff --git a/components/viz/viz.gni b/components/viz/viz.gni
index 191ddca368..a4008193b5 100644
--- a/components/viz/viz.gni
+++ b/components/viz/viz.gni
@@ -2,6 +2,7 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
+import("//build/config/jumbo.gni")
 import("//gpu/vulkan/features.gni")
 import("//skia/features.gni")
 import("//testing/test.gni")
@@ -33,7 +34,7 @@ if (!is_debug) {
 }
 
 template("viz_source_set") {
-  source_set(target_name) {
+  jumbo_source_set(target_name) {
     forward_variables_from(invoker, "*", [ "configs" ])
     if (defined(invoker.configs)) {
       configs += invoker.configs
@@ -44,7 +45,7 @@ template("viz_source_set") {
 }
 
 template("viz_component") {
-  component(target_name) {
+  jumbo_component(target_name) {
     forward_variables_from(invoker, "*", [ "configs" ])
     if (defined(invoker.configs)) {
       configs += invoker.configs
@@ -55,7 +56,7 @@ template("viz_component") {
 }
 
 template("viz_static_library") {
-  static_library(target_name) {
+  jumbo_static_library(target_name) {
     forward_variables_from(invoker, "*", [ "configs" ])
     if (defined(invoker.configs)) {
       configs += invoker.configs
diff --git a/components/viz/service/BUILD.gn b/components/viz/service/BUILD.gn
index 9f18a00af5..870c7dbae4 100644
--- a/components/viz/service/BUILD.gn
+++ b/components/viz/service/BUILD.gn
@@ -273,6 +273,14 @@ viz_component("service") {
     "transitions/transferable_resource_tracker.cc",
     "transitions/transferable_resource_tracker.h",
   ]
+  jumbo_excluded_sources = [
+    # `gpu/GLES2/gl2chromium_autogen.h` and `gpu/GLES2/gl2chromium.h` has macro confliction,
+    #  and it is included by `layers/layer_context_impl.cc`
+    # - components/viz/client/client_resource_provider.h
+    # - third_party/khronos/GLES2/gl2.h
+    # - gpu/GLES2/gl2chromium.h
+    "layers/layer_context_impl.cc"
+  ]
 
   defines = [ "VIZ_SERVICE_IMPLEMENTATION" ]
 
