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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
build / config / siso / rust_linux.star [blame]
# -*- bazel-starlark -*-
# Copyright 2023 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Siso configuration for rust/linux."""
load("@builtin//path.star", "path")
load("@builtin//lib/gn.star", "gn")
load("@builtin//struct.star", "module")
load("./config.star", "config")
load("./fuchsia.star", "fuchsia")
def __filegroups(ctx):
fg = {
"third_party/rust-toolchain:toolchain": {
"type": "glob",
"includes": [
"bin/rustc",
"lib/*.so",
"lib/libclang.so.*",
"lib/rustlib/src/rust/library/std/src/lib.rs",
"lib/rustlib/x86_64-unknown-linux-gnu/lib/*",
],
},
"third_party/rust:rustlib": {
"type": "glob",
"includes": [
"*.rs",
],
},
"build/linux/debian_bullseye_amd64-sysroot:rustlink": {
"type": "glob",
"includes": [
"*.so",
"*.so.*",
"*.o",
"*.a",
],
},
"third_party/llvm-build/Release+Asserts:rustlink": {
"type": "glob",
"includes": [
"bin/clang",
"bin/clang++",
"bin/*lld*",
"libclang*.a",
],
},
}
if fuchsia.enabled(ctx):
fg.update(fuchsia.filegroups(ctx))
return fg
def __rust_link_handler(ctx, cmd):
inputs = []
use_android_toolchain = None
target = None
args = cmd.args
# there is a case that command line sets environment variable
# like `TOOL_VERSION=xxxx "python3" ..`
if args[0] == "/bin/sh":
args = args[2].split(" ")
for i, arg in enumerate(args):
if arg.startswith("--sysroot=../../third_party/fuchsia-sdk/sdk"):
sysroot = ctx.fs.canonpath(arg.removeprefix("--sysroot="))
libpath = path.join(path.dir(sysroot), "lib")
inputs.extend([
sysroot + ":link",
libpath + ":link",
])
elif arg.startswith("--sysroot=../../third_party/android_toolchain/ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot"):
use_android_toolchain = True
inputs.append("third_party/android_toolchain/ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot:headers")
if arg == "-isysroot":
sysroot = ctx.fs.canonpath(args[i + 1])
inputs.extend([
sysroot + ":link",
])
if arg.startswith("--target="):
target = arg.removeprefix("--target=")
if arg.startswith("-Clinker="):
linker = arg.removeprefix("-Clinker=")
if linker.startswith("\""):
linker = linker[1:len(linker) - 1]
# TODO(crbug.com/380798907): expand input_deps, instead of using label?
inputs.append(ctx.fs.canonpath(linker) + ":link")
if use_android_toolchain and target:
# e.g. target=aarch64-linux-android26
android_ver = ""
i = target.find("android")
if i >= 0:
android_ver = target[i:].removeprefix("android").removeprefix("eabi")
if android_ver:
android_arch = target.removesuffix(android_ver)
filegroup = "third_party/android_toolchain/ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/%s/%s:link" % (android_arch, android_ver)
inputs.append(filegroup)
ctx.actions.fix(inputs = cmd.inputs + inputs)
def __rust_build_handler(ctx, cmd):
inputs = []
for i, arg in enumerate(cmd.args):
if arg == "--src-dir":
inputs.append(ctx.fs.canonpath(cmd.args[i + 1]))
ctx.actions.fix(inputs = cmd.inputs + inputs)
__handlers = {
"rust_link_handler": __rust_link_handler,
"rust_build_handler": __rust_build_handler,
}
def __step_config(ctx, step_config):
platform_ref = "large" # Rust actions run faster on large workers.
remote = True
# TODO: crbug.com/382399126 - Remote rust link is not supported
# for Windows target builds, yet.
if "args.gn" in ctx.metadata:
gn_args = gn.args(ctx)
if gn_args.get("target_os") == '"win"':
remote = False
clang_inputs = [
"build/linux/debian_bullseye_amd64-sysroot:rustlink",
"third_party/llvm-build/Release+Asserts:rustlink",
]
rust_toolchain = [
# TODO(b/285225184): use precomputed subtree
"third_party/rust-toolchain:toolchain",
]
rust_inputs = [
"build/action_helpers.py",
"build/gn_helpers.py",
"build/rust/rustc_wrapper.py",
] + rust_toolchain
rust_indirect_inputs = {
"includes": [
"*.h",
"*.o",
"*.rlib",
"*.rs",
"*.so",
],
}
step_config["rules"].extend([
{
"name": "rust_bin",
"action": "(.*_)?rust_bin",
"inputs": rust_inputs + clang_inputs,
"indirect_inputs": rust_indirect_inputs,
"handler": "rust_link_handler",
"deps": "none", # disable gcc scandeps
"remote": remote,
# "canonicalize_dir": True, # TODO(b/300352286)
"timeout": "2m",
"platform_ref": platform_ref,
},
{
"name": "rust_cdylib",
"action": "(.*_)?rust_cdylib",
"inputs": rust_inputs + clang_inputs,
"indirect_inputs": rust_indirect_inputs,
"handler": "rust_link_handler",
"deps": "none", # disable gcc scandeps
"remote": remote,
# "canonicalize_dir": True, # TODO(b/300352286)
"timeout": "2m",
"platform_ref": platform_ref,
},
{
"name": "rust_macro",
"action": "(.*_)?rust_macro",
"inputs": rust_inputs + clang_inputs,
"indirect_inputs": rust_indirect_inputs,
"handler": "rust_link_handler",
"deps": "none", # disable gcc scandeps
# "canonicalize_dir": True, # TODO(b/300352286)
"remote": remote,
"timeout": "2m",
"platform_ref": platform_ref,
},
{
"name": "rust_rlib",
"action": "(.*_)?rust_rlib",
"inputs": rust_inputs,
"indirect_inputs": rust_indirect_inputs,
"deps": "none", # disable gcc scandeps
"remote": remote,
# "canonicalize_dir": True, # TODO(b/300352286)
"timeout": "2m",
"platform_ref": platform_ref,
},
{
"name": "rust_staticlib",
"action": "(.*_)?rust_staticlib",
"inputs": rust_inputs,
"indirect_inputs": rust_indirect_inputs,
"deps": "none", # disable gcc scandeps
"remote": remote,
# "canonicalize_dir": True, # TODO(b/300352286)
"timeout": "2m",
"platform_ref": platform_ref,
},
{
"name": "rust/run_build_script",
"command_prefix": "python3 ../../build/rust/run_build_script.py",
"inputs": [
"third_party/rust-toolchain:toolchain",
"third_party/rust:rustlib",
],
"handler": "rust_build_handler",
"remote": remote and config.get(ctx, "cog"),
"input_root_absolute_path": True,
"timeout": "2m",
},
{
"name": "rust/find_std_rlibs",
"command_prefix": "python3 ../../build/rust/std/find_std_rlibs.py",
"inputs": [
"third_party/rust-toolchain:toolchain",
"third_party/rust-toolchain/lib/rustlib:rlib",
],
"remote": remote and config.get(ctx, "cog"),
"input_root_absolute_path": True,
"timeout": "2m",
},
{
# rust/bindgen fails remotely when *.d does not exist.
# TODO(b/356496947): need to run scandeps?
"name": "rust/bindgen",
"command_prefix": "python3 ../../build/rust/run_bindgen.py",
"inputs": rust_toolchain + clang_inputs,
"remote": False,
"timeout": "2m",
},
])
return step_config
rust = module(
"rust",
filegroups = __filegroups,
handlers = __handlers,
step_config = __step_config,
)