1# -*- mode: python; -*-
2
3# nsync is a C library that exports synchronization primitives, such as reader
4# writer locks with conditional critical sections, designed to be open sourced
5# in portable C.  See https://github.com/google/nsync
6#
7# See public/*.h for API.  When compiled with C++11 rather than C, it's in the
8# "nsync" name space.
9#
10# BUILD file usage:
11#   deps = "@nsync://nsync" for C version
12#   deps = "@nsync://nsync_cpp" for C++11 version.
13# The latter uses no OS-specific system calls or architecture-specific atomic
14# operations.
15
16package(default_visibility = ["//visibility:public"])
17
18licenses(["notice"])  # Apache 2.0
19
20exports_files(["LICENSE", "VERSION"])
21
22# ---------------------------------------------
23# Parameters to the compilation:  compiler (e.g., for atomics), architecture
24# (e.g., for load and store barrier behaviour), and OS.
25# Bazel merges these into one, somewhat slippery, "cpu" string.
26# Bazel uses a rather verbose mechanism for choosing which implementations
27# are needed on given platforms; hence all the config_setting() rules below.
28
29config_setting(
30    name = "gcc_linux_x86_32_1",
31    values = {"cpu": "piii"},
32)
33
34config_setting(
35    name = "gcc_linux_x86_64_1",
36    values = {"cpu": "k8"},
37)
38
39config_setting(
40    name = "gcc_linux_x86_64_2",
41    values = {"cpu": "haswell"},
42)
43
44config_setting(
45    name = "gcc_linux_aarch64",
46    values = {"cpu": "aarch64"},
47)
48
49config_setting(
50    name = "gcc_linux_ppc64",
51    values = {"cpu": "ppc"},
52)
53
54config_setting(
55    name = "gcc_linux_s390x",
56    values = {"cpu": "s390x"},
57)
58
59config_setting(
60    name = "clang_macos_x86_64",
61    values = {"cpu": "darwin"},
62)
63
64config_setting(
65    name = "android_x86_32",
66    values = {"cpu": "x86"},
67)
68
69config_setting(
70    name = "android_x86_64",
71    values = {"cpu": "x86_64"},
72)
73
74config_setting(
75    name = "android_armeabi",
76    values = {"cpu": "armeabi"},
77)
78
79config_setting(
80    name = "android_arm",
81    values = {"cpu": "armeabi-v7a"},
82)
83
84config_setting(
85    name = "android_arm64",
86    values = {"cpu": "arm64-v8a"},
87)
88
89config_setting(
90    name = "msvc_windows_x86_64",
91    values = {"cpu": "x64_windows"},
92)
93
94config_setting(
95    name = "freebsd",
96    values = {"cpu": "freebsd"},
97)
98
99config_setting(
100    name = "ios_x86_64",
101    values = {"cpu": "ios_x86_64"},
102)
103
104# ---------------------------------------------
105# Compilation options.
106
107load(":bazel/pkg_path_name.bzl", "pkg_path_name")
108
109# Compilation options that apply to both C++11 and C.
110NSYNC_OPTS_GENERIC = select({
111    # Select the CPU architecture include directory.
112    # This select() has no real effect in the C++11 build, but satisfies a
113    # #include that would otherwise need a #if.
114    ":gcc_linux_x86_32_1": ["-I" + pkg_path_name() + "/platform/x86_32"],
115    ":gcc_linux_x86_64_1": ["-I" + pkg_path_name() + "/platform/x86_64"],
116    ":gcc_linux_x86_64_2": ["-I" + pkg_path_name() + "/platform/x86_64"],
117    ":gcc_linux_aarch64": ["-I" + pkg_path_name() + "/platform/aarch64"],
118    ":gcc_linux_ppc64": ["-I" + pkg_path_name() + "/platform/ppc64"],
119    ":gcc_linux_s390x": ["-I" + pkg_path_name() + "/platform/s390x"],
120    ":clang_macos_x86_64": ["-I" + pkg_path_name() + "/platform/x86_64"],
121    ":freebsd": ["-I" + pkg_path_name() + "/platform/x86_64"],
122    ":ios_x86_64": ["-I" + pkg_path_name() + "/platform/x86_64"],
123    ":android_x86_32": ["-I" + pkg_path_name() + "/platform/x86_32"],
124    ":android_x86_64": ["-I" + pkg_path_name() + "/platform/x86_64"],
125    ":android_armeabi": ["-I" + pkg_path_name() + "/platform/arm"],
126    ":android_arm": ["-I" + pkg_path_name() + "/platform/arm"],
127    ":android_arm64": ["-I" + pkg_path_name() + "/platform/aarch64"],
128    ":msvc_windows_x86_64": ["-I" + pkg_path_name() + "/platform/x86_64"],
129    "//conditions:default": [],
130}) + [
131    "-I" + pkg_path_name() + "/public",
132    "-I" + pkg_path_name() + "/internal",
133    "-I" + pkg_path_name() + "/platform/posix",
134] + select({
135    ":msvc_windows_x86_64": [
136    ],
137    ":freebsd": ["-pthread"],
138    "//conditions:default": [
139        "-D_POSIX_C_SOURCE=200809L",
140        "-pthread",
141    ],
142})
143
144# Options for C build, rather then C++11 build.
145NSYNC_OPTS = select({
146    # Select the OS include directory.
147    ":gcc_linux_x86_32_1": ["-I" + pkg_path_name() + "/platform/linux"],
148    ":gcc_linux_x86_64_1": ["-I" + pkg_path_name() + "/platform/linux"],
149    ":gcc_linux_x86_64_2": ["-I" + pkg_path_name() + "/platform/linux"],
150    ":gcc_linux_aarch64": ["-I" + pkg_path_name() + "/platform/linux"],
151    ":gcc_linux_ppc64": ["-I" + pkg_path_name() + "/platform/linux"],
152    ":gcc_linux_s390x": ["-I" + pkg_path_name() + "/platform/linux"],
153    ":clang_macos_x86_64": ["-I" + pkg_path_name() + "/platform/macos"],
154    ":freebsd": ["-I" + pkg_path_name() + "/platform/freebsd"],
155    ":ios_x86_64": ["-I" + pkg_path_name() + "/platform/macos"],
156    ":android_x86_32": ["-I" + pkg_path_name() + "/platform/linux"],
157    ":android_x86_64": ["-I" + pkg_path_name() + "/platform/linux"],
158    ":android_armeabi": ["-I" + pkg_path_name() + "/platform/linux"],
159    ":android_arm": ["-I" + pkg_path_name() + "/platform/linux"],
160    ":android_arm64": ["-I" + pkg_path_name() + "/platform/linux"],
161    ":msvc_windows_x86_64": ["-I" + pkg_path_name() + "/platform/win32"],
162    "//conditions:default": [],
163}) + select({
164    # Select the compiler include directory.
165    ":gcc_linux_x86_32_1": ["-I" + pkg_path_name() + "/platform/gcc"],
166    ":gcc_linux_x86_64_1": ["-I" + pkg_path_name() + "/platform/gcc"],
167    ":gcc_linux_x86_64_2": ["-I" + pkg_path_name() + "/platform/gcc"],
168    ":gcc_linux_aarch64": ["-I" + pkg_path_name() + "/platform/gcc"],
169    ":gcc_linux_ppc64": ["-I" + pkg_path_name() + "/platform/gcc"],
170    ":gcc_linux_s390x": ["-I" + pkg_path_name() + "/platform/gcc"],
171    ":clang_macos_x86_64": ["-I" + pkg_path_name() + "/platform/clang"],
172    ":freebsd": ["-I" + pkg_path_name() + "/platform/clang"],
173    ":ios_x86_64": ["-I" + pkg_path_name() + "/platform/clang"],
174    ":android_x86_32": ["-I" + pkg_path_name() + "/platform/gcc"],
175    ":android_x86_64": ["-I" + pkg_path_name() + "/platform/gcc"],
176    ":android_armeabi": ["-I" + pkg_path_name() + "/platform/gcc"],
177    ":android_arm": ["-I" + pkg_path_name() + "/platform/gcc"],
178    ":android_arm64": ["-I" + pkg_path_name() + "/platform/gcc"],
179    ":msvc_windows_x86_64": ["-I" + pkg_path_name() + "/platform/msvc"],
180}) + select({
181    # Apple deprecated their atomics library, yet recent versions have no
182    # working version of stdatomic.h; so some recent versions need one, and
183    # other versions prefer the other.  For the moment, just ignore the
184    # depreaction.
185    ":clang_macos_x86_64": ["-Wno-deprecated-declarations"],
186    "//conditions:default": [],
187}) + NSYNC_OPTS_GENERIC
188
189# Options for C++11 build, rather then C build.
190NSYNC_OPTS_CPP = select({
191    ":msvc_windows_x86_64": [
192        "/TP",
193    ],
194    "//conditions:default": [
195        "-x",
196        "c++",
197        "-std=c++11",
198    ],
199}) + select({
200    # Some versions of MacOS (notably Sierra) require -D_DARWIN_C_SOURCE
201    # to include some standard C++11 headers, like <mutex>.
202    ":clang_macos_x86_64": ["-D_DARWIN_C_SOURCE"],
203    "//conditions:default": [],
204}) + select({
205    # On Linux, the C++11 library's synchronization primitives are
206    # surprisingly slow.   See also NSYNC_SRC_PLATFORM_CPP, below.
207    ":gcc_linux_x86_32_1": ["-I" + pkg_path_name() + "/platform/c++11.futex"],
208    ":gcc_linux_x86_64_1": ["-I" + pkg_path_name() + "/platform/c++11.futex"],
209    ":gcc_linux_x86_64_2": ["-I" + pkg_path_name() + "/platform/c++11.futex"],
210    ":gcc_linux_aarch64": ["-I" + pkg_path_name() + "/platform/c++11.futex"],
211    ":gcc_linux_ppc64": ["-I" + pkg_path_name() + "/platform/c++11.futex"],
212    ":gcc_linux_s390x": ["-I" + pkg_path_name() + "/platform/c++11.futex"],
213    "//conditions:default": [],
214}) + [
215    "-DNSYNC_ATOMIC_CPP11",
216    "-DNSYNC_USE_CPP11_TIMEPOINT",
217    "-I" + pkg_path_name() + "/platform/c++11",
218] + select({
219    # must follow the -I...platform/c++11
220    ":ios_x86_64": ["-I" + pkg_path_name() + "/platform/gcc_no_tls"],
221    ":msvc_windows_x86_64": [
222        "-I" + pkg_path_name() + "/platform/win32",
223        "-I" + pkg_path_name() + "/platform/msvc",
224    ],
225    "//conditions:default": ["-I" + pkg_path_name() + "/platform/gcc"],
226}) + NSYNC_OPTS_GENERIC
227
228# Link options (for tests) built in C (rather than C++11).
229NSYNC_LINK_OPTS = select({
230    ":msvc_windows_x86_64": [],
231    "//conditions:default": ["-pthread"],
232})
233
234# Link options (for tests) built in C++11 (rather than C).
235NSYNC_LINK_OPTS_CPP = select({
236    ":msvc_windows_x86_64": [],
237    "//conditions:default": ["-pthread"],
238})
239
240# ---------------------------------------------
241# Header files the source may include.
242
243# Internal library headers.
244NSYNC_INTERNAL_HEADERS = [
245    "internal/common.h",
246    "internal/dll.h",
247    "internal/headers.h",
248    "internal/sem.h",
249    "internal/wait_internal.h",
250]
251
252# Internal test headers.
253NSYNC_TEST_HEADERS = NSYNC_INTERNAL_HEADERS + [
254    "testing/array.h",
255    "testing/atm_log.h",
256    "testing/closure.h",
257    "testing/heap.h",
258    "testing/smprintf.h",
259    "testing/testing.h",
260    "testing/time_extra.h",
261]
262
263# Platform specific headers.
264# This declares headers for all platforms, not just the one
265# we're building for, to avoid a more complex build file.
266NSYNC_INTERNAL_HEADERS_PLATFORM = [
267    "platform/aarch64/cputype.h",
268    "platform/alpha/cputype.h",
269    "platform/arm/cputype.h",
270    "platform/atomic_ind/atomic.h",
271    "platform/c++11/atomic.h",
272    "platform/c++11/platform.h",
273    "platform/c++11.futex/platform.h",
274    "platform/c11/atomic.h",
275    "platform/clang/atomic.h",
276    "platform/clang/compiler.h",
277    "platform/cygwin/platform.h",
278    "platform/decc/compiler.h",
279    "platform/freebsd/platform.h",
280    "platform/gcc/atomic.h",
281    "platform/gcc/compiler.h",
282    "platform/gcc_new/atomic.h",
283    "platform/gcc_new_debug/atomic.h",
284    "platform/gcc_no_tls/compiler.h",
285    "platform/gcc_old/atomic.h",
286    "platform/lcc/compiler.h",
287    "platform/lcc/nsync_time_init.h",
288    "platform/linux/platform.h",
289    "platform/win32/atomic.h",
290    "platform/macos/platform_c++11_os.h",
291    "platform/msvc/compiler.h",
292    "platform/netbsd/atomic.h",
293    "platform/netbsd/platform.h",
294    "platform/openbsd/platform.h",
295    "platform/osf1/platform.h",
296    "platform/macos/atomic.h",
297    "platform/macos/platform.h",
298    "platform/pmax/cputype.h",
299    "platform/posix/cputype.h",
300    "platform/posix/nsync_time_init.h",
301    "platform/posix/platform_c++11_os.h",
302    "platform/ppc32/cputype.h",
303    "platform/ppc64/cputype.h",
304    "platform/s390x/cputype.h",
305    "platform/shark/cputype.h",
306    "platform/tcc/compiler.h",
307    "platform/win32/platform.h",
308    "platform/win32/platform_c++11_os.h",
309    "platform/x86_32/cputype.h",
310    "platform/x86_64/cputype.h",
311]
312
313# ---------------------------------------------
314# The nsync library.
315
316# Linux-specific library source.
317NSYNC_SRC_LINUX = [
318    "platform/linux/src/nsync_semaphore_futex.c",
319    "platform/posix/src/per_thread_waiter.c",
320    "platform/posix/src/yield.c",
321    "platform/posix/src/time_rep.c",
322    "platform/posix/src/nsync_panic.c",
323]
324
325# Android-specific library source.
326NSYNC_SRC_ANDROID = [
327    "platform/posix/src/nsync_semaphore_sem_t.c",
328    "platform/posix/src/per_thread_waiter.c",
329    "platform/posix/src/yield.c",
330    "platform/posix/src/time_rep.c",
331    "platform/posix/src/nsync_panic.c",
332]
333
334# MacOS-specific library source.
335NSYNC_SRC_MACOS = [
336    "platform/posix/src/clock_gettime.c",
337    "platform/posix/src/nsync_semaphore_mutex.c",
338    "platform/posix/src/per_thread_waiter.c",
339    "platform/posix/src/yield.c",
340    "platform/posix/src/time_rep.c",
341    "platform/posix/src/nsync_panic.c",
342]
343
344# Windows-specific library source.
345NSYNC_SRC_WINDOWS = [
346    "platform/posix/src/nsync_panic.c",
347    "platform/posix/src/per_thread_waiter.c",
348    "platform/posix/src/time_rep.c",
349    "platform/posix/src/yield.c",
350    "platform/win32/src/clock_gettime.c",
351    "platform/win32/src/init_callback_win32.c",
352    "platform/win32/src/nanosleep.c",
353    "platform/win32/src/nsync_semaphore_win32.c",
354    "platform/win32/src/pthread_cond_timedwait_win32.c",
355    "platform/win32/src/pthread_key_win32.cc",
356]
357
358# FreeBSD-specific library source.
359NSYNC_SRC_FREEBSD = [
360    "platform/posix/src/nsync_semaphore_sem_t.c",
361    "platform/posix/src/per_thread_waiter.c",
362    "platform/posix/src/yield.c",
363    "platform/posix/src/time_rep.c",
364    "platform/posix/src/nsync_panic.c",
365]
366
367# OS-specific library source.
368NSYNC_SRC_PLATFORM = select({
369    ":gcc_linux_x86_32_1": NSYNC_SRC_LINUX,
370    ":gcc_linux_x86_64_1": NSYNC_SRC_LINUX,
371    ":gcc_linux_x86_64_2": NSYNC_SRC_LINUX,
372    ":gcc_linux_aarch64": NSYNC_SRC_LINUX,
373    ":gcc_linux_ppc64": NSYNC_SRC_LINUX,
374    ":gcc_linux_s390x": NSYNC_SRC_LINUX,
375    ":clang_macos_x86_64": NSYNC_SRC_MACOS,
376    ":freebsd": NSYNC_SRC_FREEBSD,
377    ":ios_x86_64": NSYNC_SRC_MACOS,
378    ":android_x86_32": NSYNC_SRC_ANDROID,
379    ":android_x86_64": NSYNC_SRC_ANDROID,
380    ":android_armeabi": NSYNC_SRC_ANDROID,
381    ":android_arm": NSYNC_SRC_ANDROID,
382    ":android_arm64": NSYNC_SRC_ANDROID,
383    ":msvc_windows_x86_64": NSYNC_SRC_WINDOWS,
384})
385
386# C++11-specific (OS and architecture independent) library source.
387NSYNC_SRC_PLATFORM_CPP = [
388    "platform/c++11/src/time_rep_timespec.cc",
389    "platform/c++11/src/nsync_panic.cc",
390    "platform/c++11/src/yield.cc",
391] + select({
392    # On Linux, the C++11 library's synchronization primitives are surprisingly
393    # slow, at least at the time or writing (early 2018).  Raw kernel
394    # primitives are ten times faster for wakeups.
395    ":gcc_linux_x86_32_1": ["platform/linux/src/nsync_semaphore_futex.c"],
396    ":gcc_linux_x86_64_1": ["platform/linux/src/nsync_semaphore_futex.c"],
397    ":gcc_linux_x86_64_2": ["platform/linux/src/nsync_semaphore_futex.c"],
398    ":gcc_linux_aarch64": ["platform/linux/src/nsync_semaphore_futex.c"],
399    ":gcc_linux_ppc64": ["platform/linux/src/nsync_semaphore_futex.c"],
400    ":gcc_linux_s390x": ["platform/linux/src/nsync_semaphore_futex.c"],
401    "//conditions:default": ["platform/c++11/src/nsync_semaphore_mutex.cc"],
402}) + select({
403    # MacOS and Android don't have working C++11 thread local storage.
404    ":clang_macos_x86_64": ["platform/posix/src/per_thread_waiter.c"],
405    ":android_x86_32": ["platform/posix/src/per_thread_waiter.c"],
406    ":android_x86_64": ["platform/posix/src/per_thread_waiter.c"],
407    ":android_armeabi": ["platform/posix/src/per_thread_waiter.c"],
408    ":android_arm": ["platform/posix/src/per_thread_waiter.c"],
409    ":android_arm64": ["platform/posix/src/per_thread_waiter.c"],
410    ":ios_x86_64": ["platform/posix/src/per_thread_waiter.c"],
411    ":msvc_windows_x86_64": [
412        "platform/win32/src/clock_gettime.c",
413        # Windows has no thread-specific data with thread-exit destructors; we
414        # must emulate it with C++ per-thread class destructors.
415        "platform/win32/src/pthread_key_win32.cc",
416        "platform/win32/src/per_thread_waiter.c",
417    ],
418    # It's dangerous to use C++ class destructors if we can avoid it, because
419    # nsync may be linked into the address space multiple times.
420    "//conditions:default": ["platform/posix/src/per_thread_waiter.c"],
421})
422
423# Generic library source.
424NSYNC_SRC_GENERIC = [
425    "internal/common.c",
426    "internal/counter.c",
427    "internal/cv.c",
428    "internal/debug.c",
429    "internal/dll.c",
430    "internal/mu.c",
431    "internal/mu_wait.c",
432    "internal/note.c",
433    "internal/once.c",
434    "internal/sem_wait.c",
435    "internal/time_internal.c",
436    "internal/wait.c",
437]
438
439# Generic library header files.
440NSYNC_HDR_GENERIC = [
441    "public/nsync.h",
442    "public/nsync_atomic.h",
443    "public/nsync_counter.h",
444    "public/nsync_cpp.h",
445    "public/nsync_cv.h",
446    "public/nsync_debug.h",
447    "public/nsync_mu.h",
448    "public/nsync_mu_wait.h",
449    "public/nsync_note.h",
450    "public/nsync_once.h",
451    "public/nsync_time.h",
452    "public/nsync_time_internal.h",
453    "public/nsync_waiter.h",
454]
455
456# The library compiled in C, rather than C++11.
457cc_library(
458    name = "nsync",
459    srcs = NSYNC_SRC_GENERIC + NSYNC_SRC_PLATFORM,
460    hdrs = NSYNC_HDR_GENERIC,
461    copts = NSYNC_OPTS,
462    includes = ["public"],
463    textual_hdrs = NSYNC_INTERNAL_HEADERS + NSYNC_INTERNAL_HEADERS_PLATFORM,
464)
465
466# The library compiled in C++11, rather than C.
467cc_library(
468    name = "nsync_cpp",
469    srcs = NSYNC_SRC_GENERIC + NSYNC_SRC_PLATFORM_CPP,
470    hdrs = NSYNC_HDR_GENERIC,
471    copts = NSYNC_OPTS_CPP,
472    includes = ["public"],
473    textual_hdrs = NSYNC_INTERNAL_HEADERS + NSYNC_INTERNAL_HEADERS_PLATFORM,
474)
475
476# nsync_headers provides just the header files for use in projects that need to
477# build shared libraries for dynamic loading.  Bazel seems unable to cope
478# otherwise.
479cc_library(
480    name = "nsync_headers",
481    hdrs = glob(["public/*.h"]),
482    includes = ["public"],
483)
484
485# ---------------------------------------------
486# Test code.
487
488# Linux-specific test library source.
489NSYNC_TEST_SRC_LINUX = [
490    "platform/posix/src/start_thread.c",
491]
492
493# Android-specific test library source.
494NSYNC_TEST_SRC_ANDROID = [
495    "platform/posix/src/start_thread.c",
496]
497
498# MacOS-specific test library source.
499NSYNC_TEST_SRC_MACOS = [
500    "platform/posix/src/start_thread.c",
501]
502
503# Windows-specific test library source.
504NSYNC_TEST_SRC_WINDOWS = [
505    "platform/win32/src/start_thread.c",
506]
507
508# FreeBSD-specific test library source.
509NSYNC_TEST_SRC_FREEBSD = [
510    "platform/posix/src/start_thread.c",
511]
512
513# OS-specific test library source.
514NSYNC_TEST_SRC_PLATFORM = select({
515    ":gcc_linux_x86_32_1": NSYNC_TEST_SRC_LINUX,
516    ":gcc_linux_x86_64_1": NSYNC_TEST_SRC_LINUX,
517    ":gcc_linux_x86_64_2": NSYNC_TEST_SRC_LINUX,
518    ":gcc_linux_aarch64": NSYNC_TEST_SRC_LINUX,
519    ":gcc_linux_ppc64": NSYNC_TEST_SRC_LINUX,
520    ":gcc_linux_s390x": NSYNC_TEST_SRC_LINUX,
521    ":clang_macos_x86_64": NSYNC_TEST_SRC_MACOS,
522    ":freebsd": NSYNC_TEST_SRC_FREEBSD,
523    ":ios_x86_64": NSYNC_TEST_SRC_MACOS,
524    ":android_x86_32": NSYNC_TEST_SRC_ANDROID,
525    ":android_x86_64": NSYNC_TEST_SRC_ANDROID,
526    ":android_armeabi": NSYNC_TEST_SRC_ANDROID,
527    ":android_arm": NSYNC_TEST_SRC_ANDROID,
528    ":android_arm64": NSYNC_TEST_SRC_ANDROID,
529    ":msvc_windows_x86_64": NSYNC_TEST_SRC_WINDOWS,
530})
531
532# C++11-specific (OS and architecture independent) test library source.
533NSYNC_TEST_SRC_PLATFORM_CPP = [
534    "platform/c++11/src/start_thread.cc",
535]
536
537# Generic test library source.
538NSYNC_TEST_SRC_GENERIC = [
539    "testing/array.c",
540    "testing/atm_log.c",
541    "testing/closure.c",
542    "testing/smprintf.c",
543    "testing/testing.c",
544    "testing/time_extra.c",
545]
546
547# The test library compiled in C, rather than C++11.
548cc_library(
549    name = "nsync_test_lib",
550    testonly = 1,
551    srcs = NSYNC_TEST_SRC_GENERIC + NSYNC_TEST_SRC_PLATFORM,
552    hdrs = ["testing/testing.h"],
553    copts = NSYNC_OPTS,
554    textual_hdrs = NSYNC_TEST_HEADERS + NSYNC_INTERNAL_HEADERS_PLATFORM,
555    deps = [":nsync"],
556)
557
558# The test library compiled in C++11, rather than C.
559cc_library(
560    name = "nsync_test_lib_cpp",
561    testonly = 1,
562    srcs = NSYNC_TEST_SRC_GENERIC + NSYNC_TEST_SRC_PLATFORM_CPP,
563    hdrs = ["testing/testing.h"],
564    copts = NSYNC_OPTS_CPP,
565    textual_hdrs = NSYNC_TEST_HEADERS + NSYNC_INTERNAL_HEADERS_PLATFORM,
566    deps = [":nsync_cpp"],
567)
568
569# ---------------------------------------------
570# The tests, compiled in C rather than C++11.
571
572cc_test(
573    name = "counter_test",
574    size = "small",
575    srcs = ["testing/counter_test.c"],
576    copts = NSYNC_OPTS,
577    linkopts = NSYNC_LINK_OPTS,
578    deps = [
579        ":nsync",
580        ":nsync_test_lib",
581    ],
582)
583
584cc_test(
585    name = "cv_mu_timeout_stress_test",
586    size = "small",
587    srcs = ["testing/cv_mu_timeout_stress_test.c"],
588    copts = NSYNC_OPTS,
589    linkopts = NSYNC_LINK_OPTS,
590    deps = [
591        ":nsync",
592        ":nsync_test_lib",
593    ],
594)
595
596cc_test(
597    name = "cv_test",
598    size = "small",
599    srcs = ["testing/cv_test.c"],
600    copts = NSYNC_OPTS,
601    linkopts = NSYNC_LINK_OPTS,
602    deps = [
603        ":nsync",
604        ":nsync_test_lib",
605    ],
606)
607
608cc_test(
609    name = "cv_wait_example_test",
610    size = "small",
611    srcs = ["testing/cv_wait_example_test.c"],
612    copts = NSYNC_OPTS,
613    linkopts = NSYNC_LINK_OPTS,
614    deps = [
615        ":nsync",
616        ":nsync_test_lib",
617    ],
618)
619
620cc_test(
621    name = "dll_test",
622    size = "small",
623    srcs = ["testing/dll_test.c"],
624    copts = NSYNC_OPTS,
625    linkopts = NSYNC_LINK_OPTS,
626    deps = [
627        ":nsync",
628        ":nsync_test_lib",
629    ],
630)
631
632cc_test(
633    name = "mu_starvation_test",
634    size = "small",
635    srcs = ["testing/mu_starvation_test.c"],
636    copts = NSYNC_OPTS,
637    linkopts = NSYNC_LINK_OPTS,
638    deps = [
639        ":nsync",
640        ":nsync_test_lib",
641    ],
642)
643
644cc_test(
645    name = "mu_test",
646    size = "small",
647    srcs = ["testing/mu_test.c"],
648    copts = NSYNC_OPTS,
649    linkopts = NSYNC_LINK_OPTS,
650    deps = [
651        ":nsync",
652        ":nsync_test_lib",
653    ],
654)
655
656cc_test(
657    name = "mu_wait_example_test",
658    size = "small",
659    srcs = ["testing/mu_wait_example_test.c"],
660    copts = NSYNC_OPTS,
661    linkopts = NSYNC_LINK_OPTS,
662    deps = [
663        ":nsync",
664        ":nsync_test_lib",
665    ],
666)
667
668cc_test(
669    name = "mu_wait_test",
670    size = "small",
671    srcs = ["testing/mu_wait_test.c"],
672    copts = NSYNC_OPTS,
673    linkopts = NSYNC_LINK_OPTS,
674    deps = [
675        ":nsync",
676        ":nsync_test_lib",
677    ],
678)
679
680cc_test(
681    name = "note_test",
682    size = "small",
683    srcs = ["testing/note_test.c"],
684    copts = NSYNC_OPTS,
685    linkopts = NSYNC_LINK_OPTS,
686    deps = [
687        ":nsync",
688        ":nsync_test_lib",
689    ],
690)
691
692cc_test(
693    name = "once_test",
694    size = "small",
695    srcs = ["testing/once_test.c"],
696    copts = NSYNC_OPTS,
697    linkopts = NSYNC_LINK_OPTS,
698    deps = [
699        ":nsync",
700        ":nsync_test_lib",
701    ],
702)
703
704cc_test(
705    name = "pingpong_test",
706    size = "small",
707    srcs = ["testing/pingpong_test.c"],
708    copts = NSYNC_OPTS,
709    linkopts = NSYNC_LINK_OPTS,
710    deps = [
711        ":nsync",
712        ":nsync_test_lib",
713    ],
714)
715
716cc_test(
717    name = "wait_test",
718    size = "small",
719    srcs = ["testing/wait_test.c"],
720    copts = NSYNC_OPTS,
721    linkopts = NSYNC_LINK_OPTS,
722    deps = [
723        ":nsync",
724        ":nsync_test_lib",
725    ],
726)
727
728# ---------------------------------------------
729# The tests, compiled in C++11, rather than C.
730
731cc_test(
732    name = "counter_cpp_test",
733    size = "small",
734    srcs = ["testing/counter_test.c"],
735    copts = NSYNC_OPTS_CPP,
736    linkopts = NSYNC_LINK_OPTS_CPP,
737    deps = [
738        ":nsync_cpp",
739        ":nsync_test_lib_cpp",
740    ],
741)
742
743cc_test(
744    name = "cv_mu_timeout_stress_cpp_test",
745    size = "small",
746    srcs = ["testing/cv_mu_timeout_stress_test.c"],
747    copts = NSYNC_OPTS_CPP,
748    linkopts = NSYNC_LINK_OPTS_CPP,
749    deps = [
750        ":nsync_cpp",
751        ":nsync_test_lib_cpp",
752    ],
753)
754
755cc_test(
756    name = "cv_cpp_test",
757    size = "small",
758    srcs = ["testing/cv_test.c"],
759    copts = NSYNC_OPTS_CPP,
760    linkopts = NSYNC_LINK_OPTS_CPP,
761    deps = [
762        ":nsync_cpp",
763        ":nsync_test_lib_cpp",
764    ],
765)
766
767cc_test(
768    name = "cv_wait_example_cpp_test",
769    size = "small",
770    srcs = ["testing/cv_wait_example_test.c"],
771    copts = NSYNC_OPTS_CPP,
772    linkopts = NSYNC_LINK_OPTS_CPP,
773    deps = [
774        ":nsync_cpp",
775        ":nsync_test_lib_cpp",
776    ],
777)
778
779cc_test(
780    name = "dll_cpp_test",
781    size = "small",
782    srcs = ["testing/dll_test.c"],
783    copts = NSYNC_OPTS_CPP,
784    linkopts = NSYNC_LINK_OPTS_CPP,
785    deps = [
786        ":nsync_cpp",
787        ":nsync_test_lib_cpp",
788    ],
789)
790
791cc_test(
792    name = "mu_starvation_cpp_test",
793    size = "small",
794    srcs = ["testing/mu_starvation_test.c"],
795    copts = NSYNC_OPTS_CPP,
796    linkopts = NSYNC_LINK_OPTS_CPP,
797    deps = [
798        ":nsync_cpp",
799        ":nsync_test_lib_cpp",
800    ],
801)
802
803cc_test(
804    name = "mu_cpp_test",
805    size = "small",
806    srcs = ["testing/mu_test.c"],
807    copts = NSYNC_OPTS_CPP,
808    linkopts = NSYNC_LINK_OPTS_CPP,
809    deps = [
810        ":nsync_cpp",
811        ":nsync_test_lib_cpp",
812    ],
813)
814
815cc_test(
816    name = "mu_wait_example_cpp_test",
817    size = "small",
818    srcs = ["testing/mu_wait_example_test.c"],
819    copts = NSYNC_OPTS_CPP,
820    linkopts = NSYNC_LINK_OPTS_CPP,
821    deps = [
822        ":nsync_cpp",
823        ":nsync_test_lib_cpp",
824    ],
825)
826
827cc_test(
828    name = "mu_wait_cpp_test",
829    size = "small",
830    srcs = ["testing/mu_wait_test.c"],
831    copts = NSYNC_OPTS_CPP,
832    linkopts = NSYNC_LINK_OPTS_CPP,
833    deps = [
834        ":nsync_cpp",
835        ":nsync_test_lib_cpp",
836    ],
837)
838
839cc_test(
840    name = "note_cpp_test",
841    size = "small",
842    srcs = ["testing/note_test.c"],
843    copts = NSYNC_OPTS_CPP,
844    linkopts = NSYNC_LINK_OPTS_CPP,
845    deps = [
846        ":nsync_cpp",
847        ":nsync_test_lib_cpp",
848    ],
849)
850
851cc_test(
852    name = "once_cpp_test",
853    size = "small",
854    srcs = ["testing/once_test.c"],
855    copts = NSYNC_OPTS_CPP,
856    linkopts = NSYNC_LINK_OPTS_CPP,
857    deps = [
858        ":nsync_cpp",
859        ":nsync_test_lib_cpp",
860    ],
861)
862
863cc_test(
864    name = "pingpong_cpp_test",
865    size = "small",
866    srcs = ["testing/pingpong_test.c"],
867    copts = NSYNC_OPTS_CPP,
868    linkopts = NSYNC_LINK_OPTS_CPP,
869    deps = [
870        ":nsync_cpp",
871        ":nsync_test_lib_cpp",
872    ],
873)
874
875cc_test(
876    name = "wait_cpp_test",
877    size = "small",
878    srcs = ["testing/wait_test.c"],
879    copts = NSYNC_OPTS_CPP,
880    linkopts = NSYNC_LINK_OPTS_CPP,
881    deps = [
882        ":nsync_cpp",
883        ":nsync_test_lib_cpp",
884    ],
885)
886