Skip to content

Commit 6a36c15

Browse files
committed
Moved rust_allocator_libraries to it's own .bzl file
1 parent 4461a8a commit 6a36c15

File tree

4 files changed

+328
-294
lines changed

4 files changed

+328
-294
lines changed

ffi/rs/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
load("@rules_cc//cc:cc_library.bzl", "cc_library")
22

33
# buildifier: disable=bzl-visibility
4-
load("@rules_rust//rust/private:rust.bzl", "rust_allocator_libraries")
4+
load("@rules_rust//rust/private:rust_allocator_libraries.bzl", "rust_allocator_libraries")
55

66
rust_allocator_libraries(
77
name = "allocator_libraries_with_mangling_support",

rust/private/rust.bzl

Lines changed: 5 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
2020
load("//rust/private:common.bzl", "COMMON_PROVIDERS", "rust_common")
2121
load(
2222
"//rust/private:providers.bzl",
23-
"AllocatorLibrariesImplInfo",
24-
"AllocatorLibrariesInfo",
2523
"BuildInfo",
2624
"CrateGroupInfo",
2725
"CrateInfo",
@@ -46,6 +44,10 @@ load(
4644
"transform_deps",
4745
"transform_sources",
4846
)
47+
load(
48+
":rust_allocator_libraries.bzl",
49+
"RUSTC_ALLOCATOR_LIBRARIES_ATTRS",
50+
)
4951

5052
# TODO(marco): Separate each rule into its own file.
5153

@@ -650,19 +652,6 @@ RUSTC_ATTRS = {
650652
),
651653
}
652654

653-
# Attributes for rust-based allocator library support.
654-
# Can't add it directly to RUSTC_ATTRS above, as those are used as
655-
# aspect parameters and only support simple types ('bool', 'int' or 'string').
656-
_rustc_allocator_libraries_attrs = {
657-
# This is really internal. Not prefixed with `_` since we need to adapt this
658-
# in bootstrapping situations, e.g., when building the process wrapper
659-
# or allocator libraries themselves.
660-
"allocator_libraries": attr.label(
661-
default = "//ffi/rs:default_allocator_libraries",
662-
providers = [AllocatorLibrariesInfo],
663-
),
664-
}
665-
666655
_common_attrs = {
667656
"aliases": attr.label_keyed_string_dict(
668657
doc = dedent("""\
@@ -836,7 +825,7 @@ _common_attrs = {
836825
doc = "A setting used to determine whether or not the `--stamp` flag is enabled",
837826
default = Label("//rust/private:stamp"),
838827
),
839-
} | RUSTC_ATTRS | _rustc_allocator_libraries_attrs
828+
} | RUSTC_ATTRS | RUSTC_ALLOCATOR_LIBRARIES_ATTRS
840829

841830
_coverage_attrs = {
842831
"_collect_cc_coverage": attr.label(
@@ -1683,47 +1672,6 @@ rust_library_group = rule(
16831672
"""),
16841673
)
16851674

1686-
def _rust_allocator_libraries_impl(ctx):
1687-
toolchain = find_toolchain(ctx)
1688-
allocator_library = ctx.attr.allocator_library[AllocatorLibrariesImplInfo] if ctx.attr.allocator_library else None
1689-
global_allocator_library = ctx.attr.global_allocator_library[AllocatorLibrariesImplInfo] if ctx.attr.global_allocator_library else None
1690-
1691-
make_ccinfo = lambda info, std: toolchain.make_libstd_and_allocator_ccinfo(
1692-
ctx.label,
1693-
ctx.actions,
1694-
struct(allocator_libraries_impl_info = info),
1695-
std,
1696-
)
1697-
1698-
providers = [AllocatorLibrariesInfo(
1699-
allocator_library = allocator_library,
1700-
global_allocator_library = global_allocator_library,
1701-
libstd_and_allocator_ccinfo = make_ccinfo(allocator_library, "std"),
1702-
libstd_and_global_allocator_ccinfo = make_ccinfo(global_allocator_library, "std"),
1703-
nostd_and_global_allocator_ccinfo = make_ccinfo(global_allocator_library, "no_std_with_alloc"),
1704-
)]
1705-
1706-
return providers
1707-
1708-
rust_allocator_libraries = rule(
1709-
implementation = _rust_allocator_libraries_impl,
1710-
provides = [AllocatorLibrariesInfo],
1711-
attrs = {
1712-
"allocator_library": attr.label(
1713-
doc = "An optional library to provide when a default rust allocator is used.",
1714-
providers = [AllocatorLibrariesImplInfo],
1715-
),
1716-
"global_allocator_library": attr.label(
1717-
doc = "An optional library to provide when a default rust allocator is used.",
1718-
providers = [AllocatorLibrariesImplInfo],
1719-
),
1720-
},
1721-
toolchains = [
1722-
str(Label("//rust:toolchain_type")),
1723-
"@bazel_tools//tools/cpp:toolchain_type",
1724-
],
1725-
)
1726-
17271675
def _replace_illlegal_chars(name):
17281676
"""Replaces illegal characters in a name with underscores.
17291677

0 commit comments

Comments
 (0)