Brian Silverman | cc09f18 | 2022-03-09 15:40:20 -0800 | [diff] [blame] | 1 | """Definitions for support config settings and platform definitions""" |
| 2 | |
| 3 | load("@bazel_skylib//lib:selects.bzl", "selects") |
| 4 | load( |
| 5 | ":triple_mappings.bzl", |
| 6 | "SUPPORTED_PLATFORM_TRIPLES", |
| 7 | "cpu_arch_to_constraints", |
| 8 | "system_to_constraints", |
| 9 | "triple_to_constraint_set", |
| 10 | ) |
| 11 | |
| 12 | _SUPPORTED_CPU_ARCH = [ |
| 13 | "aarch64", |
| 14 | "arm", |
Brian Silverman | 5f6f276 | 2022-08-13 19:30:05 -0700 | [diff] [blame] | 15 | "armv7", |
Brian Silverman | cc09f18 | 2022-03-09 15:40:20 -0800 | [diff] [blame] | 16 | "i686", |
| 17 | "powerpc", |
| 18 | "s390x", |
| 19 | "x86_64", |
Brian Silverman | 5f6f276 | 2022-08-13 19:30:05 -0700 | [diff] [blame] | 20 | "riscv32", |
Adam Snaider | 1c095c9 | 2023-07-08 02:09:58 -0400 | [diff] [blame^] | 21 | "riscv64", |
Brian Silverman | cc09f18 | 2022-03-09 15:40:20 -0800 | [diff] [blame] | 22 | ] |
| 23 | |
| 24 | _SUPPORTED_SYSTEMS = [ |
| 25 | "android", |
| 26 | "darwin", |
| 27 | "freebsd", |
| 28 | "ios", |
| 29 | "linux", |
| 30 | "windows", |
| 31 | ] |
| 32 | |
| 33 | # buildifier: disable=unnamed-macro |
| 34 | def declare_config_settings(): |
| 35 | """Helper function for declaring `config_setting`s""" |
| 36 | for cpu_arch in _SUPPORTED_CPU_ARCH: |
| 37 | native.config_setting( |
| 38 | name = cpu_arch, |
| 39 | constraint_values = cpu_arch_to_constraints(cpu_arch), |
| 40 | ) |
| 41 | |
| 42 | for system in _SUPPORTED_SYSTEMS: |
| 43 | native.config_setting( |
| 44 | name = system, |
| 45 | constraint_values = system_to_constraints(system), |
| 46 | ) |
| 47 | |
| 48 | # Add alias for OSX to "darwin" to match what users will be expecting. |
| 49 | native.alias( |
| 50 | name = "osx", |
| 51 | actual = ":darwin", |
| 52 | ) |
| 53 | |
| 54 | # Add alias for OSX to "macos" to be consistent with the long-term |
| 55 | # direction of `@platforms` in using the OS's modern name. |
| 56 | native.alias( |
| 57 | name = "macos", |
| 58 | actual = ":darwin", |
| 59 | ) |
| 60 | |
| 61 | all_supported_triples = SUPPORTED_PLATFORM_TRIPLES |
| 62 | for triple in all_supported_triples: |
| 63 | native.config_setting( |
| 64 | name = triple, |
| 65 | constraint_values = triple_to_constraint_set(triple), |
| 66 | ) |
| 67 | |
| 68 | native.platform( |
| 69 | name = "wasm", |
| 70 | constraint_values = [ |
Adam Snaider | 1c095c9 | 2023-07-08 02:09:58 -0400 | [diff] [blame^] | 71 | "@platforms//cpu:wasm32", |
Brian Silverman | cc09f18 | 2022-03-09 15:40:20 -0800 | [diff] [blame] | 72 | str(Label("//rust/platform/os:unknown")), |
| 73 | ], |
| 74 | ) |
| 75 | |
| 76 | native.platform( |
| 77 | name = "wasi", |
| 78 | constraint_values = [ |
Adam Snaider | 1c095c9 | 2023-07-08 02:09:58 -0400 | [diff] [blame^] | 79 | "@platforms//cpu:wasm32", |
| 80 | "@platforms//os:wasi", |
Brian Silverman | cc09f18 | 2022-03-09 15:40:20 -0800 | [diff] [blame] | 81 | ], |
| 82 | ) |
| 83 | |
| 84 | selects.config_setting_group( |
| 85 | name = "unix", |
| 86 | match_any = [ |
| 87 | ":android", |
| 88 | ":darwin", |
| 89 | ":freebsd", |
| 90 | ":linux", |
| 91 | ], |
| 92 | ) |