• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 ChromeOS builds."""
6
7load("@builtin//lib/gn.star", "gn")
8load("@builtin//path.star", "path")
9load("@builtin//struct.star", "module")
10
11def __filegroups(ctx):
12    fg = {}
13    if not "args.gn" in ctx.metadata:
14        print("no args.gn")
15        return fg
16    gn_args = gn.args(ctx)
17    if not "cros_target_cxx" in gn_args:
18        print("no cros_target_cxx")
19        return fg
20    toolchain = gn_args.get("cros_target_cxx")
21    toolchain = toolchain.strip('"')
22    toolchain = ctx.fs.canonpath(toolchain)
23    print("toolchain = %s" % toolchain)
24    if toolchain:
25        toolchain = path.dir(path.dir(toolchain))
26        fg[toolchain + ":headers"] = {
27            "type": "glob",
28            "includes": ["*"],
29        }
30    if not "target_sysroot" in gn_args:
31        print("no target_sysroot")
32        return fg
33    sysroot = gn_args.get("target_sysroot")
34    sysroot = sysroot.strip('"')
35    sysroot = ctx.fs.canonpath(sysroot)
36    print("sysroot = %s" % sysroot)
37    if sysroot:
38        fg[path.join(sysroot, "usr/include") + ":include"] = {
39            "type": "glob",
40            "includes": ["*"],
41            # needs bits/stab.def, c++/*
42        }
43        fg[path.join(sysroot, "usr/lib") + ":headers"] = {
44            "type": "glob",
45            "includes": ["*.h", "crtbegin.o"],
46        }
47        fg[path.join(sysroot, "usr/lib64") + ":headers"] = {
48            "type": "glob",
49            "includes": ["*.h"],
50        }
51    print(fg)
52    return fg
53
54def __cros_compiler(ctx, cmd):
55    tool_inputs = cmd.tool_inputs
56    for i, arg in enumerate(cmd.args):
57        if arg.startswith("-fprofile-sample-use="):
58            # profile data is in ninja input (direct or indirect),
59            # but siso doesn't include ninja inputs for deps=gcc
60            # (it would include lots of unnecessary inputs)
61            # so just add profdata by checking command line flag.
62            profdata = ctx.fs.canonpath(arg.removeprefix("-fprofile-sample-use="))
63            tool_inputs.append(profdata)
64    ctx.actions.fix(tool_inputs = tool_inputs)
65
66__handlers = {
67    "cros_compiler": __cros_compiler,
68}
69
70def __step_config(ctx, step_config):
71    if not "args.gn" in ctx.metadata:
72        return step_config
73    gn_args = gn.args(ctx)
74    if "cros_target_cxx" in gn_args:
75        toolchain = gn_args.get("cros_target_cxx")
76        if toolchain:
77            step_config["rules"].extend([
78                {
79                    "name": "clang-cros/cxx",
80                    "action": "(.*_)?cxx",
81                    "command_prefix": "../../build/cros_cache/chrome-sdk/",
82                    "remote": True,
83                    "handler": "cros_compiler",
84                    "canonicalize_dir": True,
85                    "timeout": "5m",
86                },
87                {
88                    "name": "clang-cros/cc",
89                    "action": "(.*_)?cc",
90                    "command_prefix": "../../build/cros_cache/chrome-sdk/",
91                    "remote": True,
92                    "handler": "cros_compiler",
93                    "canonicalize_dir": True,
94                    "timeout": "5m",
95                },
96            ])
97    if "target_sysroot" in gn_args:
98        sysroot = gn_args.get("target_sysroot")
99        if sysroot:
100            sysroot = sysroot.strip('"')
101            sysroot = ctx.fs.canonpath(sysroot)
102            step_config["input_deps"].update({
103                sysroot + ":headers": [
104                    path.join(sysroot, "usr/include") + ":include",
105                    path.join(sysroot, "usr/lib") + ":headers",
106                    path.join(sysroot, "usr/lib64") + ":headers",
107                ],
108            })
109    return step_config
110
111cros = module(
112    "cros",
113    filegroups = __filegroups,
114    handlers = __handlers,
115    step_config = __step_config,
116)
117