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 | |
James Kuszmaul | 27da814 | 2019-07-21 16:13:55 -0700 | [diff] [blame] | 6 | # TODO(james): Decide what to do about webassembly/emscripten CPU and |
| 7 | # compiler configurations. Bazel does not seem to handle the fact that a select |
| 8 | # statement may not logically need to be evaluated for certain configurations |
| 9 | # (e.g., most targets can't be build for --cpu=web, so handling "web" in the |
| 10 | # cpu_select should notionally be unnecessary). |
Brian Silverman | 7a7c24d | 2018-09-01 17:49:09 -0700 | [diff] [blame] | 11 | all_cpus = [ |
| 12 | "amd64", |
| 13 | "roborio", |
| 14 | "armhf", |
Austin Schuh | de82171 | 2019-08-03 18:16:49 -0700 | [diff] [blame] | 15 | "cortex-m", |
Brian Silverman | 7a7c24d | 2018-09-01 17:49:09 -0700 | [diff] [blame] | 16 | ] |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 17 | |
Brian Silverman | 7a7c24d | 2018-09-01 17:49:09 -0700 | [diff] [blame] | 18 | """All of the CPUs we know about.""" |
| 19 | |
| 20 | """A select wrapper for CPU architectures. |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 21 | |
| 22 | Args: |
| 23 | values: A mapping from architecture names (as strings) to other things. |
Austin Schuh | de82171 | 2019-08-03 18:16:49 -0700 | [diff] [blame] | 24 | Currently amd64, roborio, armhf, and cortex are recognized. |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 25 | 'else' is also allowed as a default. |
Austin Schuh | de82171 | 2019-08-03 18:16:49 -0700 | [diff] [blame] | 26 | 'arm' is allowed instead of roborio, armhf, and cortex. |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 27 | Returns a select which evaluates to the correct element of values. |
Brian Silverman | 7a7c24d | 2018-09-01 17:49:09 -0700 | [diff] [blame] | 28 | """ |
| 29 | |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 30 | def cpu_select(values): |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame^] | 31 | if "arm" in values: |
| 32 | new_values = {} |
| 33 | for cpu in values: |
| 34 | if cpu != "arm": |
| 35 | new_values[cpu] = values[cpu] |
| 36 | new_values["armhf"] = values["arm"] |
| 37 | new_values["roborio"] = values["arm"] |
| 38 | new_values["cortex-m"] = values["arm"] |
| 39 | values = new_values |
| 40 | for cpu in all_cpus: |
| 41 | if cpu not in values: |
| 42 | if "else" in values: |
| 43 | values[cpu] = values["else"] |
| 44 | else: |
| 45 | fail("Need to handle %s CPUs!" % cpu, "values") |
| 46 | for key in values: |
| 47 | if key not in all_cpus and key != "else": |
| 48 | fail("Not sure what a %s CPU is!" % key, "values") |
| 49 | return select({ |
| 50 | "@//tools:cpu_k8": values["amd64"], |
| 51 | "@//tools:cpu_roborio": values["roborio"], |
| 52 | "@//tools:cpu_armhf": values["armhf"], |
| 53 | "@//tools:cpu_cortex_m4f": values["cortex-m"], |
| 54 | "@//tools:cpu_cortex_m4f_k22": values["cortex-m"], |
| 55 | "@//tools:cpu_web": None, |
| 56 | }) |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 57 | |
Brian Silverman | 7a7c24d | 2018-09-01 17:49:09 -0700 | [diff] [blame] | 58 | """A select wrapper for address space sizes. |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 59 | |
| 60 | Args: |
| 61 | values: A mapping from address space sizes (as strings) to other things. |
| 62 | Returns a select which evaluates to the correct element of values. |
Brian Silverman | 7a7c24d | 2018-09-01 17:49:09 -0700 | [diff] [blame] | 63 | """ |
| 64 | |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 65 | def address_size_select(values): |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame^] | 66 | if "32" not in values: |
| 67 | fail("Need to handle 32 bit addresses!", "values") |
| 68 | if "64" not in values: |
| 69 | fail("Need to handle 64 bit addresses!", "values") |
| 70 | return select({ |
| 71 | "@//tools:cpu_k8": values["64"], |
| 72 | "@//tools:cpu_roborio": values["32"], |
| 73 | "@//tools:cpu_armhf": values["32"], |
| 74 | "@//tools:cpu_cortex_m4f": values["32"], |
| 75 | "@//tools:cpu_cortex_m4f_k22": values["32"], |
| 76 | "@//tools:cpu_web": None, |
| 77 | }) |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 78 | |
Brian Silverman | 7a7c24d | 2018-09-01 17:49:09 -0700 | [diff] [blame] | 79 | """A select wrapper for compilers. |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 80 | |
| 81 | Args: |
| 82 | values: A mapping from compiler names (as strings) to other things. |
| 83 | Currently 'gcc' and 'clang' are recognized. |
| 84 | Returns a select which evaluates to the correct element of values. |
Brian Silverman | 7a7c24d | 2018-09-01 17:49:09 -0700 | [diff] [blame] | 85 | """ |
| 86 | |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 87 | def compiler_select(values): |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame^] | 88 | if "gcc" not in values: |
| 89 | fail("Need to handle gcc!", "values") |
| 90 | if "clang" not in values: |
| 91 | fail("Need to handle clang!", "values") |
| 92 | return select({ |
| 93 | "@//tools:compiler_gcc": values["gcc"], |
| 94 | "@//tools:compiler_clang": values["clang"], |
| 95 | "@//tools:compiler_emscripten": None, |
| 96 | }) |