• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2021 the V8 project authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""Build rules to choose the v8 target architecture."""
6
7load("@bazel_skylib//lib:selects.bzl", "selects")
8
9V8CpuTypeInfo = provider(
10    doc = "A singleton provider that specifies the V8 target CPU type",
11    fields = {
12        "value": "The V8 Target CPU selected.",
13    },
14)
15
16def _host_target_cpu_impl(ctx):
17    allowed_values = ["arm", "arm64", "ia32", "ppc64le", "riscv64", "s390x", "x64", "none"]
18    cpu_type = ctx.build_setting_value
19    if cpu_type in allowed_values:
20        return V8CpuTypeInfo(value = cpu_type)
21    else:
22        fail("Error setting " + str(ctx.label) + ": invalid v8 target cpu '" +
23             cpu_type + "'. Allowed values are " + str(allowed_values))
24
25v8_target_cpu = rule(
26    implementation = _host_target_cpu_impl,
27    build_setting = config.string(flag = True),
28    doc = "CPU that V8 will generate code for.",
29)
30
31def v8_configure_target_cpu(name, matching_configs):
32    selects.config_setting_group(
33        name = "is_" + name,
34        match_any = matching_configs,
35    )
36
37    # If v8_target_cpu flag is set to 'name'
38    native.config_setting(
39        name = "v8_host_target_is_" + name,
40        flag_values = {
41            ":v8_target_cpu": name,
42        },
43    )
44
45    # Default target if no v8_host_target flag is set.
46    selects.config_setting_group(
47        name = "v8_target_is_" + name,
48        match_all = [
49            ":v8_host_target_is_none",
50            ":is_" + name,
51        ],
52    )
53
54    # Select either the default target or the flag.
55    selects.config_setting_group(
56        name = "v8_target_" + name,
57        match_any = [
58            ":v8_host_target_is_" + name,
59            ":v8_target_is_" + name,
60        ],
61    )
62