Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 1 | # 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 Silverman | 7a7c24d | 2018-09-01 17:49:09 -0700 | [diff] [blame] | 6 | all_cpus = [ |
| 7 | "amd64", |
| 8 | "roborio", |
Philipp Schrader | f1bbf34 | 2022-02-05 14:30:15 -0800 | [diff] [blame] | 9 | "arm64", |
Austin Schuh | de82171 | 2019-08-03 18:16:49 -0700 | [diff] [blame] | 10 | "cortex-m", |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 11 | "cortex-m0plus", |
James Kuszmaul | 5a72856 | 2023-12-28 21:45:01 -0800 | [diff] [blame] | 12 | "cortex-m4f-imu", |
Brian Silverman | 7a7c24d | 2018-09-01 17:49:09 -0700 | [diff] [blame] | 13 | ] |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 14 | |
Brian Silverman | 7a7c24d | 2018-09-01 17:49:09 -0700 | [diff] [blame] | 15 | """All of the CPUs we know about.""" |
| 16 | |
| 17 | """A select wrapper for CPU architectures. |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 18 | |
| 19 | Args: |
| 20 | values: A mapping from architecture names (as strings) to other things. |
Austin Schuh | 1e69d42 | 2023-06-25 16:57:01 -0700 | [diff] [blame] | 21 | Currently amd64, roborio, and cortex are recognized. |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 22 | 'else' is also allowed as a default. |
Austin Schuh | 1e69d42 | 2023-06-25 16:57:01 -0700 | [diff] [blame] | 23 | 'arm' is allowed instead of roborio, and cortex. |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 24 | Returns a select which evaluates to the correct element of values. |
Brian Silverman | 7a7c24d | 2018-09-01 17:49:09 -0700 | [diff] [blame] | 25 | """ |
| 26 | |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 27 | def cpu_select(values): |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 28 | if "arm" in values: |
| 29 | new_values = {} |
| 30 | for cpu in values: |
| 31 | if cpu != "arm": |
| 32 | new_values[cpu] = values[cpu] |
Philipp Schrader | f1bbf34 | 2022-02-05 14:30:15 -0800 | [diff] [blame] | 33 | new_values["arm64"] = values["arm"] |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 34 | new_values["roborio"] = values["arm"] |
| 35 | new_values["cortex-m"] = values["arm"] |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 36 | new_values["cortex-m0plus"] = values["arm"] |
James Kuszmaul | 5a72856 | 2023-12-28 21:45:01 -0800 | [diff] [blame] | 37 | new_values["cortex-m4f-imu"] = values["arm"] |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 38 | values = new_values |
Philipp Schrader | f1bbf34 | 2022-02-05 14:30:15 -0800 | [diff] [blame] | 39 | 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 Schrader | f1bbf34 | 2022-02-05 14:30:15 -0800 | [diff] [blame] | 46 | new_values["roborio"] = values["arm32"] |
| 47 | new_values["cortex-m"] = values["arm32"] |
| 48 | new_values["cortex-m0plus"] = values["arm32"] |
James Kuszmaul | 5a72856 | 2023-12-28 21:45:01 -0800 | [diff] [blame] | 49 | new_values["cortex-m4f-imu"] = values["arm32"] |
Philipp Schrader | f1bbf34 | 2022-02-05 14:30:15 -0800 | [diff] [blame] | 50 | values = new_values |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 51 | 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 Schrader | f1bbf34 | 2022-02-05 14:30:15 -0800 | [diff] [blame] | 63 | "@//tools:cpu_arm64": values["arm64"], |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 64 | "@//tools:cpu_cortex_m4f": values["cortex-m"], |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 65 | "@//tools:cpu_cortex_m0plus": values["cortex-m0plus"], |
James Kuszmaul | 5a72856 | 2023-12-28 21:45:01 -0800 | [diff] [blame] | 66 | "@//tools:cpu_cortex-m4f-imu": values["cortex-m4f-imu"], |
Philipp Schrader | dada107 | 2020-11-24 11:34:46 -0800 | [diff] [blame] | 67 | # TODO(phil): Support this properly. |
| 68 | #"@//tools:cpu_cortex_m4f_k22": values["cortex-m"], |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 69 | }) |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 70 | |
Brian Silverman | 7a7c24d | 2018-09-01 17:49:09 -0700 | [diff] [blame] | 71 | """A select wrapper for address space sizes. |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 72 | |
| 73 | Args: |
| 74 | values: A mapping from address space sizes (as strings) to other things. |
| 75 | Returns a select which evaluates to the correct element of values. |
Brian Silverman | 7a7c24d | 2018-09-01 17:49:09 -0700 | [diff] [blame] | 76 | """ |
| 77 | |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 78 | def address_size_select(values): |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 79 | 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 Schrader | f1bbf34 | 2022-02-05 14:30:15 -0800 | [diff] [blame] | 85 | "@//tools:cpu_arm64": values["64"], |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 86 | "@//tools:cpu_roborio": values["32"], |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 87 | "@//tools:cpu_cortex_m4f": values["32"], |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 88 | "@//tools:cpu_cortex_m0plus": values["32"], |
James Kuszmaul | 5a72856 | 2023-12-28 21:45:01 -0800 | [diff] [blame] | 89 | "@//tools:cpu_cortex-m4f-imu": values["32"], |
Philipp Schrader | dada107 | 2020-11-24 11:34:46 -0800 | [diff] [blame] | 90 | # TODO(phil): Support this properly. |
| 91 | #"@//tools:cpu_cortex_m4f_k22": values["32"], |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 92 | }) |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 93 | |
Brian Silverman | 7a7c24d | 2018-09-01 17:49:09 -0700 | [diff] [blame] | 94 | """A select wrapper for compilers. |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 95 | |
| 96 | Args: |
| 97 | values: A mapping from compiler names (as strings) to other things. |
| 98 | Currently 'gcc' and 'clang' are recognized. |
| 99 | Returns a select which evaluates to the correct element of values. |
Brian Silverman | 7a7c24d | 2018-09-01 17:49:09 -0700 | [diff] [blame] | 100 | """ |
| 101 | |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 102 | def compiler_select(values): |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 103 | 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 Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 110 | }) |