Fix layering check for usage of gtest

To satisfy the layering check, we need to depend on :gtest for the headers, in
addition to :gtest_main which provides the main() function.

There are a bunch of formatting changes as a side effect of this, but they
should be harmless.

PiperOrigin-RevId: 594318263
diff --git a/bazel/BUILD b/bazel/BUILD
index be2e946..90d578f 100644
--- a/bazel/BUILD
+++ b/bazel/BUILD
@@ -52,8 +52,8 @@
     ],
     deps = [
         "@bazel_skylib//lib:paths",
-        "@rules_proto//proto:defs",
         "@bazel_tools//tools/cpp:toolchain_utils.bzl",
+        "@rules_proto//proto:defs",
     ],
 )
 
diff --git a/bazel/build_defs.bzl b/bazel/build_defs.bzl
index 1ed1ffe..2da6368 100644
--- a/bazel/build_defs.bzl
+++ b/bazel/build_defs.bzl
@@ -31,8 +31,8 @@
 UPB_DEFAULT_CPPOPTS = select({
     "//upb:windows": [],
     # begin:google_only
-#     # Override default -Oz for release builds on Android.
-#     "//bazel:android_opt": _DEFAULT_CPPOPTS + ["-O2"],
+    #     # Override default -Oz for release builds on Android.
+    #     "//bazel:android_opt": _DEFAULT_CPPOPTS + ["-O2"],
     # end:google_only
     "//conditions:default": _DEFAULT_CPPOPTS,
 })
@@ -41,8 +41,8 @@
     "//upb:windows": [],
     "//upb:fasttable_enabled_setting": ["-std=gnu99", "-DUPB_ENABLE_FASTTABLE"],
     # begin:google_only
-#     # Override default -Oz for release builds on Android.
-#     "//bazel:android_opt": _DEFAULT_COPTS + ["-O2"],
+    #     # Override default -Oz for release builds on Android.
+    #     "//bazel:android_opt": _DEFAULT_COPTS + ["-O2"],
     # end:google_only
     "//conditions:default": _DEFAULT_COPTS,
 })
diff --git a/bazel/upb_proto_library_internal/cc_library_func.bzl b/bazel/upb_proto_library_internal/cc_library_func.bzl
index 31ebe90..0c567ce 100644
--- a/bazel/upb_proto_library_internal/cc_library_func.bzl
+++ b/bazel/upb_proto_library_internal/cc_library_func.bzl
@@ -14,6 +14,7 @@
 
 def upb_use_cpp_toolchain():
     return ["@bazel_tools//tools/cpp:toolchain_type"]
+
 # end:github_only
 
 def cc_library_func(ctx, name, hdrs, srcs, copts, includes, dep_ccinfos):
diff --git a/benchmarks/BUILD b/benchmarks/BUILD
index b975bac..3b9a9cb 100644
--- a/benchmarks/BUILD
+++ b/benchmarks/BUILD
@@ -76,7 +76,6 @@
         ":benchmark_descriptor_upb_proto",
         ":benchmark_descriptor_upb_proto_reflection",
         "//:protobuf",
-        "@com_google_googletest//:gtest_main",
         "//src/google/protobuf/json",
         "//upb:base",
         "//upb:descriptor_upb_proto",
@@ -88,6 +87,8 @@
         "@com_github_google_benchmark//:benchmark_main",
         "@com_google_absl//absl/container:flat_hash_set",
         "@com_google_absl//absl/log:absl_check",
+        "@com_google_googletest//:gtest",
+        "@com_google_googletest//:gtest_main",
     ],
 )
 
diff --git a/java/internal/testing.bzl b/java/internal/testing.bzl
index b2a781b..ee8f80f 100644
--- a/java/internal/testing.bzl
+++ b/java/internal/testing.bzl
@@ -52,7 +52,7 @@
         if test_prefix:
             test_name = "%s%s" % (test_prefix, test_name)
         test_names = test_names + [test_name]
-        suite_name = prefix + '_' + test_name
+        suite_name = prefix + "_" + test_name
         _gen_suite(
             name = suite_name,
             srcs = [src],
diff --git a/protos/BUILD b/protos/BUILD
index 7712c38..f903249 100644
--- a/protos/BUILD
+++ b/protos/BUILD
@@ -132,10 +132,11 @@
     copts = UPB_DEFAULT_CPPOPTS,
     deps = [
         ":protos_internal",
-        "@com_google_googletest//:gtest_main",
-        "//upb:mem",
         "//protos_generator/tests:test_model_upb_cc_proto",
         "//protos_generator/tests:test_model_upb_proto",
+        "//upb:mem",
+        "@com_google_googletest//:gtest",
+        "@com_google_googletest//:gtest_main",
     ],
 )
 
@@ -150,6 +151,7 @@
     srcs = ["repeated_field_iterator_test.cc"],
     deps = [
         ":repeated_field",
+        "@com_google_googletest//:gtest",
         "@com_google_googletest//:gtest_main",
     ],
 )
@@ -158,12 +160,13 @@
     name = "protos_extension_lock_test",
     srcs = ["protos_extension_lock_test.cc"],
     deps = [
-        "@com_google_googletest//:gtest_main",
-        "//upb:mem",
         "//protos",
         "//protos:protos_extension_lock",
         "//protos_generator/tests:test_model_upb_cc_proto",
+        "//upb:mem",
         "@com_google_absl//absl/hash",
         "@com_google_absl//absl/log:absl_check",
+        "@com_google_googletest//:gtest",
+        "@com_google_googletest//:gtest_main",
     ],
 )
