Migrate CppLinkstampCompileHelper.getVariables() to Starlark.

PiperOrigin-RevId: 811303415
Change-Id: Ia28bbee89626b8bb3515b00fbc5cbee87d33d7fc
diff --git a/cc/common/cc_helper.bzl b/cc/common/cc_helper.bzl
index 57b0e61..970a0b4 100644
--- a/cc/common/cc_helper.bzl
+++ b/cc/common/cc_helper.bzl
@@ -24,6 +24,7 @@
     "should_create_per_object_debug_info",
     _artifact_category = "artifact_category_names",
     _extensions = "extensions",
+    _is_stamping_enabled = "is_stamping_enabled",
     _package_source_root = "package_source_root",
     _repository_exec_path = "repository_exec_path",
 )
@@ -1059,14 +1060,6 @@
                 result.append(f)
     return result
 
-def _is_stamping_enabled(ctx):
-    if ctx.configuration.is_tool_configuration():
-        return 0
-    stamp = 0
-    if hasattr(ctx.attr, "stamp"):
-        stamp = ctx.attr.stamp
-    return stamp
-
 def _has_target_constraints(ctx, constraints):
     # Constraints is a label_list.
     for constraint in constraints:
diff --git a/cc/common/cc_helper_internal.bzl b/cc/common/cc_helper_internal.bzl
index eb3eea9..3b2cc5d 100644
--- a/cc/common/cc_helper_internal.bzl
+++ b/cc/common/cc_helper_internal.bzl
@@ -216,6 +216,26 @@
         repository = repository[1:]
     return get_relative_path(prefix, repository)
 
+def is_stamping_enabled(ctx):
+    """Returns whether to encode build information into the binary.
+
+    Args:
+        ctx: The rule context.
+
+    Returns:
+    (int): 1: Always stamp the build information into the binary, even in [--nostamp][stamp] builds.
+        This setting should be avoided, since it potentially kills remote caching for the binary and
+        any downstream actions that depend on it.
+        0: Always replace build information by constant values. This gives good build result caching.
+        -1: Embedding of build information is controlled by the [--[no]stamp][stamp] flag.
+    """
+    if ctx.configuration.is_tool_configuration():
+        return 0
+    stamp = 0
+    if hasattr(ctx.attr, "stamp"):
+        stamp = ctx.attr.stamp
+    return stamp
+
 # LINT.ThenChange(https://github.com/bazelbuild/bazel/blob/master/src/main/starlark/builtins_bzl/common/cc/cc_helper_internal.bzl:forked_exports)
 
 def get_relative_path(path_a, path_b):