Skip to content

Commit c2142c6

Browse files
buildbreaker2021keertk
authored andcommitted
Automated rollback of commit 9469d5a.
*** Reason for rollback *** Rollforward of bafc72e *** Original change description *** Fix cc_shared_library error with hdr-only libraries cc_libraries with a linker_input with no libraries (either because they contain only headers or only linkopts) caused errors in cc_shared_libraries triggered by a check that made sure that a cc_library wasn't linked more than once into different shared libraries. That check can be ignored in those cases. RELNOTES:none *** Fixes #19920 PiperOrigin-RevId: 583033207 Change-Id: I227021f33596dbc5a6708fa5a705803094f24665
1 parent 61fa933 commit c2142c6

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

src/main/starlark/builtins_bzl/common/cc/cc_shared_library.bzl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,11 @@ def _filter_inputs(
454454
_add_linker_input_to_dict(linker_input.owner, transitive_exports[owner])
455455
linker_inputs_count += 1
456456
elif owner in targets_to_be_linked_statically_map:
457+
if semantics.is_bazel and not linker_input.libraries:
458+
# TODO(bazel-team): semantics.should_create_empty_archive() should be
459+
# cleaned up and return False in every case. cc_libraries shouldn't
460+
# produce empty archives. For now issue #19920 is only fixed in Bazel.
461+
continue
457462
if owner in link_once_static_libs_map:
458463
# We are building a dictionary that will allow us to give
459464
# proper errors for libraries that have been linked multiple

src/main/starlark/builtins_bzl/common/cc/semantics.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,5 @@ semantics = struct(
193193
check_cc_shared_library_tags = _check_cc_shared_library_tags,
194194
BUILD_INFO_TRANLATOR_LABEL = "@bazel_tools//tools/build_defs/build_info:cc_build_info",
195195
CC_PROTO_TOOLCHAIN = "@rules_cc//cc/proto:toolchain_type",
196+
is_bazel = True,
196197
)

src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/BUILD.builtin_test

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ cc_library(
156156
"//conditions:default": [],
157157
}),
158158
deps = select({
159-
":is_bazel": ["qux2"],
159+
":is_bazel": ["qux2", "hdr_only"],
160160
"//conditions:default": [],
161161
}) + [
162162
"bar",
@@ -298,7 +298,7 @@ cc_library(
298298
deps = [
299299
"barX",
300300
] + select({
301-
":is_bazel": ["qux2"],
301+
":is_bazel": ["qux2", "hdr_only"],
302302
"//conditions:default": [],
303303
}),
304304
)
@@ -449,6 +449,17 @@ cc_library(
449449
srcs = [":private_cc_library.cc"]
450450
)
451451

452+
genrule(
453+
name = "hdr_only_hdr",
454+
outs = ["hdr_only_hdr.h"],
455+
cmd = "touch $@",
456+
)
457+
458+
cc_library(
459+
name = "hdr_only",
460+
hdrs = [":hdr_only_hdr"],
461+
)
462+
452463
build_failure_test(
453464
name = "two_dynamic_deps_same_export_in_so_test",
454465
message = "Two shared libraries in dependencies export the same symbols",

0 commit comments

Comments
 (0)