Remove attribute for visibility file.

The same command line can be obtained with the attributes
user_link_flags and additional_linker_inputs used together.

In the first design iterations of cc_shared_library it was decided to have the
visibility_file attribute so that a cc_shared_library could be used for many
different platforms smoothly.

For this to work the visibility file would have had to be platform neutral and
then Bazel would have had to write a visibility file specific for each
platform, e.g. the version script for Unix and the exports map for Windows.

However, in the last approved design it was decided not to have Bazel get in
the business of understanding symbols and automatically writing export maps.

With this approach, it then became necessary for people to use selects() in the
visibility_file attribute depending on the platform that the file was for.

Since we have added a new way to add files with the attribute
additional_linker_inputs and we need selects() anyway,
it doesn't make sense to keep the visibility_file attribute, the
same can be achieved with selects in the other two attributes mentioned.

In any case, if this can be made more ergonomic in the future, we can do so.
However, removing this attribute after flipping the experimental flag would be
an incompatible change.

PiperOrigin-RevId: 295925566
Change-Id: I52733e006f4b0f79f50380e89fc2eeae58dbad4d
diff --git a/examples/experimental_cc_shared_library.bzl b/examples/experimental_cc_shared_library.bzl
index a95fc3b..e660742 100644
--- a/examples/experimental_cc_shared_library.bzl
+++ b/examples/experimental_cc_shared_library.bzl
@@ -279,28 +279,17 @@
 
     linking_context = _create_linker_context(ctx, 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.append(
-            "-Wl,--version-script=" + ctx.file.visibility_file.path,
-        )
-        additional_inputs = [ctx.file.visibility_file]
-
     for user_link_flag in ctx.attr.user_link_flags:
         user_link_flags.append(ctx.expand_location(user_link_flag, targets = ctx.attr.additional_linker_inputs))
 
-    additional_inputs.extend(ctx.files.additional_linker_inputs)
-
     linking_outputs = cc_common.link(
         actions = ctx.actions,
         feature_configuration = feature_configuration,
         cc_toolchain = cc_toolchain,
         linking_contexts = [linking_context],
         user_link_flags = user_link_flags,
-        additional_inputs = additional_inputs,
+        additional_inputs = ctx.files.additional_linker_inputs,
         name = ctx.label.name,
         output_type = "dynamic_library",
     )
@@ -374,7 +363,6 @@
         "preloaded_deps": attr.label_list(providers = [CcInfo]),
         "static_deps": attr.string_list(),
         "user_link_flags": attr.string_list(),
-        "visibility_file": attr.label(allow_single_file = True),
         "_cc_toolchain": attr.label(default = "@bazel_tools//tools/cpp:current_cc_toolchain"),
     },
     toolchains = ["@rules_cc//cc:toolchain_type"],  # copybara-use-repo-external-label
diff --git a/examples/test_cc_shared_library/BUILD b/examples/test_cc_shared_library/BUILD
index 875390b..e860b5c 100644
--- a/examples/test_cc_shared_library/BUILD
+++ b/examples/test_cc_shared_library/BUILD
@@ -18,7 +18,10 @@
 
 cc_shared_library(
     name = "foo_so",
-    additional_linker_inputs = [":additional_script.txt"],
+    additional_linker_inputs = [
+        ":foo.lds",
+        ":additional_script.txt",
+    ],
     dynamic_deps = ["bar_so"],
     preloaded_deps = ["preloaded_dep"],
     static_deps = [
@@ -26,9 +29,9 @@
     ],
     user_link_flags = [
         "-Wl,-rpath,kittens",
+        "-Wl,--version-script=$(location :foo.lds)",
         "-Wl,--script=$(location :additional_script.txt)",
     ],
-    visibility_file = "foo.lds",
     exports = [
         "foo",
         # Not a problem to export "baz" which is depended on by foo
@@ -82,11 +85,16 @@
 
 cc_shared_library(
     name = "bar_so",
+    additional_linker_inputs = [
+        ":bar.lds",
+    ],
     static_deps = [
         "//examples/test_cc_shared_library:barX",
         "@test_repo//:bar",
     ],
-    visibility_file = "bar.lds",
+    user_link_flags = [
+        "-Wl,--version-script=$(location :bar.lds)",
+    ],
     exports = [
         "bar",
         "bar2",