diff --git a/protos/bazel/BUILD b/protos/bazel/BUILD
index ea91541..7381375 100644
--- a/protos/bazel/BUILD
+++ b/protos/bazel/BUILD
@@ -18,8 +18,8 @@
     srcs = ["upb_cc_proto_library.bzl"],
     visibility = ["//visibility:public"],
     deps = [
-        "@bazel_skylib//lib:paths",
         "//bazel:upb_proto_library_bzl",
+        "@bazel_skylib//lib:paths",
         "@bazel_tools//tools/cpp:toolchain_utils.bzl",
     ],
 )
diff --git a/protos/bazel/upb_cc_proto_library.bzl b/protos/bazel/upb_cc_proto_library.bzl
index ad193b4..cacf709 100644
--- a/protos/bazel/upb_cc_proto_library.bzl
+++ b/protos/bazel/upb_cc_proto_library.bzl
@@ -22,6 +22,7 @@
 
 def use_cpp_toolchain():
     return ["@bazel_tools//tools/cpp:toolchain_type"]
+
 # end:github_only
 
 # Generic support code #########################################################
diff --git a/protos_generator/BUILD b/protos_generator/BUILD
index ac8cfec..d76c944 100644
--- a/protos_generator/BUILD
+++ b/protos_generator/BUILD
@@ -56,12 +56,12 @@
         ":names",
         ":output",
         "//:protobuf",
-        "@com_google_absl//absl/container:flat_hash_set",
-        "@com_google_absl//absl/strings",
         "//upb_generator:common",
         "//upb_generator:file_layout",
         "//upb_generator:keywords",
         "//upb_generator:names",
+        "@com_google_absl//absl/container:flat_hash_set",
+        "@com_google_absl//absl/strings",
     ],
 )
 
diff --git a/protos_generator/tests/BUILD b/protos_generator/tests/BUILD
index c47a71f..8ebb985 100644
--- a/protos_generator/tests/BUILD
+++ b/protos_generator/tests/BUILD
@@ -124,12 +124,13 @@
     copts = UPB_DEFAULT_CPPOPTS,
     deps = [
         # begin:google_only
-#         ":legacy_name_test_proto",
+        #         ":legacy_name_test_proto",
         # end:google_only
         ":no_package_upb_cc_proto",
         ":test_model_upb_cc_proto",
         ":test_model_upb_proto",
         ":naming_conflict_upb_cc_proto",
+        "@com_google_googletest//:gtest",
         "@com_google_googletest//:gtest_main",
         "@com_google_absl//absl/status:statusor",
         "@com_google_absl//absl/strings",
diff --git a/python/BUILD.bazel b/python/BUILD.bazel
index 608381c..8967bac 100644
--- a/python/BUILD.bazel
+++ b/python/BUILD.bazel
@@ -13,6 +13,7 @@
 # begin:github_only
 load("@rules_pkg//:mappings.bzl", "pkg_files")
 load("//python:build_targets.bzl", "build_targets")
+
 build_targets(name = "python")
 # end:github_only
 
@@ -20,7 +21,7 @@
 
 package(
     # begin:google_only
-#     default_applicable_licenses = ["//upb:license"],
+    #     default_applicable_licenses = ["//upb:license"],
     # end:google_only
     default_visibility = ["//python/dist:__pkg__"],
 )
@@ -136,10 +137,10 @@
 
 # begin:github_only
 _message_target_compatible_with = {
-   "@platforms//os:windows": ["@platforms//:incompatible"],
-   "@system_python//:none": ["@platforms//:incompatible"],
-   "@system_python//:unsupported": ["@platforms//:incompatible"],
-   "//conditions:default": [],
+    "@platforms//os:windows": ["@platforms//:incompatible"],
+    "@system_python//:none": ["@platforms//:incompatible"],
+    "@system_python//:unsupported": ["@platforms//:incompatible"],
+    "//conditions:default": [],
 }
 
 # end:github_only
@@ -176,7 +177,7 @@
         "unknown_fields.h",
     ],
     # begin:google_only
-#     compatible_with = ["//buildenv/target:non_prod"],
+    #     compatible_with = ["//buildenv/target:non_prod"],
     # end:google_only
 )
 
@@ -190,6 +191,7 @@
     ],
     target_compatible_with = select(_message_target_compatible_with),
     deps = [
+        "//third_party/utf8_range",
         "//upb:base",
         "//upb:descriptor_upb_proto_reflection",
         "//upb:eps_copy_input_stream",
@@ -203,6 +205,5 @@
         "//upb/util:compare",
         "//upb/util:def_to_proto",
         "//upb/util:required_fields",
-        "//third_party/utf8_range",
     ],
 )
diff --git a/python/pb_unit_tests/BUILD b/python/pb_unit_tests/BUILD
index 56ee250..8bb43dc 100644
--- a/python/pb_unit_tests/BUILD
+++ b/python/pb_unit_tests/BUILD
@@ -6,6 +6,7 @@
 # https://developers.google.com/open-source/licenses/bsd
 
 load(":pyproto_test_wrapper.bzl", "pyproto_test_wrapper")
+
 # begin:github_only
 load("@pip_deps//:requirements.bzl", "requirement")
 # end:github_only
@@ -39,15 +40,15 @@
     name = "numpy_test",
     srcs = ["numpy_test_wrapper.py"],
     main = "numpy_test_wrapper.py",
