Merge pull request #85 from benjaminp:modern-linking

PiperOrigin-RevId: 341368143
Change-Id: I9b86beeb90f6df6d3564209f1e97ada4ea7bc319
diff --git a/BUILD b/BUILD
index 5e0fc3a..cdaf96f 100644
--- a/BUILD
+++ b/BUILD
@@ -1,3 +1,5 @@
+load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
+
 package(default_visibility = ["//visibility:public"])
 
 licenses(["notice"])
@@ -14,3 +16,15 @@
     ],
     visibility = ["@//distro:__pkg__"],
 )
+
+bzl_library(
+    name = "internal_deps_bzl",
+    srcs = ["internal_deps.bzl"],
+    visibility = ["//visibility:private"],
+)
+
+bzl_library(
+    name = "internal_setup_bzl",
+    srcs = ["internal_setup.bzl"],
+    visibility = ["//visibility:private"],
+)
diff --git a/cc/action_names.bzl b/cc/action_names.bzl
index 60e8a5f..68251bd 100644
--- a/cc/action_names.bzl
+++ b/cc/action_names.bzl
@@ -89,7 +89,7 @@
 # A string constant for the objc fully-link link action.
 OBJC_FULLY_LINK_ACTION_NAME = "objc-fully-link"
 
-# A string constant for the clif actions.
+# A string constant for the clif action.
 CLIF_MATCH_ACTION_NAME = "clif-match"
 
 ACTION_NAMES = struct(
@@ -120,3 +120,69 @@
     objcpp_executable = OBJCPP_EXECUTABLE_ACTION_NAME,
     clif_match = CLIF_MATCH_ACTION_NAME,
 )
+
+# Names of actions that parse or compile C++ code.
+ALL_CPP_COMPILE_ACTION_NAMES = [
+    ACTION_NAMES.linkstamp_compile,
+    ACTION_NAMES.cpp_compile,
+    ACTION_NAMES.cpp_header_parsing,
+    ACTION_NAMES.cpp_module_compile,
+    ACTION_NAMES.cpp_module_codegen,
+    ACTION_NAMES.lto_backend,
+    ACTION_NAMES.clif_match,
+]
+
+# Names of actions that parse or compile C, C++ and assembly code.
+ALL_CC_COMPILE_ACTION_NAMES = ALL_CPP_COMPILE_ACTION_NAMES + [
+    ACTION_NAMES.c_compile,
+    ACTION_NAMES.preprocess_assemble,
+    ACTION_NAMES.assemble,
+]
+
+# Names of actions that link C, C++ and assembly code.
+ALL_CC_LINK_ACTION_NAMES = [
+    ACTION_NAMES.cpp_link_executable,
+    ACTION_NAMES.cpp_link_dynamic_library,
+    ACTION_NAMES.cpp_link_nodeps_dynamic_library,
+    ACTION_NAMES.lto_index_for_executable,
+    ACTION_NAMES.lto_index_for_dynamic_library,
+    ACTION_NAMES.lto_index_for_nodeps_dynamic_library,
+]
+
+# Names of actions that link entire programs.
+CC_LINK_EXECUTABLE_ACTION_NAMES = [
+    ACTION_NAMES.cpp_link_executable,
+    ACTION_NAMES.lto_index_for_executable,
+]
+
+# Names of actions that link dynamic libraries.
+DYNAMIC_LIBRARY_LINK_ACTION_NAMES = [
+    ACTION_NAMES.cpp_link_dynamic_library,
+    ACTION_NAMES.cpp_link_nodeps_dynamic_library,
+    ACTION_NAMES.lto_index_for_dynamic_library,
+    ACTION_NAMES.lto_index_for_nodeps_dynamic_library,
+]
+
+# Names of actions that link nodeps dynamic libraries.
+NODEPS_DYNAMIC_LIBRARY_LINK_ACTION_NAMES = [
+    ACTION_NAMES.cpp_link_nodeps_dynamic_library,
+    ACTION_NAMES.lto_index_for_nodeps_dynamic_library,
+]
+
+# Names of actions that link transitive dependencies.
+TRANSITIVE_LINK_ACTION_NAMES = [
+    ACTION_NAMES.cpp_link_executable,
+    ACTION_NAMES.cpp_link_dynamic_library,
+    ACTION_NAMES.lto_index_for_executable,
+    ACTION_NAMES.lto_index_for_dynamic_library,
+]
+
+ACTION_NAME_GROUPS = struct(
+    all_cc_compile_actions = ALL_CC_COMPILE_ACTION_NAMES,
+    all_cc_link_actions = ALL_CC_LINK_ACTION_NAMES,
+    all_cpp_compile_actions = ALL_CPP_COMPILE_ACTION_NAMES,
+    cc_link_executable_actions = CC_LINK_EXECUTABLE_ACTION_NAMES,
+    dynamic_library_link_actions = DYNAMIC_LIBRARY_LINK_ACTION_NAMES,
+    nodeps_dynamic_library_link_actions = NODEPS_DYNAMIC_LIBRARY_LINK_ACTION_NAMES,
+    transitive_link_actions = TRANSITIVE_LINK_ACTION_NAMES,
+)
diff --git a/examples/BUILD b/examples/BUILD
index 0bfcd24..c770074 100644
--- a/examples/BUILD
+++ b/examples/BUILD
@@ -12,6 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
 load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
 
 # A collection of examples showing the usage of rules_cc
