Skip to content

Commit e79de51

Browse files
oquenchilcopybara-github
authored andcommitted
Remove NO_EXPORTING tag from cc_shared_library
The same behavior can be achieved via an indirect cc_library (i.e. not placed in cc_shared_library.deps) that is LINKABLE_MORE_THAN_ONCE RELNOTES:none PiperOrigin-RevId: 514727112 Change-Id: Ic5053f7b534d3bd69b4c61639b299936dc9990eb
1 parent f785f28 commit e79de51

File tree

3 files changed

+1
-89
lines changed

3 files changed

+1
-89
lines changed

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

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,12 @@ load(":common/cc/cc_common.bzl", "cc_common")
3333
# used sparingly after making sure it's safe to use.
3434
LINKABLE_MORE_THAN_ONCE = "LINKABLE_MORE_THAN_ONCE"
3535

36-
# Add this as a tag to any static lib target that doesn't export any symbols,
37-
# thus can be statically linked more than once. This is useful in some cases,
38-
# for example, a static lib has a constructor that needs to be run during
39-
# loading time of the shared lib that has it linked into, which is how the
40-
# code gets called by the OS. This static lib might need to be linked as a
41-
# whole archive dep for multiple shared libs, otherwise this static lib will
42-
# be dropped by the linker since there are no incoming symbol references.
43-
NO_EXPORTING = "NO_EXPORTING"
44-
4536
GraphNodeInfo = provider(
4637
"Nodes in the graph of shared libraries.",
4738
fields = {
4839
"children": "Other GraphNodeInfo from dependencies of this target",
4940
"label": "Label of the target visited",
5041
"linkable_more_than_once": "Linkable into more than a single cc_shared_library",
51-
"no_exporting": "The static lib doesn't export any symbols so don't export it",
5242
},
5343
)
5444
CcSharedLibraryInfo = provider(
@@ -504,12 +494,7 @@ def _cc_shared_library_impl(ctx):
504494
runfiles = runfiles.merge(ctx.runfiles(files = precompiled_only_dynamic_libraries_runfiles))
505495

506496
for export in deps:
507-
export_label = str(export.label)
508-
if GraphNodeInfo in export and export[GraphNodeInfo].no_exporting:
509-
if export_label in curr_link_once_static_libs_set:
510-
curr_link_once_static_libs_set.remove(export_label)
511-
continue
512-
exports[export_label] = True
497+
exports[str(export.label)] = True
513498

514499
debug_files = []
515500
exports_debug_file = ctx.actions.declare_file(ctx.label.name + "_exports.txt")
@@ -577,19 +562,15 @@ def _graph_structure_aspect_impl(target, ctx):
577562
# TODO(bazel-team): Add flag to Bazel that can toggle the initialization of
578563
# linkable_more_than_once.
579564
linkable_more_than_once = False
580-
no_exporting = False
581565
if hasattr(ctx.rule.attr, "tags"):
582566
for tag in ctx.rule.attr.tags:
583567
if tag == LINKABLE_MORE_THAN_ONCE:
584568
linkable_more_than_once = True
585-
elif tag == NO_EXPORTING:
586-
no_exporting = True
587569

588570
return [GraphNodeInfo(
589571
label = ctx.label,
590572
children = children,
591573
linkable_more_than_once = linkable_more_than_once,
592-
no_exporting = no_exporting,
593574
)]
594575

595576
graph_structure_aspect = aspect(

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

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ load(
77
"linking_suffix_test",
88
"paths_test",
99
"runfiles_test",
10-
"no_exporting_static_lib_test",
1110
"check_already_linked_inputs_are_not_passed_to_linking_action_test",
1211
)
1312

@@ -386,51 +385,6 @@ cc_library(
386385
],
387386
)
388387

389-
cc_library(
390-
name = "static_lib_no_exporting",
391-
srcs = [
392-
"bar.cc",
393-
"bar.h",
394-
],
395-
tags = ["NO_EXPORTING"],
396-
)
397-
398-
cc_library(
399-
name = "static_lib_exporting",
400-
srcs = [
401-
"bar2.cc",
402-
"bar2.h",
403-
],
404-
)
405-
406-
cc_shared_library(
407-
name = "lib_with_no_exporting_roots_1",
408-
deps = [":static_lib_no_exporting"],
409-
)
410-
411-
cc_shared_library(
412-
name = "lib_with_no_exporting_roots_2",
413-
deps = [":static_lib_no_exporting"],
414-
dynamic_deps = [":lib_with_no_exporting_roots_3"],
415-
)
416-
417-
cc_shared_library(
418-
name = "lib_with_no_exporting_roots_3",
419-
deps = [":static_lib_no_exporting"],
420-
)
421-
422-
cc_shared_library(
423-
name = "lib_with_no_exporting_roots",
424-
deps = [
425-
":static_lib_no_exporting",
426-
":static_lib_exporting",
427-
],
428-
dynamic_deps = [
429-
":lib_with_no_exporting_roots_1",
430-
":lib_with_no_exporting_roots_2",
431-
],
432-
)
433-
434388
build_failure_test(
435389
name = "two_dynamic_deps_same_export_in_so_test",
436390
message = "Two shared libraries in dependencies export the same symbols",
@@ -466,11 +420,6 @@ runfiles_test(
466420
target_under_test = ":python_test",
467421
)
468422

469-
no_exporting_static_lib_test(
470-
name = "no_exporting_static_lib_test",
471-
target_under_test = ":lib_with_no_exporting_roots",
472-
)
473-
474423
check_already_linked_inputs_are_not_passed_to_linking_action_test(
475424
name = "check_binary_doesnt_take_already_linked_in_libs",
476425
target_under_test = ":binary",

src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/starlark_tests.bzl

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -246,21 +246,3 @@ check_already_linked_inputs_are_not_passed_to_linking_action_test = analysistest
246246
"libs_that_shouldnt_be_present": attr.string_list(),
247247
},
248248
)
249-
250-
def _no_exporting_static_lib_test_impl(ctx):
251-
env = analysistest.begin(ctx)
252-
253-
target_under_test = analysistest.target_under_test(env)
254-
255-
# There should be only one exported file
256-
actual_file = target_under_test[CcSharedLibraryInfo].exports[0]
257-
258-
# Sometimes "@" is prefixed in some test environments
259-
expected = "//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:static_lib_exporting"
260-
asserts.true(env, actual_file.endswith(expected))
261-
262-
return analysistest.end(env)
263-
264-
no_exporting_static_lib_test = analysistest.make(
265-
_no_exporting_static_lib_test_impl,
266-
)

0 commit comments

Comments
 (0)