-    deps = [
-      requirement("numpy"),
-      "//python/google/protobuf/internal/numpy:numpy_test",
-      "//python:_message",
-    ],
     target_compatible_with = select({
-      "@system_python//:supported": [],
-      "//conditions:default": ["@platforms//:incompatible"],
+        "@system_python//:supported": [],
+        "//conditions:default": ["@platforms//:incompatible"],
     }),
+    deps = [
+        requirement("numpy"),
+        "//python:_message",
+        "//python/google/protobuf/internal/numpy:numpy_test",
+    ],
 )
 # end:github_only
 
diff --git a/rust/BUILD b/rust/BUILD
index b3374f4..62ae297 100644
--- a/rust/BUILD
+++ b/rust/BUILD
@@ -2,7 +2,6 @@
 
 load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
 load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
-
 load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain")
 
 package(
@@ -74,8 +73,8 @@
     ],
     rustc_flags = ["--cfg=upb_kernel"],
     visibility = [
-        "//src/google/protobuf:__subpackages__",
         "//rust:__subpackages__",
+        "//src/google/protobuf:__subpackages__",
     ],
     deps = [
         ":utf8",
diff --git a/rust/cpp_kernel/BUILD b/rust/cpp_kernel/BUILD
index e9baa3a..6582b03 100644
--- a/rust/cpp_kernel/BUILD
+++ b/rust/cpp_kernel/BUILD
@@ -7,13 +7,13 @@
     srcs = ["cpp_api.cc"],
     hdrs = ["cpp_api.h"],
     visibility = [
-        "//src/google/protobuf:__subpackages__",
         "//rust:__subpackages__",
+        "//src/google/protobuf:__subpackages__",
     ],
     deps = [
         ":rust_alloc_for_cpp_api",  # buildcleaner: keep
-        "@com_google_absl//absl/strings:string_view",
         "//:protobuf_nowkt",
+        "@com_google_absl//absl/strings:string_view",
     ],
 )
 
diff --git a/rust/test/BUILD b/rust/test/BUILD
index 186374f..2541732 100644
--- a/rust/test/BUILD
+++ b/rust/test/BUILD
@@ -7,10 +7,15 @@
 load("@rules_cc//cc:defs.bzl", "cc_proto_library")
 
 UNITTEST_PROTO_TARGET = "//src/google/protobuf:test_protos"
+
 UNITTEST_CC_PROTO_TARGET = "//src/google/protobuf:cc_test_protos"
+
 UNITTEST_PROTO3_TARGET = "//src/google/protobuf:test_protos"
+
 UNITTEST_PROTO3_CC_TARGET = "//src/google/protobuf:cc_test_protos"
+
 UNITTEST_PROTO3_OPTIONAL_TARGET = "//src/google/protobuf:test_protos"
+
 UNITTEST_PROTO3_OPTIONAL_CC_TARGET = "//src/google/protobuf:cc_test_protos"
 
 alias(
diff --git a/rust/test/cpp/interop/BUILD b/rust/test/cpp/interop/BUILD
index bacd078..abbf0d2 100644
--- a/rust/test/cpp/interop/BUILD
+++ b/rust/test/cpp/interop/BUILD
@@ -6,9 +6,9 @@
     name = "test_utils",
     srcs = ["test_utils.cc"],
     deps = [
-        "@com_google_absl//absl/strings",
         "//rust/cpp_kernel:cpp_api",
         "//rust/test:unittest_cc_proto",
+        "@com_google_absl//absl/strings",
     ],
 )
 
@@ -21,8 +21,8 @@
     ],
     deps = [
         ":test_utils",
-        "@crate_index//:googletest",
         "//rust:protobuf_cpp",
         "//rust/test:unittest_cc_rust_proto",
+        "@crate_index//:googletest",
     ],
 )
diff --git a/rust/test/shared/BUILD b/rust/test/shared/BUILD
index 3a61c4d..9fb9a1b 100644
--- a/rust/test/shared/BUILD
+++ b/rust/test/shared/BUILD
@@ -23,8 +23,8 @@
         "//rust:protobuf_upb": "protobuf",
     },
     deps = [
-        "@crate_index//:googletest",
         "//rust:protobuf_upb",
+        "@crate_index//:googletest",
     ],
 )
 
@@ -35,8 +35,8 @@
         "//rust:protobuf_cpp": "protobuf",
     },
     deps = [
-        "@crate_index//:googletest",
         "//rust:protobuf_cpp",
+        "@crate_index//:googletest",
     ],
 )
 
@@ -48,9 +48,9 @@
         "not_build:arm",
     ],
     deps = [
-        "@crate_index//:googletest",
         "//rust/test:child_upb_rust_proto",
         "//rust/test:parent_upb_rust_proto",
+        "@crate_index//:googletest",
     ],
 )
 
@@ -62,9 +62,9 @@
         "not_build:arm",
     ],
     deps = [
-        "@crate_index//:googletest",
         "//rust/test:child_cc_rust_proto",
         "//rust/test:parent_cc_rust_proto",
+        "@crate_index//:googletest",
     ],
 )
 
@@ -76,8 +76,8 @@
         "not_build:arm",
     ],
     deps = [
-        "@crate_index//:googletest",
         "//rust/test:edition2023_cc_rust_proto",
+        "@crate_index//:googletest",
     ],
 )
 
@@ -89,8 +89,8 @@
         "not_build:arm",
     ],
     deps = [
-        "@crate_index//:googletest",
         "//rust/test:edition2023_upb_rust_proto",
+        "@crate_index//:googletest",
     ],
 )
 
