1#
2# Copyright 2017 The Abseil Authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      https://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
18load(
19    "//absl:copts/configure_copts.bzl",
20    "ABSL_DEFAULT_COPTS",
21    "ABSL_DEFAULT_LINKOPTS",
22    "ABSL_TEST_COPTS",
23)
24
25package(default_visibility = ["//visibility:public"])
26
27licenses(["notice"])  # Apache 2.0
28
29cc_library(
30    name = "atomic_hook",
31    hdrs = ["internal/atomic_hook.h"],
32    copts = ABSL_DEFAULT_COPTS,
33    linkopts = ABSL_DEFAULT_LINKOPTS,
34    visibility = [
35        "//absl:__subpackages__",
36    ],
37    deps = [
38        ":config",
39        ":core_headers",
40    ],
41)
42
43cc_library(
44    name = "errno_saver",
45    hdrs = ["internal/errno_saver.h"],
46    copts = ABSL_DEFAULT_COPTS,
47    linkopts = ABSL_DEFAULT_LINKOPTS,
48    visibility = [
49        "//absl:__subpackages__",
50    ],
51    deps = [":config"],
52)
53
54cc_library(
55    name = "log_severity",
56    srcs = ["log_severity.cc"],
57    hdrs = ["log_severity.h"],
58    copts = ABSL_DEFAULT_COPTS,
59    linkopts = ABSL_DEFAULT_LINKOPTS,
60    deps = [
61        ":config",
62        ":core_headers",
63    ],
64)
65
66cc_library(
67    name = "raw_logging_internal",
68    srcs = ["internal/raw_logging.cc"],
69    hdrs = ["internal/raw_logging.h"],
70    copts = ABSL_DEFAULT_COPTS,
71    linkopts = ABSL_DEFAULT_LINKOPTS,
72    visibility = [
73        "//absl:__subpackages__",
74    ],
75    deps = [
76        ":atomic_hook",
77        ":config",
78        ":core_headers",
79        ":log_severity",
80    ],
81)
82
83cc_library(
84    name = "spinlock_wait",
85    srcs = [
86        "internal/spinlock_akaros.inc",
87        "internal/spinlock_linux.inc",
88        "internal/spinlock_posix.inc",
89        "internal/spinlock_wait.cc",
90        "internal/spinlock_win32.inc",
91    ],
92    hdrs = ["internal/spinlock_wait.h"],
93    copts = ABSL_DEFAULT_COPTS,
94    linkopts = ABSL_DEFAULT_LINKOPTS,
95    visibility = [
96        "//absl/base:__pkg__",
97    ],
98    deps = [
99        ":base_internal",
100        ":core_headers",
101        ":errno_saver",
102    ],
103)
104
105cc_library(
106    name = "config",
107    hdrs = [
108        "config.h",
109        "options.h",
110        "policy_checks.h",
111    ],
112    copts = ABSL_DEFAULT_COPTS,
113    linkopts = ABSL_DEFAULT_LINKOPTS,
114)
115
116cc_library(
117    name = "dynamic_annotations",
118    srcs = ["dynamic_annotations.cc"],
119    hdrs = ["dynamic_annotations.h"],
120    copts = ABSL_DEFAULT_COPTS,
121    defines = ["__CLANG_SUPPORT_DYN_ANNOTATION__"],
122    linkopts = ABSL_DEFAULT_LINKOPTS,
123)
124
125cc_library(
126    name = "core_headers",
127    srcs = [
128        "internal/thread_annotations.h",
129    ],
130    hdrs = [
131        "attributes.h",
132        "const_init.h",
133        "macros.h",
134        "optimization.h",
135        "port.h",
136        "thread_annotations.h",
137    ],
138    copts = ABSL_DEFAULT_COPTS,
139    linkopts = ABSL_DEFAULT_LINKOPTS,
140    deps = [
141        ":config",
142    ],
143)
144
145cc_library(
146    name = "malloc_internal",
147    srcs = [
148        "internal/low_level_alloc.cc",
149    ],
150    hdrs = [
151        "internal/direct_mmap.h",
152        "internal/low_level_alloc.h",
153    ],
154    copts = ABSL_DEFAULT_COPTS,
155    linkopts = select({
156        "//absl:windows": [],
157        "//conditions:default": ["-pthread"],
158    }) + ABSL_DEFAULT_LINKOPTS,
159    visibility = [
160        "//visibility:public",
161    ],
162    deps = [
163        ":base",
164        ":base_internal",
165        ":config",
166        ":core_headers",
167        ":dynamic_annotations",
168        ":raw_logging_internal",
169    ],
170)
171
172cc_library(
173    name = "base_internal",
174    hdrs = [
175        "internal/hide_ptr.h",
176        "internal/identity.h",
177        "internal/inline_variable.h",
178        "internal/invoke.h",
179        "internal/scheduling_mode.h",
180    ],
181    copts = ABSL_DEFAULT_COPTS,
182    linkopts = ABSL_DEFAULT_LINKOPTS,
183    visibility = [
184        "//absl:__subpackages__",
185    ],
186    deps = [
187        ":config",
188        "//absl/meta:type_traits",
189    ],
190)
191
192cc_library(
193    name = "base",
194    srcs = [
195        "internal/cycleclock.cc",
196        "internal/spinlock.cc",
197        "internal/sysinfo.cc",
198        "internal/thread_identity.cc",
199        "internal/unscaledcycleclock.cc",
200    ],
201    hdrs = [
202        "call_once.h",
203        "casts.h",
204        "internal/cycleclock.h",
205        "internal/low_level_scheduling.h",
206        "internal/per_thread_tls.h",
207        "internal/spinlock.h",
208        "internal/sysinfo.h",
209        "internal/thread_identity.h",
210        "internal/tsan_mutex_interface.h",
211        "internal/unscaledcycleclock.h",
212    ],
213    copts = ABSL_DEFAULT_COPTS,
214    linkopts = select({
215        "//absl:windows": [
216            "-DEFAULTLIB:advapi32.lib",
217        ],
218        "//conditions:default": ["-pthread"],
219    }) + ABSL_DEFAULT_LINKOPTS,
220    deps = [
221        ":atomic_hook",
222        ":base_internal",
223        ":config",
224        ":core_headers",
225        ":dynamic_annotations",
226        ":log_severity",
227        ":raw_logging_internal",
228        ":spinlock_wait",
229        "//absl/meta:type_traits",
230    ],
231)
232
233cc_library(
234    name = "atomic_hook_test_helper",
235    testonly = 1,
236    srcs = ["internal/atomic_hook_test_helper.cc"],
237    hdrs = ["internal/atomic_hook_test_helper.h"],
238    copts = ABSL_DEFAULT_COPTS,
239    linkopts = ABSL_DEFAULT_LINKOPTS,
240    deps = [
241        ":atomic_hook",
242        ":core_headers",
243    ],
244)
245
246cc_test(
247    name = "atomic_hook_test",
248    size = "small",
249    srcs = ["internal/atomic_hook_test.cc"],
250    copts = ABSL_TEST_COPTS,
251    linkopts = ABSL_DEFAULT_LINKOPTS,
252    deps = [
253        ":atomic_hook",
254        ":atomic_hook_test_helper",
255        ":core_headers",
256        "@com_google_googletest//:gtest_main",
257    ],
258)
259
260cc_test(
261    name = "bit_cast_test",
262    size = "small",
263    srcs = [
264        "bit_cast_test.cc",
265    ],
266    copts = ABSL_TEST_COPTS,
267    linkopts = ABSL_DEFAULT_LINKOPTS,
268    deps = [
269        ":base",
270        ":core_headers",
271        "@com_google_googletest//:gtest_main",
272    ],
273)
274
275cc_library(
276    name = "throw_delegate",
277    srcs = ["internal/throw_delegate.cc"],
278    hdrs = ["internal/throw_delegate.h"],
279    copts = ABSL_DEFAULT_COPTS,
280    linkopts = ABSL_DEFAULT_LINKOPTS,
281    visibility = [
282        "//absl:__subpackages__",
283    ],
284    deps = [
285        ":config",
286        ":raw_logging_internal",
287    ],
288)
289
290cc_test(
291    name = "throw_delegate_test",
292    srcs = ["throw_delegate_test.cc"],
293    copts = ABSL_TEST_COPTS,
294    linkopts = ABSL_DEFAULT_LINKOPTS,
295    deps = [
296        ":config",
297        ":throw_delegate",
298        "@com_google_googletest//:gtest_main",
299    ],
300)
301
302cc_test(
303    name = "errno_saver_test",
304    size = "small",
305    srcs = ["internal/errno_saver_test.cc"],
306    copts = ABSL_TEST_COPTS,
307    linkopts = ABSL_DEFAULT_LINKOPTS,
308    deps = [
309        ":errno_saver",
310        ":strerror",
311        "@com_google_googletest//:gtest_main",
312    ],
313)
314
315cc_library(
316    name = "exception_testing",
317    testonly = 1,
318    hdrs = ["internal/exception_testing.h"],
319    copts = ABSL_TEST_COPTS,
320    linkopts = ABSL_DEFAULT_LINKOPTS,
321    visibility = [
322        "//absl:__subpackages__",
323    ],
324    deps = [
325        ":config",
326        "@com_google_googletest//:gtest",
327    ],
328)
329
330cc_library(
331    name = "pretty_function",
332    hdrs = ["internal/pretty_function.h"],
333    linkopts = ABSL_DEFAULT_LINKOPTS,
334    visibility = ["//absl:__subpackages__"],
335)
336
337cc_library(
338    name = "exception_safety_testing",
339    testonly = 1,
340    srcs = ["internal/exception_safety_testing.cc"],
341    hdrs = ["internal/exception_safety_testing.h"],
342    copts = ABSL_TEST_COPTS,
343    linkopts = ABSL_DEFAULT_LINKOPTS,
344    deps = [
345        ":config",
346        ":pretty_function",
347        "//absl/memory",
348        "//absl/meta:type_traits",
349        "//absl/strings",
350        "//absl/utility",
351        "@com_google_googletest//:gtest",
352    ],
353)
354
355cc_test(
356    name = "exception_safety_testing_test",
357    srcs = ["exception_safety_testing_test.cc"],
358    copts = ABSL_TEST_COPTS,
359    linkopts = ABSL_DEFAULT_LINKOPTS,
360    deps = [
361        ":exception_safety_testing",
362        "//absl/memory",
363        "@com_google_googletest//:gtest_main",
364    ],
365)
366
367cc_test(
368    name = "inline_variable_test",
369    size = "small",
370    srcs = [
371        "inline_variable_test.cc",
372        "inline_variable_test_a.cc",
373        "inline_variable_test_b.cc",
374        "internal/inline_variable_testing.h",
375    ],
376    copts = ABSL_TEST_COPTS,
377    linkopts = ABSL_DEFAULT_LINKOPTS,
378    deps = [
379        ":base_internal",
380        "@com_google_googletest//:gtest_main",
381    ],
382)
383
384cc_test(
385    name = "invoke_test",
386    size = "small",
387    srcs = ["invoke_test.cc"],
388    copts = ABSL_TEST_COPTS,
389    linkopts = ABSL_DEFAULT_LINKOPTS,
390    deps = [
391        ":base_internal",
392        "//absl/memory",
393        "//absl/strings",
394        "@com_google_googletest//:gtest_main",
395    ],
396)
397
398# Common test library made available for use in non-absl code that overrides
399# AbslInternalSpinLockDelay and AbslInternalSpinLockWake.
400cc_library(
401    name = "spinlock_test_common",
402    testonly = 1,
403    srcs = ["spinlock_test_common.cc"],
404    copts = ABSL_TEST_COPTS,
405    linkopts = ABSL_DEFAULT_LINKOPTS,
406    deps = [
407        ":base",
408        ":base_internal",
409        ":core_headers",
410        "//absl/synchronization",
411        "@com_google_googletest//:gtest",
412    ],
413    alwayslink = 1,
414)
415
416cc_test(
417    name = "spinlock_test",
418    size = "medium",
419    srcs = ["spinlock_test_common.cc"],
420    copts = ABSL_TEST_COPTS,
421    linkopts = ABSL_DEFAULT_LINKOPTS,
422    deps = [
423        ":base",
424        ":base_internal",
425        ":core_headers",
426        "//absl/synchronization",
427        "@com_google_googletest//:gtest_main",
428    ],
429)
430
431cc_library(
432    name = "spinlock_benchmark_common",
433    testonly = 1,
434    srcs = ["internal/spinlock_benchmark.cc"],
435    copts = ABSL_TEST_COPTS,
436    linkopts = ABSL_DEFAULT_LINKOPTS,
437    visibility = [
438        "//absl/base:__pkg__",
439    ],
440    deps = [
441        ":base",
442        ":base_internal",
443        ":raw_logging_internal",
444        "//absl/synchronization",
445        "@com_github_google_benchmark//:benchmark_main",
446    ],
447    alwayslink = 1,
448)
449
450cc_binary(
451    name = "spinlock_benchmark",
452    testonly = 1,
453    copts = ABSL_DEFAULT_COPTS,
454    linkopts = ABSL_DEFAULT_LINKOPTS,
455    tags = ["benchmark"],
456    visibility = ["//visibility:private"],
457    deps = [
458        ":spinlock_benchmark_common",
459    ],
460)
461
462cc_library(
463    name = "endian",
464    hdrs = [
465        "internal/endian.h",
466        "internal/unaligned_access.h",
467    ],
468    copts = ABSL_DEFAULT_COPTS,
469    linkopts = ABSL_DEFAULT_LINKOPTS,
470    deps = [
471        ":config",
472        ":core_headers",
473    ],
474)
475
476cc_test(
477    name = "endian_test",
478    srcs = ["internal/endian_test.cc"],
479    copts = ABSL_TEST_COPTS,
480    deps = [
481        ":config",
482        ":endian",
483        "@com_google_googletest//:gtest_main",
484    ],
485)
486
487cc_test(
488    name = "config_test",
489    srcs = ["config_test.cc"],
490    copts = ABSL_TEST_COPTS,
491    linkopts = ABSL_DEFAULT_LINKOPTS,
492    deps = [
493        ":config",
494        "//absl/synchronization:thread_pool",
495        "@com_google_googletest//:gtest_main",
496    ],
497)
498
499cc_test(
500    name = "call_once_test",
501    srcs = ["call_once_test.cc"],
502    copts = ABSL_TEST_COPTS,
503    linkopts = ABSL_DEFAULT_LINKOPTS,
504    deps = [
505        ":base",
506        ":core_headers",
507        "//absl/synchronization",
508        "@com_google_googletest//:gtest_main",
509    ],
510)
511
512cc_test(
513    name = "raw_logging_test",
514    srcs = ["raw_logging_test.cc"],
515    copts = ABSL_TEST_COPTS,
516    linkopts = ABSL_DEFAULT_LINKOPTS,
517    deps = [
518        ":raw_logging_internal",
519        "//absl/strings",
520        "@com_google_googletest//:gtest_main",
521    ],
522)
523
524cc_test(
525    name = "sysinfo_test",
526    size = "small",
527    srcs = ["internal/sysinfo_test.cc"],
528    copts = ABSL_TEST_COPTS,
529    linkopts = ABSL_DEFAULT_LINKOPTS,
530    deps = [
531        ":base",
532        "//absl/synchronization",
533        "@com_google_googletest//:gtest_main",
534    ],
535)
536
537cc_test(
538    name = "low_level_alloc_test",
539    size = "medium",
540    srcs = ["internal/low_level_alloc_test.cc"],
541    copts = ABSL_TEST_COPTS,
542    linkopts = ABSL_DEFAULT_LINKOPTS,
543    tags = ["no_test_ios_x86_64"],
544    deps = [":malloc_internal"],
545)
546
547cc_test(
548    name = "thread_identity_test",
549    size = "small",
550    srcs = ["internal/thread_identity_test.cc"],
551    copts = ABSL_TEST_COPTS,
552    linkopts = ABSL_DEFAULT_LINKOPTS,
553    deps = [
554        ":base",
555        ":core_headers",
556        "//absl/synchronization",
557        "@com_google_googletest//:gtest_main",
558    ],
559)
560
561cc_test(
562    name = "thread_identity_benchmark",
563    srcs = ["internal/thread_identity_benchmark.cc"],
564    copts = ABSL_TEST_COPTS,
565    linkopts = ABSL_DEFAULT_LINKOPTS,
566    tags = ["benchmark"],
567    visibility = ["//visibility:private"],
568    deps = [
569        ":base",
570        "//absl/synchronization",
571        "@com_github_google_benchmark//:benchmark_main",
572    ],
573)
574
575cc_library(
576    name = "bits",
577    hdrs = ["internal/bits.h"],
578    linkopts = ABSL_DEFAULT_LINKOPTS,
579    visibility = [
580        "//absl:__subpackages__",
581    ],
582    deps = [
583        ":config",
584        ":core_headers",
585    ],
586)
587
588cc_test(
589    name = "bits_test",
590    size = "small",
591    srcs = ["internal/bits_test.cc"],
592    copts = ABSL_TEST_COPTS,
593    linkopts = ABSL_DEFAULT_LINKOPTS,
594    deps = [
595        ":bits",
596        "@com_google_googletest//:gtest_main",
597    ],
598)
599
600cc_library(
601    name = "exponential_biased",
602    srcs = ["internal/exponential_biased.cc"],
603    hdrs = ["internal/exponential_biased.h"],
604    linkopts = ABSL_DEFAULT_LINKOPTS,
605    visibility = [
606        "//absl:__subpackages__",
607    ],
608    deps = [
609        ":config",
610        ":core_headers",
611    ],
612)
613
614cc_test(
615    name = "exponential_biased_test",
616    size = "small",
617    srcs = ["internal/exponential_biased_test.cc"],
618    copts = ABSL_TEST_COPTS,
619    linkopts = ABSL_DEFAULT_LINKOPTS,
620    visibility = ["//visibility:private"],
621    deps = [
622        ":exponential_biased",
623        "//absl/strings",
624        "@com_google_googletest//:gtest_main",
625    ],
626)
627
628cc_library(
629    name = "periodic_sampler",
630    srcs = ["internal/periodic_sampler.cc"],
631    hdrs = ["internal/periodic_sampler.h"],
632    copts = ABSL_DEFAULT_COPTS,
633    linkopts = ABSL_DEFAULT_LINKOPTS,
634    deps = [
635        ":core_headers",
636        ":exponential_biased",
637    ],
638)
639
640cc_test(
641    name = "periodic_sampler_test",
642    size = "small",
643    srcs = ["internal/periodic_sampler_test.cc"],
644    copts = ABSL_TEST_COPTS,
645    linkopts = ABSL_DEFAULT_LINKOPTS,
646    visibility = ["//visibility:private"],
647    deps = [
648        ":core_headers",
649        ":periodic_sampler",
650        "@com_google_googletest//:gtest_main",
651    ],
652)
653
654cc_binary(
655    name = "periodic_sampler_benchmark",
656    testonly = 1,
657    srcs = ["internal/periodic_sampler_benchmark.cc"],
658    copts = ABSL_TEST_COPTS,
659    linkopts = ABSL_DEFAULT_LINKOPTS,
660    tags = ["benchmark"],
661    visibility = ["//visibility:private"],
662    deps = [
663        ":core_headers",
664        ":periodic_sampler",
665        "@com_github_google_benchmark//:benchmark_main",
666    ],
667)
668
669cc_library(
670    name = "scoped_set_env",
671    testonly = 1,
672    srcs = ["internal/scoped_set_env.cc"],
673    hdrs = ["internal/scoped_set_env.h"],
674    linkopts = ABSL_DEFAULT_LINKOPTS,
675    visibility = [
676        "//absl:__subpackages__",
677    ],
678    deps = [
679        ":config",
680        ":raw_logging_internal",
681    ],
682)
683
684cc_test(
685    name = "scoped_set_env_test",
686    size = "small",
687    srcs = ["internal/scoped_set_env_test.cc"],
688    copts = ABSL_TEST_COPTS,
689    linkopts = ABSL_DEFAULT_LINKOPTS,
690    deps = [
691        ":scoped_set_env",
692        "@com_google_googletest//:gtest_main",
693    ],
694)
695
696cc_test(
697    name = "log_severity_test",
698    size = "small",
699    srcs = ["log_severity_test.cc"],
700    copts = ABSL_TEST_COPTS,
701    linkopts = ABSL_DEFAULT_LINKOPTS,
702    deps = [
703        ":log_severity",
704        "//absl/flags:flag_internal",
705        "//absl/flags:marshalling",
706        "//absl/strings",
707        "@com_google_googletest//:gtest_main",
708    ],
709)
710
711cc_library(
712    name = "strerror",
713    srcs = ["internal/strerror.cc"],
714    hdrs = ["internal/strerror.h"],
715    copts = ABSL_DEFAULT_COPTS,
716    linkopts = ABSL_DEFAULT_LINKOPTS,
717    visibility = [
718        "//absl:__subpackages__",
719    ],
720    deps = [
721        ":config",
722        ":core_headers",
723        ":errno_saver",
724    ],
725)
726
727cc_test(
728    name = "strerror_test",
729    size = "small",
730    srcs = ["internal/strerror_test.cc"],
731    copts = ABSL_TEST_COPTS,
732    linkopts = ABSL_DEFAULT_LINKOPTS,
733    deps = [
734        ":strerror",
735        "//absl/strings",
736        "@com_google_googletest//:gtest_main",
737    ],
738)
739
740cc_binary(
741    name = "strerror_benchmark",
742    testonly = 1,
743    srcs = ["internal/strerror_benchmark.cc"],
744    copts = ABSL_TEST_COPTS,
745    linkopts = ABSL_DEFAULT_LINKOPTS,
746    tags = ["benchmark"],
747    visibility = ["//visibility:private"],
748    deps = [
749        ":strerror",
750        "@com_github_google_benchmark//:benchmark_main",
751    ],
752)
753
754cc_library(
755    name = "fast_type_id",
756    hdrs = ["internal/fast_type_id.h"],
757    copts = ABSL_DEFAULT_COPTS,
758    linkopts = ABSL_DEFAULT_LINKOPTS,
759    visibility = [
760        "//absl:__subpackages__",
761    ],
762    deps = [
763        ":config",
764    ],
765)
766
767cc_test(
768    name = "fast_type_id_test",
769    size = "small",
770    srcs = ["internal/fast_type_id_test.cc"],
771    copts = ABSL_TEST_COPTS,
772    linkopts = ABSL_DEFAULT_LINKOPTS,
773    deps = [
774        ":fast_type_id",
775        "@com_google_googletest//:gtest_main",
776    ],
777)
778