Skip to content

Commit 3b7e233

Browse files
oquenchilcopybara-github
authored andcommitted
Remove preloaded_deps attribute from cc_shared_library
This attribute came out of the design doc for cc_shared_library for a use case that hasn't materialized. Adding this attribute later would be a compatible change. If/when a use case does materialize we can easily add it back and fix any problems with it then. From a search across many different repositories, it looks like no one has ever used the attribute. RELNOTES:none PiperOrigin-RevId: 510419035 Change-Id: I569d631ad78a78312e348913325438aa7f0256dc
1 parent 5013103 commit 3b7e233

File tree

7 files changed

+5
-91
lines changed

7 files changed

+5
-91
lines changed

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

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"""cc_binary Starlark implementation replacing native"""
1616

1717
load(":common/cc/semantics.bzl", "semantics")
18-
load(":common/cc/experimental_cc_shared_library.bzl", "CcSharedLibraryInfo", "GraphNodeInfo", "build_exports_map_from_only_dynamic_deps", "build_link_once_static_libs_map", "merge_cc_shared_library_infos", "throw_linked_but_not_exported_errors")
18+
load(":common/cc/experimental_cc_shared_library.bzl", "GraphNodeInfo", "build_exports_map_from_only_dynamic_deps", "build_link_once_static_libs_map", "merge_cc_shared_library_infos", "throw_linked_but_not_exported_errors")
1919
load(":common/cc/cc_helper.bzl", "cc_helper", "linker_mode")
2020
load(":common/cc/cc_info.bzl", "CcInfo")
2121