@@ -105,10 +105,10 @@
         "not_build:arm",
     ],
     deps = [
-        "@crate_index//:googletest",
         "//rust:protobuf_cpp",
         "//rust/test:enums_cc_rust_proto",
         "//rust/test:unittest_cc_rust_proto",
+        "@crate_index//:googletest",
     ],
 )
 
@@ -123,10 +123,10 @@
         "not_build:arm",
     ],
     deps = [
-        "@crate_index//:googletest",
         "//rust:protobuf_upb",
         "//rust/test:enums_upb_rust_proto",
         "//rust/test:unittest_upb_rust_proto",
+        "@crate_index//:googletest",
     ],
 )
 
@@ -166,9 +166,9 @@
         "not_build:arm",
     ],
     deps = [
-        "@crate_index//:googletest",
         "//rust/test:reserved_cc_rust_proto",
         "//rust/test:unittest_cc_rust_proto",
+        "@crate_index//:googletest",
     ],
 )
 
@@ -180,9 +180,9 @@
         "not_build:arm",
     ],
     deps = [
-        "@crate_index//:googletest",
         "//rust/test:reserved_upb_rust_proto",
         "//rust/test:unittest_upb_rust_proto",
+        "@crate_index//:googletest",
     ],
 )
 
@@ -221,10 +221,10 @@
         "not_build:arm",
     ],
     deps = [
-        "@crate_index//:googletest",
         "//rust:protobuf_cpp",
         "//rust/test:unittest_cc_rust_proto",
         "//rust/test/shared:matchers_cpp",
+        "@crate_index//:googletest",
     ],
 )
 
@@ -243,10 +243,10 @@
         "not_build:arm",
     ],
     deps = [
-        "@crate_index//:googletest",
         "//rust:protobuf_upb",
         "//rust/test:unittest_upb_rust_proto",
         "//rust/test/shared:matchers_upb",
+        "@crate_index//:googletest",
     ],
 )
 
@@ -262,11 +262,11 @@
         "not_build:arm",
     ],
     deps = [
-        "@crate_index//:googletest",
         "//rust:protobuf_cpp",
         "//rust/test:unittest_proto3_cc_rust_proto",
         "//rust/test:unittest_proto3_optional_cc_rust_proto",
         "//rust/test/shared:matchers_cpp",
+        "@crate_index//:googletest",
     ],
 )
 
@@ -282,11 +282,11 @@
         "not_build:arm",
     ],
     deps = [
-        "@crate_index//:googletest",
         "//rust:protobuf_upb",
         "//rust/test:unittest_proto3_optional_upb_rust_proto",
         "//rust/test:unittest_proto3_upb_rust_proto",
         "//rust/test/shared:matchers_upb",
+        "@crate_index//:googletest",
     ],
 )
 
@@ -298,8 +298,8 @@
         "not_build:arm",
     ],
     deps = [
-        "@crate_index//:googletest",
         "//rust/test:unittest_upb_rust_proto",
+        "@crate_index//:googletest",
     ],
 )
 
@@ -311,8 +311,8 @@
         "not_build:arm",
     ],
     deps = [
-        "@crate_index//:googletest",
         "//rust/test:unittest_cc_rust_proto",
+        "@crate_index//:googletest",
     ],
 )
 
@@ -324,8 +324,8 @@
         "not_build:arm",
     ],
     deps = [
-        "@crate_index//:googletest",
         "//rust/test:nested_cc_rust_proto",
+        "@crate_index//:googletest",
     ],
 )
 
@@ -337,8 +337,8 @@
         "not_build:arm",
     ],
     deps = [
-        "@crate_index//:googletest",
         "//rust/test:nested_upb_rust_proto",
+        "@crate_index//:googletest",
     ],
 )
 
@@ -356,9 +356,9 @@
         "not_build:arm",
     ],
     deps = [
-        "@crate_index//:googletest",
         "//rust:protobuf_cpp",
         "//rust/test:unittest_cc_rust_proto",
+        "@crate_index//:googletest",
     ],
 )
 
@@ -376,9 +376,9 @@
         "not_build:arm",
     ],
     deps = [
-        "@crate_index//:googletest",
         "//rust:protobuf_upb",
         "//rust/test:unittest_upb_rust_proto",
+        "@crate_index//:googletest",
     ],
 )
 
@@ -393,8 +393,8 @@
         "not_build:arm",
     ],
     deps = [
-        "@crate_index//:googletest",
         "//rust/test:map_unittest_cc_rust_proto",
+        "@crate_index//:googletest",
     ],
 )
 
@@ -409,7 +409,7 @@
         "not_build:arm",
     ],
     deps = [
-        "@crate_index//:googletest",
         "//rust/test:map_unittest_upb_rust_proto",
+        "@crate_index//:googletest",
     ],
 )
diff --git a/rust/upb_kernel/BUILD b/rust/upb_kernel/BUILD
index 3c37332..62ae49a 100644
--- a/rust/upb_kernel/BUILD
+++ b/rust/upb_kernel/BUILD
@@ -4,8 +4,8 @@
     name = "upb_c_api",
     srcs = ["upb_api.c"],
     visibility = [
-        "//src/google/protobuf:__subpackages__",
         "//rust:__subpackages__",
+        "//src/google/protobuf:__subpackages__",
     ],
     deps = [
         "//upb:mem",
diff --git a/src/google/protobuf/editions/BUILD b/src/google/protobuf/editions/BUILD
index 52c6a40..76d1a0e 100644
--- a/src/google/protobuf/editions/BUILD
+++ b/src/google/protobuf/editions/BUILD
@@ -84,6 +84,7 @@
         "@com_google_absl//absl/status:statusor",
         "@com_google_absl//absl/strings",
         "@com_google_absl//absl/strings:string_view",
+        "@com_google_googletest//:gtest",
         "@com_google_googletest//:gtest_main",
     ],
 )
