Skip to content

Commit

Permalink
Update rust build rules to use dict union rather than adding dict_ite…
Browse files Browse the repository at this point in the history
…ms (#3003)
  • Loading branch information
pefoley2 authored Nov 18, 2024
1 parent 60515a1 commit 7685b69
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
10 changes: 8 additions & 2 deletions rust/platform/triple_mappings.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,19 @@ SUPPORTED_T3_PLATFORM_TRIPLES = {
}

SUPPORTED_PLATFORM_TRIPLES = sorted(
SUPPORTED_T1_PLATFORM_TRIPLES.keys() + SUPPORTED_T2_PLATFORM_TRIPLES.keys() + SUPPORTED_T3_PLATFORM_TRIPLES.keys(),
list(SUPPORTED_T1_PLATFORM_TRIPLES.keys()) +
list(SUPPORTED_T2_PLATFORM_TRIPLES.keys()) +
list(SUPPORTED_T3_PLATFORM_TRIPLES.keys()),
)

# Represents all platform triples `rules_rust` is configured to handle in some way.
# Note that with T3 platforms some artifacts may not be available which can lead to
# failures in the analysis phase. This list should be used sparingly.
ALL_PLATFORM_TRIPLES = SUPPORTED_T1_PLATFORM_TRIPLES.keys() + SUPPORTED_T2_PLATFORM_TRIPLES.keys() + _T3_PLATFORM_TRIPLES.keys()
ALL_PLATFORM_TRIPLES = (
list(SUPPORTED_T1_PLATFORM_TRIPLES.keys()) +
list(SUPPORTED_T2_PLATFORM_TRIPLES.keys()) +
list(_T3_PLATFORM_TRIPLES.keys())
)

# CPUs that map to a `@platforms//cpu` entry
_CPU_ARCH_TO_BUILTIN_PLAT_SUFFIX = {
Expand Down
32 changes: 16 additions & 16 deletions rust/private/rust.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ libc's `malloc`. This label must refer to a `cc_library` rule.
),
}

_rust_test_attrs = dict({
_rust_test_attrs = {
"crate": attr.label(
mandatory = False,
doc = dedent("""\
Expand Down Expand Up @@ -817,12 +817,12 @@ _rust_test_attrs = dict({
"""),
),
"_use_grep_includes": attr.bool(default = True),
}.items() + _coverage_attrs.items() + _experimental_use_cc_common_link_attrs.items())
} | _coverage_attrs | _experimental_use_cc_common_link_attrs

rust_library = rule(
implementation = _rust_library_impl,
provides = COMMON_PROVIDERS,
attrs = dict(_common_attrs.items() + {
attrs = _common_attrs | {
"disable_pipelining": attr.bool(
default = False,
doc = dedent("""\
Expand All @@ -831,7 +831,7 @@ rust_library = rule(
crates will instead use the `.rlib` file.
"""),
),
}.items()),
},
fragments = ["cpp"],
toolchains = [
str(Label("//rust:toolchain_type")),
Expand Down Expand Up @@ -920,15 +920,15 @@ _rust_static_library_transition = transition(

rust_static_library = rule(
implementation = _rust_static_library_impl,
attrs = dict(_common_attrs.items() + {
attrs = _common_attrs | {
"platform": attr.label(
doc = "Optional platform to transition the static library to.",
default = None,
),
"_allowlist_function_transition": attr.label(
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
),
}.items()),
},
fragments = ["cpp"],
cfg = _rust_static_library_transition,
toolchains = [
Expand Down Expand Up @@ -966,7 +966,7 @@ _rust_shared_library_transition = transition(

rust_shared_library = rule(
implementation = _rust_shared_library_impl,
attrs = dict(_common_attrs.items() + _experimental_use_cc_common_link_attrs.items() + {
attrs = _common_attrs | _experimental_use_cc_common_link_attrs | {
"platform": attr.label(
doc = "Optional platform to transition the shared library to.",
default = None,
Expand All @@ -975,7 +975,7 @@ rust_shared_library = rule(
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
),
"_use_grep_includes": attr.bool(default = True),
}.items()),
},
fragments = ["cpp"],
cfg = _rust_shared_library_transition,
toolchains = [
Expand Down Expand Up @@ -1040,7 +1040,7 @@ rust_proc_macro = rule(
"""),
)

_rust_binary_attrs = dict({
_rust_binary_attrs = {
"binary_name": attr.string(
doc = dedent("""\
Override the resulting binary file name. By default, the binary file will be named using the `name` attribute on this rule,
Expand Down Expand Up @@ -1084,7 +1084,7 @@ _rust_binary_attrs = dict({
),
"stamp": _stamp_attribute(default_value = -1),
"_use_grep_includes": attr.bool(default = True),
}.items() + _experimental_use_cc_common_link_attrs.items())
} | _experimental_use_cc_common_link_attrs

def _rust_binary_transition_impl(settings, attr):
return {
Expand All @@ -1104,15 +1104,15 @@ _rust_binary_transition = transition(
rust_binary = rule(
implementation = _rust_binary_impl,
provides = COMMON_PROVIDERS,
attrs = dict(_common_attrs.items() + _rust_binary_attrs.items() + {
attrs = _common_attrs | _rust_binary_attrs | {
"platform": attr.label(
doc = "Optional platform to transition the binary to.",
default = None,
),
"_allowlist_function_transition": attr.label(
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
),
}.items()),
},
executable = True,
fragments = ["cpp"],
cfg = _rust_binary_transition,
Expand Down Expand Up @@ -1246,15 +1246,15 @@ def _common_attrs_for_binary_without_process_wrapper(attrs):
rust_binary_without_process_wrapper = rule(
implementation = _rust_binary_impl,
provides = COMMON_PROVIDERS,
attrs = _common_attrs_for_binary_without_process_wrapper(_common_attrs.items() + _rust_binary_attrs.items() + {
attrs = _common_attrs_for_binary_without_process_wrapper(_common_attrs | _rust_binary_attrs | {
"platform": attr.label(
doc = "Optional platform to transition the binary to.",
default = None,
),
"_allowlist_function_transition": attr.label(
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
),
}.items()),
}),
executable = True,
fragments = ["cpp"],
cfg = _rust_binary_transition,
Expand Down Expand Up @@ -1293,15 +1293,15 @@ _rust_test_transition = transition(
rust_test = rule(
implementation = _rust_test_impl,
provides = COMMON_PROVIDERS,
attrs = dict(_common_attrs.items() + _rust_test_attrs.items() + {
attrs = _common_attrs | _rust_test_attrs | {
"platform": attr.label(
doc = "Optional platform to transition the test to.",
default = None,
),
"_allowlist_function_transition": attr.label(
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
),
}.items()),
},
executable = True,
fragments = ["cpp"],
cfg = _rust_test_transition,
Expand Down

0 comments on commit 7685b69

Please sign in to comment.