File: dist.bzl

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (100 lines) | stat: -rw-r--r-- 3,093 bytes parent folder | download | duplicates (5)
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
"""
This module exports the pkg_cross_compiled_binaries rule. This rule is used to create a pkg_filegroup
that contains the cross compiled binaries for each cpu.
"""

load("@rules_pkg//pkg:mappings.bzl", "pkg_attributes", "pkg_filegroup", "pkg_files")

def _cpu_transition_impl(settings, attr):
    _ignore = (settings)  # @unused
    return [{"//command_line_option:cpu": attr.cpu}]

_cpu_transition = transition(
    implementation = _cpu_transition_impl,
    inputs = [],
    outputs = [
        "//command_line_option:cpu",
    ],
)

def _cross_compiled_binary_impl(ctx):
    target = ctx.attr.target

    default_info = target[0][DefaultInfo]
    files = default_info.files
    runfiles = default_info.default_runfiles

    files = depset(transitive = [files])

    return [
        DefaultInfo(
            files = files,
            runfiles = runfiles,
        ),
    ]

_cross_compiled_binary = rule(
    implementation = _cross_compiled_binary_impl,
    attrs = {
        "target": attr.label(
            mandatory = True,
            cfg = _cpu_transition,
        ),
        "cpu": attr.string(),
        "_allowlist_function_transition": attr.label(
            default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
        ),
    },
)

def pkg_cross_compiled_binaries(name, cpus, targets, prefix, tags, visibility = None):
    """Creates a pkg_filegroup that contains the cross compiled binaries for each cpu.

    This rule is used to create a pkg_filegroup that contains the cross compiled binaries for each
    cpu. The binaries are created by an aspect that changes the cpu configuration for each target.
    The targets are placed into a directory that is named after the cpu.

    Args:
      name: The name of the pkg_filegroup.
      cpus: The cpus to cross compile for.
      targets: The targets to cross compile.
      prefix: The prefix to add to the pkg_filegroup.
      tags: The tags to add to the pkg_filegroup.
      visibility: The visibility of the pkg_filegroup.
    """

    filegroups = []
    for cpu in cpus:
        compiled_targets = []
        for target in targets:
            target_name = target.split(":")[1]
            bin_target_name = name + "_" + cpu + "_" + target_name
            _cross_compiled_binary(
                name = bin_target_name,
                cpu = cpu,
                target = target,
            )
            compiled_targets.append(Label(":" + bin_target_name))
        files_name = name + "_" + cpu + "_src"
        filegroup_name = files_name + "_dir"
        filegroups.append(Label(":" + filegroup_name))
        pkg_files(
            name = files_name,
            srcs = compiled_targets,
            attributes = pkg_attributes(
                mode = "0755",
            ),
        )
        pkg_filegroup(
            name = filegroup_name,
            srcs = [Label(":" + files_name)],
            prefix = cpu,
        )
    pkg_filegroup(
        name = name,
        srcs = filegroups,
        prefix = prefix,
        tags = tags,
        visibility = visibility,
    )
    return