Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move implementation detail settings into private module #2305

Merged
merged 3 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions rust/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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.

Expand Down
19 changes: 19 additions & 0 deletions rust/private/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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"],
Expand Down
12 changes: 6 additions & 6 deletions rust/private/rust.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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,
)

Expand Down
14 changes: 10 additions & 4 deletions test/unit/is_proc_macro_dep/is_proc_macro_dep_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
Loading