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", |
Brian Silverman | 7a7c24d | 2018-09-01 17:49:09 -0700 | [diff] [blame] | 12 | ] |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 13 | |
Brian Silverman | 7a7c24d | 2018-09-01 17:49:09 -0700 | [diff] [blame] | 14 | """All of the CPUs we know about.""" |
| 15 | |
| 16 | """A select wrapper for CPU architectures. |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 17 | |
| 18 | Args: |
| 19 | values: A mapping from architecture names (as strings) to other things. |
Austin Schuh | 1e69d42 | 2023-06-25 16:57:01 -0700 | [diff] [blame^] | 20 | Currently amd64, roborio, and cortex are recognized. |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 21 | 'else' is also allowed as a default. |
Austin Schuh | 1e69d42 | 2023-06-25 16:57:01 -0700 | [diff] [blame^] | 22 | 'arm' is allowed instead of roborio, and cortex. |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 23 | Returns a select which evaluates to the correct element of values. |
Brian Silverman | 7a7c24d | 2018-09-01 17:49:09 -0700 | [diff] [blame] | 24 | """ |
| 25 | |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 26 | def cpu_select(values): |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 27 | if "arm" in values: |
| 28 | new_values = {} |
| 29 | for cpu in values: |
| 30 | if cpu != "arm": |
| 31 | new_values[cpu] = values[cpu] |
Philipp Schrader | f1bbf34 | 2022-02-05 14:30:15 -0800 | [diff] [blame] | 32 | new_values["arm64"] = values["arm"] |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 33 | new_values["roborio"] = values["arm"] |
| 34 | new_values["cortex-m"] = values["arm"] |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 35 | new_values["cortex-m0plus"] = values["arm"] |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 36 | values = new_values |
Philipp Schrader | f1bbf34 | 2022-02-05 14:30:15 -0800 | [diff] [blame] | 37 | elif "arm32" in values: |
| 38 | if "arm64" not in values: |
| 39 | fail("Need to handle 'arm64' CPU if handling 'arm32' CPU.") |
| 40 | new_values = {} |
| 41 | for cpu in values: |
| 42 | if cpu != "arm32": |
| 43 | new_values[cpu] = values[cpu] |
Philipp Schrader | f1bbf34 | 2022-02-05 14:30:15 -0800 | [diff] [blame] | 44 | new_values["roborio"] = values["arm32"] |
| 45 | new_values["cortex-m"] = values["arm32"] |
| 46 | new_values["cortex-m0plus"] = values["arm32"] |
| 47 | values = new_values |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 48 | for cpu in all_cpus: |
| 49 | if cpu not in values: |
| 50 | if "else" in values: |
| 51 | values[cpu] = values["else"] |
| 52 | else: |
| 53 | fail("Need to handle %s CPUs!" % cpu, "values") |
| 54 | for key in values: |
| 55 | if key not in all_cpus and key != "else": |
| 56 | fail("Not sure what a %s CPU is!" % key, "values") |
| 57 | return select({ |
| 58 | "@//tools:cpu_k8": values["amd64"], |
| 59 | "@//tools:cpu_roborio": values["roborio"], |
Philipp Schrader | f1bbf34 | 2022-02-05 14:30:15 -0800 | [diff] [blame] | 60 | "@//tools:cpu_arm64": values["arm64"], |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 61 | "@//tools:cpu_cortex_m4f": values["cortex-m"], |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 62 | "@//tools:cpu_cortex_m0plus": values["cortex-m0plus"], |
Philipp Schrader | dada107 | 2020-11-24 11:34:46 -0800 | [diff] [blame] | 63 | # TODO(phil): Support this properly. |
| 64 | #"@//tools:cpu_cortex_m4f_k22": values["cortex-m"], |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 65 | }) |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 66 | |
Brian Silverman | 7a7c24d | 2018-09-01 17:49:09 -0700 | [diff] [blame] | 67 | """A select wrapper for address space sizes. |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 68 | |
| 69 | Args: |
| 70 | values: A mapping from address space sizes (as strings) to other things. |
| 71 | Returns a select which evaluates to the correct element of values. |
Brian Silverman | 7a7c24d | 2018-09-01 17:49:09 -0700 | [diff] [blame] | 72 | """ |
| 73 | |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 74 | def address_size_select(values): |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 75 | if "32" not in values: |
| 76 | fail("Need to handle 32 bit addresses!", "values") |
| 77 | if "64" not in values: |
| 78 | fail("Need to handle 64 bit addresses!", "values") |
| 79 | return select({ |
| 80 | "@//tools:cpu_k8": values["64"], |
Philipp Schrader | f1bbf34 | 2022-02-05 14:30:15 -0800 | [diff] [blame] | 81 | "@//tools:cpu_arm64": values["64"], |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 82 | "@//tools:cpu_roborio": values["32"], |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 83 | "@//tools:cpu_cortex_m4f": values["32"], |
Austin Schuh | 0a96ea3 | 2022-01-01 22:29:30 -0800 | [diff] [blame] | 84 | "@//tools:cpu_cortex_m0plus": values["32"], |
Philipp Schrader | dada107 | 2020-11-24 11:34:46 -0800 | [diff] [blame] | 85 | # TODO(phil): Support this properly. |
| 86 | #"@//tools:cpu_cortex_m4f_k22": values["32"], |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 87 | }) |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 88 | |
Brian Silverman | 7a7c24d | 2018-09-01 17:49:09 -0700 | [diff] [blame] | 89 | """A select wrapper for compilers. |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 90 | |
| 91 | Args: |
| 92 | values: A mapping from compiler names (as strings) to other things. |
| 93 | Currently 'gcc' and 'clang' are recognized. |
| 94 | Returns a select which evaluates to the correct element of values. |
Brian Silverman | 7a7c24d | 2018-09-01 17:49:09 -0700 | [diff] [blame] | 95 | """ |
| 96 | |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 97 | def compiler_select(values): |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 98 | if "gcc" not in values: |
| 99 | fail("Need to handle gcc!", "values") |
| 100 | if "clang" not in values: |
| 101 | fail("Need to handle clang!", "values") |
| 102 | return select({ |
| 103 | "@//tools:compiler_gcc": values["gcc"], |
| 104 | "@//tools:compiler_clang": values["clang"], |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 105 | }) |