From f91b186e8fe3b87b10437bc4bc4a5f733e03f45a Mon Sep 17 00:00:00 2001
From: UebelAndre <github@uebelandre.com>
Date: Thu, 7 Dec 2023 09:38:42 -0800
Subject: [PATCH] Move implementation detail settings into private module
 (#2305)

`is_proc_macro_dep` and `is_proc_macro_dep_enabled` are not expected to
be something users care about so I think it'd be cleaner to have them
live in `//rust/private`
---
 BUILD.bazel                                   | 20 -------------------
 rust/defs.bzl                                 |  8 --------
 rust/private/BUILD.bazel                      | 19 ++++++++++++++++++
 rust/private/rust.bzl                         | 12 +++++------
 .../is_proc_macro_dep_test.bzl                | 14 +++++++++----
 5 files changed, 35 insertions(+), 38 deletions(-)

diff --git a/BUILD.bazel b/BUILD.bazel
index 21f409580a..3f71f8cf98 100644
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -9,8 +9,6 @@ load(
     "extra_exec_rustc_flags",
     "extra_rustc_flag",
     "extra_rustc_flags",
-    "is_proc_macro_dep",
-    "is_proc_macro_dep_enabled",
     "no_std",
     "per_crate_rustc_flag",
     "rustc_output_diagnostics",
@@ -51,24 +49,6 @@ clippy_flags(
     visibility = ["//visibility:public"],
 )
 
-# This setting may be used to identify dependencies of proc-macro-s.
-# This feature is only enabled if `is_proc_macro_dep_enabled` is true.
-# Its value controls the BAZEL_RULES_RUST_IS_PROC_MACRO_DEP environment variable
-# made available to the rustc invocation.
-is_proc_macro_dep(
-    name = "is_proc_macro_dep",
-    build_setting_default = False,
-    visibility = ["//visibility:public"],
-)
-
-# This setting enables the feature to identify dependencies of proc-macro-s,
-# see `is_proc_macro_dep`.
-is_proc_macro_dep_enabled(
-    name = "is_proc_macro_dep_enabled",
-    build_setting_default = False,
-    visibility = ["//visibility:public"],
-)
-
 # This setting may be used to pass extra options to rustc from the command line
 # in non-exec configuration.
 # It applies across all targets whereas the rustc_flags option on targets applies only
diff --git a/rust/defs.bzl b/rust/defs.bzl
index e6afbba47c..8573048e3d 100644
--- a/rust/defs.bzl
+++ b/rust/defs.bzl
@@ -48,8 +48,6 @@ load(
     _extra_exec_rustc_flags = "extra_exec_rustc_flags",
     _extra_rustc_flag = "extra_rustc_flag",
     _extra_rustc_flags = "extra_rustc_flags",
-    _is_proc_macro_dep = "is_proc_macro_dep",
-    _is_proc_macro_dep_enabled = "is_proc_macro_dep_enabled",
     _no_std = "no_std",
     _per_crate_rustc_flag = "per_crate_rustc_flag",
     _rustc_output_diagnostics = "rustc_output_diagnostics",
@@ -128,12 +126,6 @@ extra_exec_rustc_flag = _extra_exec_rustc_flag
 extra_exec_rustc_flags = _extra_exec_rustc_flags
 # See @rules_rust//rust/private:rustc.bzl for a complete description.
 
-is_proc_macro_dep = _is_proc_macro_dep
-# See @rules_rust//rust/private:rustc.bzl for a complete description.
-
-is_proc_macro_dep_enabled = _is_proc_macro_dep_enabled
-# See @rules_rust//rust/private:rustc.bzl for a complete description.
-
 per_crate_rustc_flag = _per_crate_rustc_flag
 # See @rules_rust//rust/private:rustc.bzl for a complete description.
 
diff --git a/rust/private/BUILD.bazel b/rust/private/BUILD.bazel
index 3c963cdcb5..99d0fd79fd 100644
--- a/rust/private/BUILD.bazel
+++ b/rust/private/BUILD.bazel
@@ -1,5 +1,6 @@
 load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
 load("//rust/private:rust_analyzer.bzl", "rust_analyzer_detect_sysroot")
+load("//rust/private:rustc.bzl", "is_proc_macro_dep", "is_proc_macro_dep_enabled")
 load("//rust/private:stamp.bzl", "stamp_build_setting")
 
 bzl_library(
@@ -11,6 +12,24 @@ bzl_library(
 
 stamp_build_setting(name = "stamp")
 
+# This setting may be used to identify dependencies of proc-macro-s.
+# This feature is only enabled if `is_proc_macro_dep_enabled` is true.
+# Its value controls the BAZEL_RULES_RUST_IS_PROC_MACRO_DEP environment variable
+# made available to the rustc invocation.
+is_proc_macro_dep(
+    name = "is_proc_macro_dep",
+    build_setting_default = False,
+    visibility = ["//visibility:public"],
+)
+
+# This setting enables the feature to identify dependencies of proc-macro-s,
+# see `is_proc_macro_dep`.
+is_proc_macro_dep_enabled(
+    name = "is_proc_macro_dep_enabled",
+    build_setting_default = False,
+    visibility = ["//visibility:public"],
+)
+
 rust_analyzer_detect_sysroot(
     name = "rust_analyzer_detect_sysroot",
     visibility = ["//visibility:public"],
diff --git a/rust/private/rust.bzl b/rust/private/rust.bzl
index d9caf28114..7e5b76aada 100644
--- a/rust/private/rust.bzl
+++ b/rust/private/rust.bzl
@@ -634,10 +634,10 @@ _common_attrs = {
         cfg = "exec",
     ),
     "_is_proc_macro_dep": attr.label(
-        default = Label("//:is_proc_macro_dep"),
+        default = Label("//rust/private:is_proc_macro_dep"),
     ),
     "_is_proc_macro_dep_enabled": attr.label(
-        default = Label("//:is_proc_macro_dep_enabled"),
+        default = Label("//rust/private:is_proc_macro_dep_enabled"),
     ),
     "_per_crate_rustc_flag": attr.label(
         default = Label("//:experimental_per_crate_rustc_flag"),
@@ -887,14 +887,14 @@ rust_shared_library = rule(
 )
 
 def _proc_macro_dep_transition_impl(settings, _attr):
-    if settings["//:is_proc_macro_dep_enabled"]:
-        return {"//:is_proc_macro_dep": True}
+    if settings["//rust/private:is_proc_macro_dep_enabled"]:
+        return {"//rust/private:is_proc_macro_dep": True}
     else:
         return []
 
 _proc_macro_dep_transition = transition(
-    inputs = ["//:is_proc_macro_dep_enabled"],
-    outputs = ["//:is_proc_macro_dep"],
+    inputs = ["//rust/private:is_proc_macro_dep_enabled"],
+    outputs = ["//rust/private:is_proc_macro_dep"],
     implementation = _proc_macro_dep_transition_impl,
 )
 
diff --git a/test/unit/is_proc_macro_dep/is_proc_macro_dep_test.bzl b/test/unit/is_proc_macro_dep/is_proc_macro_dep_test.bzl
index eb947bde22..26e2dcd7a1 100644
--- a/test/unit/is_proc_macro_dep/is_proc_macro_dep_test.bzl
+++ b/test/unit/is_proc_macro_dep/is_proc_macro_dep_test.bzl
@@ -31,19 +31,25 @@ attach_dep_actions_aspect = rule(
 )
 
 def _enable_is_proc_macro_dep_transition_impl(_settings, _attr):
-    return {"//:is_proc_macro_dep_enabled": True}
+    return {"//rust/private:is_proc_macro_dep_enabled": True}
 
 enable_is_proc_macro_dep_transition = transition(
     inputs = [],
-    outputs = ["//:is_proc_macro_dep_enabled"],
+    outputs = ["//rust/private:is_proc_macro_dep_enabled"],
     implementation = _enable_is_proc_macro_dep_transition_impl,
 )
 
 attach_dep_actions_and_enable_is_proc_macro_dep_aspect = rule(
     implementation = _attach_dep_actions_aspect_impl,
     attrs = {
-        "dep": attr.label(aspects = [collect_dep_actions_aspect]),
-        "_allowlist_function_transition": attr.label(default = Label("//tools/allowlists/function_transition_allowlist")),
+        "dep": attr.label(
+            aspects = [collect_dep_actions_aspect],
+        ),
+        "_allowlist_function_transition": attr.label(
+            default = Label(
+                "//tools/allowlists/function_transition_allowlist",
+            ),
+        ),
     },
     cfg = enable_is_proc_macro_dep_transition,
 )