@@ -246,6 +247,7 @@
         ":test_messages_proto3_editions_cc_proto",
         "//:protobuf",
         "//src/google/protobuf:test_textproto",
+        "@com_google_googletest//:gtest",
         "@com_google_googletest//:gtest_main",
     ],
 )
@@ -255,6 +257,7 @@
     srcs = ["generated_reflection_test.cc"],
     deps = [
         ":test_messages_proto2_editions_cc_proto",
+        "@com_google_googletest//:gtest",
         "@com_google_googletest//:gtest_main",
     ],
 )
diff --git a/third_party/utf8_range/BUILD.bazel b/third_party/utf8_range/BUILD.bazel
index d24e8a1..fdc1a49 100644
--- a/third_party/utf8_range/BUILD.bazel
+++ b/third_party/utf8_range/BUILD.bazel
@@ -59,6 +59,7 @@
         ":utf8_range",
         ":utf8_validity",
         "@com_google_absl//absl/strings",
+        "@com_google_googletest//:gtest",
         "@com_google_googletest//:gtest_main",
     ],
 )
diff --git a/upb/BUILD b/upb/BUILD
index e6cdff7..1304764 100644
--- a/upb/BUILD
+++ b/upb/BUILD
@@ -498,16 +498,16 @@
             "**/*.c",
             "**/*.h",
             "**/*.hpp",
-       ],
+        ],
         exclude = [
             "**/conformance_upb.c",
             "reflection/stage0/**/*",
         ],
     ),
     visibility = [
-        "//upb/cmake:__pkg__",
         "//python/dist:__pkg__",
-    ]
+        "//upb/cmake:__pkg__",
+    ],
 )
 # end:github_only
 
diff --git a/upb/base/BUILD b/upb/base/BUILD
index 1a025c2..2fce94b 100644
--- a/upb/base/BUILD
+++ b/upb/base/BUILD
@@ -47,8 +47,8 @@
         ],
     ),
     visibility = [
-        "//upb/cmake:__pkg__",
         "//python/dist:__pkg__",
-    ]
+        "//upb/cmake:__pkg__",
+    ],
 )
 # end:github_only
diff --git a/upb/collections/BUILD b/upb/collections/BUILD
index 8437cd5..5a900c6 100644
--- a/upb/collections/BUILD
+++ b/upb/collections/BUILD
@@ -29,8 +29,8 @@
         ],
     ),
     visibility = [
-        "//upb/cmake:__pkg__",
         "//python/dist:__pkg__",
-    ]
+        "//upb/cmake:__pkg__",
+    ],
 )
 # end:github_only
diff --git a/upb/hash/BUILD b/upb/hash/BUILD
index 7ef3bd7..b061413 100644
--- a/upb/hash/BUILD
+++ b/upb/hash/BUILD
@@ -32,10 +32,11 @@
     srcs = ["test.cc"],
     deps = [
         ":hash",
-        "@com_google_googletest//:gtest_main",
         "//upb:mem",
         "//upb:port",
         "@com_google_absl//absl/container:flat_hash_map",
+        "@com_google_googletest//:gtest",
+        "@com_google_googletest//:gtest_main",
     ],
 )
 
@@ -49,9 +50,9 @@
         ],
     ),
     visibility = [
-        "//upb/cmake:__pkg__",
         "//python/dist:__pkg__",
-    ]
+        "//upb/cmake:__pkg__",
+    ],
 )
 # end:github_only
 
diff --git a/upb/io/BUILD b/upb/io/BUILD
index 3164864..490096a 100644
--- a/upb/io/BUILD
+++ b/upb/io/BUILD
@@ -64,8 +64,9 @@
     srcs = ["string_test.cc"],
     deps = [
         ":string",
-        "@com_google_googletest//:gtest_main",
         "//upb:mem",
+        "@com_google_googletest//:gtest",
+        "@com_google_googletest//:gtest_main",
     ],
 )
 
@@ -78,12 +79,13 @@
         ":string",
         ":tokenizer",
         ":zero_copy_stream",
-        "@com_google_googletest//:gtest_main",
-        "@com_google_absl//absl/strings",
-        "@com_google_absl//absl/strings:str_format",
         "//upb:lex",
         "//upb:mem",
         "//upb:port",
+        "@com_google_absl//absl/strings",
+        "@com_google_absl//absl/strings:str_format",
+        "@com_google_googletest//:gtest",
+        "@com_google_googletest//:gtest_main",
     ],
 )
 
@@ -96,8 +98,9 @@
     deps = [
         ":chunked_stream",
         ":zero_copy_stream",
-        "@com_google_googletest//:gtest_main",
         "//upb:base",
         "//upb:mem",
+        "@com_google_googletest//:gtest",
+        "@com_google_googletest//:gtest_main",
     ],
 )
diff --git a/upb/json/BUILD b/upb/json/BUILD
index b04c4fd..6331725 100644
--- a/upb/json/BUILD
+++ b/upb/json/BUILD
@@ -40,10 +40,11 @@
         ":struct_upb_proto",
         ":test_upb_proto",
         ":test_upb_proto_reflection",
