[ObjC] Enable editions conformance tests.

PiperOrigin-RevId: 590328722
diff --git a/conformance/BUILD.bazel b/conformance/BUILD.bazel
index 99827fc..1d9ea15 100644
--- a/conformance/BUILD.bazel
+++ b/conformance/BUILD.bazel
@@ -328,6 +328,8 @@
         ":conformance_objc_proto",
         "//:test_messages_proto2_objc_proto",
         "//:test_messages_proto3_objc_proto",
+        "//src/google/protobuf/editions:test_messages_proto2_editions_objc_proto",
+        "//src/google/protobuf/editions:test_messages_proto3_editions_objc_proto",
     ],
 )
 
diff --git a/conformance/conformance_objc.m b/conformance/conformance_objc.m
index 5060ce9..8a37b72 100644
--- a/conformance/conformance_objc.m
+++ b/conformance/conformance_objc.m
@@ -10,6 +10,8 @@
 #import "Conformance.pbobjc.h"
 #import "google/protobuf/TestMessagesProto2.pbobjc.h"
 #import "google/protobuf/TestMessagesProto3.pbobjc.h"
+#import "google/protobuf/editions/golden/TestMessagesProto2Editions.pbobjc.h"
+#import "google/protobuf/editions/golden/TestMessagesProto3Editions.pbobjc.h"
 
 static void Die(NSString *format, ...) __dead2;
 
