fork/rules_rust

git clone https://git.julia.blue/fork/rules_rust

cfrantzAdd support for riscv32 targets (#1323)0049ce38

0.5.0
2.1 KiB90 linesraw
1"""Definitions for support config settings and platform definitions"""
2
3load("@bazel_skylib//lib:selects.bzl", "selects")
4load(
5    ":triple_mappings.bzl",
6    "SUPPORTED_PLATFORM_TRIPLES",
7    "cpu_arch_to_constraints",
8    "system_to_constraints",
9    "triple_to_constraint_set",
10)
11
12_SUPPORTED_CPU_ARCH = [
13    "aarch64",
14    "arm",
15    "i686",
16    "powerpc",
17    "s390x",
18    "x86_64",
19    "riscv32",
20]
21
22_SUPPORTED_SYSTEMS = [
23    "android",
24    "darwin",
25    "freebsd",
26    "ios",
27    "linux",
28    "windows",
29]
30
31# buildifier: disable=unnamed-macro
32def declare_config_settings():
33    """Helper function for declaring `config_setting`s"""
34    for cpu_arch in _SUPPORTED_CPU_ARCH:
35        native.config_setting(
36            name = cpu_arch,
37            constraint_values = cpu_arch_to_constraints(cpu_arch),
38        )
39
40    for system in _SUPPORTED_SYSTEMS:
41        native.config_setting(
42            name = system,
43            constraint_values = system_to_constraints(system),
44        )
45
46    # Add alias for OSX to "darwin" to match what users will be expecting.
47    native.alias(
48        name = "osx",
49        actual = ":darwin",
50    )
51
52    # Add alias for OSX to "macos" to be consistent with the long-term
53    # direction of `@platforms` in using the OS's modern name.
54    native.alias(
55        name = "macos",
56        actual = ":darwin",
57    )
58
59    all_supported_triples = SUPPORTED_PLATFORM_TRIPLES
60    for triple in all_supported_triples:
61        native.config_setting(
62            name = triple,
63            constraint_values = triple_to_constraint_set(triple),
64        )
65
66    native.platform(
67        name = "wasm",
68        constraint_values = [
69            str(Label("//rust/platform/cpu:wasm32")),
70            str(Label("//rust/platform/os:unknown")),
71        ],
72    )
73
74    native.platform(
75        name = "wasi",
76        constraint_values = [
77            str(Label("//rust/platform/cpu:wasm32")),
78            str(Label("//rust/platform/os:wasi")),
79        ],
80    )
81
82    selects.config_setting_group(
83        name = "unix",
84        match_any = [
85            ":android",
86            ":darwin",
87            ":freebsd",
88            ":linux",
89        ],
90    )