Migrate Protobuf Python C extensions to rules_python toolchain targets.

Update _message to use rules_python's py_extension macro (which
automatically injects required toolchain headers and manages shared library
extensions across platforms), and update _api_implementation.so to depend
directly on `@rules_python//python/cc:current_py_cc_headers` instead of
`@system_python`.

Using `py_extension` and `current_py_cc_headers` decouples Python C
extensions from the custom system_python.bzl script while maintaining
current host-interpreter behavior during the migration.

#test-continuous

PiperOrigin-RevId: 966345187
diff --git a/MODULE.bazel b/MODULE.bazel
index e8e6af5..bf32036 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -33,7 +33,7 @@
 bazel_dep(name = "rules_kotlin", version = "2.3.20")
 bazel_dep(name = "rules_license", version = "1.0.0")
 bazel_dep(name = "rules_pkg", version = "1.0.1")
-bazel_dep(name = "rules_python", version = "1.6.0")
+bazel_dep(name = "rules_python", version = "2.3.0")
 bazel_dep(name = "rules_rust", version = "0.69.0")
 
 bazel_dep(name = "rules_ruby", version = "0.20.1", dev_dependency = True)
diff --git a/examples/MODULE.bazel b/examples/MODULE.bazel
index 464407c..f13e8f7 100644
--- a/examples/MODULE.bazel
+++ b/examples/MODULE.bazel
@@ -22,4 +22,4 @@
 bazel_dep(name = "rules_cc", version = "0.2.18")
 bazel_dep(name = "rules_java", version = "8.6.1")
 bazel_dep(name = "rules_pkg", version = "1.0.1")
-bazel_dep(name = "rules_python", version = "1.6.0")
+bazel_dep(name = "rules_python", version = "2.3.0")
diff --git a/protobuf_deps.bzl b/protobuf_deps.bzl
index 72785fb..31b2fa3 100644
--- a/protobuf_deps.bzl
+++ b/protobuf_deps.bzl
@@ -131,9 +131,9 @@
     if not native.existing_rule("rules_python"):
         http_archive(
             name = "rules_python",
-            sha256 = "fa7dd2c6b7d63b3585028dd8a90a6cf9db83c33b250959c2ee7b583a6c130e12",
-            strip_prefix = "rules_python-1.6.0",
-            url = "https://github.com/bazel-contrib/rules_python/releases/download/1.6.0/rules_python-1.6.0.tar.gz",
+            sha256 = "70c519e8f0a5d9244c0d3496a6993bd42edf111c4499b68ce2f155c26fc8d4ee",
+            strip_prefix = "rules_python-2.3.0",
+            url = "https://github.com/bazel-contrib/rules_python/releases/download/2.3.0/rules_python-2.3.0.tar.gz",
         )
 
     if not native.existing_rule("system_python"):
diff --git a/python/build_targets.bzl b/python/build_targets.bzl
index f7417b1..df412dd 100644
--- a/python/build_targets.bzl
+++ b/python/build_targets.bzl
@@ -12,6 +12,7 @@
 load("@rules_cc//cc:defs.bzl", "cc_library")
 load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix")
 load("@rules_python//python:defs.bzl", "py_library")
+load("@rules_python//python/cc:py_extension.bzl", "py_extension")
 load("//:protobuf.bzl", "internal_py_proto_library")
 load("//bazel/toolchains:proto_lang_toolchain.bzl", "proto_lang_toolchain")
 load("//build_defs:arch_tests.bzl", "aarch64_test", "x86_64_test")
@@ -33,7 +34,7 @@
             "//conditions:default": [],
             ":use_fast_cpp_protos": [
                 ":google/protobuf/internal/_api_implementation.so",
-                ":google/protobuf/pyext/_message.so",
+                ":google/protobuf/pyext/_message",
             ],
         }),
         visibility = ["//:__pkg__"],
@@ -99,7 +100,7 @@
             # https://docs.bazel.build/versions/master/be/common-definitions.html#common-attributes
             "manual",
         ],
-        deps = ["@system_python//:python_headers"],
+        deps = ["@rules_python//python/cc:current_py_cc_headers"],
     )
 
     native.config_setting(
@@ -114,8 +115,8 @@
         visibility = ["//python:__subpackages__"],
     )
 
-    cc_binary(
-        name = "google/protobuf/pyext/_message.so",
+    py_extension(
+        name = "google/protobuf/pyext/_message",
         srcs = native.glob([
             "google/protobuf/pyext/*.cc",
             "google/protobuf/pyext/*.h",
@@ -162,7 +163,6 @@
             "@abseil-cpp//absl/strings",
             "@abseil-cpp//absl/synchronization",
             "@abseil-cpp//absl/types:span",
-            "@system_python//:python_headers",
         ],
     )
 
@@ -170,7 +170,7 @@
         name = "aarch64_test",
         bazel_binaries = [
             "google/protobuf/internal/_api_implementation.so",
-            "google/protobuf/pyext/_message.so",
+            "google/protobuf/pyext/_message",
         ],
     )
 
@@ -178,7 +178,7 @@
         name = "x86_64_test",
         bazel_binaries = [
             "google/protobuf/internal/_api_implementation.so",
-            "google/protobuf/pyext/_message.so",
+            "google/protobuf/pyext/_message",
         ],
     )
 
@@ -485,7 +485,7 @@
             "@abseil-cpp//absl/log:absl_check",
             "@abseil-cpp//absl/status",
             "@abseil-cpp//absl/status:statusor",
-            "@system_python//:python_headers",
+            "@rules_python//python/cc:current_py_cc_headers",
         ],
     )