-        "@com_google_googletest//:gtest_main",
         "//upb:base",
         "//upb:mem",
         "//upb:reflection",
+        "@com_google_googletest//:gtest",
+        "@com_google_googletest//:gtest_main",
     ],
 )
 
@@ -55,10 +56,11 @@
         ":struct_upb_proto",
         ":test_upb_proto",
         ":test_upb_proto_reflection",
-        "@com_google_googletest//:gtest_main",
         "//upb:base",
         "//upb:mem",
         "//upb:reflection",
+        "@com_google_googletest//:gtest",
+        "@com_google_googletest//:gtest_main",
     ],
 )
 
@@ -96,7 +98,7 @@
 #         ":json",
 #         ":test_upb_proto",
 #         ":test_upb_proto_reflection",
-#         "@com_google_googletest//:gtest_main",
+#         "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main",
 #         "//testing/fuzzing:fuzztest",
 #         "//upb:base",
 #         "//upb:mem",
@@ -118,6 +120,7 @@
     ),
     visibility = ["//pkg:__pkg__"],
 )
+
 filegroup(
     name = "test_utils",
     srcs = glob(
diff --git a/upb/lex/BUILD b/upb/lex/BUILD
index 2dbf258..81c6c89 100644
--- a/upb/lex/BUILD
+++ b/upb/lex/BUILD
@@ -31,8 +31,9 @@
     srcs = ["atoi_test.cc"],
     deps = [
         ":lex",
-        "@com_google_googletest//:gtest_main",
         "@com_google_absl//absl/strings",
+        "@com_google_googletest//:gtest",
+        "@com_google_googletest//:gtest_main",
     ],
 )
 
@@ -46,9 +47,9 @@
         ],
     ),
     visibility = [
-        "//upb/cmake:__pkg__",
         "//python/dist:__pkg__",
-    ]
+        "//upb/cmake:__pkg__",
+    ],
 )
 # end:github_only
 
diff --git a/upb/mem/BUILD b/upb/mem/BUILD
index a26b92e..9227a31 100644
--- a/upb/mem/BUILD
+++ b/upb/mem/BUILD
@@ -43,12 +43,13 @@
     srcs = ["arena_test.cc"],
     deps = [
         ":mem",
-        "@com_google_googletest//:gtest_main",
         "//upb:port",
         "@com_google_absl//absl/random",
         "@com_google_absl//absl/random:distributions",
         "@com_google_absl//absl/synchronization",
         "@com_google_absl//absl/time",
+        "@com_google_googletest//:gtest",
+        "@com_google_googletest//:gtest_main",
     ],
 )
 
@@ -63,9 +64,9 @@
         ],
     ),
     visibility = [
-        "//upb/cmake:__pkg__",
         "//python/dist:__pkg__",
-    ]
+        "//upb/cmake:__pkg__",
+    ],
 )
 # end:github_only
 
diff --git a/upb/message/BUILD b/upb/message/BUILD
index 76eb94c..969b2ec 100644
--- a/upb/message/BUILD
+++ b/upb/message/BUILD
@@ -228,7 +228,6 @@
         ":accessors",
         ":message",
         "//:protobuf",
-        "@com_google_googletest//:gtest_main",
         "//upb:base",
         "//upb:mem",
         "//upb:mini_descriptor",
@@ -242,6 +241,8 @@
         "//upb/test:test_messages_proto3_upb_proto",
         "//upb/test:test_upb_proto",
         "@com_google_absl//absl/container:flat_hash_set",
+        "@com_google_googletest//:gtest",
+        "@com_google_googletest//:gtest_main",
     ],
 )
 
@@ -250,9 +251,10 @@
     srcs = ["array_test.cc"],
     deps = [
         ":message",
-        "@com_google_googletest//:gtest_main",
         "//upb:base",
         "//upb:mem",
+        "@com_google_googletest//:gtest",
+        "@com_google_googletest//:gtest_main",
     ],
 )
 
@@ -264,7 +266,6 @@
         ":copy",
         ":message",
         "//:protobuf",
-        "@com_google_googletest//:gtest_main",
         "//upb:base",
         "//upb:mem",
         "//upb:mini_table",
@@ -274,6 +275,8 @@
         "//upb/test:test_messages_proto2_upb_proto",
         "//upb/test:test_upb_proto",
         "@com_google_absl//absl/container:flat_hash_set",
+        "@com_google_googletest//:gtest",
+        "@com_google_googletest//:gtest_main",
     ],
 )
 
@@ -282,9 +285,10 @@
     srcs = ["map_test.cc"],
     deps = [
         ":message",
-        "@com_google_googletest//:gtest_main",
         "//upb:base",
         "//upb:mem",
+        "@com_google_googletest//:gtest",
+        "@com_google_googletest//:gtest_main",
     ],
 )
 
@@ -298,7 +302,6 @@
         ":promote",
         ":tagged_ptr",
         "//:protobuf",
-        "@com_google_googletest//:gtest_main",
         "//upb:base",
         "//upb:mem",
         "//upb:mini_descriptor",
@@ -310,6 +313,8 @@
         "//upb/test:test_proto_upb_minitable",
         "//upb/test:test_upb_proto",
         "@com_google_absl//absl/container:flat_hash_set",
+        "@com_google_googletest//:gtest",
+        "@com_google_googletest//:gtest_main",
     ],
 )
 
@@ -323,7 +328,6 @@
         ":message_test_upb_proto",
         ":message_test_upb_proto_reflection",
         ":value",
