blob: d9e18ee1a5601ec2cb1e73ffd119dca0c12e9e86 [file] [log] [blame]
Yannic Bonenberger8b93b8e2020-07-08 17:21:38 +02001load("@rules_cc//cc:defs.bzl", "objc_library")
David L. Jonesd76f8c82022-04-22 16:58:16 -07002load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
Adam Cozzette7286ffc2023-09-12 13:06:39 -07003load("//upb/cmake:build_defs.bzl", "staleness_test")
Mike Kruskaled5c57a2022-08-10 22:51:29 -07004load("//conformance:defs.bzl", "conformance_test")
Protobuf Team Bote2aa06e2023-02-10 14:11:22 -08005load(":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#
Thomas Van Lenten17ee68a2023-05-03 13:48:06 -070010# 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.
Protobuf Team Bote2aa06e2023-02-10 14:11:22 -080013
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 ]),
Deanna Garciaf8a51422023-05-01 12:00:29 -070045 tags = ["manual"],
Adam Cozzette501ecec2023-09-26 14:36:20 -070046 tools = ["//:protoc"],
Protobuf Team Bote2aa06e2023-02-10 14:11:22 -080047)
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################################################################################
Yannic Bonenberger8b93b8e2020-07-08 17:21:38 +020059
60objc_library(
61 name = "objectivec",
62 hdrs = [
Thomas Van Lenten17ee68a2023-05-03 13:48:06 -070063 "GPBAny.pbobjc.h",
64 "GPBApi.pbobjc.h",
65 "GPBDuration.pbobjc.h",
66 "GPBEmpty.pbobjc.h",
67 "GPBFieldMask.pbobjc.h",
68 "GPBSourceContext.pbobjc.h",
69 "GPBStruct.pbobjc.h",
70 "GPBTimestamp.pbobjc.h",
71 "GPBType.pbobjc.h",
72 "GPBWrappers.pbobjc.h",
Yannic Bonenberger8b93b8e2020-07-08 17:21:38 +020073 "GPBArray.h",
74 "GPBBootstrap.h",
75 "GPBCodedInputStream.h",
76 "GPBCodedOutputStream.h",
77 "GPBDescriptor.h",
78 "GPBDictionary.h",
79 "GPBExtensionInternals.h",
80 "GPBExtensionRegistry.h",
81 "GPBMessage.h",
82 "GPBProtocolBuffers.h",
83 "GPBProtocolBuffers_RuntimeSupport.h",
84 "GPBRootObject.h",
85 "GPBRuntimeTypes.h",
86 "GPBUnknownField.h",
87 "GPBUnknownFieldSet.h",
88 "GPBUtilities.h",
89 "GPBWellKnownTypes.h",
90 "GPBWireFormat.h",
91 "google/protobuf/Any.pbobjc.h",
92 "google/protobuf/Api.pbobjc.h",
93 "google/protobuf/Duration.pbobjc.h",
94 "google/protobuf/Empty.pbobjc.h",
95 "google/protobuf/FieldMask.pbobjc.h",
96 "google/protobuf/SourceContext.pbobjc.h",
97 "google/protobuf/Struct.pbobjc.h",
98 "google/protobuf/Timestamp.pbobjc.h",
99 "google/protobuf/Type.pbobjc.h",
100 "google/protobuf/Wrappers.pbobjc.h",
101 # Package private headers, but exposed because the generated sources
102 # need to use them.
103 "GPBArray_PackagePrivate.h",
104 "GPBCodedInputStream_PackagePrivate.h",
105 "GPBCodedOutputStream_PackagePrivate.h",
106 "GPBDescriptor_PackagePrivate.h",
107 "GPBDictionary_PackagePrivate.h",
108 "GPBMessage_PackagePrivate.h",
109 "GPBRootObject_PackagePrivate.h",
110 "GPBUnknownFieldSet_PackagePrivate.h",
111 "GPBUnknownField_PackagePrivate.h",
112 "GPBUtilities_PackagePrivate.h",
Thomas Van Lenten17ee68a2023-05-03 13:48:06 -0700113 ],
Yannic Bonenberger8b93b8e2020-07-08 17:21:38 +0200114 copts = [
115 "-Wno-vla",
116 ],
117 includes = [
118 ".",
119 ],
120 non_arc_srcs = [
Thomas Van Lenten17ee68a2023-05-03 13:48:06 -0700121 "GPBAny.pbobjc.m",
122 "GPBApi.pbobjc.m",
Yannic Bonenberger8b93b8e2020-07-08 17:21:38 +0200123 "GPBArray.m",
124 "GPBCodedInputStream.m",
125 "GPBCodedOutputStream.m",
126 "GPBDescriptor.m",
127 "GPBDictionary.m",
Thomas Van Lenten17ee68a2023-05-03 13:48:06 -0700128 "GPBDuration.pbobjc.m",
129 "GPBEmpty.pbobjc.m",
Yannic Bonenberger8b93b8e2020-07-08 17:21:38 +0200130 "GPBExtensionInternals.m",
131 "GPBExtensionRegistry.m",
Thomas Van Lenten17ee68a2023-05-03 13:48:06 -0700132 "GPBFieldMask.pbobjc.m",
Yannic Bonenberger8b93b8e2020-07-08 17:21:38 +0200133 "GPBMessage.m",
134 "GPBRootObject.m",
Thomas Van Lenten17ee68a2023-05-03 13:48:06 -0700135 "GPBSourceContext.pbobjc.m",
136 "GPBStruct.pbobjc.m",
137 "GPBTimestamp.pbobjc.m",
138 "GPBType.pbobjc.m",
Yannic Bonenberger8b93b8e2020-07-08 17:21:38 +0200139 "GPBUnknownField.m",
140 "GPBUnknownFieldSet.m",
141 "GPBUtilities.m",
142 "GPBWellKnownTypes.m",
143 "GPBWireFormat.m",
Thomas Van Lenten17ee68a2023-05-03 13:48:06 -0700144 "GPBWrappers.pbobjc.m",
145 ],
Protobuf Team Botb977cf52023-02-09 12:02:43 -0800146 target_compatible_with = select({
147 "@platforms//os:macos": [],
148 "@platforms//os:ios": [],
149 "@platforms//os:tvos": [],
150 "@platforms//os:watchos": [],
151 "//conditions:default": ["@platforms//:incompatible"],
152 }),
Yannic Bonenberger8b93b8e2020-07-08 17:21:38 +0200153 visibility = ["//visibility:public"],
154)
David L. Jonesd76f8c82022-04-22 16:58:16 -0700155
Mike Kruskaled5c57a2022-08-10 22:51:29 -0700156################################################################################
157# Tests
158################################################################################
159
160conformance_test(
161 name = "conformance_test",
162 failure_list = "//conformance:failure_list_objc.txt",
Thomas Van Lenten6c7c5a52023-12-12 14:03:01 -0800163 maximum_edition = "2023",
Protobuf Team Botb977cf52023-02-09 12:02:43 -0800164 target_compatible_with = ["@platforms//os:macos"],
Protobuf Team Bota2c5ea62023-02-13 10:09:00 -0800165 testee = "//conformance:conformance_objc",
Mike Kruskaled5c57a2022-08-10 22:51:29 -0700166)
167
Protobuf Team Bot2fed1e32023-02-09 11:28:29 -0800168# -------------------------------------------------------------------
169# Current Version Check between Generator and Runtime Sources
170sh_test(
171 name = "check_version_stamps",
172 size = "small",
173 srcs = ["DevTools/check_version_stamps.sh"],
174 data = [
175 "GPBBootstrap.h",
176 "//src/google/protobuf/compiler/objectivec:file.cc",
177 ],
178)
179
Protobuf Team Bot26dae8d2023-02-09 14:10:41 -0800180# -------------------------------------------------------------------
181# Validation of pddm expansion.
182
183py_binary(
184 name = "pddm",
185 srcs = ["DevTools/pddm.py"],
186)
187
188py_test(
189 name = "pddm_tests",
190 size = "small",
191 srcs = [
192 "DevTools/pddm.py",
193 "DevTools/pddm_tests.py",
194 ],
195)
196
197sh_test(
198 name = "sources_pddm_expansion_test",
199 size = "small",
200 srcs = ["DevTools/sources_pddm_expansion_test.sh"],
201 data = [":pddm"] + glob([
202 "**/*.h",
203 "**/*.m",
204 "**/*.pddm",
205 ]),
206)
207
Mike Kruskaled5c57a2022-08-10 22:51:29 -0700208################################################################################
209# Distribution files
210################################################################################
211
David L. Jonesd76f8c82022-04-22 16:58:16 -0700212pkg_files(
213 name = "dist_files",
214 srcs = glob([
215 "*.h",
216 "*.m",
217 "**/*.h",
218 "**/*.m",
219 "**/*.mm",
220 "**/*.swift",
221 "DevTools/*.sh",
222 "DevTools/*.py",
223 "ProtocolBuffers_iOS.xcodeproj/**/*",
224 "ProtocolBuffers_OSX.xcodeproj/**/*",
225 "ProtocolBuffers_tvOS.xcodeproj/**/*",
David L. Jonesd76f8c82022-04-22 16:58:16 -0700226 "Tests/*.pddm",
227 "Tests/*.txt",
228 "Tests/*.plist",
229 "Tests/*.proto",
230 ]) + [
231 ".clang-format",
David L. Jones95da0ba2022-04-29 17:57:55 -0700232 "BUILD.bazel",
David L. Jonesd76f8c82022-04-22 16:58:16 -0700233 "README.md",
234 "Tests/golden_message",
235 "Tests/golden_packed_fields_message",
236 "generate_well_known_types.sh",
237 ],
238 strip_prefix = strip_prefix.from_root(""),
239 visibility = ["//pkg:__pkg__"],
240)