From e79de51b91263b33ced77f0a749a1856972510d1 Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 7 Mar 2023 07:30:30 -0800 Subject: [PATCH] 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 --- .../cc/experimental_cc_shared_library.bzl | 21 +------- .../test_cc_shared_library/BUILD.builtin_test | 51 ------------------- .../test_cc_shared_library/starlark_tests.bzl | 18 ------- 3 files changed, 1 insertion(+), 89 deletions(-) diff --git a/src/main/starlark/builtins_bzl/common/cc/experimental_cc_shared_library.bzl b/src/main/starlark/builtins_bzl/common/cc/experimental_cc_shared_library.bzl index 28018e561ebacb..b06d341a606709 100644 --- a/src/main/starlark/builtins_bzl/common/cc/experimental_cc_shared_library.bzl +++ b/src/main/starlark/builtins_bzl/common/cc/experimental_cc_shared_library.bzl @@ -33,22 +33,12 @@ load(":common/cc/cc_common.bzl", "cc_common") # used sparingly after making sure it's safe to use. LINKABLE_MORE_THAN_ONCE = "LINKABLE_MORE_THAN_ONCE" -# Add this as a tag to any static lib target that doesn't export any symbols, -# thus can be statically linked more than once. This is useful in some cases, -# for example, a static lib has a constructor that needs to be run during -# loading time of the shared lib that has it linked into, which is how the -# code gets called by the OS. This static lib might need to be linked as a -# whole archive dep for multiple shared libs, otherwise this static lib will -# be dropped by the linker since there are no incoming symbol references. -NO_EXPORTING = "NO_EXPORTING" - GraphNodeInfo = provider( "Nodes in the graph of shared libraries.", fields = { "children": "Other GraphNodeInfo from dependencies of this target", "label": "Label of the target visited", "linkable_more_than_once": "Linkable into more than a single cc_shared_library", - "no_exporting": "The static lib doesn't export any symbols so don't export it", }, ) CcSharedLibraryInfo = provider( @@ -504,12 +494,7 @@ def _cc_shared_library_impl(ctx): runfiles = runfiles.merge(ctx.runfiles(files = precompiled_only_dynamic_libraries_runfiles)) for export in deps: - export_label = str(export.label) - if GraphNodeInfo in export and export[GraphNodeInfo].no_exporting: - if export_label in curr_link_once_static_libs_set: - curr_link_once_static_libs_set.remove(export_label) - continue - exports[export_label] = True + exports[str(export.label)] = True debug_files = [] exports_debug_file = ctx.actions.declare_file(ctx.label.name + "_exports.txt") @@ -577,19 +562,15 @@ def _graph_structure_aspect_impl(target, ctx): # TODO(bazel-team): Add flag to Bazel that can toggle the initialization of # linkable_more_than_once. linkable_more_than_once = False - no_exporting = False if hasattr(ctx.rule.attr, "tags"): for tag in ctx.rule.attr.tags: if tag == LINKABLE_MORE_THAN_ONCE: linkable_more_than_once = True - elif tag == NO_EXPORTING: - no_exporting = True return [GraphNodeInfo( label = ctx.label, children = children, linkable_more_than_once = linkable_more_than_once, - no_exporting = no_exporting, )] graph_structure_aspect = aspect( diff --git a/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/BUILD.builtin_test b/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/BUILD.builtin_test index d1d12ae87dea8b..4dd8bc4c266aa3 100644 --- a/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/BUILD.builtin_test +++ b/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/BUILD.builtin_test @@ -7,7 +7,6 @@ load( "linking_suffix_test", "paths_test", "runfiles_test", - "no_exporting_static_lib_test", "check_already_linked_inputs_are_not_passed_to_linking_action_test", ) @@ -386,51 +385,6 @@ cc_library( ], ) -cc_library( - name = "static_lib_no_exporting", - srcs = [ - "bar.cc", - "bar.h", - ], - tags = ["NO_EXPORTING"], -) - -cc_library( - name = "static_lib_exporting", - srcs = [ - "bar2.cc", - "bar2.h", - ], -) - -cc_shared_library( - name = "lib_with_no_exporting_roots_1", - deps = [":static_lib_no_exporting"], -) - -cc_shared_library( - name = "lib_with_no_exporting_roots_2", - deps = [":static_lib_no_exporting"], - dynamic_deps = [":lib_with_no_exporting_roots_3"], -) - -cc_shared_library( - name = "lib_with_no_exporting_roots_3", - deps = [":static_lib_no_exporting"], -) - -cc_shared_library( - name = "lib_with_no_exporting_roots", - deps = [ - ":static_lib_no_exporting", - ":static_lib_exporting", - ], - dynamic_deps = [ - ":lib_with_no_exporting_roots_1", - ":lib_with_no_exporting_roots_2", - ], -) - build_failure_test( name = "two_dynamic_deps_same_export_in_so_test", message = "Two shared libraries in dependencies export the same symbols", @@ -466,11 +420,6 @@ runfiles_test( target_under_test = ":python_test", ) -no_exporting_static_lib_test( - name = "no_exporting_static_lib_test", - target_under_test = ":lib_with_no_exporting_roots", -) - check_already_linked_inputs_are_not_passed_to_linking_action_test( name = "check_binary_doesnt_take_already_linked_in_libs", target_under_test = ":binary", diff --git a/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/starlark_tests.bzl b/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/starlark_tests.bzl index 678c03bba188e4..8732cea67f1932 100644 --- a/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/starlark_tests.bzl +++ b/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/starlark_tests.bzl @@ -246,21 +246,3 @@ check_already_linked_inputs_are_not_passed_to_linking_action_test = analysistest "libs_that_shouldnt_be_present": attr.string_list(), }, ) - -def _no_exporting_static_lib_test_impl(ctx): - env = analysistest.begin(ctx) - - target_under_test = analysistest.target_under_test(env) - - # There should be only one exported file - actual_file = target_under_test[CcSharedLibraryInfo].exports[0] - - # Sometimes "@" is prefixed in some test environments - expected = "//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:static_lib_exporting" - asserts.true(env, actual_file.endswith(expected)) - - return analysistest.end(env) - -no_exporting_static_lib_test = analysistest.make( - _no_exporting_static_lib_test_impl, -)