summaryrefslogtreecommitdiff
path: root/build/config/siso/cros.star
blob: b33a09454225aa08776436618adb0021fede17b2 (plain)
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
# -*- 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 ChromeOS builds."""

load("@builtin//lib/gn.star", "gn")
load("@builtin//path.star", "path")
load("@builtin//struct.star", "module")

def __filegroups(ctx):
    fg = {}
    if not "args.gn" in ctx.metadata:
        print("no args.gn")
        return fg
    gn_args = gn.args(ctx)
    if not "cros_target_cxx" in gn_args:
        print("no cros_target_cxx")
        return fg
    toolchain = gn_args.get("cros_target_cxx")
    toolchain = toolchain.strip('"')
    toolchain = ctx.fs.canonpath(toolchain)
    print("toolchain = %s" % toolchain)
    if toolchain:
        toolchain = path.dir(path.dir(toolchain))
        fg[toolchain + ":headers"] = {
            "type": "glob",
            "includes": ["*"],
        }
    if not "target_sysroot" in gn_args:
        print("no target_sysroot")
        return fg
    sysroot = gn_args.get("target_sysroot")
    sysroot = sysroot.strip('"')
    sysroot = ctx.fs.canonpath(sysroot)
    print("sysroot = %s" % sysroot)
    if sysroot:
        fg[path.join(sysroot, "usr/include") + ":include"] = {
            "type": "glob",
            "includes": ["*"],
            # needs bits/stab.def, c++/*
        }
        fg[path.join(sysroot, "usr/lib") + ":headers"] = {
            "type": "glob",
            "includes": ["*.h", "crtbegin.o"],
        }
        fg[path.join(sysroot, "usr/lib64") + ":headers"] = {
            "type": "glob",
            "includes": ["*.h"],
        }
    print(fg)
    return fg

def __cros_compiler(ctx, cmd):
    tool_inputs = cmd.tool_inputs
    for i, arg in enumerate(cmd.args):
        if arg.startswith("-fprofile-sample-use="):
            # profile data is in ninja input (direct or indirect),
            # but siso doesn't include ninja inputs for deps=gcc
            # (it would include lots of unnecessary inputs)
            # so just add profdata by checking command line flag.
            profdata = ctx.fs.canonpath(arg.removeprefix("-fprofile-sample-use="))
            tool_inputs.append(profdata)
    ctx.actions.fix(tool_inputs = tool_inputs)

__handlers = {
    "cros_compiler": __cros_compiler,
}

def __step_config(ctx, step_config):
    if not "args.gn" in ctx.metadata:
        return step_config
    gn_args = gn.args(ctx)
    if "cros_target_cxx" in gn_args:
        toolchain = gn_args.get("cros_target_cxx")
        if toolchain:
            step_config["rules"].extend([
                {
                    "name": "clang-cros/cxx",
                    "action": "(.*_)?cxx",
                    "command_prefix": "../../build/cros_cache/chrome-sdk/",
                    "remote": True,
                    "handler": "cros_compiler",
                    "canonicalize_dir": True,
                    "timeout": "5m",
                },
                {
                    "name": "clang-cros/cc",
                    "action": "(.*_)?cc",
                    "command_prefix": "../../build/cros_cache/chrome-sdk/",
                    "remote": True,
                    "handler": "cros_compiler",
                    "canonicalize_dir": True,
                    "timeout": "5m",
                },
            ])
    if "target_sysroot" in gn_args:
        sysroot = gn_args.get("target_sysroot")
        if sysroot:
            sysroot = sysroot.strip('"')
            sysroot = ctx.fs.canonpath(sysroot)
            step_config["input_deps"].update({
                sysroot + ":headers": [
                    path.join(sysroot, "usr/include") + ":include",
                    path.join(sysroot, "usr/lib") + ":headers",
                    path.join(sysroot, "usr/lib64") + ":headers",
                ],
            })
    return step_config

cros = module(
    "cros",
    filegroups = __filegroups,
    handlers = __handlers,
    step_config = __step_config,
)