Removed the `third_party/upb/upb/bazel` directory.

We are absorbing its contents into other directories. This will reduce the 3:1 merge to `upb/bazel` in GitHub to 2:1 (soon to be 1:1).

PiperOrigin-RevId: 860299666
diff --git a/bazel/BUILD.bazel b/bazel/BUILD.bazel
index cf15afc..82122f2 100644
--- a/bazel/BUILD.bazel
+++ b/bazel/BUILD.bazel
@@ -53,18 +53,6 @@
 )
 
 bzl_library(
-    name = "upb_proto_library_bzl",
-    srcs = [
-        "upb_c_proto_library.bzl",
-        "upb_minitable_proto_library.bzl",
-        "upb_proto_library.bzl",
-        "upb_proto_reflection_library.bzl",
-    ],
-    visibility = ["//visibility:public"],
-    deps = ["//bazel/private:upb_proto_library_internal_bzl"],
-)
-
-bzl_library(
     name = "proto_descriptor_set_bzl",
     srcs = ["proto_descriptor_set.bzl"],
     visibility = ["//visibility:public"],
diff --git a/bazel/private/BUILD b/bazel/private/BUILD
index f81daa6..edd76b3 100644
--- a/bazel/private/BUILD
+++ b/bazel/private/BUILD
@@ -29,22 +29,6 @@
 )
 
 bzl_library(
-    name = "upb_proto_library_internal_bzl",
-    srcs = [
-        "upb_proto_library_internal/aspect.bzl",
-        "upb_proto_library_internal/cc_library_func.bzl",
-        "upb_proto_library_internal/copts.bzl",
-        "upb_proto_library_internal/rule.bzl",
-    ],
-    visibility = ["//bazel:__pkg__"],
-    deps = [
-        "//bazel/common:proto_common_bzl",
-        "@bazel_skylib//lib:paths",
-        "@bazel_tools//tools/cpp:toolchain_utils.bzl",
-    ],
-)
-
-bzl_library(
     name = "native_bzl",
     srcs = [
         "native.bzl",
diff --git a/benchmarks/BUILD b/benchmarks/BUILD
index cd4ec26..84eb9bc 100644
--- a/benchmarks/BUILD
+++ b/benchmarks/BUILD
@@ -9,9 +9,9 @@
 load("@rules_python//python:defs.bzl", "py_binary")
 load("//bazel:cc_proto_library.bzl", "cc_proto_library")
 load("//bazel:proto_library.bzl", "proto_library")
-load("//bazel:upb_minitable_proto_library.bzl", "upb_minitable_proto_library")
+load("//upb/bazel:upb_minitable_proto_library.bzl", "upb_minitable_proto_library")
 load(
-    "//bazel:upb_proto_library.bzl",
+    "//upb/bazel:upb_proto_library.bzl",
     "upb_c_proto_library",
     "upb_proto_reflection_library",
 )
diff --git a/editions/BUILD b/editions/BUILD
index 916ca29..91b7a0a 100644
--- a/editions/BUILD
+++ b/editions/BUILD
@@ -9,7 +9,7 @@
 load("//bazel:java_lite_proto_library.bzl", "java_lite_proto_library")
 load("//bazel:java_proto_library.bzl", "java_proto_library")
 load("//bazel:proto_library.bzl", "proto_library")
-load("//bazel:upb_proto_library.bzl", "upb_c_proto_library", "upb_proto_reflection_library")
+load("//upb/bazel:upb_proto_library.bzl", "upb_c_proto_library", "upb_proto_reflection_library")
 load(":defaults.bzl", "compile_edition_defaults", "embed_edition_defaults")
 
 bzl_library(
diff --git a/hpb/bazel/BUILD b/hpb/bazel/BUILD
index 8c9711d..9460138 100644
--- a/hpb/bazel/BUILD
+++ b/hpb/bazel/BUILD
@@ -16,8 +16,8 @@
     srcs = ["hpb_proto_library.bzl"],
     visibility = ["//visibility:public"],
     deps = [
-        "//bazel:upb_proto_library_bzl",
         "//bazel/common:proto_common_bzl",
+        "//upb/bazel:upb_proto_library_bzl",
         "@bazel_skylib//lib:paths",
         "@bazel_tools//tools/cpp:toolchain_utils.bzl",
     ],
diff --git a/hpb/bazel/hpb_proto_library.bzl b/hpb/bazel/hpb_proto_library.bzl
index 3b84418..6ed9f6d 100644
--- a/hpb/bazel/hpb_proto_library.bzl
+++ b/hpb/bazel/hpb_proto_library.bzl
@@ -12,10 +12,10 @@
 load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "use_cpp_toolchain")
 load("@rules_cc//cc/common:cc_common.bzl", "cc_common")
 load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
-load("//bazel:upb_proto_library.bzl", "GeneratedSrcsInfo", "UpbWrappedCcInfo", "upb_proto_library_aspect")
 load("//bazel/common:proto_common.bzl", "proto_common")
 load("//bazel/common:proto_info.bzl", "ProtoInfo")
-load("//bazel/private:upb_proto_library_internal/cc_library_func.bzl", "cc_library_func")  # buildifier: disable=bzl-visibility
+load("//upb/bazel:upb_proto_library.bzl", "GeneratedSrcsInfo", "UpbWrappedCcInfo", "upb_proto_library_aspect")
+load("//upb/bazel/private:upb_proto_library_internal/cc_library_func.bzl", "cc_library_func")  # buildifier: disable=bzl-visibility
 
 def upb_use_cpp_toolchain():
     return use_cpp_toolchain()
diff --git a/hpb_generator/tests/BUILD b/hpb_generator/tests/BUILD
index 16a376b..4732dfe 100644
--- a/hpb_generator/tests/BUILD
+++ b/hpb_generator/tests/BUILD
@@ -12,17 +12,17 @@
 )
 load("//bazel:proto_library.bzl", "proto_library")
 load(
-    "//bazel:upb_minitable_proto_library.bzl",
+    "//hpb/bazel:hpb_proto_library.bzl",
+    "hpb_proto_library",
+)
+load(
+    "//upb/bazel:upb_minitable_proto_library.bzl",
     "upb_minitable_proto_library",
 )
 load(
-    "//bazel:upb_proto_library.bzl",
+    "//upb/bazel:upb_proto_library.bzl",
     "upb_c_proto_library",
 )
-load(
-    "//hpb/bazel:hpb_proto_library.bzl",
-    "hpb_proto_library",
-)
 
 package(default_applicable_licenses = ["//:license"])
 
diff --git a/lua/BUILD.bazel b/lua/BUILD.bazel
index db95671..9eccb2d 100644
--- a/lua/BUILD.bazel
+++ b/lua/BUILD.bazel
@@ -14,7 +14,7 @@
     "lua_proto_library",
 )
 load(
-    "//upb/bazel:build_defs.bzl",
+    "//upb/bazel:copts.bzl",
     "UPB_DEFAULT_COPTS",
     "UPB_DEFAULT_CPPOPTS",
 )
