mirror of https://github.com/bazelbuild/rules_cc
Merge branch 'master' into ad/readme
This commit is contained in:
commit
7849626f6e
|
@ -101,7 +101,7 @@ def cc_autoconf_impl(repository_ctx, overriden_tools = dict()):
|
|||
"@rules_cc//cc/private/toolchain:empty_cc_toolchain_config.bzl",
|
||||
])
|
||||
repository_ctx.symlink(paths["@rules_cc//cc/private/toolchain:empty_cc_toolchain_config.bzl"], "cc_toolchain_config.bzl")
|
||||
repository_ctx.symlink(paths("@rules_cc//cc/private/toolchain:BUILD.empty"), "BUILD")
|
||||
repository_ctx.symlink(paths["@rules_cc//cc/private/toolchain:BUILD.empty"], "BUILD")
|
||||
elif cpu_value == "freebsd":
|
||||
paths = resolve_labels(repository_ctx, [
|
||||
"@rules_cc//cc/private/toolchain:BUILD.static.freebsd",
|
||||
|
|
|
@ -223,14 +223,18 @@ def _cc_shared_library_impl(ctx):
|
|||
|
||||
linking_context = _create_linker_context(ctx, static_linker_inputs, dynamic_linker_inputs)
|
||||
|
||||
# TODO(plf): Decide whether ctx.attr.user_link_flags should come before or after options
|
||||
# added by the rule logic.
|
||||
user_link_flags = []
|
||||
additional_inputs = []
|
||||
if ctx.file.visibility_file != None:
|
||||
user_link_flags = [
|
||||
user_link_flags.append(
|
||||
"-Wl,--version-script=" + ctx.file.visibility_file.path,
|
||||
]
|
||||
)
|
||||
additional_inputs = [ctx.file.visibility_file]
|
||||
|
||||
user_link_flags.extend(ctx.attr.user_link_flags)
|
||||
|
||||
linking_outputs = cc_common.link(
|
||||
actions = ctx.actions,
|
||||
feature_configuration = feature_configuration,
|
||||
|
@ -278,7 +282,7 @@ def _graph_structure_aspect_impl(target, ctx):
|
|||
|
||||
linked_statically_by = []
|
||||
if hasattr(ctx.rule.attr, "linked_statically_by"):
|
||||
linked_statically_by = ctx.rule.attr.linked_statically_by
|
||||
linked_statically_by = [str(label) for label in ctx.rule.attr.linked_statically_by]
|
||||
|
||||
return [GraphNodeInfo(
|
||||
label = str(ctx.label),
|
||||
|
@ -296,6 +300,7 @@ cc_shared_library = rule(
|
|||
attrs = {
|
||||
"dynamic_deps": attr.label_list(providers = [CcSharedLibraryInfo]),
|
||||
"preloaded_deps": attr.label_list(providers = [CcInfo]),
|
||||
"user_link_flags": attr.string_list(),
|
||||
"visibility_file": attr.label(allow_single_file = True),
|
||||
"exports": attr.label_list(providers = [CcInfo], aspects = [graph_structure_aspect]),
|
||||
"_cc_toolchain": attr.label(default = "@bazel_tools//tools/cpp:current_cc_toolchain"),
|
||||
|
|
|
@ -1,6 +1,13 @@
|
|||
load("//cc:defs.bzl", "cc_binary", "cc_library")
|
||||
load("//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
|
||||
load("//examples:experimental_cc_shared_library.bzl", "cc_shared_library")
|
||||
|
||||
cc_test(
|
||||
name = "cc_test",
|
||||
srcs = ["main.cc"],
|
||||
dynamic_deps = ["foo_so"],
|
||||
deps = ["foo"],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "binary",
|
||||
srcs = ["main.cc"],
|
||||
|
@ -12,6 +19,7 @@ cc_shared_library(
|
|||
name = "foo_so",
|
||||
dynamic_deps = ["bar_so"],
|
||||
preloaded_deps = ["preloaded_dep"],
|
||||
user_link_flags = ["-Wl,-rpath,kittens"],
|
||||
visibility_file = "foo.lds",
|
||||
exports = [
|
||||
"foo",
|
||||
|
@ -121,6 +129,7 @@ sh_test(
|
|||
data = [
|
||||
":bar_so",
|
||||
":binary",
|
||||
":cc_test",
|
||||
":foo_so",
|
||||
],
|
||||
)
|
||||
|
|
|
@ -43,13 +43,33 @@ function test_shared_library_symbols() {
|
|||
check_symbol_absent "$symbols" "_Z4bar4v"
|
||||
}
|
||||
|
||||
function test_binary() {
|
||||
binary=$(find . -name binary)
|
||||
symbols=$(nm -D $binary)
|
||||
check_symbol_present "$symbols" "T _Z13preloaded_depv"
|
||||
check_symbol_present "$symbols" "U _Z3foov"
|
||||
$binary | (grep -q "hello 42" || (echo "Expected 'hello 42'" && exit 1))
|
||||
function test_shared_library_user_link_flags() {
|
||||
foo_so=$(find . -name libfoo_so.so)
|
||||
objdump -x $foo_so | grep RUNPATH | grep "kittens" > /dev/null \
|
||||
|| (echo "Expected to have RUNPATH contain 'kittens' (set by user_link_flags)" \
|
||||
&& exit 1)
|
||||
}
|
||||
|
||||
function do_test_binary() {
|
||||
symbols=$(nm -D $1)
|
||||
check_symbol_present "$symbols" "U _Z3foov"
|
||||
$1 | (grep -q "hello 42" || (echo "Expected 'hello 42'" && exit 1))
|
||||
}
|
||||
|
||||
function test_binary() {
|
||||
binary=$(find . -name binary)
|
||||
do_test_binary $binary
|
||||
check_symbol_present "$symbols" "T _Z13preloaded_depv"
|
||||
}
|
||||
|
||||
function test_cc_test() {
|
||||
cc_test=$(find . -name cc_test)
|
||||
do_test_binary $cc_test
|
||||
check_symbol_absent "$symbols" "_Z13preloaded_depv"
|
||||
ldd $cc_test | (grep -q "preloaded_Udep.so" || (echo "Expected '"preloaded_Udep.so"'" && exit 1))
|
||||
}
|
||||
|
||||
test_shared_library_user_link_flags
|
||||
test_shared_library_symbols
|
||||
test_binary
|
||||
test_cc_test
|
||||
|
|
Loading…
Reference in New Issue