blob: 23addf5a57145578f2dddddaf0e5f937c51c4b8e [file] [log] [blame]
Brian Silvermana7ba3aa2015-10-12 00:33:03 -04001# This file contains replacements for select where the keys have more abstract
2# meanings so we can map multiple conditions to the same value easily and
3# quickly find issues where something new isn't handled.
4# It will also make adding ORs when it makes sense easy to do nicely.
5
Brian Silverman7a7c24d2018-09-01 17:49:09 -07006all_cpus = [
7 "amd64",
8 "roborio",
9 "armhf",
Austin Schuhde821712019-08-03 18:16:49 -070010 "cortex-m",
Brian Silverman7a7c24d2018-09-01 17:49:09 -070011]
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040012
Brian Silverman7a7c24d2018-09-01 17:49:09 -070013"""All of the CPUs we know about."""
14
15"""A select wrapper for CPU architectures.
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040016
17Args:
18 values: A mapping from architecture names (as strings) to other things.
Austin Schuhde821712019-08-03 18:16:49 -070019 Currently amd64, roborio, armhf, and cortex are recognized.
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040020 'else' is also allowed as a default.
Austin Schuhde821712019-08-03 18:16:49 -070021 'arm' is allowed instead of roborio, armhf, and cortex.
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040022Returns a select which evaluates to the correct element of values.
Brian Silverman7a7c24d2018-09-01 17:49:09 -070023"""
24
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040025def cpu_select(values):
Austin Schuh8e17be92019-12-24 09:32:11 -080026 if "arm" in values:
27 new_values = {}
28 for cpu in values:
29 if cpu != "arm":
30 new_values[cpu] = values[cpu]
31 new_values["armhf"] = values["arm"]
32 new_values["roborio"] = values["arm"]
33 new_values["cortex-m"] = values["arm"]
34 values = new_values
35 for cpu in all_cpus:
36 if cpu not in values:
37 if "else" in values:
38 values[cpu] = values["else"]
39 else:
40 fail("Need to handle %s CPUs!" % cpu, "values")
41 for key in values:
42 if key not in all_cpus and key != "else":
43 fail("Not sure what a %s CPU is!" % key, "values")
44 return select({
45 "@//tools:cpu_k8": values["amd64"],
46 "@//tools:cpu_roborio": values["roborio"],
47 "@//tools:cpu_armhf": values["armhf"],
48 "@//tools:cpu_cortex_m4f": values["cortex-m"],
Philipp Schraderdada1072020-11-24 11:34:46 -080049 # TODO(phil): Support this properly.
50 #"@//tools:cpu_cortex_m4f_k22": values["cortex-m"],
Austin Schuh8e17be92019-12-24 09:32:11 -080051 })
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040052
Brian Silverman7a7c24d2018-09-01 17:49:09 -070053"""A select wrapper for address space sizes.
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040054
55Args:
56 values: A mapping from address space sizes (as strings) to other things.
57Returns a select which evaluates to the correct element of values.
Brian Silverman7a7c24d2018-09-01 17:49:09 -070058"""
59
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040060def address_size_select(values):
Austin Schuh8e17be92019-12-24 09:32:11 -080061 if "32" not in values:
62 fail("Need to handle 32 bit addresses!", "values")
63 if "64" not in values:
64 fail("Need to handle 64 bit addresses!", "values")
65 return select({
66 "@//tools:cpu_k8": values["64"],
67 "@//tools:cpu_roborio": values["32"],
68 "@//tools:cpu_armhf": values["32"],
69 "@//tools:cpu_cortex_m4f": values["32"],
Philipp Schraderdada1072020-11-24 11:34:46 -080070 # TODO(phil): Support this properly.
71 #"@//tools:cpu_cortex_m4f_k22": values["32"],
Austin Schuh8e17be92019-12-24 09:32:11 -080072 })
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040073
Brian Silverman7a7c24d2018-09-01 17:49:09 -070074"""A select wrapper for compilers.
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040075
76Args:
77 values: A mapping from compiler names (as strings) to other things.
78 Currently 'gcc' and 'clang' are recognized.
79Returns a select which evaluates to the correct element of values.
Brian Silverman7a7c24d2018-09-01 17:49:09 -070080"""
81
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040082def compiler_select(values):
Austin Schuh8e17be92019-12-24 09:32:11 -080083 if "gcc" not in values:
84 fail("Need to handle gcc!", "values")
85 if "clang" not in values:
86 fail("Need to handle clang!", "values")
87 return select({
88 "@//tools:compiler_gcc": values["gcc"],
89 "@//tools:compiler_clang": values["clang"],
Austin Schuh8e17be92019-12-24 09:32:11 -080090 })