@@ -28,3 +29,9 @@
     build_setting_default = False,
     visibility = ["//visibility:public"],
 )
+
+bzl_library(
+    name = "experimental_cc_shared_library_bzl",
+    srcs = ["experimental_cc_shared_library.bzl"],
+    visibility = ["//visibility:private"],
+)
diff --git a/examples/my_c_archive/BUILD b/examples/my_c_archive/BUILD
index 59bcd56..4484684 100644
--- a/examples/my_c_archive/BUILD
+++ b/examples/my_c_archive/BUILD
@@ -14,6 +14,7 @@
 
 # Example showing how to create a custom Starlark rule that rules_cc can depend on
 
+load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
 load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
 load("//examples/my_c_archive:my_c_archive.bzl", "my_c_archive")
 load("//examples/my_c_compile:my_c_compile.bzl", "my_c_compile")
@@ -41,3 +42,9 @@
     name = "bar",
     srcs = ["bar.c"],
 )
+
+bzl_library(
+    name = "my_c_archive_bzl",
+    srcs = ["my_c_archive.bzl"],
+    visibility = ["//visibility:private"],
+)
diff --git a/examples/my_c_compile/BUILD b/examples/my_c_compile/BUILD
index efcabf4..b045509 100644
--- a/examples/my_c_compile/BUILD
+++ b/examples/my_c_compile/BUILD
@@ -1,3 +1,4 @@
+load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
 load("//examples/my_c_compile:my_c_compile.bzl", "my_c_compile")
 
 # Copyright 2019 The Bazel Authors. All rights reserved.
@@ -21,3 +22,9 @@
     name = "foo",
     src = "foo.c",
 )
+
+bzl_library(
+    name = "my_c_compile_bzl",
+    srcs = ["my_c_compile.bzl"],
+    visibility = ["//visibility:private"],
+)
diff --git a/examples/test_cc_shared_library/BUILD b/examples/test_cc_shared_library/BUILD
index 027717c..5f3d03b 100644
--- a/examples/test_cc_shared_library/BUILD
+++ b/examples/test_cc_shared_library/BUILD
@@ -1,3 +1,4 @@
+load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
 load("//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
 load("//examples:experimental_cc_shared_library.bzl", "LINKABLE_MORE_THAN_ONCE", "cc_shared_library")
 load(":starlark_tests.bzl", "additional_inputs_test", "build_failure_test", "linking_suffix_test", "paths_test")
@@ -195,3 +196,9 @@
     message = "can only list targets that are in the same package or a sub-package",
     target_under_test = "//examples/test_cc_shared_library/failing_targets:permissions_fail",
 )
+
+bzl_library(
+    name = "test_cc_shared_library_starlark_tests_bzl",
+    srcs = ["starlark_tests.bzl"],
+    visibility = ["//visibility:private"],
+)
diff --git a/examples/write_cc_toolchain_cpu/BUILD b/examples/write_cc_toolchain_cpu/BUILD
index fcee153..c9ee72f 100644
--- a/examples/write_cc_toolchain_cpu/BUILD
+++ b/examples/write_cc_toolchain_cpu/BUILD
@@ -1,3 +1,4 @@
+load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
 load("//examples/write_cc_toolchain_cpu:write_cc_toolchain_cpu.bzl", "write_cc_toolchain_cpu")
 
 # Copyright 2019 The Bazel Authors. All rights reserved.
@@ -18,3 +19,9 @@
 licenses(["notice"])
 
 write_cc_toolchain_cpu(name = "write_me_the_cpu")
+
+bzl_library(
+    name = "write_cc_toolchain_cpu_bzl",
+    srcs = ["write_cc_toolchain_cpu.bzl"],
+    visibility = ["//visibility:private"],
+)
diff --git a/tests/load_from_macro/BUILD b/tests/load_from_macro/BUILD
index 7084344..93b902a 100644
--- a/tests/load_from_macro/BUILD
+++ b/tests/load_from_macro/BUILD
@@ -12,6 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
 load("//cc:defs.bzl", "cc_library")
 load(":tags.bzl", "TAGS")
 
@@ -22,3 +23,9 @@
     srcs = ["foo.cc"],
     tags = TAGS,
 )
+
+bzl_library(
+    name = "tags_bzl",
+    srcs = ["tags.bzl"],
+    visibility = ["//visibility:private"],
+)
diff --git a/tools/migration/BUILD b/tools/migration/BUILD
index 0cef4ae..443299b 100644
--- a/tools/migration/BUILD
+++ b/tools/migration/BUILD
@@ -12,6 +12,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
+
 # Go rules
 load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test")
 
@@ -131,3 +133,15 @@
 )
 
 exports_files(["ctoolchain_compare.bzl"])
+
+bzl_library(
+    name = "ctoolchain_compare_bzl",
+    srcs = ["ctoolchain_compare.bzl"],
+    visibility = ["//visibility:private"],
+)
+
+bzl_library(
+    name = "cc_toolchain_config_comparator_bzl",
+    srcs = ["cc_toolchain_config_comparator.bzl"],
+    visibility = ["//visibility:private"],
+)