mirror of https://github.com/bazelbuild/rules_cc
C++: Tests for cc_binary linking shared libraries
This is guarded behind the --experimental_cc_shared_library flag PiperOrigin-RevId: 283982821 Change-Id: Ifec330c01d7b480b641f8432ce94175291e79238
This commit is contained in:
parent
01d4a48911
commit
cd7e8a690c
|
@ -227,7 +227,6 @@ def _cc_shared_library_impl(ctx):
|
|||
additional_inputs = []
|
||||
if ctx.file.visibility_file != None:
|
||||
user_link_flags = [
|
||||
"-Wl,--no-undefined", # Just here for testing.
|
||||
"-Wl,--version-script=" + ctx.file.visibility_file.path,
|
||||
]
|
||||
additional_inputs = [ctx.file.visibility_file]
|
||||
|
|
|
@ -1,9 +1,17 @@
|
|||
load("//cc:defs.bzl", "cc_library")
|
||||
load("//cc:defs.bzl", "cc_binary", "cc_library")
|
||||
load("//examples:experimental_cc_shared_library.bzl", "cc_shared_library")
|
||||
|
||||
cc_binary(
|
||||
name = "binary",
|
||||
srcs = ["main.cc"],
|
||||
dynamic_deps = ["foo_so"],
|
||||
deps = ["foo"],
|
||||
)
|
||||
|
||||
cc_shared_library(
|
||||
name = "foo_so",
|
||||
dynamic_deps = ["bar_so"],
|
||||
preloaded_deps = ["preloaded_dep"],
|
||||
visibility_file = "foo.lds",
|
||||
exports = [
|
||||
"foo",
|
||||
|
@ -25,11 +33,19 @@ cc_shared_library(
|
|||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "preloaded_dep",
|
||||
srcs = ["preloaded_dep.cc"],
|
||||
hdrs = ["preloaded_dep.h"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "foo",
|
||||
srcs = ["foo.cc"],
|
||||
hdrs = ["foo.h"],
|
||||
linked_statically_by = ["//examples/test_cc_shared_library:foo_so"],
|
||||
deps = [
|
||||
"preloaded_dep",
|
||||
"bar",
|
||||
"baz",
|
||||
# Not exported.
|
||||
|
@ -40,12 +56,14 @@ cc_library(
|
|||
cc_library(
|
||||
name = "baz",
|
||||
srcs = ["baz.cc"],
|
||||
hdrs = ["baz.h"],
|
||||
linked_statically_by = ["//examples/test_cc_shared_library:foo_so"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "qux",
|
||||
srcs = ["qux.cc"],
|
||||
hdrs = ["qux.h"],
|
||||
linked_statically_by = ["//examples/test_cc_shared_library:foo_so"],
|
||||
)
|
||||
|
||||
|
@ -70,6 +88,7 @@ cc_library(
|
|||
cc_library(
|
||||
name = "bar2",
|
||||
srcs = ["bar2.cc"],
|
||||
hdrs = ["bar2.h"],
|
||||
linked_statically_by = [
|
||||
"//examples/test_cc_shared_library:bar_so",
|
||||
"//examples/test_cc_shared_library:foo_so",
|
||||
|
@ -79,6 +98,7 @@ cc_library(
|
|||
cc_library(
|
||||
name = "bar3",
|
||||
srcs = ["bar3.cc"],
|
||||
hdrs = ["bar3.h"],
|
||||
linked_statically_by = [
|
||||
"//examples/test_cc_shared_library:bar_so",
|
||||
"//examples/test_cc_shared_library:foo_so",
|
||||
|
@ -88,6 +108,7 @@ cc_library(
|
|||
cc_library(
|
||||
name = "bar4",
|
||||
srcs = ["bar4.cc"],
|
||||
hdrs = ["bar4.h"],
|
||||
linked_statically_by = [
|
||||
"//examples/test_cc_shared_library:bar_so",
|
||||
"//examples/test_cc_shared_library:foo_so",
|
||||
|
@ -99,6 +120,7 @@ sh_test(
|
|||
srcs = ["cc_shared_library_integration_test.sh"],
|
||||
data = [
|
||||
":bar_so",
|
||||
":binary",
|
||||
":foo_so",
|
||||
],
|
||||
)
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
#include "examples/test_cc_shared_library/bar2.h"
|
||||
|
||||
int bar2() { return 42; }
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef EXAMPLES_TEST_CC_SHARED_LIBRARY_BAR_2_H_
|
||||
#define EXAMPLES_TEST_CC_SHARED_LIBRARY_BAR_2_H_
|
||||
|
||||
int bar2();
|
||||
|
||||
#endif // EXAMPLES_TEST_CC_SHARED_LIBRARY_BAR_2_H_
|
|
@ -1 +1,3 @@
|
|||
#include "examples/test_cc_shared_library/bar3.h"
|
||||
|
||||
int bar3() { return 42; }
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef EXAMPLES_TEST_CC_SHARED_LIBRARY_BAR_3_H_
|
||||
#define EXAMPLES_TEST_CC_SHARED_LIBRARY_BAR_3_H_
|
||||
|
||||
int bar3();
|
||||
|
||||
#endif // EXAMPLES_TEST_CC_SHARED_LIBRARY_BAR_3_H_
|
|
@ -1 +1,3 @@
|
|||
#include "examples/test_cc_shared_library/bar4.h"
|
||||
|
||||
int bar4() { return 42; }
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef EXAMPLES_TEST_CC_SHARED_LIBRARY_BAR_4_H_
|
||||
#define EXAMPLES_TEST_CC_SHARED_LIBRARY_BAR_4_H_
|
||||
|
||||
int bar4();
|
||||
|
||||
#endif // EXAMPLES_TEST_CC_SHARED_LIBRARY_BAR_4_H_
|
|
@ -1 +1,3 @@
|
|||
#include "examples/test_cc_shared_library/baz.h"
|
||||
|
||||
int baz() { return 42; }
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef EXAMPLES_TEST_CC_SHARED_LIBRARY_BAZ_H_
|
||||
#define EXAMPLES_TEST_CC_SHARED_LIBRARY_BAZ_H_
|
||||
|
||||
int baz();
|
||||
|
||||
#endif // EXAMPLES_TEST_CC_SHARED_LIBRARY_BAZ_H_
|
|
@ -29,18 +29,27 @@ function check_symbol_absent() {
|
|||
fi
|
||||
}
|
||||
|
||||
function test_output {
|
||||
function test_shared_library_symbols() {
|
||||
foo_so=$(find . -name libfoo_so.so)
|
||||
symbols=$(nm -D $foo_so)
|
||||
check_symbol_present "$symbols" "U _Z3barv"
|
||||
check_symbol_present "$symbols" "T _Z3bazv"
|
||||
check_symbol_present "$symbols" "T _Z3foov"
|
||||
# Check that the preloaded dep symbol is not present
|
||||
check_symbol_present "$symbols" "U _Z13preloaded_depv"
|
||||
|
||||
check_symbol_absent "$symbols" "_Z3quxv"
|
||||
check_symbol_absent "$symbols" "_Z4bar3v"
|
||||
check_symbol_absent "$symbols" "_Z4bar4v"
|
||||
|
||||
exit 0
|
||||
}
|
||||
|
||||
test_output
|
||||
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))
|
||||
}
|
||||
|
||||
test_shared_library_symbols
|
||||
test_binary
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
#include "examples/test_cc_shared_library/bar.h"
|
||||
#include "examples/test_cc_shared_library/baz.h"
|
||||
#include "examples/test_cc_shared_library/preloaded_dep.h"
|
||||
#include "examples/test_cc_shared_library/qux.h"
|
||||
|
||||
int foo() {
|
||||
bar();
|
||||
baz();
|
||||
qux();
|
||||
preloaded_dep();
|
||||
return 42;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef EXAMPLES_TEST_CC_SHARED_LIBRARY_FOO_H_
|
||||
#define EXAMPLES_TEST_CC_SHARED_LIBRARY_FOO_H_
|
||||
|
||||
int foo();
|
||||
|
||||
#endif // EXAMPLES_TEST_CC_SHARED_LIBRARY_FOO_H_
|
|
@ -0,0 +1,8 @@
|
|||
#include <iostream>
|
||||
|
||||
#include "examples/test_cc_shared_library/foo.h"
|
||||
|
||||
int main() {
|
||||
std::cout << "hello " << foo() << std::endl;
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
#include "examples/test_cc_shared_library/preloaded_dep.h"
|
||||
|
||||
int preloaded_dep() { return 42; }
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef EXAMPLES_TEST_CC_SHARED_LIBRARY_PRELOADED_DEP_H_
|
||||
#define EXAMPLES_TEST_CC_SHARED_LIBRARY_PRELOADED_DEP_H_
|
||||
|
||||
int preloaded_dep();
|
||||
|
||||
#endif // EXAMPLES_TEST_CC_SHARED_LIBRARY_PRELOADED_DEP_H_
|
|
@ -1 +1,3 @@
|
|||
#include "examples/test_cc_shared_library/qux.h"
|
||||
|
||||
int qux() { return 42; }
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef EXAMPLES_TEST_CC_SHARED_LIBRARY_QUX_H_
|
||||
#define EXAMPLES_TEST_CC_SHARED_LIBRARY_QUX_H_
|
||||
|
||||
int qux();
|
||||
|
||||
#endif // EXAMPLES_TEST_CC_SHARED_LIBRARY_QUX_H_
|
Loading…
Reference in New Issue