-
Notifications
You must be signed in to change notification settings - Fork 12
/
extensions.bzl
98 lines (93 loc) · 4.05 KB
/
extensions.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
load("//:rules.bzl", "DEFAULT_IMAGE", "UBUNTU16_04_IMAGE", "UBUNTU20_04_IMAGE", "UBUNTU22_04_IMAGE", bb_macro = "buildbuddy")
def _ext_impl(mctx):
found_root_module = False
root_module = struct()
for m in mctx.modules:
if m.is_root:
found_root_module = True
root_module = m
break
if not found_root_module:
fail("buildbuddy must be used in root module")
tags = root_module.tags
if len(tags.platform) > 1:
fail("buildbuddy.platform can only be specified once per module")
if len(tags.gcc_toolchain) > 1:
fail("buildbuddy.gcc_toolchain can only be specified once per module")
if len(tags.msvc_toolchain) > 1:
fail("buildbuddy.msvc_toolchain can only be specified once per module")
platform_tag = tags.platform[0] if tags.platform else None
gcc_toolchain_tag = tags.gcc_toolchain[0] if tags.gcc_toolchain else None
msvc_toolchain_tag = tags.msvc_toolchain[0] if tags.msvc_toolchain else None
macro_args = dict()
if platform_tag:
if platform_tag.buildbuddy_container_image and platform_tag.container_image:
fail("buildbuddy.platform.container_image and buildbuddy.platform.buildbuddy_container_image cannot be specified together")
if platform_tag.buildbuddy_container_image:
if platform_tag.buildbuddy_container_image == "DEFAULT_IMAGE":
image = DEFAULT_IMAGE
elif platform_tag.buildbuddy_container_image == "UBUNTU16_04_IMAGE":
image = UBUNTU16_04_IMAGE
elif platform_tag.buildbuddy_container_image == "UBUNTU20_04_IMAGE":
image = UBUNTU20_04_IMAGE
elif platform_tag.buildbuddy_container_image == "UBUNTU22_04_IMAGE":
image = UBUNTU22_04_IMAGE
else:
fail("Unknown buildbuddy.platform.buildbuddy_container_image value: %s" % platform_tag.buildbuddy_container_image)
else:
image = platform_tag.container_image
macro_args |= {
"container_image": image,
}
if gcc_toolchain_tag:
macro_args |= {
"gcc_major_version": gcc_toolchain_tag.gcc_major_version,
"extra_cxx_builtin_include_directories": gcc_toolchain_tag.extra_cxx_builtin_include_directories,
}
if msvc_toolchain_tag:
macro_args |= {
"msvc_edition": msvc_toolchain_tag.msvc_edition,
"msvc_release": msvc_toolchain_tag.msvc_release,
"msvc_version": msvc_toolchain_tag.msvc_version,
"windows_kits_release": msvc_toolchain_tag.windows_kits_release,
"windows_kits_version": msvc_toolchain_tag.windows_kits_version,
}
bb_macro(
name = "buildbuddy_toolchain",
**macro_args,
)
buildbuddy = module_extension(
implementation = _ext_impl,
tag_classes = {
"gcc_toolchain": tag_class(
attrs = {
"gcc_major_version": attr.string(),
"extra_cxx_builtin_include_directories": attr.string_list(),
},
),
"msvc_toolchain": tag_class(
attrs = {
"msvc_edition": attr.string(values = ["Community", "Professional", "Enterprise"]),
"msvc_release": attr.string(),
"msvc_version": attr.string(),
"windows_kits_release": attr.string(),
"windows_kits_version": attr.string(),
},
),
"platform": tag_class(
attrs = {
# Only one of these can be specified
"container_image": attr.string(doc = "custom container image to use as execution sandbox"),
"buildbuddy_container_image": attr.string(
values = [
"DEFAULT_IMAGE",
"UBUNTU16_04_IMAGE",
"UBUNTU20_04_IMAGE",
"UBUNTU22_04_IMAGE"
],
doc = "buildbuddy's pre-built container image to use as execution sandbox",
),
},
),
},
)