Migrate ruby and php to the new utf8_range repo
diff --git a/php/BUILD.bazel b/php/BUILD.bazel
index 3c97ad8..ac33702 100644
--- a/php/BUILD.bazel
+++ b/php/BUILD.bazel
@@ -34,7 +34,7 @@
     name = "build_extension",
     cmd = """
         mkdir -p php/ext/google/protobuf/third_party/utf8_range
-        cp third_party/utf8_range/* php/ext/google/protobuf/third_party/utf8_range
+        cp external/utf8_range/* php/ext/google/protobuf/third_party/utf8_range
 
         pushd  php/ext/google/protobuf
         phpize
@@ -48,7 +48,7 @@
     name = "extension",
     srcs = [
         ":source_files",
-        "//third_party/utf8_range:all_files",
+        "@utf8_range//:utf8_range_srcs",
     ],
     tools = [":build_extension"],
     outs = ["protobuf.so"],
diff --git a/php/tests/compile_extension.sh b/php/tests/compile_extension.sh
index dc42aa3..f9fb8cd 100755
--- a/php/tests/compile_extension.sh
+++ b/php/tests/compile_extension.sh
@@ -4,6 +4,9 @@
 
 cd $(dirname $0)/..
 
+# Pull in dependencies.
+git submodule update --init --recursive
+
 # utf8_range has to live in the base third_party directory.
 # We copy it into the ext/google/protobuf directory for the build
 # (and for the release to PECL).
diff --git a/protobuf_deps.bzl b/protobuf_deps.bzl
index 5e5f511..95e7124 100644
--- a/protobuf_deps.bzl
+++ b/protobuf_deps.bzl
@@ -67,8 +67,8 @@
         _github_archive(
             name = "utf8_range",
             repo = "https://github.com/protocolbuffers/utf8_range",
-            commit = "77f787ec84cce7c4c7059a614e3147eac23d511e",
-            sha256 = "e9ece5beebe0949cb4a4768b7fc9ca85b64fec41b3175b0c898bdd3f848c4ed1",
+            commit = "45fbf543fec00020a08650791a37575319a3ea1d",
+            sha256 = "dd93db062025f563068abaa224549e9d341434b5851e959c7853dfa263c96416",
         )
 
     if not native.existing_rule("rules_cc"):
diff --git a/ruby/BUILD.bazel b/ruby/BUILD.bazel
index 5e15d92..d4114b5 100644
--- a/ruby/BUILD.bazel
+++ b/ruby/BUILD.bazel
@@ -71,7 +71,7 @@
     name = "protobuf",
     srcs = [
         ":srcs",
-        "//third_party/utf8_range:all_files",
+        "@utf8_range//:utf8_range_srcs",
     ] + select({
         ":java_ruby": [":protobuf_java"],
         "@bazel_tools//src/conditions:darwin": [":protobuf_c_mac"],
diff --git a/ruby/Rakefile b/ruby/Rakefile
index 89a00e1..e6b774c 100644
--- a/ruby/Rakefile
+++ b/ruby/Rakefile
@@ -84,12 +84,16 @@
 else
   unless ENV['IN_DOCKER'] == 'true'
     # We need utf8_range in-tree.
+    if  ENV['BAZEL'] == 'true'
+      utf8_root = '../external/utf8_range'
+    else
+      utf8_root = '../third_party/utf8_range'
+    end
     FileUtils.mkdir_p("ext/google/protobuf_c/third_party/utf8_range")
-    FileUtils.cp("../third_party/utf8_range/utf8_range.h", "ext/google/protobuf_c/third_party/utf8_range")
-    FileUtils.cp("../third_party/utf8_range/naive.c", "ext/google/protobuf_c/third_party/utf8_range")
-    FileUtils.cp("../third_party/utf8_range/range2-neon.c", "ext/google/protobuf_c/third_party/utf8_range")
-    FileUtils.cp("../third_party/utf8_range/range2-sse.c", "ext/google/protobuf_c/third_party/utf8_range")
-    FileUtils.cp("../third_party/utf8_range/LICENSE", "ext/google/protobuf_c/third_party/utf8_range")
+    FileUtils.cp(utf8_root+"/utf8_range.h", "ext/google/protobuf_c/third_party/utf8_range")
+    FileUtils.cp(utf8_root+"/naive.c", "ext/google/protobuf_c/third_party/utf8_range")
+    FileUtils.cp(utf8_root+"/range2-neon.c", "ext/google/protobuf_c/third_party/utf8_range")
+    FileUtils.cp(utf8_root+"/range2-sse.c", "ext/google/protobuf_c/third_party/utf8_range")
   end
 
   Rake::ExtensionTask.new("protobuf_c", spec) do |ext|
diff --git a/ruby/internal.bzl b/ruby/internal.bzl
index 74a2d10..10ae108 100644
--- a/ruby/internal.bzl
+++ b/ruby/internal.bzl
@@ -23,7 +23,7 @@
             ":srcs",
             ":test_ruby_protos",
             ":tests",
-            "//third_party/utf8_range:all_files",
+            "@utf8_range//:utf8_range_srcs",
         ],
         tags = ["manual"],
         outs = [extension],