-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtoolchain.bzl
More file actions
121 lines (112 loc) · 4.22 KB
/
toolchain.bzl
File metadata and controls
121 lines (112 loc) · 4.22 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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
"""The Mojo compiler toolchain."""
load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
load("//mojo:providers.bzl", "MojoCoptsToolchainInfo", "MojoInfo", "MojoToolchainInfo")
def _mojo_toolchain_impl(ctx):
tool_files = []
for dep in ctx.attr.implicit_deps + ctx.attr.extra_tools + [ctx.attr.lld, ctx.attr.mojo]:
tool_files.append(dep[DefaultInfo].default_runfiles.files)
tool_files.append(dep[DefaultInfo].files)
copts = list(ctx.attr.copts)
package_copts = list(ctx.attr.package_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")
is_macos = ctx.target_platform_has_constraint(ctx.attr._macos_constraint[platform_common.ConstraintValueInfo])
if is_macos:
min_os = ctx.fragments.cpp.minimum_os_version() or ctx.fragments.apple.macos_minimum_os_flag
if min_os:
copts.append("--target-triple=arm64-apple-macosx{}".format(min_os))
copts_toolchain = ctx.toolchains["//:copts_toolchain_type"]
if copts_toolchain:
copts.extend(copts_toolchain.copts_toolchain_info.copts)
package_copts = copts_toolchain.copts_toolchain_info.package_copts
return [
platform_common.ToolchainInfo(
mojo_toolchain_info = MojoToolchainInfo(
all_tools = tool_files,
copts = copts,
package_copts = package_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.",
),
"package_copts": attr.string_list(
mandatory = False,
doc = "Additional compiler options to pass to the Mojo compiler when running 'mojo package'.",
),
"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.",
),
"_macos_constraint": attr.label(
default = Label("@platforms//os:macos"),
),
},
doc = """\
Defines the Mojo compiler toolchain.
""",
toolchains = [
config_common.toolchain_type("//:gpu_toolchain_type", mandatory = False),
config_common.toolchain_type("//:copts_toolchain_type", mandatory = False),
],
fragments = ["cpp", "apple"],
)
def _mojo_copts_toolchain_impl(ctx):
return [
platform_common.ToolchainInfo(
copts_toolchain_info = MojoCoptsToolchainInfo(
copts = ctx.attr.copts,
package_copts = ctx.attr.package_copts,
),
),
]
mojo_copts_toolchain = rule(
implementation = _mojo_copts_toolchain_impl,
attrs = {
"copts": attr.string_list(
mandatory = True,
doc = "Additional compiler options to pass to the Mojo compiler.",
),
"package_copts": attr.string_list(
mandatory = True,
doc = "Additional compiler options to pass to the Mojo compiler when running 'mojo package'.",
),
},
doc = """\
Defines additional compiler options for the Mojo compiler.
""",
)