Adds getShareableArtifact to ActionConstructionContext interface.

In C++ we need to call this method but we won't have the rule context
available from Skylark. Instead we will have ctx.actions from which we can get
the ActionConstructionContext.

More in depth discussion in:
https://docs.google.com/document/d/1_irTE1a8aTg8Hhf5mmlEXsFcwOw6-hz3a8FxufCyVKA/edit?ts=5bd862f7#heading=h.7795zogmlqtv

RELNOTES:none
PiperOrigin-RevId: 219440126
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java b/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java
index d59175c..113d995 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java
@@ -665,14 +665,7 @@
         relative, getConfiguration().getGenfilesDirectory(rule.getRepository()));
   }
 
-  /**
-   * Returns an artifact that can be an output of shared actions. Only use when there is no other
-   * option.
-   *
-   * <p>This artifact can be created anywhere in the output tree, which, in addition to making
-   * sharing possible, opens up the possibility of action conflicts and makes it impossible to infer
-   * the label of the rule creating the artifact from the path of the artifact.
-   */
+  @Override
   public Artifact getShareableArtifact(PathFragment rootRelativePath, ArtifactRoot root) {
     return getAnalysisEnvironment().getDerivedArtifact(rootRelativePath, root);
   }
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/actions/ActionConstructionContext.java b/src/main/java/com/google/devtools/build/lib/analysis/actions/ActionConstructionContext.java
index 4025c22..2ce75c5 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/actions/ActionConstructionContext.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/actions/ActionConstructionContext.java
@@ -57,6 +57,16 @@
   Artifact getDerivedArtifact(PathFragment rootRelativePath, ArtifactRoot root);
 
   /**
+   * Returns an artifact that can be an output of shared actions. Only use when there is no other
+   * option.
+   *
+   * <p>This artifact can be created anywhere in the output tree, which, in addition to making
+   * sharing possible, opens up the possibility of action conflicts and makes it impossible to infer
+   * the label of the rule creating the artifact from the path of the artifact.
+   */
+  Artifact getShareableArtifact(PathFragment rootRelativePath, ArtifactRoot root);
+
+  /**
    * Returns the implicit output artifact for a given template function. If multiple or no artifacts
    * can be found as a result of the template, an exception is thrown.
    */
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java
index 33376dc..3c5318f 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java
@@ -671,7 +671,8 @@
    */
   public Artifact getDynamicLibrarySymlink(Artifact library, boolean preserveName) {
     return SolibSymlinkAction.getDynamicLibrarySymlink(
-        ruleContext,
+        /* actionRegistry= */ ruleContext,
+        /* actionConstructionContext= */ ruleContext,
         ccToolchain.getSolibDirectory(),
         library,
         preserveName,
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcImport.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcImport.java
index cdf0d3b..ddb6775 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcImport.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcImport.java
@@ -166,7 +166,8 @@
     } else {
       Artifact dynamicLibrarySymlink =
           SolibSymlinkAction.getDynamicLibrarySymlink(
-              ruleContext,
+              /* actionRegistry= */ ruleContext,
+              /* actionConstructionContext= */ ruleContext,
               ccToolchain.getSolibDirectory(),
               sharedLibraryArtifact,
               /* preserveName= */ true,
@@ -192,7 +193,8 @@
     } else {
       Artifact dynamicLibrarySymlink =
           SolibSymlinkAction.getDynamicLibrarySymlink(
-              ruleContext,
+              /* actionRegistry= */ ruleContext,
+              /* actionConstructionContext= */ ruleContext,
               ccToolchain.getSolibDirectory(),
               interfaceLibraryArtifact,
               /* preserveName= */ true,
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingHelper.java
index 23a0e10..3000100 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingHelper.java
@@ -749,7 +749,8 @@
       } else {
         Artifact implLibraryLinkArtifact =
             SolibSymlinkAction.getDynamicLibrarySymlink(
-                ruleContext,
+                /* actionRegistry= */ ruleContext,
+                /* actionConstructionContext= */ ruleContext,
                 ccToolchain.getSolibDirectory(),
                 dynamicLibrary.getArtifact(),
                 /* preserveName= */ false,
@@ -766,7 +767,8 @@
         } else {
           Artifact libraryLinkArtifact =
               SolibSymlinkAction.getDynamicLibrarySymlink(
-                  ruleContext,
+                  /* actionRegistry= */ ruleContext,
+                  /* actionConstructionContext= */ ruleContext,
                   ccToolchain.getSolibDirectory(),
                   interfaceLibrary.getArtifact(),
                   /* preserveName= */ false,
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcModule.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcModule.java
index d61badc..bda65df 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcModule.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcModule.java
@@ -348,7 +348,8 @@
       SkylarkRuleContext skylarkRuleContext, CcToolchainProvider ccToolchain, Artifact library) {
     Artifact dynamicLibrarySymlink =
         SolibSymlinkAction.getDynamicLibrarySymlink(
-            skylarkRuleContext.getRuleContext(),
+            /* actionRegistry= */ skylarkRuleContext.getRuleContext(),
+            /* actionConstructionContext= */ skylarkRuleContext.getRuleContext(),
             ccToolchain.getSolibDirectory(),
             library,
             /* preserveName= */ true,
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java
index 5c8bd22..39eb822 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java
@@ -602,7 +602,13 @@
                 ? SolibSymlinkAction.getCppRuntimeSymlink(
                     ruleContext, artifact, solibDir, solibDirOverride, configuration)
                 : SolibSymlinkAction.getDynamicLibrarySymlink(
-                    ruleContext, solibDir, artifact, false, true, configuration));
+                    /* actionRegistry= */ ruleContext,
+                    /* actionConstructionContext= */ ruleContext,
+                    solibDir,
+                    artifact,
+                    /* preserveName= */ false,
+                    /* prefixConsumer= */ true,
+                    configuration));
       }
       artifacts = symlinkedArtifacts;
       purpose += "_with_solib";
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/SolibSymlinkAction.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/SolibSymlinkAction.java
index f6cf4f7..d1419f3 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/SolibSymlinkAction.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/SolibSymlinkAction.java
@@ -22,12 +22,15 @@
 import com.google.devtools.build.lib.actions.ActionExecutionException;
 import com.google.devtools.build.lib.actions.ActionKeyContext;
 import com.google.devtools.build.lib.actions.ActionOwner;
+import com.google.devtools.build.lib.actions.ActionRegistry;
 import com.google.devtools.build.lib.actions.ActionResult;
 import com.google.devtools.build.lib.actions.Actions;
 import com.google.devtools.build.lib.actions.Artifact;
 import com.google.devtools.build.lib.actions.ArtifactRoot;
 import com.google.devtools.build.lib.analysis.RuleContext;
+import com.google.devtools.build.lib.analysis.actions.ActionConstructionContext;
 import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
+import com.google.devtools.build.lib.cmdline.Label;
 import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
 import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
 import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization;
@@ -102,7 +105,8 @@
    * (by essentially "collecting" as many shared libraries as possible in the single directory),
    * since we will be paying quadratic price for each additional entry on the -rpath.
    *
-   * @param ruleContext rule context, that requested symlink.
+   * @param actionRegistry action registry of rule requesting symlink.
+   * @param actionConstructionContext action construction context of rule requesting symlink
    * @param solibDir String giving the solib directory
    * @param library Shared library artifact that needs to be mangled.
    * @param preserveName whether to preserve the name of the library
@@ -110,7 +114,8 @@
    * @return mangled symlink artifact.
    */
   public static Artifact getDynamicLibrarySymlink(
-      final RuleContext ruleContext,
+      ActionRegistry actionRegistry,
+      ActionConstructionContext actionConstructionContext,
       String solibDir,
       final Artifact library,
       boolean preserveName,
@@ -118,14 +123,13 @@
       BuildConfiguration configuration) {
     PathFragment mangledName =
         getMangledName(
-            ruleContext,
+            actionRegistry.getOwner().getLabel(),
             solibDir,
             library.getRootRelativePath(),
             preserveName,
-            prefixConsumer,
-            configuration.getFragment(CppConfiguration.class));
+            prefixConsumer);
     return getDynamicLibrarySymlinkInternal(
-        ruleContext, library, mangledName, configuration);
+        actionRegistry, actionConstructionContext, library, mangledName);
   }
 
   /**
@@ -143,46 +147,50 @@
         PathFragment.create(
             solibDirOverride != null ? solibDirOverride : toolchainProvidedSolibDir);
     PathFragment symlinkName = solibDir.getRelative(library.getRootRelativePath().getBaseName());
-    return getDynamicLibrarySymlinkInternal(ruleContext, library, symlinkName, configuration);
+    return getDynamicLibrarySymlinkInternal(
+        /* actionRegistry= */ ruleContext,
+        /* actionConstructionContext= */ ruleContext,
+        library,
+        symlinkName);
   }
 
   /**
-   * Internal implementation that takes a pre-determined symlink name; supports both the
-   * generic {@link #getDynamicLibrarySymlink} and the specialized {@link #getCppRuntimeSymlink}.
+   * Internal implementation that takes a pre-determined symlink name; supports both the generic
+   * {@link #getDynamicLibrarySymlink} and the specialized {@link #getCppRuntimeSymlink}.
    */
