Lukasz Anforowicz | abf02de | 2023-02-21 16:39:55 -0800 | [diff] [blame] | 1 | # Part of the Crubit project, under the Apache License v2.0 with LLVM |
| 2 | # Exceptions. See /LICENSE for license information. |
| 3 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 4 | |
Jing Lu | 44f03fa | 2023-08-29 07:20:14 -0700 | [diff] [blame] | 5 | load("@bazel_skylib//lib:selects.bzl", "selects") |
Lukasz Anforowicz | abf02de | 2023-02-21 16:39:55 -0800 | [diff] [blame] | 6 | load( |
Yongheng Chen | 8c9013f | 2024-08-28 12:57:57 -0700 | [diff] [blame^] | 7 | "//rs_bindings_from_cc/bazel_support:additional_rust_srcs_for_crubit_bindings_aspect_hint.bzl", |
| 8 | "additional_rust_srcs_for_crubit_bindings", |
| 9 | ) |
| 10 | load( |
Lukasz Anforowicz | abf02de | 2023-02-21 16:39:55 -0800 | [diff] [blame] | 11 | "//rs_bindings_from_cc/bazel_support:toolchain_headers.bzl", |
| 12 | "bindings_for_toolchain_headers", |
| 13 | ) |
| 14 | |
Lukasz Anforowicz | aaa2a0f | 2023-04-11 09:01:14 -0700 | [diff] [blame] | 15 | package(default_applicable_licenses = ["//:license"]) |
Lukasz Anforowicz | abf02de | 2023-02-21 16:39:55 -0800 | [diff] [blame] | 16 | |
| 17 | filegroup( |
| 18 | name = "extra_rs_srcs_for_cc_std", |
Yongheng Chen | 8c9013f | 2024-08-28 12:57:57 -0700 | [diff] [blame^] | 19 | srcs = glob( |
| 20 | [ |
| 21 | "*.rs", |
| 22 | ], |
| 23 | exclude = ["cpp_std_string.rs"], |
| 24 | ), |
Lukasz Anforowicz | abf02de | 2023-02-21 16:39:55 -0800 | [diff] [blame] | 25 | ) |
| 26 | |
| 27 | LIBCXX_HEADERS = [ |
| 28 | "algorithm", |
| 29 | "any", |
| 30 | "array", |
| 31 | "atomic", |
| 32 | "bitset", |
| 33 | "cassert", |
| 34 | "cctype", |
| 35 | "cerrno", |
| 36 | "cfenv", |
| 37 | "cfloat", |
| 38 | "charconv", |
| 39 | "chrono", |
| 40 | "cinttypes", |
| 41 | "climits", |
| 42 | "cmath", |
| 43 | "condition_variable", |
| 44 | "csetjmp", |
| 45 | "csignal", |
| 46 | "cstdarg", |
| 47 | "cstddef", |
| 48 | "cstdint", |
| 49 | "cstdio", |
| 50 | "cstdlib", |
| 51 | "cstring", |
| 52 | "ctime", |
| 53 | "cuchar", |
| 54 | "cwchar", |
| 55 | "cwctype", |
| 56 | "deque", |
| 57 | "exception", |
| 58 | "forward_list", |
| 59 | "functional", |
| 60 | "initializer_list", |
| 61 | "ios", |
| 62 | "limits", |
| 63 | "list", |
| 64 | "map", |
| 65 | "memory", |
| 66 | "mutex", |
| 67 | "new", |
| 68 | "numeric", |
| 69 | "optional", |
| 70 | "queue", |
| 71 | "ratio", |
| 72 | "set", |
| 73 | "scoped_allocator", |
| 74 | "stack", |
| 75 | "stdexcept", |
| 76 | "streambuf", |
| 77 | "string", |
| 78 | "string_view", |
| 79 | "system_error", |
| 80 | "tuple", |
| 81 | "type_traits", |
| 82 | "typeindex", |
| 83 | "typeinfo", |
| 84 | "unordered_map", |
| 85 | "unordered_set", |
| 86 | "utility", |
| 87 | "variant", |
Jing Lu | d64e9f9 | 2024-02-09 03:08:10 -0800 | [diff] [blame] | 88 | "vector", |
Lukasz Anforowicz | abf02de | 2023-02-21 16:39:55 -0800 | [diff] [blame] | 89 | ] |
| 90 | |
| 91 | LIBC_HEADERS = [] |
| 92 | |
Jing Lu | 92e07a4 | 2023-05-31 04:04:56 -0700 | [diff] [blame] | 93 | _CPU = { |
| 94 | "arm": "//third_party/bazel_platforms/cpu:aarch64", |
| 95 | "x86": "//third_party/bazel_platforms/cpu:x86_64", |
Krasimir Georgiev | a0db24a | 2024-04-23 09:24:19 -0700 | [diff] [blame] | 96 | "diorite_acc": "//buildenv/platforms/settings:diorite_acc", |
| 97 | "diorite_imc": "//buildenv/platforms/settings:diorite_imc", |
Jing Lu | 92e07a4 | 2023-05-31 04:04:56 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | _GRTE = { |
| 101 | "v4": "//third_party/grte:grte_v4", |
| 102 | "v5": "//third_party/grte:grte_v5", |
| 103 | } |
| 104 | |
Krasimir Georgiev | a0db24a | 2024-04-23 09:24:19 -0700 | [diff] [blame] | 105 | _CPU_GRTE_VERSIONS = { |
| 106 | # diorite is v5-only. |
| 107 | "diorite_acc": ["v5"], |
| 108 | "diorite_imc": ["v5"], |
| 109 | } |
| 110 | |
Jing Lu | 92e07a4 | 2023-05-31 04:04:56 -0700 | [diff] [blame] | 111 | [ |
| 112 | selects.config_setting_group( |
| 113 | name = "grte_{grte_name}_cpu_{cpu_name}".format( |
| 114 | cpu_name = cpu_name, |
| 115 | grte_name = grte_name, |
| 116 | ), |
| 117 | match_all = [ |
| 118 | grte_config_setting, |
| 119 | cpu_config_setting, |
| 120 | ], |
| 121 | ) |
| 122 | for (cpu_name, cpu_config_setting) in _CPU.items() |
| 123 | for (grte_name, grte_config_setting) in _GRTE.items() |
Krasimir Georgiev | a0db24a | 2024-04-23 09:24:19 -0700 | [diff] [blame] | 124 | if grte_name in _CPU_GRTE_VERSIONS.get( |
| 125 | cpu_name, |
| 126 | [grte_name], |
| 127 | ) |
Jing Lu | 92e07a4 | 2023-05-31 04:04:56 -0700 | [diff] [blame] | 128 | ] |
| 129 | |
| 130 | alias( |
| 131 | name = "grte", |
| 132 | actual = select({ |
| 133 | "grte_{grte}_cpu_{cpu}".format( |
| 134 | cpu = cpu, |
| 135 | grte = grte, |
| 136 | ): "//third_party/grte/{grte}_{cpu}/release/usr/grte/{grte}:compile".format( |
| 137 | cpu = cpu, |
| 138 | grte = grte, |
| 139 | ) |
| 140 | for cpu in _CPU.keys() |
| 141 | for grte in _GRTE.keys() |
Krasimir Georgiev | a0db24a | 2024-04-23 09:24:19 -0700 | [diff] [blame] | 142 | if grte in _CPU_GRTE_VERSIONS.get( |
| 143 | cpu, |
| 144 | [grte], |
| 145 | ) |
Jing Lu | 92e07a4 | 2023-05-31 04:04:56 -0700 | [diff] [blame] | 146 | }), |
| 147 | ) |
| 148 | |
Lukasz Anforowicz | abf02de | 2023-02-21 16:39:55 -0800 | [diff] [blame] | 149 | filegroup( |
| 150 | name = "toolchain_headers", |
| 151 | srcs = select({ |
Jing Lu | 92e07a4 | 2023-05-31 04:04:56 -0700 | [diff] [blame] | 152 | "//third_party/crosstool:unstable_config": ["//nowhere/llvm:cc-std-headers"], |
| 153 | "//conditions:default": ["//nowhere/llvm:cc-std-headers"], |
| 154 | }) + [ |
| 155 | ":grte", |
| 156 | ], |
Lukasz Anforowicz | abf02de | 2023-02-21 16:39:55 -0800 | [diff] [blame] | 157 | visibility = ["//visibility:private"], |
| 158 | ) |
| 159 | |
| 160 | bindings_for_toolchain_headers( |
| 161 | name = "cc_std", |
| 162 | hdrs = ":toolchain_headers", |
| 163 | extra_rs_srcs = [":extra_rs_srcs_for_cc_std"], |
| 164 | public_libc_hdrs = LIBC_HEADERS, |
| 165 | public_libcxx_hdrs = LIBCXX_HEADERS, |
Googler | 39f69b3 | 2023-05-02 04:25:26 -0700 | [diff] [blame] | 166 | visibility = [ |
| 167 | "//visibility:public", |
| 168 | ], |
Lukasz Anforowicz | abf02de | 2023-02-21 16:39:55 -0800 | [diff] [blame] | 169 | ) |
Yongheng Chen | 8c9013f | 2024-08-28 12:57:57 -0700 | [diff] [blame^] | 170 | |
| 171 | additional_rust_srcs_for_crubit_bindings( |
| 172 | name = "cpp_std_string_rust", |
| 173 | srcs = ["cpp_std_string.rs"], |
| 174 | ) |
| 175 | |
| 176 | cc_library( |
| 177 | name = "cpp_std_string", |
| 178 | hdrs = ["cpp_std_string.h"], |
| 179 | aspect_hints = [ |
| 180 | "//features:experimental", |
| 181 | ":cpp_std_string_rust", |
| 182 | ], |
| 183 | visibility = [ |
| 184 | "//visibility:public", |
| 185 | ], |
| 186 | ) |