Publish gencode for the well-known types instead of invoking protoc at build time

This will make it possible for users to build and use our well-known types
crate without necessarily having protoc installed.

PiperOrigin-RevId: 811841486
diff --git a/rust/release_crates/protobuf_well_known_types/BUILD.bazel b/rust/release_crates/protobuf_well_known_types/BUILD.bazel
index 610a03e..10a21cd 100644
--- a/rust/release_crates/protobuf_well_known_types/BUILD.bazel
+++ b/rust/release_crates/protobuf_well_known_types/BUILD.bazel
@@ -6,6 +6,7 @@
     srcs = [
         ":crate_root_files",
         ":well_known_types",
+        ":well_known_types_gencode",
         "//rust/release_crates:license",
     ],
     prefix = "protobuf_well_known_types",
@@ -34,3 +35,31 @@
     srcs = ["//src/google/protobuf:well_known_type_protos"],
     prefix = "proto/google/protobuf",
 )
+
+genrule(
+    name = "gen_well_known_types",
+    srcs = [
+        "//src/google/protobuf:well_known_type_protos",
+    ],
+    outs = [
+        "google/protobuf/any.u.pb.rs",
+        "google/protobuf/api.u.pb.rs",
+        "google/protobuf/duration.u.pb.rs",
+        "google/protobuf/empty.u.pb.rs",
+        "google/protobuf/field_mask.u.pb.rs",
+        "google/protobuf/generated.rs",
+        "google/protobuf/source_context.u.pb.rs",
+        "google/protobuf/struct.u.pb.rs",
+        "google/protobuf/timestamp.u.pb.rs",
+        "google/protobuf/type.u.pb.rs",
+        "google/protobuf/wrappers.u.pb.rs",
+    ],
+    cmd = "echo $(SRCS) | sed 's?^src/??' | xargs $(location //:protoc) -I src --rust_out=$(@D) --rust_opt=experimental-codegen=enabled,kernel=upb",
+    tools = ["//:protoc"],
+)
+
+pkg_files(
+    name = "well_known_types_gencode",
+    srcs = [":gen_well_known_types"],
+    prefix = "src",
+)
diff --git a/rust/release_crates/protobuf_well_known_types/Cargo-template.toml b/rust/release_crates/protobuf_well_known_types/Cargo-template.toml
index a2d4104..6cde30d 100644
--- a/rust/release_crates/protobuf_well_known_types/Cargo-template.toml
+++ b/rust/release_crates/protobuf_well_known_types/Cargo-template.toml
@@ -8,6 +8,3 @@
 [dependencies]
 protobuf = { version = "{VERSION}", path = "../protobuf", package = "protobuf" }
 protobuf-codegen = { version = "{VERSION}", path = "../protobuf_codegen", package = "protobuf-codegen" }
-
-[build-dependencies]
-protobuf-codegen = { version = "{VERSION}", path = "../protobuf_codegen", package = "protobuf-codegen" }
diff --git a/rust/release_crates/protobuf_well_known_types/build.rs b/rust/release_crates/protobuf_well_known_types/build.rs
deleted file mode 100644
index 779124c..0000000
--- a/rust/release_crates/protobuf_well_known_types/build.rs
+++ /dev/null
@@ -1,20 +0,0 @@
-use protobuf_codegen::CodeGen;
-
-fn main() {
-    CodeGen::new()
-        .inputs([
-            "google/protobuf/any.proto",
-            "google/protobuf/api.proto",
-            "google/protobuf/duration.proto",
-            "google/protobuf/empty.proto",
-            "google/protobuf/field_mask.proto",
-            "google/protobuf/source_context.proto",
-            "google/protobuf/struct.proto",
-            "google/protobuf/timestamp.proto",
-            "google/protobuf/type.proto",
-            "google/protobuf/wrappers.proto",
-        ])
-        .include("proto")
-        .generate_and_compile()
-        .unwrap();
-}
diff --git a/rust/release_crates/protobuf_well_known_types/src/lib.rs b/rust/release_crates/protobuf_well_known_types/src/lib.rs
index 5220afa..b30e22d 100644
--- a/rust/release_crates/protobuf_well_known_types/src/lib.rs
+++ b/rust/release_crates/protobuf_well_known_types/src/lib.rs
@@ -1,6 +1,7 @@
 use std::path::Path;
 
-include!(concat!(env!("OUT_DIR"), "/protobuf_generated/google/protobuf/generated.rs"));
+mod generated;
+pub use generated::*;
 
 pub fn get_dependency(crate_name: &str) -> Vec<protobuf_codegen::Dependency> {
     vec![protobuf_codegen::Dependency {