blob: 0b5f16879eb32b1fe63dd8a5ad97e60a6c63fcd8 [file] [log] [blame]
Lukasz Anforowiczabf02de2023-02-21 16:39:55 -08001# 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 Lu44f03fa2023-08-29 07:20:14 -07005load("@bazel_skylib//lib:selects.bzl", "selects")
Lukasz Anforowiczabf02de2023-02-21 16:39:55 -08006load(
Yongheng Chen8c9013f2024-08-28 12:57:57 -07007 "//rs_bindings_from_cc/bazel_support:additional_rust_srcs_for_crubit_bindings_aspect_hint.bzl",
8 "additional_rust_srcs_for_crubit_bindings",
9)
10load(
Lukasz Anforowiczabf02de2023-02-21 16:39:55 -080011 "//rs_bindings_from_cc/bazel_support:toolchain_headers.bzl",
12 "bindings_for_toolchain_headers",
13)
14
Lukasz Anforowiczaaa2a0f2023-04-11 09:01:14 -070015package(default_applicable_licenses = ["//:license"])
Lukasz Anforowiczabf02de2023-02-21 16:39:55 -080016
17filegroup(
18 name = "extra_rs_srcs_for_cc_std",
Yongheng Chen8c9013f2024-08-28 12:57:57 -070019 srcs = glob(
20 [
21 "*.rs",
22 ],
23 exclude = ["cpp_std_string.rs"],
24 ),
Lukasz Anforowiczabf02de2023-02-21 16:39:55 -080025)
26
27LIBCXX_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 Lud64e9f92024-02-09 03:08:10 -080088 "vector",
Lukasz Anforowiczabf02de2023-02-21 16:39:55 -080089]
90
91LIBC_HEADERS = []
92
Jing Lu92e07a42023-05-31 04:04:56 -070093_CPU = {
94 "arm": "//third_party/bazel_platforms/cpu:aarch64",
95 "x86": "//third_party/bazel_platforms/cpu:x86_64",
Krasimir Georgieva0db24a2024-04-23 09:24:19 -070096 "diorite_acc": "//buildenv/platforms/settings:diorite_acc",
97 "diorite_imc": "//buildenv/platforms/settings:diorite_imc",
Jing Lu92e07a42023-05-31 04:04:56 -070098}
99
100_GRTE = {
101 "v4": "//third_party/grte:grte_v4",
102 "v5": "//third_party/grte:grte_v5",
103}
104
Krasimir Georgieva0db24a2024-04-23 09:24:19 -0700105_CPU_GRTE_VERSIONS = {
106 # diorite is v5-only.
107 "diorite_acc": ["v5"],
108 "diorite_imc": ["v5"],
109}
110
Jing Lu92e07a42023-05-31 04:04:56 -0700111[
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 Georgieva0db24a2024-04-23 09:24:19 -0700124 if grte_name in _CPU_GRTE_VERSIONS.get(
125 cpu_name,
126 [grte_name],
127 )
Jing Lu92e07a42023-05-31 04:04:56 -0700128]
129
130alias(
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 Georgieva0db24a2024-04-23 09:24:19 -0700142 if grte in _CPU_GRTE_VERSIONS.get(
143 cpu,
144 [grte],
145 )
Jing Lu92e07a42023-05-31 04:04:56 -0700146 }),
147)
148
Lukasz Anforowiczabf02de2023-02-21 16:39:55 -0800149filegroup(
150 name = "toolchain_headers",
151 srcs = select({
Jing Lu92e07a42023-05-31 04:04:56 -0700152 "//third_party/crosstool:unstable_config": ["//nowhere/llvm:cc-std-headers"],
153 "//conditions:default": ["//nowhere/llvm:cc-std-headers"],
154 }) + [
155 ":grte",
156 ],
Lukasz Anforowiczabf02de2023-02-21 16:39:55 -0800157 visibility = ["//visibility:private"],
158)
159
160bindings_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,
Googler39f69b32023-05-02 04:25:26 -0700166 visibility = [
167 "//visibility:public",
168 ],
Lukasz Anforowiczabf02de2023-02-21 16:39:55 -0800169)
Yongheng Chen8c9013f2024-08-28 12:57:57 -0700170
171additional_rust_srcs_for_crubit_bindings(
172 name = "cpp_std_string_rust",
173 srcs = ["cpp_std_string.rs"],
174)
175
176cc_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)