Merge branch 'master' into ad/readme
diff --git a/cc/private/toolchain/cc_configure.bzl b/cc/private/toolchain/cc_configure.bzl
index 9500efc..b26f2b5 100644
--- a/cc/private/toolchain/cc_configure.bzl
+++ b/cc/private/toolchain/cc_configure.bzl
@@ -101,7 +101,7 @@
             "@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",
diff --git a/examples/experimental_cc_shared_library.bzl b/examples/experimental_cc_shared_library.bzl
index aff1f78..b54ecc7 100644
--- a/examples/experimental_cc_shared_library.bzl
+++ b/examples/experimental_cc_shared_library.bzl
@@ -223,14 +223,18 @@
 
     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 @@
 
     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 @@
     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"),
diff --git a/examples/test_cc_shared_library/BUILD b/examples/test_cc_shared_library/BUILD
index 137a9ca..b45ca15 100644
--- a/examples/test_cc_shared_library/BUILD
+++ b/examples/test_cc_shared_library/BUILD
@@ -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 @@
     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 @@
     data = [
         ":bar_so",
         ":binary",
+        ":cc_test",
         ":foo_so",
     ],
 )
diff --git a/examples/test_cc_shared_library/cc_shared_library_integration_test.sh b/examples/test_cc_shared_library/cc_shared_library_integration_test.sh
index f999b03..7e9b947 100755
--- a/examples/test_cc_shared_library/cc_shared_library_integration_test.sh
+++ b/examples/test_cc_shared_library/cc_shared_library_integration_test.sh
@@ -43,13 +43,33 @@
   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