1# Copyright (c) 2016, Google Inc.
2#
3# Permission to use, copy, modify, and/or distribute this software for any
4# purpose with or without fee is hereby granted, provided that the above
5# copyright notice and this permission notice appear in all copies.
6#
7# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10# SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12# OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14
15load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
16load(
17    ":BUILD.generated.bzl",
18    "crypto_headers",
19    "crypto_internal_headers",
20    "crypto_sources",
21    "crypto_sources_linux_ppc64le",
22    "crypto_sources_linux_x86_64",
23    "crypto_sources_mac_x86_64",
24    "fips_fragments",
25    "ssl_headers",
26    "ssl_internal_headers",
27    "ssl_sources",
28    "tool_headers",
29    "tool_sources",
30)
31
32licenses(["notice"])
33
34exports_files(["LICENSE"])
35
36config_setting(
37    name = "linux_x86_64",
38    values = {"cpu": "k8"},
39)
40
41config_setting(
42    name = "linux_ppc64le",
43    values = {"cpu": "ppc"},
44)
45
46config_setting(
47    name = "mac_x86_64",
48    values = {"cpu": "darwin"},
49)
50
51config_setting(
52    name = "windows_x86_64",
53    values = {"cpu": "x64_windows"},
54)
55
56config_setting(
57    name = "android",
58    values = {"crosstool_top": "//external:android/crosstool"},
59)
60
61posix_copts = [
62    # Assembler option --noexecstack adds .note.GNU-stack to each object to
63    # ensure that binaries can be built with non-executable stack.
64    "-Wa,--noexecstack",
65
66    # This is needed on Linux systems (at least) to get rwlock in pthread.
67    "-D_XOPEN_SOURCE=700",
68
69    # This list of warnings should match those in the top-level CMakeLists.txt.
70    "-Wall",
71    "-Werror",
72    "-Wformat=2",
73    "-Wsign-compare",
74    "-Wmissing-field-initializers",
75    "-Wwrite-strings",
76    "-Wshadow",
77    "-fno-common",
78
79    # Modern build environments should be able to set this to use atomic
80    # operations for reference counting rather than locks. However, it's
81    # known not to work on some Android builds.
82    # "-DOPENSSL_C11_ATOMIC",
83]
84
85boringssl_copts = select({
86    ":linux_ppc64le": posix_copts,
87    ":linux_x86_64": posix_copts,
88    ":mac_x86_64": posix_copts,
89    ":windows_x86_64": [
90        "-DWIN32_LEAN_AND_MEAN",
91        "-DOPENSSL_NO_ASM",
92    ],
93    "//conditions:default": ["-DOPENSSL_NO_ASM"],
94})
95
96crypto_sources_asm = select({
97    ":linux_ppc64le": crypto_sources_linux_ppc64le,
98    ":linux_x86_64": crypto_sources_linux_x86_64,
99    ":mac_x86_64": crypto_sources_mac_x86_64,
100    "//conditions:default": [],
101})
102
103# For C targets only (not C++), compile with C11 support.
104posix_copts_c11 = [
105    "-std=c11",
106    "-Wmissing-prototypes",
107    "-Wold-style-definition",
108    "-Wstrict-prototypes",
109]
110
111boringssl_copts_c11 = boringssl_copts + select({
112    ":linux_ppc64le": posix_copts_c11,
113    ":linux_x86_64": posix_copts_c11,
114    ":mac_x86_64": posix_copts_c11,
115    "//conditions:default": [],
116})
117
118# For C++ targets only (not C), compile with C++11 support.
119posix_copts_cxx = [
120    "-std=c++11",
121    "-Wmissing-declarations",
122]
123
124boringssl_copts_cxx = boringssl_copts + select({
125    ":linux_ppc64le": posix_copts_cxx,
126    ":linux_x86_64": posix_copts_cxx,
127    ":mac_x86_64": posix_copts_cxx,
128    "//conditions:default": [],
129})
130
131cc_library(
132    name = "crypto",
133    srcs = crypto_sources + crypto_internal_headers + crypto_sources_asm,
134    hdrs = crypto_headers + fips_fragments,
135    copts = boringssl_copts_c11,
136    includes = ["src/include"],
137    linkopts = select({
138        # Android supports pthreads, but does not provide a libpthread
139        # to link against.
140        ":android": [],
141        ":mac_x86_64": [],
142        ":windows_x86_64": ["-defaultlib:advapi32.lib"],
143        "//conditions:default": ["-lpthread"],
144    }),
145    visibility = ["//visibility:public"],
146)
147
148cc_library(
149    name = "ssl",
150    srcs = ssl_sources + ssl_internal_headers,
151    hdrs = ssl_headers,
152    copts = boringssl_copts_cxx,
153    includes = ["src/include"],
154    visibility = ["//visibility:public"],
155    deps = [
156        ":crypto",
157    ],
158)
159
160cc_binary(
161    name = "bssl",
162    srcs = tool_sources + tool_headers,
163    copts = boringssl_copts_cxx,
164    visibility = ["//visibility:public"],
165    deps = [":ssl"],
166)
167