-        "@com_google_googletest//:gtest_main",
         "//upb:base",
         "//upb:json",
         "//upb:mem",
@@ -333,6 +337,8 @@
         "//upb:wire",
         "//upb/test:fuzz_util",
         "//upb/test:test_messages_proto3_upb_proto",
+        "@com_google_googletest//:gtest",
+        "@com_google_googletest//:gtest_main",
     ],
 )
 
@@ -361,10 +367,11 @@
     deps = [
         ":utf8_test_upb_minitable_proto",
         ":utf8_test_upb_proto",
-        "@com_google_googletest//:gtest_main",
         "//upb:base",
         "//upb:mem",
         "//upb:wire",
+        "@com_google_googletest//:gtest",
+        "@com_google_googletest//:gtest_main",
     ],
 )
 
@@ -378,9 +385,9 @@
         ],
     ),
     visibility = [
-        "//upb/cmake:__pkg__",
         "//python/dist:__pkg__",
-    ]
+        "//upb/cmake:__pkg__",
+    ],
 )
 # end:github_only
 
@@ -394,6 +401,7 @@
     ),
     visibility = ["//pkg:__pkg__"],
 )
+
 filegroup(
     name = "test_utils",
     srcs = glob(
diff --git a/upb/mini_descriptor/BUILD b/upb/mini_descriptor/BUILD
index 1857b9c..b1932ea 100644
--- a/upb/mini_descriptor/BUILD
+++ b/upb/mini_descriptor/BUILD
@@ -60,7 +60,6 @@
         ":internal",
         ":mini_descriptor",
         "//:protobuf",
-        "@com_google_googletest//:gtest_main",
         "//upb:base",
         "//upb:mem",
         "//upb:message_accessors",
@@ -68,6 +67,8 @@
         "//upb:port",
         "//upb:wire",
         "@com_google_absl//absl/container:flat_hash_set",
+        "@com_google_googletest//:gtest",
+        "@com_google_googletest//:gtest_main",
     ],
 )
 
@@ -81,9 +82,9 @@
         ],
     ),
     visibility = [
-        "//upb/cmake:__pkg__",
         "//python/dist:__pkg__",
-    ]
+        "//upb/cmake:__pkg__",
+    ],
 )
 # end:github_only
 
diff --git a/upb/mini_table/BUILD b/upb/mini_table/BUILD
index 71de9f2..221e87b 100644
--- a/upb/mini_table/BUILD
+++ b/upb/mini_table/BUILD
@@ -82,11 +82,12 @@
     name = "compat_test",
     srcs = ["compat_test.cc"],
     deps = [
-        "@com_google_googletest//:gtest_main",
         "//upb:mini_table_compat",
         "//upb/test:test_messages_proto2_upb_minitable",
         "//upb/test:test_messages_proto3_upb_minitable",
         "//upb/test:test_upb_proto",
+        "@com_google_googletest//:gtest",
+        "@com_google_googletest//:gtest_main",
     ],
 )
 
@@ -100,9 +101,9 @@
         ],
     ),
     visibility = [
-        "//upb/cmake:__pkg__",
         "//python/dist:__pkg__",
-    ]
+        "//upb/cmake:__pkg__",
+    ],
 )
 # end:github_only
 
diff --git a/upb/port/BUILD b/upb/port/BUILD
index fe20c08..db3a91f 100644
--- a/upb/port/BUILD
+++ b/upb/port/BUILD
@@ -45,8 +45,8 @@
         ],
     ),
     visibility = [
-        "//upb/cmake:__pkg__",
         "//python/dist:__pkg__",
-    ]
+        "//upb/cmake:__pkg__",
+    ],
 )
 # end:github_only
diff --git a/upb/reflection/BUILD b/upb/reflection/BUILD
index 5854704..e42ebda 100644
--- a/upb/reflection/BUILD
+++ b/upb/reflection/BUILD
@@ -176,7 +176,6 @@
     ],
     deps = [
         ":descriptor_upb_proto",
-        "@com_google_googletest//:gtest_main",
         "//upb:base",
         "//upb:hash",
         "//upb:mem",
@@ -184,6 +183,8 @@
         "//upb:reflection",
         "//upb:reflection_internal",
         "@com_google_absl//absl/strings",
+        "@com_google_googletest//:gtest",
+        "@com_google_googletest//:gtest_main",
     ],
 )
 
@@ -223,8 +224,8 @@
         exclude = ["stage0/**"],
     ),
     visibility = [
-        "//upb/cmake:__pkg__",
         "//python/dist:__pkg__",
-    ]
+        "//upb/cmake:__pkg__",
+    ],
 )
 # end:github_only
diff --git a/upb/test/BUILD b/upb/test/BUILD
index 186dacd..493a51e 100644
--- a/upb/test/BUILD
+++ b/upb/test/BUILD
@@ -179,8 +179,9 @@
     deps = [
         ":proto3_test_upb_proto",
         ":proto3_test_upb_proto_reflection",
-        "@com_google_googletest//:gtest_main",
         "//upb:reflection",
+        "@com_google_googletest//:gtest",
+        "@com_google_googletest//:gtest_main",
     ],
 )
 
@@ -191,10 +192,11 @@
     deps = [
         ":editions_test_upb_c_proto",
         ":editions_test_upb_proto_reflection",
-        "@com_google_googletest//:gtest_main",
         "//upb:base",
         "//upb:mem",
         "//upb:reflection",
+        "@com_google_googletest//:gtest",
+        "@com_google_googletest//:gtest_main",
     ],
 )
 