diff --git a/python/BUILD.bazel b/python/BUILD.bazel
index 291a4cc..03298f2 100644
--- a/python/BUILD.bazel
+++ b/python/BUILD.bazel
@@ -8,7 +8,7 @@
 load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag")
 load("//python:build_targets.bzl", "build_targets")
 load("//python:py_extension.bzl", "py_extension")
-load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_COPTS")
+load("//upb/bazel:copts.bzl", "UPB_DEFAULT_COPTS")
 
 build_targets(name = "python")
 
diff --git a/src/google/protobuf/BUILD.bazel b/src/google/protobuf/BUILD.bazel
index b5467bf..8e6d6f1 100644
--- a/src/google/protobuf/BUILD.bazel
+++ b/src/google/protobuf/BUILD.bazel
@@ -6,14 +6,14 @@
 load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix")
 load("//bazel:cc_proto_library.bzl", "cc_proto_library")
 load("//bazel:proto_library.bzl", "proto_library")
-load("//bazel:upb_c_proto_library.bzl", "upb_c_proto_library")
-load("//bazel:upb_minitable_proto_library.bzl", "upb_minitable_proto_library")
-load("//bazel:upb_proto_reflection_library.bzl", "upb_proto_reflection_library")
 load(
     "//bazel/tests:protobuf_test_proto_library.bzl",
     "protobuf_test_proto_library",
 )
 load("//build_defs:cpp_opts.bzl", "COPTS", "LINK_OPTS")
+load("//upb/bazel:upb_c_proto_library.bzl", "upb_c_proto_library")
+load("//upb/bazel:upb_minitable_proto_library.bzl", "upb_minitable_proto_library")
+load("//upb/bazel:upb_proto_reflection_library.bzl", "upb_proto_reflection_library")
 load("//upb/cmake:build_defs.bzl", "staleness_test")
 
 package(
diff --git a/src/google/protobuf/compiler/BUILD.bazel b/src/google/protobuf/compiler/BUILD.bazel
index 6fb7231..9b8ea6a 100644
--- a/src/google/protobuf/compiler/BUILD.bazel
+++ b/src/google/protobuf/compiler/BUILD.bazel
@@ -7,14 +7,13 @@
     "@rules_pkg//pkg:mappings.bzl",
     "pkg_attributes",
     "pkg_files",
-    "strip_prefix",
 )
 load("//bazel:cc_proto_library.bzl", "cc_proto_library")
 load("//bazel:proto_library.bzl", "proto_library")
-load("//bazel:upb_c_proto_library.bzl", "upb_c_proto_library")
-load("//bazel:upb_proto_reflection_library.bzl", "upb_proto_reflection_library")
 load("//build_defs:arch_tests.bzl", "aarch64_test", "x86_64_test")
 load("//build_defs:cpp_opts.bzl", "COPTS")