@@ -49,22 +51,25 @@
       break;
 
     case ConformanceRequest_Payload_OneOfCase_ProtobufPayload: {
-      Class msgClass = nil;
-      if ([request.messageType isEqual:@"protobuf_test_messages.proto3.TestAllTypesProto3"]) {
-        msgClass = [Proto3TestAllTypesProto3 class];
-      } else if ([request.messageType
-                     isEqual:@"protobuf_test_messages.proto2.TestAllTypesProto2"]) {
-        msgClass = [Proto2TestAllTypesProto2 class];
+      NSDictionary *mappings = @{
+        @"protobuf_test_messages.proto2.TestAllTypesProto2" : [Proto2TestAllTypesProto2 class],
+        @"protobuf_test_messages.proto3.TestAllTypesProto3" : [Proto3TestAllTypesProto3 class],
+        @"protobuf_test_messages.editions.proto2.TestAllTypesProto2" :
+            [EditionsProto2TestAllTypesProto2 class],
+        @"protobuf_test_messages.editions.proto3.TestAllTypesProto3" :
+            [EditionsProto3TestAllTypesProto3 class],
+      };
+      Class msgClass = mappings[request.messageType];
+      if (msgClass) {
+        NSError *error = nil;
+        testMessage = [msgClass parseFromData:request.protobufPayload error:&error];
+        if (!testMessage) {
+          response.parseError = [NSString stringWithFormat:@"Parse error: %@", error];
+        }
       } else {
         response.runtimeError =
             [NSString stringWithFormat:@"Protobuf request had an unknown message_type: %@",
                                        request.messageType];
-        break;
-      }
-      NSError *error = nil;
-      testMessage = [msgClass parseFromData:request.protobufPayload error:&error];
-      if (!testMessage) {
-        response.parseError = [NSString stringWithFormat:@"Parse error: %@", error];
       }
       break;
     }
diff --git a/objectivec/BUILD.bazel b/objectivec/BUILD.bazel
index cb0d7c8..d9e18ee 100644
--- a/objectivec/BUILD.bazel
+++ b/objectivec/BUILD.bazel
@@ -160,6 +160,7 @@
 conformance_test(
     name = "conformance_test",
     failure_list = "//conformance:failure_list_objc.txt",
+    maximum_edition = "2023",
     target_compatible_with = ["@platforms//os:macos"],
     testee = "//conformance:conformance_objc",
 )
diff --git a/protobuf.bzl b/protobuf.bzl
index 8fe845a..3c8afcc 100644
--- a/protobuf.bzl
+++ b/protobuf.bzl
@@ -80,6 +80,7 @@
     srcs = ctx.files.srcs
     langs = ctx.attr.langs or []
     out_type = ctx.attr.out_type
+    enable_editions = ctx.attr.enable_editions
     deps = depset(direct = ctx.files.srcs)
     source_dir = _SourceDir(ctx)
     gen_dir = _GenDir(ctx).rstrip("/")
@@ -130,6 +131,8 @@
     generated_files = []
     for src in srcs:
         args = []
+        if enable_editions:
+            args.append("--experimental_editions")
 
         in_gen_dir = src.root.path == gen_dir
         if in_gen_dir:
@@ -247,6 +250,7 @@
     attrs = {
         "srcs": attr.label_list(allow_files = True),
         "deps": attr.label_list(providers = [ProtoGenInfo]),
+        "enable_editions": attr.bool(),
         "includes": attr.string_list(),
         "protoc": attr.label(
             cfg = "exec",
@@ -406,11 +410,11 @@
         includes = ["."],
         default_runtime = Label("//:protobuf_objc"),
         protoc = Label("//:protoc"),
+        enable_editions = False,
         testonly = None,
         visibility = ["//visibility:public"],
         **kwargs):
-    """Bazel rule to create a Objective-C protobuf library from proto source
-    files
+    """Bazel rule to create a Objective-C protobuf library from proto sources
 
     NOTE: the rule is only an internal workaround to generate protos. The
     interface may change and the rule may be removed when bazel has introduced
@@ -423,9 +427,10 @@
       outs: a list of expected output files.
       proto_deps: a list of proto file dependencies that don't have a
         objc_proto_library rule.
-      include: a string indicating the include path of the .proto files.
+      includes: a string indicating the include path of the .proto files.
       default_runtime: the Objective-C Protobuf runtime
       protoc: the label of the protocol compiler to generate the sources.
+      enable_editions: if editions should be enabled while invoking the compiler.
       testonly: common rule attribute (see:
           https://bazel.build/reference/be/common-definitions#common-attributes)
       visibility: the visibility of the generated files.
@@ -440,6 +445,7 @@
             testonly = testonly,
             srcs = proto_deps,
             protoc = protoc,
+            enable_editions = enable_editions,
             includes = includes,
         )
         full_deps.append(":%s_deps_genproto" % name)
@@ -454,6 +460,7 @@
         out_type = "hdrs",
         includes = includes,
         protoc = protoc,
+        enable_editions = enable_editions,
         testonly = testonly,
         visibility = visibility,
         tags = ["manual"],
@@ -467,6 +474,7 @@
         out_type = "srcs",
         includes = includes,
         protoc = protoc,
+        enable_editions = enable_editions,
         testonly = testonly,
         visibility = visibility,
         tags = ["manual"],
diff --git a/src/google/protobuf/editions/BUILD b/src/google/protobuf/editions/BUILD
index e22c9ac..96fc9b1 100644
--- a/src/google/protobuf/editions/BUILD
+++ b/src/google/protobuf/editions/BUILD
@@ -3,6 +3,7 @@
 load("@rules_cc//cc:defs.bzl", "cc_proto_library")
 load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
 load(":defaults.bzl", "compile_edition_defaults", "embed_edition_defaults")
+load("//:protobuf.bzl", "internal_objc_proto_library")
 
 bzl_library(
     name = "defaults",
@@ -100,6 +101,14 @@
     deps = [":test_messages_proto2_editions_proto"],
 )
 
+internal_objc_proto_library(
+    name = "test_messages_proto2_editions_objc_proto",
+    testonly = True,
+    srcs = ["golden/test_messages_proto2_editions.proto"],
+    enable_editions = True,
+    visibility = ["//conformance:__pkg__"],
+)
+
 py_proto_library(
     name = "test_messages_proto2_editions_py_pb2",
     testonly = True,
@@ -142,6 +151,19 @@
     deps = [":test_messages_proto3_editions_proto"],
 )
 
+internal_objc_proto_library(
+    name = "test_messages_proto3_editions_objc_proto",
+    testonly = True,
+    srcs = ["golden/test_messages_proto3_editions.proto"],
+    enable_editions = True,
+    includes = [
+        ".",
+        "src",
+    ],
+    proto_deps = ["//:well_known_type_protos"],
+    visibility = ["//conformance:__pkg__"],
+)
+
 py_proto_library(
     name = "test_messages_proto3_editions_py_pb2",
     testonly = True,
diff --git a/src/google/protobuf/editions/golden/test_messages_proto2_editions.proto b/src/google/protobuf/editions/golden/test_messages_proto2_editions.proto
index 225e85d..9f4f198 100644
--- a/src/google/protobuf/editions/golden/test_messages_proto2_editions.proto
+++ b/src/google/protobuf/editions/golden/test_messages_proto2_editions.proto
@@ -19,7 +19,7 @@
 option features.repeated_field_encoding = EXPANDED;
 option features.utf8_validation = NONE;
 option java_package = "com.google.protobuf_test_messages.editions.proto2";
-option objc_class_prefix = "Proto2";
+option objc_class_prefix = "EditionsProto2";
 
 // This is the default, but we specify it here explicitly.
 option optimize_for = SPEED;
diff --git a/src/google/protobuf/editions/golden/test_messages_proto3_editions.proto b/src/google/protobuf/editions/golden/test_messages_proto3_editions.proto
index 9dbf63e..c092ea6 100644
--- a/src/google/protobuf/editions/golden/test_messages_proto3_editions.proto
+++ b/src/google/protobuf/editions/golden/test_messages_proto3_editions.proto
@@ -24,7 +24,7 @@
 
 option features.field_presence = IMPLICIT;
 option java_package = "com.google.protobuf_test_messages.editions.proto3";
-option objc_class_prefix = "Proto3";
+option objc_class_prefix = "EditionsProto3";
 
 // This is the default, but we specify it here explicitly.
 option optimize_for = SPEED;