Add deprecation warnings for (py|cc|java)_generic_service.

PiperOrigin-RevId: 935047511
diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc
index 7599793..39482d3 100644
--- a/src/google/protobuf/compiler/command_line_interface.cc
+++ b/src/google/protobuf/compiler/command_line_interface.cc
@@ -1413,6 +1413,20 @@
       validation_error = true;
     }
 
+    if (file->options().cc_generic_services() ||
+        file->options().java_generic_services() ||
+        file->options().py_generic_services()) {
+      error_collector->RecordWarning(
+          file->name(), "options", nullptr,
+          DescriptorPool::ErrorCollector::OPTION_VALUE,
+          "Generic services (cc_generic_services, java_generic_services, and "
+          "py_generic_services) are deprecated in favor of using plugins that "
+          "generate code specific to your particular RPC system. Additional "
+          "code generator options may be required to enable generic services "
+          "and total removal of these options is planned in future breaking "
+          "releases.");
+    }
+
     google::protobuf::internal::VisitDescriptors(
         *file, [&](const FieldDescriptor& field) {
           if (HasReservedFieldNumber(&field)) {
diff --git a/src/google/protobuf/compiler/command_line_interface_unittest.cc b/src/google/protobuf/compiler/command_line_interface_unittest.cc
index 718d791..1a78f10 100644
--- a/src/google/protobuf/compiler/command_line_interface_unittest.cc
+++ b/src/google/protobuf/compiler/command_line_interface_unittest.cc
@@ -5714,6 +5714,42 @@
       "be `export` with STRICT default_symbol_visibility");
 }
 
+TEST_F(CommandLineInterfaceTest, JavaGenericServicesWarning) {
+  CreateTempFile("foo.proto",
+                 "syntax = \"proto2\";\n"
+                 "option java_generic_services = true;\n"
+                 "message Foo {}\n");
+
+  Run("protocol_compiler --test_out=$tmpdir "
+      "--proto_path=$tmpdir foo.proto");
+
+  ExpectWarningSubstring("Generic services");
+}
+
+TEST_F(CommandLineInterfaceTest, CppGenericServicesWarning) {
+  CreateTempFile("foo.proto",
+                 "syntax = \"proto2\";\n"
+                 "option cc_generic_services = true;\n"
+                 "message Foo {}\n");
+
+  Run("protocol_compiler --test_out=$tmpdir "
+      "--proto_path=$tmpdir foo.proto");
+
+  ExpectWarningSubstring("Generic services");
+}
+
+TEST_F(CommandLineInterfaceTest, PythonGenericServicesWarning) {
+  CreateTempFile("foo.proto",
+                 "syntax = \"proto2\";\n"
+                 "option py_generic_services = true;\n"
+                 "message Foo {}\n");
+
+  Run("protocol_compiler --test_out=$tmpdir "
+      "--proto_path=$tmpdir foo.proto");
+
+  ExpectWarningSubstring("Generic services");
+}
+
 // ===================================================================
 
 // Test for --encode and --decode.  Note that it would be easier to do this
diff --git a/src/google/protobuf/compiler/java/generator_unittest.cc b/src/google/protobuf/compiler/java/generator_unittest.cc
index ec7c3a8..c3c2096 100644
--- a/src/google/protobuf/compiler/java/generator_unittest.cc
+++ b/src/google/protobuf/compiler/java/generator_unittest.cc
@@ -137,7 +137,7 @@
       "protocol_compiler --proto_path=$tmpdir --java_out=$tmpdir "
       "--experimental_editions foo.proto");
 
-  ExpectNoErrors();
+  ExpectWarningSubstring("Generic services");
   EXPECT_TRUE(FileGenerated(PACKAGE_PREFIX "proto2_unittest/FooProto.java"));
   EXPECT_TRUE(FileGenerated(PACKAGE_PREFIX "proto2_unittest/MessageA.java"));
   EXPECT_TRUE(FileGenerated(PACKAGE_PREFIX "proto2_unittest/MessageB.java"));
@@ -246,7 +246,7 @@
       "protocol_compiler --proto_path=$tmpdir --java_out=$tmpdir "
       "--experimental_editions foo.proto");
 
-  ExpectNoErrors();
+  ExpectWarningSubstring("Generic services");
   EXPECT_TRUE(FileGenerated(PACKAGE_PREFIX "proto2_unittest/FooProto.java"));
   EXPECT_TRUE(
       FileGenerated(PACKAGE_PREFIX "proto2_unittest/UnnestedService.java"));