-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtoolchain.bzl
More file actions
72 lines (67 loc) · 2.39 KB
/
toolchain.bzl
File metadata and controls
72 lines (67 loc) · 2.39 KB
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
"""The Mojo compiler toolchain."""
load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
load("//mojo:providers.bzl", "MojoInfo", "MojoToolchainInfo")
def _mojo_toolchain_impl(ctx):
tool_files = [ctx.attr.mojo[DefaultInfo].files]
for dep in ctx.attr.implicit_deps + ctx.attr.extra_tools + [ctx.attr.lld]:
tool_files.append(dep[DefaultInfo].default_runfiles.files)
tool_files.append(dep[DefaultInfo].files_to_run)
copts = list(ctx.attr.copts)
gpu_toolchain = ctx.toolchains["//:gpu_toolchain_type"]
if gpu_toolchain:
copts.append("--target-accelerator=" + gpu_toolchain.mojo_gpu_toolchain_info.target_accelerator)
else:
copts.append("--target-accelerator=NONE")
return [
platform_common.ToolchainInfo(
mojo_toolchain_info = MojoToolchainInfo(
all_tools = tool_files,
copts = copts,
lld = ctx.executable.lld,
mojo = ctx.executable.mojo,
implicit_deps = ctx.attr.implicit_deps,
),
),
]
mojo_toolchain = rule(
implementation = _mojo_toolchain_impl,
attrs = {
"copts": attr.string_list(
mandatory = False,
doc = "Additional compiler options to pass to the Mojo compiler.",
),
"extra_tools": attr.label_list(
providers = [DefaultInfo],
allow_files = True,
mandatory = False,
cfg = "exec",
doc = "Additional tools to make available to every Mojo action.",
),
"lld": attr.label(
allow_files = True,
mandatory = True,
executable = True,
cfg = "exec",
doc = "The lld executable to link with.",
),
"mojo": attr.label(
allow_files = True,
mandatory = True,
executable = True,
cfg = "exec",
doc = "The mojo compiler executable to build with.",
),
"implicit_deps": attr.label_list(
providers = [[CcInfo], [MojoInfo]],
mandatory = True,
cfg = "target",
doc = "Implicit dependencies that every target should depend on, providing either CcInfo, or MojoInfo.",
),
},
doc = """\
Defines the Mojo compiler toolchain.
""",
toolchains = [
config_common.toolchain_type("//:gpu_toolchain_type", mandatory = False),
],
)