@@ -207,11 +209,12 @@
         ":test_cpp_upb_proto_reflection",
         ":timestamp_upb_proto",
         ":timestamp_upb_proto_reflection",
-        "@com_google_googletest//:gtest_main",
         "//upb:base",
         "//upb:json",
         "//upb:port",
         "//upb:reflection",
+        "@com_google_googletest//:gtest",
+        "@com_google_googletest//:gtest_main",
     ],
 )
 
@@ -225,11 +228,12 @@
         ":test_messages_proto2_upb_proto",
         ":test_messages_proto3_upb_proto",
         ":test_upb_proto",
-        "@com_google_googletest//:gtest_main",
         "//upb:base",
         "//upb:mem",
         "//upb:message",
         "//upb:port",
+        "@com_google_googletest//:gtest",
+        "@com_google_googletest//:gtest_main",
     ],
 )
 
@@ -243,8 +247,9 @@
         ":proto3_test_upb_proto",
         ":test_messages_proto2_upb_minitable",
         ":test_upb_proto",
-        "@com_google_googletest//:gtest_main",
         "//upb:mini_table",
+        "@com_google_googletest//:gtest",
+        "@com_google_googletest//:gtest_main",
     ],
 )
 
@@ -296,6 +301,7 @@
     srcs = ["test_import_empty_srcs.cc"],
     deps = [
         ":test_import_empty_srcs_upb_minitable_proto",
+        "@com_google_googletest//:gtest",
         "@com_google_googletest//:gtest_main",
     ],
 )
@@ -311,6 +317,7 @@
     ),
     visibility = ["//pkg:__pkg__"],
 )
+
 filegroup(
     name = "test_utils",
     srcs = glob(
diff --git a/upb/text/BUILD b/upb/text/BUILD
index 7bc0953..6a1a97c 100644
--- a/upb/text/BUILD
+++ b/upb/text/BUILD
@@ -38,8 +38,8 @@
         ],
     ),
     visibility = [
-        "//upb/cmake:__pkg__",
         "//python/dist:__pkg__",
-    ]
+        "//upb/cmake:__pkg__",
+    ],
 )
 # end:github_only
diff --git a/upb/util/BUILD b/upb/util/BUILD
index e299780..e43b239 100644
--- a/upb/util/BUILD
+++ b/upb/util/BUILD
@@ -67,12 +67,13 @@
         ":def_to_proto_test_upb_proto",
         ":def_to_proto_test_upb_proto_reflection",
         "//:protobuf",
-        "@com_google_googletest//:gtest_main",
         "//upb:descriptor_upb_proto_reflection",
         "//upb:mem",
         "//upb:reflection",
         "//upb/test:parse_text_proto",
         "@com_google_absl//absl/strings",
+        "@com_google_googletest//:gtest",
+        "@com_google_googletest//:gtest_main",
     ],
 )
 
@@ -83,7 +84,7 @@
 #     tags = ["clang_only"],
 #     deps = [
 #         ":def_to_proto_test_lib",
-#         "@com_google_googletest//:gtest_main",
+#         "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main",
 #         "//testing/fuzzing:fuzztest",
 #     ],
 # )
@@ -130,13 +131,14 @@
         ":required_fields",
         ":required_fields_test_upb_proto",
         ":required_fields_test_upb_proto_reflection",
-        "@com_google_googletest//:gtest_main",
         "//upb:base",
         "//upb:json",
         "//upb:mem",
         "//upb:reflection",
         "//upb:reflection_internal",
         "@com_google_absl//absl/strings",
+        "@com_google_googletest//:gtest",
+        "@com_google_googletest//:gtest_main",
     ],
 )
 
@@ -161,10 +163,11 @@
     srcs = ["compare_test.cc"],
     deps = [
         ":compare",
-        "@com_google_googletest//:gtest_main",
         "//upb:port",
         "//upb:wire_reader",
         "@com_google_absl//absl/strings",
+        "@com_google_googletest//:gtest",
+        "@com_google_googletest//:gtest_main",
     ],
 )
 
@@ -193,6 +196,7 @@
     ),
     visibility = ["//pkg:__pkg__"],
 )
+
 filegroup(
     name = "test_utils",
     srcs = glob(
diff --git a/upb/wire/BUILD b/upb/wire/BUILD
index 5130a71..56b8927 100644
--- a/upb/wire/BUILD
+++ b/upb/wire/BUILD
@@ -26,6 +26,7 @@
     deps = [
         ":eps_copy_input_stream",
         ":reader",
+        "//third_party/utf8_range",
         "//upb:base",
         "//upb:hash",
         "//upb:mem",
@@ -37,7 +38,6 @@
         "//upb:port",
         "//upb/mem:internal",
         "//upb/mini_table:internal",
-        "//third_party/utf8_range",
     ],
 )
 
@@ -75,8 +75,9 @@
     srcs = ["eps_copy_input_stream_test.cc"],
     deps = [
         ":eps_copy_input_stream",
-        "@com_google_googletest//:gtest_main",
         "//upb:mem",
+        "@com_google_googletest//:gtest",
+        "@com_google_googletest//:gtest_main",
     ],
 )
 
@@ -90,9 +91,9 @@
         ],
     ),
     visibility = [
-        "//upb/cmake:__pkg__",
         "//python/dist:__pkg__",
-    ]
+        "//upb/cmake:__pkg__",
+    ],
 )
 # end:github_only