1# -*- bazel-starlark -*- 2# Copyright 2023 The Chromium Authors 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5"""Siso configuration for rust/linux.""" 6 7load("@builtin//path.star", "path") 8load("@builtin//struct.star", "module") 9load("./config.star", "config") 10load("./fuchsia.star", "fuchsia") 11 12# TODO: b/323091468 - Propagate fuchsia arch and version from GN, 13# and remove the hardcoded filegroups. 14fuchsia_archs = [ 15 "arm64", 16 "riscv64", 17 "x64", 18] 19 20fuchsia_versions = [12, 14, 15, 16, 17, 18] 21 22def __filegroups(ctx): 23 fg = { 24 "third_party/rust-toolchain:toolchain": { 25 "type": "glob", 26 "includes": [ 27 "bin/rustc", 28 "lib/*.so", 29 "lib/rustlib/src/rust/library/std/src/lib.rs", 30 "lib/rustlib/x86_64-unknown-linux-gnu/lib/*", 31 ], 32 }, 33 "third_party/rust:rustlib": { 34 "type": "glob", 35 "includes": [ 36 "*.rs", 37 ], 38 }, 39 "build/linux/debian_bullseye_amd64-sysroot:rustlink": { 40 "type": "glob", 41 "includes": [ 42 "*.so", 43 "*.so.*", 44 "*.o", 45 "*.a", 46 ], 47 }, 48 "third_party/llvm-build/Release+Asserts:rustlink": { 49 "type": "glob", 50 "includes": [ 51 "bin/clang", 52 "bin/clang++", 53 "bin/*lld", 54 "libclang*.a", 55 ], 56 }, 57 } 58 if fuchsia.enabled(ctx): 59 for arch in fuchsia_archs: 60 group = "third_party/fuchsia-sdk/sdk/arch/%s:rustlink" % arch 61 fg[group] = { 62 "type": "glob", 63 "includes": [ 64 "lib/*", 65 "sysroot/lib/*", 66 ], 67 } 68 for ver in fuchsia_versions: 69 group = "third_party/fuchsia-sdk/sdk/obj/%s-api-%s:rustlink" % (arch, ver) 70 fg[group] = { 71 "type": "glob", 72 "includes": [ 73 "lib/*", 74 "sysroot/lib/*", 75 ], 76 } 77 return fg 78 79def __rust_bin_handler(ctx, cmd): 80 inputs = [] 81 use_android_toolchain = None 82 target = None 83 for i, arg in enumerate(cmd.args): 84 if arg.startswith("--sysroot=../../third_party/fuchsia-sdk/sdk"): 85 # Get the corresponding sdk filegroup from --sysroot. 86 # e.g. --sysroot=../../third_party/fuchsia-sdk/sdk/obj/x64-api-16/sysroot -> third_party/fuchsia-sdk/sdk/obj/x64-api-16:rustlink 87 filegroup = "%s:rustlink" % path.dir(ctx.fs.canonpath(arg.removeprefix("--sysroot="))) 88 inputs.append(filegroup) 89 elif arg.startswith("--sysroot=../../third_party/android_toolchain/ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot"): 90 use_android_toolchain = True 91 if arg.startswith("--target="): 92 target = arg.removeprefix("--target=") 93 if use_android_toolchain and target: 94 # e.g. target=aarch64-linux-android26 95 android_ver = "" 96 i = target.find("android") 97 if i >= 0: 98 android_ver = target[i:].removeprefix("android").removeprefix("eabi") 99 if android_ver: 100 android_arch = target.removesuffix(android_ver) 101 filegroup = "third_party/android_toolchain/ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/%s/%s:link" % (android_arch, android_ver) 102 inputs.append(filegroup) 103 104 ctx.actions.fix(inputs = cmd.inputs + inputs) 105 106__handlers = { 107 "rust_bin_handler": __rust_bin_handler, 108} 109 110def __step_config(ctx, step_config): 111 remote_run = True # Turn this to False when you do file access trace. 112 platform_ref = "large" # Rust actions run faster on large workers. 113 clang_inputs = [ 114 "build/linux/debian_bullseye_amd64-sysroot:rustlink", 115 "third_party/llvm-build/Release+Asserts:rustlink", 116 ] 117 rust_inputs = [ 118 "build/action_helpers.py", 119 "build/gn_helpers.py", 120 "build/rust/rustc_wrapper.py", 121 # TODO(b/285225184): use precomputed subtree 122 "third_party/rust-toolchain:toolchain", 123 ] 124 rust_indirect_inputs = { 125 "includes": [ 126 "*.h", 127 "*.o", 128 "*.rlib", 129 "*.rs", 130 "*.so", 131 ], 132 } 133 step_config["rules"].extend([ 134 { 135 "name": "rust_bin", 136 "action": "(.*_)?rust_bin", 137 "inputs": rust_inputs + clang_inputs, 138 "indirect_inputs": rust_indirect_inputs, 139 "handler": "rust_bin_handler", 140 "deps": "none", # disable gcc scandeps 141 "remote": remote_run, 142 # "canonicalize_dir": True, # TODO(b/300352286) 143 "timeout": "2m", 144 "platform_ref": platform_ref, 145 }, 146 { 147 "name": "rust_cdylib", 148 "action": "(.*_)?rust_cdylib", 149 "inputs": rust_inputs + clang_inputs, 150 "indirect_inputs": rust_indirect_inputs, 151 "deps": "none", # disable gcc scandeps 152 "remote": remote_run, 153 # "canonicalize_dir": True, # TODO(b/300352286) 154 "timeout": "2m", 155 "platform_ref": platform_ref, 156 }, 157 { 158 "name": "rust_macro", 159 "action": "(.*_)?rust_macro", 160 "inputs": rust_inputs + clang_inputs, 161 "indirect_inputs": rust_indirect_inputs, 162 "deps": "none", # disable gcc scandeps 163 # "canonicalize_dir": True, # TODO(b/300352286) 164 "remote": remote_run, 165 "timeout": "2m", 166 "platform_ref": platform_ref, 167 }, 168 { 169 "name": "rust_rlib", 170 "action": "(.*_)?rust_rlib", 171 "inputs": rust_inputs, 172 "indirect_inputs": rust_indirect_inputs, 173 "deps": "none", # disable gcc scandeps 174 "remote": remote_run, 175 # "canonicalize_dir": True, # TODO(b/300352286) 176 "timeout": "2m", 177 "platform_ref": platform_ref, 178 }, 179 { 180 "name": "rust_staticlib", 181 "action": "(.*_)?rust_staticlib", 182 "inputs": rust_inputs, 183 "indirect_inputs": rust_indirect_inputs, 184 "deps": "none", # disable gcc scandeps 185 "remote": remote_run, 186 # "canonicalize_dir": True, # TODO(b/300352286) 187 "timeout": "2m", 188 "platform_ref": platform_ref, 189 }, 190 { 191 "name": "rust/run_build_script", 192 "command_prefix": "python3 ../../build/rust/run_build_script.py", 193 "inputs": [ 194 "build/action_helpers.py", 195 "build/gn_helpers.py", 196 "third_party/rust-toolchain:toolchain", 197 "third_party/rust:rustlib", 198 # XXX: -src-dir? 199 "third_party/rust-toolchain/lib/rustlib/src/rust/library/std", 200 "third_party/rust-toolchain/lib/rustlib/src/rust/vendor/libc-0.2.153", 201 "third_party/rust-toolchain/lib/rustlib/src/rust/vendor/memchr-2.5.0", 202 "third_party/rust-toolchain/lib/rustlib/src/rust/vendor/compiler_builtins-0.1.108", 203 ], 204 "remote": config.get(ctx, "cog"), 205 "input_root_absolute_path": True, 206 "timeout": "2m", 207 }, 208 { 209 "name": "rust/find_std_rlibs", 210 "command_prefix": "python3 ../../build/rust/std/find_std_rlibs.py", 211 "inputs": [ 212 "third_party/rust-toolchain:toolchain", 213 "third_party/rust-toolchain/lib/rustlib:rlib", 214 ], 215 "remote": config.get(ctx, "cog"), 216 "input_root_absolute_path": True, 217 "timeout": "2m", 218 }, 219 ]) 220 return step_config 221 222rust = module( 223 "rust", 224 filegroups = __filegroups, 225 handlers = __handlers, 226 step_config = __step_config, 227) 228