• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1load("@rules_cc//cc:defs.bzl", "objc_library")
2load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix")
3load("//conformance:defs.bzl", "conformance_test")
4load("//upb/cmake:build_defs.bzl", "staleness_test")
5load(":defs.bzl", "objc_proto_camel_case_name")
6
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.
9#
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.
13
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",
25]
26
27_OBJC_WKT_NAMES = [objc_proto_camel_case_name(x) for x in _WELL_KNOWN_TYPES]
28
29_OBJC_EXTS = [
30    ".pbobjc.h",
31    ".pbobjc.m",
32]
33
34genrule(
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"],
47)
48
49staleness_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"],
54)
55
56################################################################################
57# Objective-C Runtime Library
58################################################################################
59
60objc_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        "GPBUnknownFieldSet.h",
93        "GPBUtilities.h",
94        "GPBWellKnownTypes.h",
95        "GPBWireFormat.h",
96        "google/protobuf/Any.pbobjc.h",
97        "google/protobuf/Api.pbobjc.h",
98        "google/protobuf/Duration.pbobjc.h",
99        "google/protobuf/Empty.pbobjc.h",
100        "google/protobuf/FieldMask.pbobjc.h",
101        "google/protobuf/SourceContext.pbobjc.h",
102        "google/protobuf/Struct.pbobjc.h",
103        "google/protobuf/Timestamp.pbobjc.h",
104        "google/protobuf/Type.pbobjc.h",
105        "google/protobuf/Wrappers.pbobjc.h",
106        # Package private headers, but exposed because the generated sources
107        # need to use them.
108        "GPBArray_PackagePrivate.h",
109        "GPBCodedInputStream_PackagePrivate.h",
110        "GPBCodedOutputStream_PackagePrivate.h",
111        "GPBDescriptor_PackagePrivate.h",
112        "GPBDictionary_PackagePrivate.h",
113        "GPBMessage_PackagePrivate.h",
114        "GPBRootObject_PackagePrivate.h",
115        "GPBUnknownFieldSet_PackagePrivate.h",
116        "GPBUnknownField_PackagePrivate.h",
117        "GPBUtilities_PackagePrivate.h",
118    ],
119    copts = [
120        "-Wno-vla",
121    ],
122    includes = [
123        ".",
124    ],
125    non_arc_srcs = [
126        "GPBAny.pbobjc.m",
127        "GPBApi.pbobjc.m",
128        "GPBArray.m",
129        "GPBCodedInputStream.m",
130        "GPBCodedOutputStream.m",
131        "GPBDescriptor.m",
132        "GPBDictionary.m",
133        "GPBDuration.pbobjc.m",
134        "GPBEmpty.pbobjc.m",
135        "GPBExtensionInternals.m",
136        "GPBExtensionRegistry.m",
137        "GPBFieldMask.pbobjc.m",
138        "GPBMessage.m",
139        "GPBRootObject.m",
140        "GPBSourceContext.pbobjc.m",
141        "GPBStruct.pbobjc.m",
142        "GPBTimestamp.pbobjc.m",
143        "GPBType.pbobjc.m",
144        "GPBUnknownField.m",
145        "GPBUnknownFieldSet.m",
146        "GPBUnknownFields.m",
147        "GPBUtilities.m",
148        "GPBWellKnownTypes.m",
149        "GPBWireFormat.m",
150        "GPBWrappers.pbobjc.m",
151    ],
152    target_compatible_with = select({
153        "@platforms//os:macos": [],
154        "@platforms//os:ios": [],
155        "@platforms//os:tvos": [],
156        "@platforms//os:watchos": [],
157        "//conditions:default": ["@platforms//:incompatible"],
158    }),
159    visibility = ["//visibility:public"],
160)
161
162################################################################################
163# Tests
164################################################################################
165
166conformance_test(
167    name = "conformance_test",
168    failure_list = "//conformance:failure_list_objc.txt",
169    maximum_edition = "2023",
170    target_compatible_with = ["@platforms//os:macos"],
171    testee = "//conformance:conformance_objc",
172)
173
174# -------------------------------------------------------------------
175# Current Version Check between Generator and Runtime Sources
176sh_test(
177    name = "check_version_stamps",
178    size = "small",
179    srcs = ["DevTools/check_version_stamps.sh"],
180    data = [
181        "GPBBootstrap.h",
182        "//src/google/protobuf/compiler/objectivec:file.cc",
183    ],
184)
185
186# -------------------------------------------------------------------
187# Validation of pddm expansion.
188
189py_binary(
190    name = "pddm",
191    srcs = ["DevTools/pddm.py"],
192)
193
194py_test(
195    name = "pddm_tests",
196    size = "small",
197    srcs = [
198        "DevTools/pddm.py",
199        "DevTools/pddm_tests.py",
200    ],
201)
202
203sh_test(
204    name = "sources_pddm_expansion_test",
205    size = "small",
206    srcs = ["DevTools/sources_pddm_expansion_test.sh"],
207    data = [":pddm"] + glob([
208        "**/*.h",
209        "**/*.m",
210        "**/*.pddm",
211    ]),
212)
213
214################################################################################
215# Distribution files
216################################################################################
217
218pkg_files(
219    name = "dist_files",
220    srcs = glob([
221        "*.h",
222        "*.m",
223        "**/*.h",
224        "**/*.m",
225        "**/*.mm",
226        "**/*.swift",
227        "DevTools/*.sh",
228        "DevTools/*.py",
229        "ProtocolBuffers_iOS.xcodeproj/**/*",
230        "ProtocolBuffers_OSX.xcodeproj/**/*",
231        "ProtocolBuffers_tvOS.xcodeproj/**/*",
232        "Tests/*.pddm",
233        "Tests/*.txt",
234        "Tests/*.plist",
235        "Tests/*.proto",
236    ]) + [
237        ".clang-format",
238        "BUILD.bazel",
239        "README.md",
240        "Tests/golden_message",
241        "Tests/golden_packed_fields_message",
242        "generate_well_known_types.sh",
243    ],
244    strip_prefix = strip_prefix.from_root(""),
245    visibility = ["//pkg:__pkg__"],
246)
247