Skip to content

Commit

Permalink
[7.0.0] Fix cc_shared_library error with hdr-only libraries (#20228)
Browse files Browse the repository at this point in the history
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
Commit
886b13f

PiperOrigin-RevId: 583033207
Change-Id: I227021f33596dbc5a6708fa5a705803094f24665

Co-authored-by: Googler <[email protected]>
  • Loading branch information
keertk and buildbreaker2021 authored Nov 16, 2023
1 parent 6eb3a12 commit 8c4b1c9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,11 @@ def _filter_inputs(
_add_linker_input_to_dict(linker_input.owner, transitive_exports[owner])
linker_inputs_count += 1
elif owner in targets_to_be_linked_statically_map:
if semantics.is_bazel and not linker_input.libraries:
# TODO(bazel-team): semantics.should_create_empty_archive() should be
# cleaned up and return False in every case. cc_libraries shouldn't
# produce empty archives. For now issue #19920 is only fixed in Bazel.
continue
if owner in link_once_static_libs_map:
# We are building a dictionary that will allow us to give
# proper errors for libraries that have been linked multiple
Expand Down
1 change: 1 addition & 0 deletions src/main/starlark/builtins_bzl/common/cc/semantics.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,5 @@ semantics = struct(
check_cc_shared_library_tags = _check_cc_shared_library_tags,
BUILD_INFO_TRANLATOR_LABEL = "@bazel_tools//tools/build_defs/build_info:cc_build_info",
CC_PROTO_TOOLCHAIN = "@rules_cc//cc/proto:toolchain_type",
is_bazel = True,
)
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ cc_library(
"//conditions:default": [],
}),
deps = select({
":is_bazel": ["qux2"],
":is_bazel": ["qux2", "hdr_only"],
"//conditions:default": [],
}) + [
"bar",
Expand Down Expand Up @@ -298,7 +298,7 @@ cc_library(
deps = [
"barX",
] + select({
":is_bazel": ["qux2"],
":is_bazel": ["qux2", "hdr_only"],
"//conditions:default": [],
}),
)
Expand Down Expand Up @@ -449,6 +449,17 @@ cc_library(
srcs = [":private_cc_library.cc"]
)

genrule(
name = "hdr_only_hdr",
outs = ["hdr_only_hdr.h"],
cmd = "touch $@",
)

cc_library(
name = "hdr_only",
hdrs = [":hdr_only_hdr"],
)

build_failure_test(
name = "two_dynamic_deps_same_export_in_so_test",
message = "Two shared libraries in dependencies export the same symbols",
Expand Down

0 comments on commit 8c4b1c9

Please sign in to comment.