+load("//upb/bazel:upb_c_proto_library.bzl", "upb_c_proto_library")
+load("//upb/bazel:upb_proto_reflection_library.bzl", "upb_proto_reflection_library")
 load(
     "//upb_generator:bootstrap_compiler.bzl",
     "bootstrap_cc_library",
diff --git a/upb/BUILD b/upb/BUILD
index bc545ec..e31be63 100644
--- a/upb/BUILD
+++ b/upb/BUILD
@@ -8,9 +8,9 @@
 load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
 load("@rules_cc//cc:defs.bzl", "cc_library")
 load("@rules_python//python:defs.bzl", "py_binary")
-load("//bazel/private:upb_proto_library_internal/copts.bzl", "upb_proto_library_copts")
-load("//upb/bazel:amalgamation.bzl", "upb_amalgamation")
-load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_COPTS")
+load("//upb/bazel:copts.bzl", "UPB_DEFAULT_COPTS")
+load("//upb/bazel/private:upb_proto_library_internal/copts.bzl", "upb_proto_library_copts")
+load("//upb/bazel/private/oss:amalgamation.bzl", "upb_amalgamation")  # buildifier: disable=bzl-visibility
 
 package(default_applicable_licenses = ["//:license"])
 
@@ -41,7 +41,7 @@
 bool_flag(
     name = "fasttable_enabled",
     build_setting_default = False,
-    visibility = ["//bazel:__pkg__"],
+    visibility = ["//upb/bazel:__pkg__"],
 )
 
 config_setting(
@@ -58,7 +58,7 @@
 upb_proto_library_copts(
     name = "upb_proto_library_copts",
     copts = UPB_DEFAULT_COPTS,
-    visibility = ["//bazel:__pkg__"],
+    visibility = ["//upb/bazel:__pkg__"],
 )
 
 # Please update copy.bara.sky target = ":friends" if
diff --git a/upb/base/BUILD b/upb/base/BUILD
index f668845..49323ba 100644
--- a/upb/base/BUILD
+++ b/upb/base/BUILD
@@ -7,7 +7,7 @@
 
 load("@rules_cc//cc:cc_test.bzl", "cc_test")
 load("@rules_cc//cc:defs.bzl", "cc_library")
-load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_COPTS")
+load("//upb/bazel:copts.bzl", "UPB_DEFAULT_COPTS")
 
 package(default_applicable_licenses = ["//:license"])
 
diff --git a/upb/bazel/BUILD b/upb/bazel/BUILD
index 7223b75..5a45e28 100644
--- a/upb/bazel/BUILD
+++ b/upb/bazel/BUILD
@@ -5,11 +5,28 @@
 # license that can be found in the LICENSE file or at
 # https://developers.google.com/open-source/licenses/bsd
 
-load("@bazel_skylib//lib:selects.bzl", "selects")
-load("@rules_python//python:defs.bzl", "py_binary")
+load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
 
-py_binary(
-    name = "amalgamate",
-    srcs = ["amalgamate.py"],
-    visibility = ["//visibility:private"],
+package(default_applicable_licenses = ["//:license"])
+
+licenses(["notice"])
+
+bzl_library(
+    name = "upb_proto_library_bzl",
+    srcs = [
+        "upb_c_proto_library.bzl",
+        "upb_minitable_proto_library.bzl",
+        "upb_proto_library.bzl",
+        "upb_proto_reflection_library.bzl",
+        "visibility.bzl",
+    ],
+    visibility = [
+        "//visibility:public",
+    ],
+    deps = [
+        "//bazel/common:proto_common_bzl",
+        "//bazel/common:proto_info_bzl",
+        "//upb/bazel/private:upb_proto_library_internal_bzl",
+        "@rules_cc//cc/common",
+    ],
 )
diff --git a/upb/bazel/build_defs.bzl b/upb/bazel/build_defs.bzl
deleted file mode 100644
index 5f47cec..0000000
--- a/upb/bazel/build_defs.bzl
+++ /dev/null
@@ -1,95 +0,0 @@
-# Copyright (c) 2009-2021, Google LLC
-# All rights reserved.
-#
-# Use of this source code is governed by a BSD-style
-# license that can be found in the LICENSE file or at
-# https://developers.google.com/open-source/licenses/bsd
-
-"""Internal rules for building upb."""
-
-_DEFAULT_CPPOPTS = []
-_DEFAULT_COPTS = [
-    # this is a compile error in C++ clang and GNU C, but not clang C by default
-    "-Werror=incompatible-pointer-types",
-    # GCC does not seem to support the no_sanitize attribute in some places
-    # where we use it.
-    "-Wno-error=attributes",
-]
-
-_DEFAULT_CPPOPTS.extend([
-    "-Wextra",
-    # "-Wshorten-64-to-32",  # not in GCC (and my Kokoro images doesn't have Clang)
-    "-Wno-unused-parameter",
-    "-Wno-long-long",
-])
-_DEFAULT_COPTS.extend([
-    "-std=c99",
-    "-Wall",
-    "-Wstrict-prototypes",
-    # GCC (at least) emits spurious warnings for this that cannot be fixed
-    # without introducing redundant initialization (with runtime cost):
-    #   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80635
-    #"-Wno-maybe-uninitialized",
-])
-
-UPB_DEFAULT_CPPOPTS = select({
-    "//upb:windows": [],
-    "//conditions:default": _DEFAULT_CPPOPTS,
-}) + select({
-    "//upb:fasttable_enabled_setting": ["-DUPB_ENABLE_FASTTABLE"],
-    "//conditions:default": [],
-}) + select({
-    "//conditions:default": [],
-})
-
-UPB_DEFAULT_COPTS = select({
-    "//upb:windows": [],
-    "//conditions:default": _DEFAULT_COPTS,
-}) + select({
-    "//upb:fasttable_enabled_setting": ["-DUPB_ENABLE_FASTTABLE"],
-    "//conditions:default": [],
-}) + select({
-    "//conditions:default": [],
-})
-
-runfiles_init = """\
-# --- begin runfiles.bash initialization v2 ---
-# Copy-pasted from the Bazel Bash runfiles library v2.
-set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash
-source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
-  source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
-  source "$0.runfiles/$f" 2>/dev/null || \
-  source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
-  source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
-  { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
-# --- end runfiles.bash initialization v2 ---
-"""
-
-def _get_real_short_path(file):
-    # For some reason, files from other archives have short paths that look like:
-    #   ../com_google_protobuf/google/protobuf/descriptor.proto
-    short_path = file.short_path
-    if short_path.startswith("../"):
-        second_slash = short_path.index("/", 3)
-        short_path = short_path[second_slash + 1:]
-    return short_path
-
-def _get_real_root(file):
-    real_short_path = _get_real_short_path(file)
-    return file.path[:-len(real_short_path) - 1]
-
-def _get_real_roots(files):
-    roots = {}
-    for file in files:
-        real_root = _get_real_root(file)
-        if real_root:
-            roots[real_root] = True
-    return roots.keys()
-
-def make_shell_script(name, contents, out):
-    contents = contents.replace("$", "$$")
-    native.genrule(
-        name = "gen_" + name,
-        outs = [out],
-        cmd = "(cat <<'HEREDOC'\n%s\nHEREDOC\n) > $@" % contents,
-    )
diff --git a/upb/bazel/copts.bzl b/upb/bazel/copts.bzl
new file mode 100644
index 0000000..2036e76
--- /dev/null
+++ b/upb/bazel/copts.bzl
@@ -0,0 +1,60 @@
+# Copyright (c) 2009-2021, Google LLC
+# All rights reserved.
+#
+# Use of this source code is governed by a BSD-style
+# license that can be found in the LICENSE file or at
+# https://developers.google.com/open-source/licenses/bsd
+
+"""Common copts for building upb."""
+
+visibility([
+    "//lua/...",
+    "//python/...",
+    "//upb/...",
+    "//upb_generator/...",
+])
+
+_DEFAULT_CPPOPTS = []
+_DEFAULT_COPTS = [
+    # this is a compile error in C++ clang and GNU C, but not clang C by default
+    "-Werror=incompatible-pointer-types",
+    # GCC does not seem to support the no_sanitize attribute in some places
+    # where we use it.
+    "-Wno-error=attributes",
+]
+
+_DEFAULT_CPPOPTS.extend([
+    "-Wextra",
+    # "-Wshorten-64-to-32",  # not in GCC (and my Kokoro images doesn't have Clang)
+    "-Wno-unused-parameter",
+    "-Wno-long-long",
+])
+_DEFAULT_COPTS.extend([
+    "-std=c99",
+    "-Wall",
+    "-Wstrict-prototypes",
+    # GCC (at least) emits spurious warnings for this that cannot be fixed
+    # without introducing redundant initialization (with runtime cost):
+    #   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80635
+    #"-Wno-maybe-uninitialized",
+])
+
+UPB_DEFAULT_CPPOPTS = select({
+    "//upb:windows": [],
+    "//conditions:default": _DEFAULT_CPPOPTS,
+}) + select({
+    "//upb:fasttable_enabled_setting": ["-DUPB_ENABLE_FASTTABLE"],
+    "//conditions:default": [],
+}) + select({
+    "//conditions:default": [],
+})
+
+UPB_DEFAULT_COPTS = select({
+    "//upb:windows": [],
+    "//conditions:default": _DEFAULT_COPTS,
+}) + select({
+    "//upb:fasttable_enabled_setting": ["-DUPB_ENABLE_FASTTABLE"],
+    "//conditions:default": [],
+}) + select({
+    "//conditions:default": [],
+})
diff --git a/upb/bazel/private/BUILD b/upb/bazel/private/BUILD
new file mode 100644
index 0000000..0c7ac5d
--- /dev/null
+++ b/upb/bazel/private/BUILD
@@ -0,0 +1,28 @@
+# Copyright (c) 2009-2021, Google LLC
+# All rights reserved.
+#
+# Use of this source code is governed by a BSD-style
+# license that can be found in the LICENSE file or at
+# https://developers.google.com/open-source/licenses/bsd
+
+load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
+load("@bazel_skylib//lib:selects.bzl", "selects")
+
+bzl_library(
+    name = "upb_proto_library_internal_bzl",
+    srcs = [
+        "upb_proto_library_internal/aspect.bzl",
+        "upb_proto_library_internal/cc_library_func.bzl",
+        "upb_proto_library_internal/copts.bzl",
+        "upb_proto_library_internal/rule.bzl",
+    ],
+    visibility = [
+        "//upb/bazel:__pkg__",
+    ],
+    deps = [
+        "//bazel/common:proto_common_bzl",
+        "//bazel/common:proto_info_bzl",
+        "@bazel_skylib//lib:paths",
+        "@bazel_tools//tools/cpp:toolchain_utils.bzl",
+    ],
+)
diff --git a/upb/bazel/private/oss/BUILD b/upb/bazel/private/oss/BUILD
new file mode 100644
index 0000000..7223b75
--- /dev/null
+++ b/upb/bazel/private/oss/BUILD
@@ -0,0 +1,15 @@
+# Copyright (c) 2009-2021, Google LLC
+# All rights reserved.
+#
+# Use of this source code is governed by a BSD-style
+# license that can be found in the LICENSE file or at
+# https://developers.google.com/open-source/licenses/bsd
+
+load("@bazel_skylib//lib:selects.bzl", "selects")
+load("@rules_python//python:defs.bzl", "py_binary")
+
+py_binary(
+    name = "amalgamate",
+    srcs = ["amalgamate.py"],
+    visibility = ["//visibility:private"],
+)
diff --git a/upb/bazel/amalgamate.py b/upb/bazel/private/oss/amalgamate.py
similarity index 94%
rename from upb/bazel/amalgamate.py
rename to upb/bazel/private/oss/amalgamate.py
index f474216..dd54cb4 100755
--- a/upb/bazel/amalgamate.py
+++ b/upb/bazel/private/oss/amalgamate.py
@@ -30,17 +30,20 @@
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-import sys
-import re
 import os
+import re
+import sys
 
 INCLUDE_RE = re.compile('^#include "([^"]*)"')
 
+
 def parse_include(line):
   match = INCLUDE_RE.match(line)
   return match.groups()[0] if match else None
 
+
 class Amalgamator:
+
   def __init__(self, h_out, c_out):
     self.include_paths = ["."]
     self.included = set()
@@ -52,6 +55,7 @@
     self.h_files = set(h_files)
     self.output_c.write("/* Amalgamated source file */\n")
     self.output_c.write('#include "%s"\n' % (self.h_out))
+
     self.output_h.write("/* Amalgamated source file */\n")
 
     port_def = self._find_include_file("upb/port/def.inc")
@@ -99,7 +103,9 @@
         or include.startswith("google")
     ):
       return False
-    if include and (include.endswith("port/def.inc") or include.endswith("port/undef.inc")):
+    if include and (
+        include.endswith("port/def.inc") or include.endswith("port/undef.inc")
+    ):
       # Skip, we handle this separately
       return True
     if include.endswith("hpp"):
@@ -120,7 +126,13 @@
         self.included.add(include)
         self._process_file(h_file, self.output_h)
         return True
-      raise RuntimeError("Couldn't find include: " + include + ", h_files=" + repr(self.h_files))
+      raise RuntimeError(
+          "Couldn't find include: "
+          + include
+          + ", h_files="
+          + repr(self.h_files)
+      )
+
 
 # ---- main ----
 
diff --git a/upb/bazel/amalgamation.bzl b/upb/bazel/private/oss/amalgamation.bzl
similarity index 93%
rename from upb/bazel/amalgamation.bzl
rename to upb/bazel/private/oss/amalgamation.bzl
index 8f19516..4373ced 100644
--- a/upb/bazel/amalgamation.bzl
+++ b/upb/bazel/private/oss/amalgamation.bzl
@@ -7,7 +7,7 @@
 
 """Internal rules for building upb."""
 
-load("//bazel:upb_proto_library.bzl", "GeneratedSrcsInfo")
+load("//upb/bazel:upb_proto_library.bzl", "GeneratedSrcsInfo")
 
 # upb_amalgamation() rule, with file_list aspect.
 
@@ -54,7 +54,7 @@
         "_amalgamator": attr.label(
             executable = True,
             cfg = "exec",
-            default = "//upb/bazel:amalgamate",
+            default = "//upb/bazel/private/oss:amalgamate",
         ),
         "prefix": attr.string(
             default = "",
diff --git a/bazel/private/upb_proto_library_internal/aspect.bzl b/upb/bazel/private/upb_proto_library_internal/aspect.bzl
similarity index 100%
rename from bazel/private/upb_proto_library_internal/aspect.bzl
rename to upb/bazel/private/upb_proto_library_internal/aspect.bzl
diff --git a/bazel/private/upb_proto_library_internal/cc_library_func.bzl b/upb/bazel/private/upb_proto_library_internal/cc_library_func.bzl
similarity index 100%
rename from bazel/private/upb_proto_library_internal/cc_library_func.bzl
rename to upb/bazel/private/upb_proto_library_internal/cc_library_func.bzl
diff --git a/bazel/private/upb_proto_library_internal/copts.bzl b/upb/bazel/private/upb_proto_library_internal/copts.bzl
similarity index 100%
rename from bazel/private/upb_proto_library_internal/copts.bzl
rename to upb/bazel/private/upb_proto_library_internal/copts.bzl
diff --git a/bazel/private/upb_proto_library_internal/rule.bzl b/upb/bazel/private/upb_proto_library_internal/rule.bzl
similarity index 100%
rename from bazel/private/upb_proto_library_internal/rule.bzl
rename to upb/bazel/private/upb_proto_library_internal/rule.bzl
diff --git a/bazel/upb_c_proto_library.bzl b/upb/bazel/upb_c_proto_library.bzl
similarity index 82%
rename from bazel/upb_c_proto_library.bzl
rename to upb/bazel/upb_c_proto_library.bzl
index 216b1ed..cb3208f 100644
--- a/bazel/upb_c_proto_library.bzl
+++ b/upb/bazel/upb_c_proto_library.bzl
@@ -1,12 +1,12 @@
 """upb_c_proto_library() exposes upb's generated C API for protobuf (foo.upb.h)"""
 
 load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
-load("//bazel:upb_minitable_proto_library.bzl", "UpbMinitableCcInfo", "upb_minitable_proto_library_aspect")
-load("//bazel:visibility.bzl", "upb_clients")
 load("//bazel/common:proto_info.bzl", "ProtoInfo")
-load("//bazel/private:upb_proto_library_internal/aspect.bzl", "upb_proto_aspect_impl")
-load("//bazel/private:upb_proto_library_internal/cc_library_func.bzl", "upb_use_cpp_toolchain")
-load("//bazel/private:upb_proto_library_internal/rule.bzl", "upb_proto_rule_impl")
+load("//upb/bazel:upb_minitable_proto_library.bzl", "UpbMinitableCcInfo", "upb_minitable_proto_library_aspect")
+load("//upb/bazel:visibility.bzl", "upb_clients")
+load("//upb/bazel/private:upb_proto_library_internal/aspect.bzl", "upb_proto_aspect_impl")
+load("//upb/bazel/private:upb_proto_library_internal/cc_library_func.bzl", "upb_use_cpp_toolchain")
+load("//upb/bazel/private:upb_proto_library_internal/rule.bzl", "upb_proto_rule_impl")
 
 visibility(upb_clients)
 
diff --git a/bazel/upb_minitable_proto_library.bzl b/upb/bazel/upb_minitable_proto_library.bzl
similarity index 88%
rename from bazel/upb_minitable_proto_library.bzl
rename to upb/bazel/upb_minitable_proto_library.bzl
index 7db2dad..6a27082 100644
--- a/bazel/upb_minitable_proto_library.bzl
+++ b/upb/bazel/upb_minitable_proto_library.bzl
@@ -2,11 +2,11 @@
 
 load("@rules_cc//cc/common:cc_common.bzl", "cc_common")
 load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
-load("//bazel:visibility.bzl", "upb_clients")
 load("//bazel/common:proto_info.bzl", "ProtoInfo")
-load("//bazel/private:upb_proto_library_internal/aspect.bzl", "upb_proto_aspect_impl")
-load("//bazel/private:upb_proto_library_internal/cc_library_func.bzl", "upb_use_cpp_toolchain")
-load("//bazel/private:upb_proto_library_internal/rule.bzl", "upb_proto_rule_impl")
+load("//upb/bazel:visibility.bzl", "upb_clients")
+load("//upb/bazel/private:upb_proto_library_internal/aspect.bzl", "upb_proto_aspect_impl")
+load("//upb/bazel/private:upb_proto_library_internal/cc_library_func.bzl", "upb_use_cpp_toolchain")
+load("//upb/bazel/private:upb_proto_library_internal/rule.bzl", "upb_proto_rule_impl")
 
 visibility(upb_clients)
 
diff --git a/bazel/upb_proto_library.bzl b/upb/bazel/upb_proto_library.bzl
similarity index 81%
rename from bazel/upb_proto_library.bzl
rename to upb/bazel/upb_proto_library.bzl
index 474ef1d..bb706e3 100644
--- a/bazel/upb_proto_library.bzl
+++ b/upb/bazel/upb_proto_library.bzl
@@ -11,18 +11,18 @@
 """
 
 load(
-    "//bazel:upb_c_proto_library.bzl",
+    "//upb/bazel:upb_c_proto_library.bzl",
     _UpbWrappedCcInfo = "UpbWrappedCcInfo",
     _upb_c_proto_library = "upb_c_proto_library",
     _upb_c_proto_library_aspect = "upb_c_proto_library_aspect",
 )
 load(
-    "//bazel:upb_proto_reflection_library.bzl",
+    "//upb/bazel:upb_proto_reflection_library.bzl",
     _upb_proto_reflection_library = "upb_proto_reflection_library",
 )
-load("//bazel:visibility.bzl", "upb_clients")
+load("//upb/bazel:visibility.bzl", "upb_clients")
 load(
-    "//bazel/private:upb_proto_library_internal/aspect.bzl",
+    "//upb/bazel/private:upb_proto_library_internal/aspect.bzl",
     _GeneratedSrcsInfo = "GeneratedSrcsInfo",
 )
 
diff --git a/bazel/upb_proto_reflection_library.bzl b/upb/bazel/upb_proto_reflection_library.bzl
similarity index 83%
rename from bazel/upb_proto_reflection_library.bzl
rename to upb/bazel/upb_proto_reflection_library.bzl
index d1a4e76..627a2eb 100644
--- a/bazel/upb_proto_reflection_library.bzl
+++ b/upb/bazel/upb_proto_reflection_library.bzl
@@ -1,13 +1,13 @@
 """upb_c_proto_reflection_library() exposes upb reflection for protobuf (foo.upbdefs.h)"""
 
 load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
-load("//bazel:upb_minitable_proto_library.bzl", "UpbMinitableCcInfo", "upb_minitable_proto_library_aspect")
-load("//bazel:visibility.bzl", "upb_clients")
 load("//bazel/common:proto_common.bzl", "proto_common")
 load("//bazel/common:proto_info.bzl", "ProtoInfo")
-load("//bazel/private:upb_proto_library_internal/aspect.bzl", "upb_proto_aspect_impl")
-load("//bazel/private:upb_proto_library_internal/cc_library_func.bzl", "upb_use_cpp_toolchain")
-load("//bazel/private:upb_proto_library_internal/rule.bzl", "upb_proto_rule_impl")
+load("//upb/bazel:upb_minitable_proto_library.bzl", "UpbMinitableCcInfo", "upb_minitable_proto_library_aspect")
+load("//upb/bazel:visibility.bzl", "upb_clients")
+load("//upb/bazel/private:upb_proto_library_internal/aspect.bzl", "upb_proto_aspect_impl")
+load("//upb/bazel/private:upb_proto_library_internal/cc_library_func.bzl", "upb_use_cpp_toolchain")
+load("//upb/bazel/private:upb_proto_library_internal/rule.bzl", "upb_proto_rule_impl")
 
 visibility(upb_clients)
 
diff --git a/bazel/visibility.bzl b/upb/bazel/visibility.bzl
similarity index 100%
rename from bazel/visibility.bzl
rename to upb/bazel/visibility.bzl
diff --git a/upb/conformance/BUILD b/upb/conformance/BUILD
index c4d7ac8..f7c6e99 100644
--- a/upb/conformance/BUILD
+++ b/upb/conformance/BUILD
@@ -7,16 +7,13 @@
 
 load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
 load("@rules_shell//shell:sh_test.bzl", "sh_test")
+load("//upb/bazel:copts.bzl", "UPB_DEFAULT_COPTS")
 load(
-    "//bazel:upb_proto_library.bzl",
+    "//upb/bazel:upb_proto_library.bzl",
     "upb_c_proto_library",
     "upb_proto_reflection_library",
 )
-load(
-    "//upb/bazel:build_defs.bzl",
-    "UPB_DEFAULT_COPTS",
-    "make_shell_script",
-)
+load(":build_defs.bzl", "make_shell_script")
 
 package(default_applicable_licenses = ["//:license"])
 
diff --git a/upb/conformance/build_defs.bzl b/upb/conformance/build_defs.bzl
new file mode 100644
index 0000000..abb59bf
--- /dev/null
+++ b/upb/conformance/build_defs.bzl
@@ -0,0 +1,50 @@
+# Copyright (c) 2009-2021, Google LLC
+# All rights reserved.
+#
+# Use of this source code is governed by a BSD-style
+# license that can be found in the LICENSE file or at
+# https://developers.google.com/open-source/licenses/bsd
+
+"""Internal rules for building upb."""
+
+runfiles_init = """\
+# --- begin runfiles.bash initialization v2 ---
+# Copy-pasted from the Bazel Bash runfiles library v2.
+set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash
+source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
+  source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
+  source "$0.runfiles/$f" 2>/dev/null || \
+  source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
+  source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
+  { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
+# --- end runfiles.bash initialization v2 ---
+"""
+
+def _get_real_short_path(file):
+    # For some reason, files from other archives have short paths that look like:
+    #   ../com_google_protobuf/google/protobuf/descriptor.proto
+    short_path = file.short_path
+    if short_path.startswith("../"):
+        second_slash = short_path.index("/", 3)
+        short_path = short_path[second_slash + 1:]
+    return short_path
+
+def _get_real_root(file):
+    real_short_path = _get_real_short_path(file)
+    return file.path[:-len(real_short_path) - 1]
+
+def _get_real_roots(files):
+    roots = {}
+    for file in files:
+        real_root = _get_real_root(file)
+        if real_root:
+            roots[real_root] = True
+    return roots.keys()
+
+def make_shell_script(name, contents, out):
+    contents = contents.replace("$", "$$")
+    native.genrule(
+        name = "gen_" + name,
+        outs = [out],
+        cmd = "(cat <<'HEREDOC'\n%s\nHEREDOC\n) > $@" % contents,
+    )
diff --git a/upb/hash/BUILD b/upb/hash/BUILD
index b8a4b5b..e891780 100644
--- a/upb/hash/BUILD
+++ b/upb/hash/BUILD
@@ -7,7 +7,7 @@
 
 load("@rules_cc//cc:cc_test.bzl", "cc_test")
 load("@rules_cc//cc:defs.bzl", "cc_library")
-load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_COPTS")
+load("//upb/bazel:copts.bzl", "UPB_DEFAULT_COPTS")
 
 package(default_applicable_licenses = ["//:license"])
 
diff --git a/upb/json/BUILD b/upb/json/BUILD
index 714b093..a9d073c 100644
--- a/upb/json/BUILD
+++ b/upb/json/BUILD
@@ -3,12 +3,12 @@
 load("@rules_cc//cc:cc_test.bzl", "cc_test")
 load("@rules_cc//cc:defs.bzl", "cc_library")
 load("//bazel:proto_library.bzl", "proto_library")
+load("//upb/bazel:copts.bzl", "UPB_DEFAULT_COPTS")
 load(
-    "//bazel:upb_proto_library.bzl",
+    "//upb/bazel:upb_proto_library.bzl",
     "upb_c_proto_library",
     "upb_proto_reflection_library",
 )
-load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_COPTS")
 
 package(default_applicable_licenses = ["//:license"])
 
diff --git a/upb/lex/BUILD b/upb/lex/BUILD
index 762aa70..28e00cc 100644
--- a/upb/lex/BUILD
+++ b/upb/lex/BUILD
@@ -7,7 +7,7 @@
 
 load("@rules_cc//cc:cc_test.bzl", "cc_test")
 load("@rules_cc//cc:defs.bzl", "cc_library")
-load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_COPTS")
+load("//upb/bazel:copts.bzl", "UPB_DEFAULT_COPTS")
 
 package(default_applicable_licenses = ["//:license"])
 
diff --git a/upb/mem/BUILD b/upb/mem/BUILD
index 28bf1af..70e41c7 100644
--- a/upb/mem/BUILD
+++ b/upb/mem/BUILD
@@ -7,7 +7,7 @@
 
 load("@rules_cc//cc:cc_test.bzl", "cc_test")
 load("@rules_cc//cc:defs.bzl", "cc_library")
-load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_COPTS")
+load("//upb/bazel:copts.bzl", "UPB_DEFAULT_COPTS")
 
 package(default_applicable_licenses = ["//:license"])
 
diff --git a/upb/message/BUILD b/upb/message/BUILD
index acf679d..0832e44 100644
--- a/upb/message/BUILD
+++ b/upb/message/BUILD
@@ -9,16 +9,16 @@
 load("@rules_cc//cc:cc_test.bzl", "cc_test")
 load("@rules_cc//cc:defs.bzl", "cc_library")
 load("//bazel:proto_library.bzl", "proto_library")
+load("//upb/bazel:copts.bzl", "UPB_DEFAULT_COPTS", "UPB_DEFAULT_CPPOPTS")
 load(
-    "//bazel:upb_minitable_proto_library.bzl",
+    "//upb/bazel:upb_minitable_proto_library.bzl",
     "upb_minitable_proto_library",
 )
 load(
-    "//bazel:upb_proto_library.bzl",
+    "//upb/bazel:upb_proto_library.bzl",
     "upb_c_proto_library",
     "upb_proto_reflection_library",
 )
-load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_COPTS", "UPB_DEFAULT_CPPOPTS")
 
 package(default_applicable_licenses = ["//:license"])
 
diff --git a/upb/mini_descriptor/BUILD b/upb/mini_descriptor/BUILD
index 9ca4a2a..0cc2f13 100644
--- a/upb/mini_descriptor/BUILD
+++ b/upb/mini_descriptor/BUILD
@@ -1,7 +1,7 @@
 load("@rules_cc//cc:cc_test.bzl", "cc_test")
 load("@rules_cc//cc:defs.bzl", "cc_library")
 load(
-    "//upb/bazel:build_defs.bzl",
+    "//upb/bazel:copts.bzl",
     "UPB_DEFAULT_COPTS",
     "UPB_DEFAULT_CPPOPTS",
 )
diff --git a/upb/mini_table/BUILD b/upb/mini_table/BUILD
index c83a297..46cf9cb 100644
--- a/upb/mini_table/BUILD
+++ b/upb/mini_table/BUILD
@@ -10,12 +10,12 @@
 load("@rules_cc//cc:defs.bzl", "cc_library")
 load("//bazel:proto_library.bzl", "proto_library")
 load(
-    "//bazel:upb_minitable_proto_library.bzl",
-    "upb_minitable_proto_library",
+    "//upb/bazel:copts.bzl",
+    "UPB_DEFAULT_COPTS",
 )
 load(
-    "//upb/bazel:build_defs.bzl",
-    "UPB_DEFAULT_COPTS",
+    "//upb/bazel:upb_minitable_proto_library.bzl",
+    "upb_minitable_proto_library",
 )
 load(
     "//upb/cmake:build_defs.bzl",
diff --git a/upb/port/BUILD b/upb/port/BUILD
index 217659e..5a80192 100644
--- a/upb/port/BUILD
+++ b/upb/port/BUILD
@@ -6,7 +6,7 @@
 # https://developers.google.com/open-source/licenses/bsd
 
 load("@rules_cc//cc:defs.bzl", "cc_library")
-load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_COPTS")
+load("//upb/bazel:copts.bzl", "UPB_DEFAULT_COPTS")
 
 package(default_applicable_licenses = ["//:license"])
 
diff --git a/upb/reflection/BUILD b/upb/reflection/BUILD
index 6edb7dd..7c75cfe 100644
--- a/upb/reflection/BUILD
+++ b/upb/reflection/BUILD
@@ -12,7 +12,7 @@
     "compile_edition_defaults",
     "embed_edition_defaults",
 )
-load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_COPTS")
+load("//upb/bazel:copts.bzl", "UPB_DEFAULT_COPTS")
 load(
     "//upb/cmake:build_defs.bzl",
     "staleness_test",
diff --git a/upb/test/BUILD b/upb/test/BUILD
index 4ce0bd0..0ddd8e9 100644
--- a/upb/test/BUILD
+++ b/upb/test/BUILD
@@ -9,18 +9,18 @@
 load("@rules_cc//cc:defs.bzl", "cc_library")
 load("//bazel:proto_library.bzl", "proto_library")
 load(
-    "//bazel:upb_minitable_proto_library.bzl",
+    "//upb/bazel:copts.bzl",
+    "UPB_DEFAULT_CPPOPTS",
+)
+load(
+    "//upb/bazel:upb_minitable_proto_library.bzl",
     "upb_minitable_proto_library",
 )
 load(
-    "//bazel:upb_proto_library.bzl",
+    "//upb/bazel:upb_proto_library.bzl",
     "upb_c_proto_library",
     "upb_proto_reflection_library",
 )
-load(
-    "//upb/bazel:build_defs.bzl",
-    "UPB_DEFAULT_CPPOPTS",
-)
 
 package(default_applicable_licenses = ["//:license"])
 
diff --git a/upb/text/BUILD b/upb/text/BUILD
index a593ed1..8e7f3d9 100644
--- a/upb/text/BUILD
+++ b/upb/text/BUILD
@@ -7,7 +7,7 @@
 
 load("@rules_cc//cc:cc_test.bzl", "cc_test")
 load("@rules_cc//cc:defs.bzl", "cc_library")
-load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_COPTS")
+load("//upb/bazel:copts.bzl", "UPB_DEFAULT_COPTS")
 
 package(default_applicable_licenses = ["//:license"])
 
diff --git a/upb/util/BUILD b/upb/util/BUILD
index 9fc5d76..4cfcd84 100644
--- a/upb/util/BUILD
+++ b/upb/util/BUILD
@@ -2,7 +2,7 @@
 load("@rules_cc//cc:defs.bzl", "cc_library")
 load("//bazel:proto_library.bzl", "proto_library")
 load(
-    "//bazel:upb_proto_library.bzl",
+    "//upb/bazel:upb_proto_library.bzl",
     "upb_c_proto_library",
     "upb_proto_reflection_library",
 )
diff --git a/upb/wire/BUILD b/upb/wire/BUILD
index af6c178..8220865 100644
--- a/upb/wire/BUILD
+++ b/upb/wire/BUILD
@@ -8,7 +8,7 @@
 load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
 load("@rules_cc//cc:cc_test.bzl", "cc_test")
 load("@rules_cc//cc:defs.bzl", "cc_library")
-load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_COPTS", "UPB_DEFAULT_CPPOPTS")
+load("//upb/bazel:copts.bzl", "UPB_DEFAULT_COPTS", "UPB_DEFAULT_CPPOPTS")
 
 package(default_applicable_licenses = ["//:license"])
 
diff --git a/upb/wire/decode_fast/BUILD b/upb/wire/decode_fast/BUILD
index 012ba13..342eacf 100644
--- a/upb/wire/decode_fast/BUILD
+++ b/upb/wire/decode_fast/BUILD
@@ -9,7 +9,7 @@
 load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
 load("@rules_cc//cc:cc_test.bzl", "cc_test")
 load("@rules_cc//cc:defs.bzl", "cc_library")
-load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_COPTS")
+load("//upb/bazel:copts.bzl", "UPB_DEFAULT_COPTS")
 
 package(default_applicable_licenses = ["//:license"])
 
diff --git a/upb/wire/test_util/BUILD b/upb/wire/test_util/BUILD
index 93ede12..d6329c7 100644
--- a/upb/wire/test_util/BUILD
+++ b/upb/wire/test_util/BUILD
@@ -6,7 +6,7 @@
 # https://developers.google.com/open-source/licenses/bsd
 
 load("@rules_cc//cc:defs.bzl", "cc_library")
-load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_CPPOPTS")
+load("//upb/bazel:copts.bzl", "UPB_DEFAULT_CPPOPTS")
 
 package(default_applicable_licenses = ["//:license"])
 
diff --git a/upb_generator/BUILD b/upb_generator/BUILD
index 739c0be..d0b0406 100644
--- a/upb_generator/BUILD
+++ b/upb_generator/BUILD
@@ -6,7 +6,7 @@
 # https://developers.google.com/open-source/licenses/bsd
 
 load("@rules_cc//cc:defs.bzl", "cc_library")
-load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_CPPOPTS")
+load("//upb/bazel:copts.bzl", "UPB_DEFAULT_CPPOPTS")
 load(
     "//upb_generator:bootstrap_compiler.bzl",
     "bootstrap_cc_library",
diff --git a/upb_generator/bootstrap_compiler.bzl b/upb_generator/bootstrap_compiler.bzl
index 5ebc6a5..4e8c53c 100644
--- a/upb_generator/bootstrap_compiler.bzl
+++ b/upb_generator/bootstrap_compiler.bzl
@@ -3,11 +3,11 @@
 load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
 load("@rules_cc//cc:defs.bzl", "cc_library")
 load(
-    "//bazel:upb_minitable_proto_library.bzl",
+    "//upb/bazel:upb_minitable_proto_library.bzl",
     "upb_minitable_proto_library",
 )
 load(
-    "//bazel:upb_proto_library.bzl",
+    "//upb/bazel:upb_proto_library.bzl",
     "upb_proto_library",
 )
 load(
diff --git a/upb_generator/c/BUILD b/upb_generator/c/BUILD
index e9cc806..0b1b99a 100644
--- a/upb_generator/c/BUILD
+++ b/upb_generator/c/BUILD
@@ -8,7 +8,7 @@
 load("@rules_cc//cc:defs.bzl", "cc_library")
 load("//bazel/toolchains:proto_lang_toolchain.bzl", "proto_lang_toolchain")
 load(
-    "//upb/bazel:build_defs.bzl",
+    "//upb/bazel:copts.bzl",
     "UPB_DEFAULT_CPPOPTS",
 )
 load("//upb_generator:bootstrap_compiler.bzl", "bootstrap_cc_binary")
@@ -87,5 +87,5 @@
     plugin_format_flag = "--plugin=protoc-gen-upb=%s",
     progress_message = "Generating upb protos",
     runtime = "//upb:generated_code_support",
-    visibility = ["//bazel:__pkg__"],
+    visibility = ["//upb/bazel:__pkg__"],
 )
diff --git a/upb_generator/minitable/BUILD b/upb_generator/minitable/BUILD
index c098ef7..7377cec 100644
--- a/upb_generator/minitable/BUILD
+++ b/upb_generator/minitable/BUILD
@@ -7,7 +7,7 @@
 
 load("@rules_cc//cc:defs.bzl", "cc_library")
 load("//bazel/toolchains:proto_lang_toolchain.bzl", "proto_lang_toolchain")
-load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_CPPOPTS")
+load("//upb/bazel:copts.bzl", "UPB_DEFAULT_CPPOPTS")
 load(
     "//upb_generator:bootstrap_compiler.bzl",
     "bootstrap_cc_binary",
@@ -129,5 +129,5 @@
     plugin_format_flag = "--plugin=protoc-gen-upb_minitable=%s",
     progress_message = "Generating upb minitables",
     runtime = "//upb:generated_code_support",
-    visibility = ["//bazel:__pkg__"],
+    visibility = ["//upb/bazel:__pkg__"],
 )
diff --git a/upb_generator/reflection/BUILD b/upb_generator/reflection/BUILD
index 1292ed4..97fabdd 100644
--- a/upb_generator/reflection/BUILD
+++ b/upb_generator/reflection/BUILD
@@ -8,7 +8,7 @@
 load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
 load("@rules_cc//cc:defs.bzl", "cc_library")
 load("//bazel/toolchains:proto_lang_toolchain.bzl", "proto_lang_toolchain")
-load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_CPPOPTS")
+load("//upb/bazel:copts.bzl", "UPB_DEFAULT_CPPOPTS")
 
 package(default_applicable_licenses = ["//:license"])
 
@@ -75,5 +75,5 @@
     plugin_format_flag = "--plugin=protoc-gen-upbdefs=%s",
     progress_message = "Generating upb protos",
     runtime = "//upb/reflection:generated_reflection_support",
-    visibility = ["//bazel:__pkg__"],
+    visibility = ["//upb/bazel:__pkg__"],
 )