@@ -352,19 +352,8 @@ def _separate_static_and_dynamic_link_libraries(direct_children, can_be_linked_d
352352
all_children.extend(node.children)
353353
return (link_statically_labels, link_dynamically_labels)
354354

355-
def _get_preloaded_deps_from_dynamic_deps(ctx):
356-
cc_infos = []
357-
for dep in ctx.attr.dynamic_deps:
358-
cc_shared_library_info = dep[CcSharedLibraryInfo]
359-
preloaded_deps_field = cc_shared_library_info.preloaded_deps
360-
if preloaded_deps_field != None:
361-
cc_infos.append(preloaded_deps_field)
362-
363-
return cc_common.merge_cc_infos(direct_cc_infos = cc_infos, cc_infos = cc_infos).linking_context.linker_inputs.to_list()
364-
365355
def _filter_libraries_that_are_linked_dynamically(ctx, cc_linking_context, cpp_config):
366356
merged_cc_shared_library_infos = merge_cc_shared_library_infos(ctx)
367-
preloaded_deps = _get_preloaded_deps_from_dynamic_deps(ctx)
368357
link_once_static_libs_map = build_link_once_static_libs_map(merged_cc_shared_library_infos)
369358
exports_map = build_exports_map_from_only_dynamic_deps(merged_cc_shared_library_infos)
370359
static_linker_inputs = []
@@ -400,16 +389,15 @@ def _filter_libraries_that_are_linked_dynamically(ctx, cc_linking_context, cpp_c
400389
rule_impl_debug_files = None
401390
if cpp_config.experimental_cc_shared_library_debug():
402391
debug_linker_inputs_file = ["Owner: " + str(ctx.label)]
403-
static_linker_inputs_and_preloaded_deps = static_linker_inputs + preloaded_deps
404-
for linker_input in static_linker_inputs_and_preloaded_deps:
392+
for linker_input in static_linker_inputs:
405393
debug_linker_inputs_file.append(str(linker_input.owner))
406394
link_once_static_libs_debug_file = ctx.actions.declare_file(ctx.label.name + "_link_once_static_libs.txt")
407395
ctx.actions.write(link_once_static_libs_debug_file, "\n".join(debug_linker_inputs_file), False)
408396
transitive_debug_files_list = []
409397
for dep in ctx.attr.dynamic_deps:
410398
transitive_debug_files_list.append(dep[OutputGroupInfo].rule_impl_debug_files)
411399
rule_impl_debug_files = depset([link_once_static_libs_debug_file], transitive = transitive_debug_files_list)
412-
return (cc_common.create_linking_context(linker_inputs = depset(exports_map.values() + static_linker_inputs + preloaded_deps, order = "topological")), rule_impl_debug_files)
400+
return (cc_common.create_linking_context(linker_inputs = depset(exports_map.values() + static_linker_inputs, order = "topological")), rule_impl_debug_files)
413401

414402
def _create_transitive_linking_actions(
415403
ctx,

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

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,14 @@ CcSharedLibraryInfo = provider(
6868
"initializers. If we try to link them more than once, " +
6969
"we will throw an error",
7070
"linker_input": "the resulting linker input artifact for the shared library",
71-
"preloaded_deps": "cc_libraries needed by this cc_shared_library that should" +
72-
" be linked the binary. If this is set, this cc_shared_library has to " +
73-
" be a direct dependency of the cc_binary",
7471
},
7572
)
7673

7774
# For each target, find out whether it should be linked statically or
7875
# dynamically.
7976
def _separate_static_and_dynamic_link_libraries(
8077
direct_children,
81-
can_be_linked_dynamically,
82-
preloaded_deps_direct_labels):
78+
can_be_linked_dynamically):
8379
node = None
8480
all_children = list(direct_children)
8581
targets_to_be_linked_statically_map = {}
@@ -101,7 +97,7 @@ def _separate_static_and_dynamic_link_libraries(
10197

10298
if node_label in can_be_linked_dynamically:
10399
targets_to_be_linked_dynamically_set[node_label] = True
104-
elif node_label not in preloaded_deps_direct_labels:
100+
else:
105101
targets_to_be_linked_statically_map[node_label] = node.linkable_more_than_once
106102
all_children.extend(node.children)
107103

@@ -116,11 +112,6 @@ def _merge_cc_shared_library_infos(ctx):
116112
dynamic_deps = []
117113
transitive_dynamic_deps = []
118114
for dep in ctx.attr.dynamic_deps:
119-
# This error is not relevant for cc_binary.
120-
if not hasattr(ctx.attr, "_cc_binary") and dep[CcSharedLibraryInfo].preloaded_deps != None:
121-
fail("{} can only be a direct dependency of a " +
122-
" cc_binary because it has " +
123-
"preloaded_deps".format(str(dep.label)))
124115
dynamic_dep_entry = (
125116
dep[CcSharedLibraryInfo].exports,
126117
dep[CcSharedLibraryInfo].linker_input,
@@ -254,7 +245,6 @@ def _filter_inputs(
254245
cc_toolchain,
255246
deps,
256247
transitive_exports,
257-
preloaded_deps_direct_labels,
258248
link_once_static_libs_map):
259249
linker_inputs = []
260250
curr_link_once_static_libs_set = {}
@@ -278,7 +268,6 @@ def _filter_inputs(
278268
(targets_to_be_linked_statically_map, targets_to_be_linked_dynamically_set) = _separate_static_and_dynamic_link_libraries(
279269
graph_structure_aspect_nodes,
280270
can_be_linked_dynamically,
281-
preloaded_deps_direct_labels,
282271
)
283272

284273
# We keep track of precompiled_only_dynamic_libraries, so that we can add
@@ -473,16 +462,6 @@ def _cc_shared_library_impl(ctx):
473462

474463
_check_if_target_should_be_exported_without_filter(export.label, ctx.label, _get_permissions(ctx))
475464

476-
preloaded_deps_direct_labels = {}
477-
preloaded_dep_merged_cc_info = None
478-
if len(ctx.attr.preloaded_deps) != 0:
479-
preloaded_deps_cc_infos = []
480-
for preloaded_dep in ctx.attr.preloaded_deps:
481-
preloaded_deps_direct_labels[str(preloaded_dep.label)] = True
482-
preloaded_deps_cc_infos.append(preloaded_dep[CcInfo])
483-
484-
preloaded_dep_merged_cc_info = cc_common.merge_cc_infos(cc_infos = preloaded_deps_cc_infos)
485-
486465
link_once_static_libs_map = _build_link_once_static_libs_map(merged_cc_shared_library_info)
487466

488467
(exports, linker_inputs, curr_link_once_static_libs_set, precompiled_only_dynamic_libraries) = _filter_inputs(
@@ -491,7 +470,6 @@ def _cc_shared_library_impl(ctx):
491470
cc_toolchain,
492471
deps,
493472
exports_map,
494-
preloaded_deps_direct_labels,
495473
link_once_static_libs_map,
496474
)
497475

@@ -620,7 +598,6 @@ def _cc_shared_library_impl(ctx):
620598
owner = ctx.label,
621599
libraries = depset([linking_outputs.library_to_link] + precompiled_only_dynamic_libraries),
622600
),
623-
preloaded_deps = preloaded_dep_merged_cc_info,
624601
),
625602
]
626603

@@ -692,7 +669,6 @@ cc_shared_library = rule(
692669
"dynamic_deps": attr.label_list(providers = [CcSharedLibraryInfo]),
693670
"exports_filter": attr.string_list(),
694671
"permissions": attr.label_list(providers = [CcSharedLibraryPermissionsInfo]),
695-
"preloaded_deps": attr.label_list(providers = [CcInfo]),
696672
"win_def_file": attr.label(allow_single_file = [".def"]),
697673
"roots": attr.label_list(providers = [CcInfo], aspects = [graph_structure_aspect]),
698674
"deps": attr.label_list(providers = [CcInfo], aspects = [graph_structure_aspect]),

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ cc_shared_library(
109109
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library3:diff_pkg_so"
110110
],
111111
features = ["windows_export_all_symbols"],
112-
preloaded_deps = ["preloaded_dep"],
113112
deps = [
114113
"baz",
115114
"foo",
@@ -125,12 +124,6 @@ cc_shared_library(
125124
}),
126125
)
127126

128-
cc_library(
129-
name = "preloaded_dep",
130-
srcs = ["preloaded_dep.cc"],
131-
hdrs = ["preloaded_dep.h"],
132-
)
133-
134127
cc_library(
135128
name = "foo",
136129
srcs = [
@@ -146,7 +139,6 @@ cc_library(
146139
"//conditions:default": [],
147140
}),
148141
deps = [
149-
"preloaded_dep",
150142
"bar",
151143
"baz",
152144
# Not exported.

src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/cc_shared_library_integration_test.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ function test_shared_library_symbols() {
4242
check_symbol_present "$symbols" "U _Z3barv"
4343
check_symbol_present "$symbols" "T _Z3bazv"
4444
check_symbol_present "$symbols" "T _Z3foov"
45-
# Check that the preloaded dep symbol is not present
46-
check_symbol_present "$symbols" "U _Z13preloaded_depv"
4745

4846
check_symbol_absent "$symbols" "_Z3quxv"
4947
check_symbol_absent "$symbols" "_Z4bar3v"
@@ -66,14 +64,11 @@ function do_test_binary() {
6664
function test_binary() {
6765
binary=$(find . -name binary)
6866
do_test_binary $binary
69-
check_symbol_present "$symbols" "T _Z13preloaded_depv"
7067
}
7168

7269
function test_cc_test() {
7370
cc_test=$(find . -name cc_test)
7471
do_test_binary $cc_test
75-
check_symbol_absent "$symbols" "_Z13preloaded_depv"
76-
$LDD_BINARY $cc_test | (grep -q "preloaded_Udep.so" || (echo "Expected '"preloaded_Udep.so"'" && exit 1))
7772
}
7873

7974
test_shared_library_user_link_flags

src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/foo.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/baz.h"
1616
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/direct_so_file_cc_lib.h"
1717
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/direct_so_file_cc_lib2.h"
18-
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/preloaded_dep.h"
1918
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/qux.h"
2019
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library3/diff_pkg.h"
2120

@@ -27,7 +26,6 @@ int foo() {
2726
#ifdef IS_LINUX
2827
direct_so_file_cc_lib();
2928
direct_so_file_cc_lib2();
30-
preloaded_dep();
3129
#endif
3230
return 42;
3331
}

src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/preloaded_dep.cc

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/preloaded_dep.h

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)