blob: 98e295a97c5be538a9ebeba34d1314c5009e4c9b [file] [log] [blame]
Brian Silvermancc09f182022-03-09 15:40:20 -08001"""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",
Brian Silverman5f6f2762022-08-13 19:30:05 -070015 "armv7",
Brian Silvermancc09f182022-03-09 15:40:20 -080016 "i686",
17 "powerpc",
18 "s390x",
19 "x86_64",
Brian Silverman5f6f2762022-08-13 19:30:05 -070020 "riscv32",
Brian Silvermancc09f182022-03-09 15:40:20 -080021]
22
23_SUPPORTED_SYSTEMS = [
24 "android",
25 "darwin",
26 "freebsd",
27 "ios",
28 "linux",
29 "windows",
30]
31
32# buildifier: disable=unnamed-macro
33def declare_config_settings():
34 """Helper function for declaring `config_setting`s"""
35 for cpu_arch in _SUPPORTED_CPU_ARCH:
36 native.config_setting(
37 name = cpu_arch,
38 constraint_values = cpu_arch_to_constraints(cpu_arch),
39 )
40
41 for system in _SUPPORTED_SYSTEMS:
42 native.config_setting(
43 name = system,
44 constraint_values = system_to_constraints(system),
45 )
46
47 # Add alias for OSX to "darwin" to match what users will be expecting.
48 native.alias(
49 name = "osx",
50 actual = ":darwin",
51 )
52
53 # Add alias for OSX to "macos" to be consistent with the long-term
54 # direction of `@platforms` in using the OS's modern name.
55 native.alias(
56 name = "macos",
57 actual = ":darwin",
58 )
59
60 all_supported_triples = SUPPORTED_PLATFORM_TRIPLES
61 for triple in all_supported_triples:
62 native.config_setting(
63 name = triple,
64 constraint_values = triple_to_constraint_set(triple),
65 )
66
67 native.platform(
68 name = "wasm",
69 constraint_values = [
70 str(Label("//rust/platform/cpu:wasm32")),
71 str(Label("//rust/platform/os:unknown")),
72 ],
73 )
74
75 native.platform(
76 name = "wasi",
77 constraint_values = [
78 str(Label("//rust/platform/cpu:wasm32")),
79 str(Label("//rust/platform/os:wasi")),
80 ],
81 )
82
83 selects.config_setting_group(
84 name = "unix",
85 match_any = [
86 ":android",
87 ":darwin",
88 ":freebsd",
89 ":linux",
90 ],
91 )