Avoid recursive call to `Insert` in the flat case.
[google-protobuf.git] / objectivec / BUILD.bazel
blob7dbbb353c195f0a6c8481a20c06a58430f1e12fd
1 load("@rules_cc//cc:defs.bzl", "objc_library")
2 load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix")
3 load("//conformance:defs.bzl", "conformance_test")
4 load("//upb/cmake:build_defs.bzl", "staleness_test")
5 load(":defs.bzl", "objc_proto_camel_case_name")
7 # The WKTs have to be checked in to support the CocoaPods and Xcode builds. This
8 # generule and test ensure the source are current.
10 # TODO: Improve the bazel build so it uses these generated headers so it is
11 # always current, and only the builds that can't easily build protoc and
12 # generate the files rely on the checked in ones.
14 _WELL_KNOWN_TYPES = [
15     "any",
16     "api",
17     "duration",
18     "empty",
19     "field_mask",
20     "source_context",
21     "struct",
22     "timestamp",
23     "type",
24     "wrappers",
27 _OBJC_WKT_NAMES = [objc_proto_camel_case_name(x) for x in _WELL_KNOWN_TYPES]
29 _OBJC_EXTS = [
30     ".pbobjc.h",
31     ".pbobjc.m",
34 genrule(
35     name = "gen_wkt_sources",
36     srcs = ["//src/google/protobuf:well_known_type_protos"],
37     outs = ["wkt/GPB" + wkt + ext for wkt in _OBJC_WKT_NAMES for ext in _OBJC_EXTS],
38     cmd = " && ".join([
39         "$(execpath //:protoc) --objc_out=$(RULEDIR)/wkt --proto_path=src $(SRCS)",
40     ] + [
41         "mv $(RULEDIR)/wkt/google/protobuf/" + wkt + ext + " $(RULEDIR)/wkt/GPB" + wkt + ext
42         for wkt in _OBJC_WKT_NAMES
43         for ext in _OBJC_EXTS
44     ]),
45     tags = ["manual"],
46     tools = ["//:protoc"],
49 staleness_test(
50     name = "well_known_types_staleness_test",
51     outs = ["GPB" + wkt + ext for wkt in _OBJC_WKT_NAMES for ext in _OBJC_EXTS],
52     generated_pattern = "wkt/%s",
53     tags = ["manual"],
56 ################################################################################
57 # Objective-C Runtime Library
58 ################################################################################
60 objc_library(
61     name = "objectivec",
62     srcs = [
63         # Private headers that aren't used from the generated sources.
64         "GPBUnknownFields_PackagePrivate.h",
65     ],
66     hdrs = [
67         "GPBAny.pbobjc.h",
68         "GPBApi.pbobjc.h",
69         "GPBDuration.pbobjc.h",
70         "GPBEmpty.pbobjc.h",
71         "GPBFieldMask.pbobjc.h",
72         "GPBSourceContext.pbobjc.h",
73         "GPBStruct.pbobjc.h",
74         "GPBTimestamp.pbobjc.h",
75         "GPBType.pbobjc.h",
76         "GPBWrappers.pbobjc.h",
77         "GPBArray.h",
78         "GPBBootstrap.h",
79         "GPBCodedInputStream.h",
80         "GPBCodedOutputStream.h",
81         "GPBDescriptor.h",
82         "GPBDictionary.h",
83         "GPBExtensionInternals.h",
84         "GPBExtensionRegistry.h",
85         "GPBMessage.h",
86         "GPBProtocolBuffers.h",
87         "GPBProtocolBuffers_RuntimeSupport.h",
88         "GPBRootObject.h",
89         "GPBRuntimeTypes.h",
90         "GPBUnknownField.h",
91         "GPBUnknownFields.h",
92         "GPBUtilities.h",
93         "GPBWellKnownTypes.h",
94         "GPBWireFormat.h",
95         # Package private headers, but exposed because the generated sources
96         # need to use them.
97         "GPBArray_PackagePrivate.h",
98         "GPBCodedInputStream_PackagePrivate.h",
99         "GPBCodedOutputStream_PackagePrivate.h",
100         "GPBDescriptor_PackagePrivate.h",
101         "GPBDictionary_PackagePrivate.h",
102         "GPBMessage_PackagePrivate.h",
103         "GPBRootObject_PackagePrivate.h",
104         "GPBUnknownField_PackagePrivate.h",
105         "GPBUtilities_PackagePrivate.h",
106     ],
107     copts = [
108         "-Wno-vla",
109     ],
110     includes = [
111         ".",
112     ],
113     non_arc_srcs = [
114         "GPBAny.pbobjc.m",
115         "GPBApi.pbobjc.m",
116         "GPBArray.m",
117         "GPBCodedInputStream.m",
118         "GPBCodedOutputStream.m",
119         "GPBDescriptor.m",
120         "GPBDictionary.m",
121         "GPBDuration.pbobjc.m",
122         "GPBEmpty.pbobjc.m",
123         "GPBExtensionInternals.m",
124         "GPBExtensionRegistry.m",
125         "GPBFieldMask.pbobjc.m",
126         "GPBMessage.m",
127         "GPBRootObject.m",
128         "GPBSourceContext.pbobjc.m",
129         "GPBStruct.pbobjc.m",
130         "GPBTimestamp.pbobjc.m",
131         "GPBType.pbobjc.m",
132         "GPBUnknownField.m",
133         "GPBUnknownFields.m",
134         "GPBUtilities.m",
135         "GPBWellKnownTypes.m",
136         "GPBWireFormat.m",
137         "GPBWrappers.pbobjc.m",
138     ],
139     target_compatible_with = select({
140         "@platforms//os:macos": [],
141         "@platforms//os:ios": [],
142         "@platforms//os:tvos": [],
143         "@platforms//os:watchos": [],
144         "//conditions:default": ["@platforms//:incompatible"],
145     }),
146     visibility = ["//visibility:public"],
149 ################################################################################
150 # Tests
151 ################################################################################
153 conformance_test(
154     name = "conformance_test",
155     failure_list = "//conformance:failure_list_objc.txt",
156     maximum_edition = "2023",
157     target_compatible_with = ["@platforms//os:macos"],
158     testee = "//conformance:conformance_objc",
161 # -------------------------------------------------------------------
162 # Current Version Check between Generator and Runtime Sources
163 sh_test(
164     name = "check_version_stamps",
165     size = "small",
166     srcs = ["DevTools/check_version_stamps.sh"],
167     data = [
168         "GPBBootstrap.h",
169         "//src/google/protobuf/compiler/objectivec:file.cc",
170     ],
173 # -------------------------------------------------------------------
174 # Validation of pddm expansion.
176 py_binary(
177     name = "pddm",
178     srcs = ["DevTools/pddm.py"],
181 py_test(
182     name = "pddm_tests",
183     size = "small",
184     srcs = [
185         "DevTools/pddm.py",
186         "DevTools/pddm_tests.py",
187     ],
190 sh_test(
191     name = "sources_pddm_expansion_test",
192     size = "small",
193     srcs = ["DevTools/sources_pddm_expansion_test.sh"],
194     data = [":pddm"] + glob([
195         "**/*.h",
196         "**/*.m",
197         "**/*.pddm",
198     ]),
201 ################################################################################
202 # Distribution files
203 ################################################################################
205 pkg_files(
206     name = "dist_files",
207     srcs = glob([
208         "*.h",
209         "*.m",
210         "**/*.h",
211         "**/*.m",
212         "**/*.mm",
213         "**/*.swift",
214         "DevTools/*.sh",
215         "DevTools/*.py",
216         "ProtocolBuffers_iOS.xcodeproj/**/*",
217         "ProtocolBuffers_OSX.xcodeproj/**/*",
218         "ProtocolBuffers_tvOS.xcodeproj/**/*",
219         "Tests/*.pddm",
220         "Tests/*.txt",
221         "Tests/*.plist",
222         "Tests/*.proto",
223     ]) + [
224         ".clang-format",
225         "BUILD.bazel",
226         "README.md",
227         "Tests/golden_message",
228         "Tests/golden_packed_fields_message",
229         "generate_well_known_types.sh",
230     ],
231     strip_prefix = strip_prefix.from_root(""),
232     visibility = ["//pkg:__pkg__"],