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