Skip to content

Commit c71cf12

Browse files
bmzhaotensorflower-gardener
authored andcommitted
Introduce aliasing behavior for tf_proto_library, such that foo_proto is now guaranteed to have cc_libraries foo_proto_cc_headers_only and foo_proto_cc_impl. The name foo_proto_cc aliases to either foo_proto_cc_headers_only or foo_proto_cc_impl depending on whether make_default_target_header_only is True.
This also fixes a bug where header only tf_proto_libraries did not declare dependencies on the header-only tf_proto_libraries that they depend on. This is needed as part of the Tensorflow Build Improvement RFC, described here: tensorflow/community#179 PiperOrigin-RevId: 282674607 Change-Id: I408ef6a9dd841d2c3779c7d526c4b83d75040b53
1 parent 222f243 commit c71cf12

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

tensorflow/core/platform/default/build_config.bzl

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,14 @@ def cc_proto_library(
165165
**kargs: other keyword arguments that are passed to cc_library.
166166
"""
167167

168+
wkt_deps = ["@com_google_protobuf//:cc_wkt_protos"]
169+
all_protolib_deps = protolib_deps + wkt_deps
170+
168171
includes = []
169172
if include != None:
170173
includes = [include]
171174
if protolib_name == None:
172175
protolib_name = name
173-
if not protolib_deps:
174-
protolib_deps = deps
175176

176177
if internal_bootstrap_hack:
177178
# For pre-checked-in generated files, we add the internal_bootstrap_hack
@@ -182,7 +183,7 @@ def cc_proto_library(
182183
includes = includes,
183184
protoc = protoc,
184185
visibility = ["//visibility:public"],
185-
deps = [s + "_genproto" for s in protolib_deps],
186+
deps = [s + "_genproto" for s in all_protolib_deps],
186187
)
187188

188189
# An empty cc_library to make rule dependency consistent.
@@ -214,7 +215,7 @@ def cc_proto_library(
214215
plugin_options = plugin_options,
215216
protoc = protoc,
216217
visibility = ["//visibility:public"],
217-
deps = [s + "_genproto" for s in protolib_deps],
218+
deps = [s + "_genproto" for s in all_protolib_deps],
218219
)
219220

220221
if use_grpc_plugin:
@@ -223,12 +224,22 @@ def cc_proto_library(
223224
"//conditions:default": ["//external:grpc_lib"],
224225
})
225226

227+
impl_name = name + "_impl"
228+
header_only_name = name + "_headers_only"
229+
header_only_deps = tf_deps(protolib_deps, "_cc_headers_only")
230+
226231
if make_default_target_header_only:
227-
header_only_name = name
228-
impl_name = name + "_impl"
232+
native.alias(
233+
name = name,
234+
actual = header_only_name,
235+
visibility = kargs["visibility"],
236+
)
229237
else:
230-
header_only_name = name + "_headers_only"
231-
impl_name = name
238+
native.alias(
239+
name = name,
240+
actual = impl_name,
241+
visibility = kargs["visibility"],
242+
)
232243

233244
native.cc_library(
234245
name = impl_name,
@@ -241,7 +252,9 @@ def cc_proto_library(
241252
)
242253
native.cc_library(
243254
name = header_only_name,
244-
deps = ["@com_google_protobuf//:protobuf_headers"] + if_static([impl_name]),
255+
deps = [
256+
"@com_google_protobuf//:protobuf_headers",
257+
] + header_only_deps + if_static([impl_name]),
245258
hdrs = gen_hdrs,
246259
**kargs
247260
)
@@ -385,6 +398,14 @@ def tf_proto_library_cc(
385398
testonly = testonly,
386399
visibility = visibility,
387400
)
401+
402+
native.alias(
403+
name = cc_name + "_headers_only",
404+
actual = cc_name,
405+
testonly = testonly,
406+
visibility = visibility,
407+
)
408+
388409
native.cc_library(
389410
name = cc_name,
390411
deps = cc_deps + ["@com_google_protobuf//:protobuf_headers"] + if_static([name + "_cc_impl"]),
@@ -418,7 +439,7 @@ def tf_proto_library_cc(
418439
use_grpc_namespace = use_grpc_namespace,
419440
visibility = visibility,
420441
deps = cc_deps + ["@com_google_protobuf//:cc_wkt_protos"],
421-
protolib_deps = protolib_deps + ["@com_google_protobuf//:cc_wkt_protos"],
442+
protolib_deps = protolib_deps,
422443
)
423444

424445
def tf_proto_library_py(

0 commit comments

Comments
 (0)