blob: cdeeb25417e3604c46027c08b12f359098e36293 [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",
Austin Schuh0a96ea32022-01-01 22:29:30 -080011 "cortex-m0plus",
Brian Silverman7a7c24d2018-09-01 17:49:09 -070012]
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040013
Brian Silverman7a7c24d2018-09-01 17:49:09 -070014"""All of the CPUs we know about."""
15
16"""A select wrapper for CPU architectures.
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040017
18Args:
19 values: A mapping from architecture names (as strings) to other things.
Austin Schuhde821712019-08-03 18:16:49 -070020 Currently amd64, roborio, armhf, and cortex are recognized.
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040021 'else' is also allowed as a default.
Austin Schuhde821712019-08-03 18:16:49 -070022 'arm' is allowed instead of roborio, armhf, and cortex.
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040023Returns a select which evaluates to the correct element of values.
Brian Silverman7a7c24d2018-09-01 17:49:09 -070024"""
25
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040026def cpu_select(values):
Austin Schuh8e17be92019-12-24 09:32:11 -080027 if "arm" in values:
28 new_values = {}
29 for cpu in values:
30 if cpu != "arm":
31 new_values[cpu] = values[cpu]
32 new_values["armhf"] = values["arm"]
33 new_values["roborio"] = values["arm"]
34 new_values["cortex-m"] = values["arm"]
Austin Schuh0a96ea32022-01-01 22:29:30 -080035 new_values["cortex-m0plus"] = values["arm"]
Austin Schuh8e17be92019-12-24 09:32:11 -080036 values = new_values
37 for cpu in all_cpus:
38 if cpu not in values:
39 if "else" in values:
40 values[cpu] = values["else"]
41 else:
42 fail("Need to handle %s CPUs!" % cpu, "values")
43 for key in values:
44 if key not in all_cpus and key != "else":
45 fail("Not sure what a %s CPU is!" % key, "values")
46 return select({
47 "@//tools:cpu_k8": values["amd64"],
48 "@//tools:cpu_roborio": values["roborio"],
49 "@//tools:cpu_armhf": values["armhf"],
50 "@//tools:cpu_cortex_m4f": values["cortex-m"],
Austin Schuh0a96ea32022-01-01 22:29:30 -080051 "@//tools:cpu_cortex_m0plus": values["cortex-m0plus"],
Philipp Schraderdada1072020-11-24 11:34:46 -080052 # TODO(phil): Support this properly.
53 #"@//tools:cpu_cortex_m4f_k22": values["cortex-m"],
Austin Schuh8e17be92019-12-24 09:32:11 -080054 })
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040055
Brian Silverman7a7c24d2018-09-01 17:49:09 -070056"""A select wrapper for address space sizes.
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040057
58Args:
59 values: A mapping from address space sizes (as strings) to other things.
60Returns a select which evaluates to the correct element of values.
Brian Silverman7a7c24d2018-09-01 17:49:09 -070061"""
62
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040063def address_size_select(values):
Austin Schuh8e17be92019-12-24 09:32:11 -080064 if "32" not in values:
65 fail("Need to handle 32 bit addresses!", "values")
66 if "64" not in values:
67 fail("Need to handle 64 bit addresses!", "values")
68 return select({
69 "@//tools:cpu_k8": values["64"],
70 "@//tools:cpu_roborio": values["32"],
71 "@//tools:cpu_armhf": values["32"],
72 "@//tools:cpu_cortex_m4f": values["32"],
Austin Schuh0a96ea32022-01-01 22:29:30 -080073 "@//tools:cpu_cortex_m0plus": values["32"],
Philipp Schraderdada1072020-11-24 11:34:46 -080074 # TODO(phil): Support this properly.
75 #"@//tools:cpu_cortex_m4f_k22": values["32"],
Austin Schuh8e17be92019-12-24 09:32:11 -080076 })
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040077
Brian Silverman7a7c24d2018-09-01 17:49:09 -070078"""A select wrapper for compilers.
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040079
80Args:
81 values: A mapping from compiler names (as strings) to other things.
82 Currently 'gcc' and 'clang' are recognized.
83Returns a select which evaluates to the correct element of values.
Brian Silverman7a7c24d2018-09-01 17:49:09 -070084"""
85
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040086def compiler_select(values):
Austin Schuh8e17be92019-12-24 09:32:11 -080087 if "gcc" not in values:
88 fail("Need to handle gcc!", "values")
89 if "clang" not in values:
90 fail("Need to handle clang!", "values")
91 return select({
92 "@//tools:compiler_gcc": values["gcc"],
93 "@//tools:compiler_clang": values["clang"],
Austin Schuh8e17be92019-12-24 09:32:11 -080094 })