Skip to content

Commit

Permalink
Use a symbolic macro if supported
Browse files Browse the repository at this point in the history
With Bazel 8 and if the wrapped kind is not a legacy macro, use a symbolic macro instead of a legacy macro.
  • Loading branch information
fmeum committed Dec 6, 2024
1 parent 65b3c02 commit f652ee0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module(
compatibility_level = 1,
)

bazel_dep(name = "bazel_features", version = "1.22.0")
bazel_dep(name = "bazel_skylib", version = "1.4.1")
bazel_dep(name = "platforms", version = "0.0.6")

Expand Down
1 change: 1 addition & 0 deletions with_cfg/private/providers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ RuleInfo = provider(fields = [
"kind",
"native",
"providers",
"supports_inheritance",
"test",
])

Expand Down
5 changes: 5 additions & 0 deletions with_cfg/private/with_cfg.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def with_cfg(
implicit_targets = implicit_targets,
providers = DEFAULT_PROVIDERS + extra_providers,
native = _is_native(kind),
supports_inheritance = _supports_inheritance(kind),
)
return make_builder(rule_info)

Expand Down Expand Up @@ -155,5 +156,9 @@ def is_test(rule_name):
def _is_native(kind):
return str(kind).startswith("<built-in rule ")

def _supports_inheritance(kind):
# Legacy macros don't support inheritance.
return not str(kind).startswith("<function ")

def get_implicit_targets(rule_name):
return IMPLICIT_TARGETS.get(rule_name, [])
9 changes: 8 additions & 1 deletion with_cfg/private/wrapper.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@bazel_features//:features.bzl", "bazel_features")
load(":args.bzl", "rewrite_args")
load(":rewrite.bzl", "make_label_rewriter", "rewrite_locations_in_attr")
load(":select.bzl", "map_attr")
Expand All @@ -15,7 +16,7 @@ def make_wrapper(
values,
original_settings_label,
attrs_to_reset):
return lambda *, name, **kwargs: _wrapper(
wrapper_impl = lambda *, name, **kwargs: _wrapper(
name = name,
kwargs = kwargs,
rule_info = rule_info,
Expand All @@ -25,6 +26,12 @@ def make_wrapper(
original_settings_label = original_settings_label,
attrs_to_reset = attrs_to_reset,
)
if bazel_features.globals.macro and rule_info.supports_inheritance:
return bazel_features.globals.macro(
implementation = wrapper_impl,
inherit_attrs = rule_info.kind,
)
return wrapper_impl

# Attributes common to all rules.
# These attributes are applied to all targets generated by the wrapper.
Expand Down

0 comments on commit f652ee0

Please sign in to comment.