forked from facebook/buck2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
linkables.bzl
53 lines (49 loc) · 1.69 KB
/
linkables.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under both the MIT license found in the
# LICENSE-MIT file in the root directory of this source tree and the Apache
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
# of this source tree.
load(
"@prelude//utils:utils.bzl",
"expect",
)
load(
":link_groups.bzl",
"LinkGroupLibInfo",
)
load(
":link_info.bzl",
"MergedLinkInfo",
)
load(
":linkable_graph.bzl",
"LinkableGraph",
"LinkableRootInfo",
)
load(
":shared_libraries.bzl",
"SharedLibraryInfo",
)
# A record containing all provider types used for linking in the prelude. This
# is essentially the minimal subset of a "linkable" `dependency` that user rules
# need to implement linking, and avoids needing functions to take the heavier-
# weight `dependency` type.
LinkableProviders = record(
link_group_lib_info = field(LinkGroupLibInfo),
linkable_graph = field([LinkableGraph, None], None),
merged_link_info = field(MergedLinkInfo),
shared_library_info = field(SharedLibraryInfo),
linkable_root_info = field([LinkableRootInfo, None], None),
)
def linkable(dep: Dependency) -> LinkableProviders:
expect(LinkGroupLibInfo in dep, str(dep.label.raw_target()))
return LinkableProviders(
shared_library_info = dep[SharedLibraryInfo],
linkable_graph = dep.get(LinkableGraph),
merged_link_info = dep[MergedLinkInfo],
link_group_lib_info = dep[LinkGroupLibInfo],
linkable_root_info = dep.get(LinkableRootInfo),
)
def linkables(deps: list[Dependency]) -> list[LinkableProviders]:
return [linkable(dep) for dep in deps if MergedLinkInfo in dep]