blob: 25f6bd680cf607e1c8032c46e04357fe8a8c4489 [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",
Philipp Schraderf1bbf342022-02-05 14:30:15 -08009 "arm64",
Austin Schuhde821712019-08-03 18:16:49 -070010 "cortex-m",
Austin Schuh0a96ea32022-01-01 22:29:30 -080011 "cortex-m0plus",
James Kuszmaul5a728562023-12-28 21:45:01 -080012 "cortex-m4f-imu",
Brian Silverman7a7c24d2018-09-01 17:49:09 -070013]
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040014
Brian Silverman7a7c24d2018-09-01 17:49:09 -070015"""All of the CPUs we know about."""
16
17"""A select wrapper for CPU architectures.
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040018
19Args:
20 values: A mapping from architecture names (as strings) to other things.
Austin Schuh1e69d422023-06-25 16:57:01 -070021 Currently amd64, roborio, and cortex are recognized.
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040022 'else' is also allowed as a default.
Austin Schuh1e69d422023-06-25 16:57:01 -070023 'arm' is allowed instead of roborio, and cortex.
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040024Returns a select which evaluates to the correct element of values.
Brian Silverman7a7c24d2018-09-01 17:49:09 -070025"""
26
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040027def cpu_select(values):
Austin Schuh8e17be92019-12-24 09:32:11 -080028 if "arm" in values:
29 new_values = {}
30 for cpu in values:
31 if cpu != "arm":
32 new_values[cpu] = values[cpu]
Philipp Schraderf1bbf342022-02-05 14:30:15 -080033 new_values["arm64"] = values["arm"]
Austin Schuh8e17be92019-12-24 09:32:11 -080034 new_values["roborio"] = values["arm"]
35 new_values["cortex-m"] = values["arm"]
Austin Schuh0a96ea32022-01-01 22:29:30 -080036 new_values["cortex-m0plus"] = values["arm"]
James Kuszmaul5a728562023-12-28 21:45:01 -080037 new_values["cortex-m4f-imu"] = values["arm"]
Austin Schuh8e17be92019-12-24 09:32:11 -080038 values = new_values
Philipp Schraderf1bbf342022-02-05 14:30:15 -080039 elif "arm32" in values:
40 if "arm64" not in values:
41 fail("Need to handle 'arm64' CPU if handling 'arm32' CPU.")
42 new_values = {}
43 for cpu in values:
44 if cpu != "arm32":
45 new_values[cpu] = values[cpu]
Philipp Schraderf1bbf342022-02-05 14:30:15 -080046 new_values["roborio"] = values["arm32"]
47 new_values["cortex-m"] = values["arm32"]
48 new_values["cortex-m0plus"] = values["arm32"]
James Kuszmaul5a728562023-12-28 21:45:01 -080049 new_values["cortex-m4f-imu"] = values["arm32"]
Philipp Schraderf1bbf342022-02-05 14:30:15 -080050 values = new_values
Austin Schuh8e17be92019-12-24 09:32:11 -080051 for cpu in all_cpus:
52 if cpu not in values:
53 if "else" in values:
54 values[cpu] = values["else"]
55 else:
56 fail("Need to handle %s CPUs!" % cpu, "values")
57 for key in values:
58 if key not in all_cpus and key != "else":
59 fail("Not sure what a %s CPU is!" % key, "values")
60 return select({
61 "@//tools:cpu_k8": values["amd64"],
62 "@//tools:cpu_roborio": values["roborio"],
Philipp Schraderf1bbf342022-02-05 14:30:15 -080063 "@//tools:cpu_arm64": values["arm64"],
Austin Schuh8e17be92019-12-24 09:32:11 -080064 "@//tools:cpu_cortex_m4f": values["cortex-m"],
Austin Schuh0a96ea32022-01-01 22:29:30 -080065 "@//tools:cpu_cortex_m0plus": values["cortex-m0plus"],
James Kuszmaul5a728562023-12-28 21:45:01 -080066 "@//tools:cpu_cortex-m4f-imu": values["cortex-m4f-imu"],
Philipp Schraderdada1072020-11-24 11:34:46 -080067 # TODO(phil): Support this properly.
68 #"@//tools:cpu_cortex_m4f_k22": values["cortex-m"],
Austin Schuh8e17be92019-12-24 09:32:11 -080069 })
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040070
Brian Silverman7a7c24d2018-09-01 17:49:09 -070071"""A select wrapper for address space sizes.
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040072
73Args:
74 values: A mapping from address space sizes (as strings) to other things.
75Returns a select which evaluates to the correct element of values.
Brian Silverman7a7c24d2018-09-01 17:49:09 -070076"""
77
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040078def address_size_select(values):
Austin Schuh8e17be92019-12-24 09:32:11 -080079 if "32" not in values:
80 fail("Need to handle 32 bit addresses!", "values")
81 if "64" not in values:
82 fail("Need to handle 64 bit addresses!", "values")
83 return select({
84 "@//tools:cpu_k8": values["64"],
Philipp Schraderf1bbf342022-02-05 14:30:15 -080085 "@//tools:cpu_arm64": values["64"],
Austin Schuh8e17be92019-12-24 09:32:11 -080086 "@//tools:cpu_roborio": values["32"],
Austin Schuh8e17be92019-12-24 09:32:11 -080087 "@//tools:cpu_cortex_m4f": values["32"],
Austin Schuh0a96ea32022-01-01 22:29:30 -080088 "@//tools:cpu_cortex_m0plus": values["32"],
James Kuszmaul5a728562023-12-28 21:45:01 -080089 "@//tools:cpu_cortex-m4f-imu": values["32"],
Philipp Schraderdada1072020-11-24 11:34:46 -080090 # TODO(phil): Support this properly.
91 #"@//tools:cpu_cortex_m4f_k22": values["32"],
Austin Schuh8e17be92019-12-24 09:32:11 -080092 })
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040093
Brian Silverman7a7c24d2018-09-01 17:49:09 -070094"""A select wrapper for compilers.
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040095
96Args:
97 values: A mapping from compiler names (as strings) to other things.
98 Currently 'gcc' and 'clang' are recognized.
99Returns a select which evaluates to the correct element of values.
Brian Silverman7a7c24d2018-09-01 17:49:09 -0700100"""
101
Brian Silvermana7ba3aa2015-10-12 00:33:03 -0400102def compiler_select(values):
Austin Schuh8e17be92019-12-24 09:32:11 -0800103 if "gcc" not in values:
104 fail("Need to handle gcc!", "values")
105 if "clang" not in values:
106 fail("Need to handle clang!", "values")
107 return select({
108 "@//tools:compiler_gcc": values["gcc"],
109 "@//tools:compiler_clang": values["clang"],
Austin Schuh8e17be92019-12-24 09:32:11 -0800110 })