-  private static Artifact getDynamicLibrarySymlinkInternal(RuleContext ruleContext,
-      Artifact library, PathFragment symlinkName, BuildConfiguration configuration) {
+  private static Artifact getDynamicLibrarySymlinkInternal(
+      ActionRegistry actionRegistry,
+      ActionConstructionContext actionConstructionContext,
+      Artifact library,
+      PathFragment symlinkName) {
     Preconditions.checkArgument(Link.SHARED_LIBRARY_FILETYPES.matches(library.getFilename()));
     Preconditions.checkArgument(!library.getRootRelativePath().getSegment(0).startsWith("_solib_"));
 
     // Ignore libraries that are already represented by the symlinks.
-    ArtifactRoot root = configuration.getBinDirectory(ruleContext.getRule().getRepository());
-    Artifact symlink = ruleContext.getShareableArtifact(symlinkName, root);
-    ruleContext.registerAction(
-        new SolibSymlinkAction(
-            ruleContext.getActionOwner(), library, symlink));
+    ArtifactRoot root = actionConstructionContext.getBinDirectory();
+    Artifact symlink = actionConstructionContext.getShareableArtifact(symlinkName, root);
+    actionRegistry.registerAction(
+        new SolibSymlinkAction(actionConstructionContext.getActionOwner(), library, symlink));
     return symlink;
   }
 
   /**
    * Returns the name of the symlink that will be created for a library, given its name.
    *
-   * @param ruleContext rule context that requests symlink
+   * @param label label of the rule calling this
    * @param solibDir a String giving the solib directory
    * @param libraryPath the root-relative path of the library
    * @param preserveName true if filename should be preserved
    * @param prefixConsumer true if the result should be prefixed with the label of the consumer
    * @returns root relative path name
    */
-  public static PathFragment getMangledName(
-      RuleContext ruleContext,
+  private static PathFragment getMangledName(
+      Label label,
       String solibDir,
       PathFragment libraryPath,
       boolean preserveName,
-      boolean prefixConsumer,
-      CppConfiguration cppConfiguration) {
-    String escapedRulePath = Actions.escapedPath(
-        "_" + ruleContext.getLabel());
+      boolean prefixConsumer) {
+    String escapedRulePath = Actions.escapedPath("_" + label);
     String soname = getDynamicLibrarySoname(libraryPath, preserveName);
     PathFragment solibDirPath = PathFragment.create(solibDir);
     if (preserveName) {