blob: 1ec2bdf183ccd97653a76f283114cd5a0964acd7 [file] [log] [blame]
David Benjaminc895d6b2016-08-11 13:26:41 -04001# 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
Tobias Thierer43be7d22020-03-02 19:23:34 +000015load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
David Benjaminc895d6b2016-08-11 13:26:41 -040016load(
17 ":BUILD.generated.bzl",
18 "crypto_headers",
19 "crypto_internal_headers",
20 "crypto_sources",
Pete Bentley83b8e972022-02-28 19:23:25 +000021 "crypto_sources_apple_aarch64",
22 "crypto_sources_apple_x86_64",
Pete Bentley00a7c402021-07-23 17:57:12 +010023 "crypto_sources_linux_aarch64",
Pete Bentley5c2e48f2020-08-27 15:48:43 +000024 "crypto_sources_linux_ppc64le",
Pete Bentleyf23caaf2020-09-22 18:02:11 +010025 "crypto_sources_linux_x86_64",
Robert Sloan8ff03552017-06-14 12:40:58 -070026 "fips_fragments",
David Benjaminc895d6b2016-08-11 13:26:41 -040027 "ssl_headers",
28 "ssl_internal_headers",
Robert Sloanfe7cd212017-08-07 09:03:39 -070029 "ssl_sources",
Pete Bentley5c2e48f2020-08-27 15:48:43 +000030 "tool_headers",
Pete Bentleyf23caaf2020-09-22 18:02:11 +010031 "tool_sources",
David Benjaminc895d6b2016-08-11 13:26:41 -040032)
33
Pete Bentleyf23caaf2020-09-22 18:02:11 +010034licenses(["notice"])
35
36exports_files(["LICENSE"])
37
David Benjaminc895d6b2016-08-11 13:26:41 -040038config_setting(
Pete Bentley00a7c402021-07-23 17:57:12 +010039 name = "linux_aarch64",
Pete Bentley83b8e972022-02-28 19:23:25 +000040 constraint_values = [
41 "@platforms//os:linux",
42 "@platforms//cpu:aarch64",
43 ],
Pete Bentley00a7c402021-07-23 17:57:12 +010044)
45
46config_setting(
David Benjaminc895d6b2016-08-11 13:26:41 -040047 name = "linux_x86_64",
Pete Bentley83b8e972022-02-28 19:23:25 +000048 constraint_values = [
49 "@platforms//os:linux",
50 "@platforms//cpu:x86_64",
51 ],
David Benjaminc895d6b2016-08-11 13:26:41 -040052)
53
54config_setting(
Adam Vartanianbfcf3a72018-08-10 14:55:24 +010055 name = "linux_ppc64le",
Pete Bentley83b8e972022-02-28 19:23:25 +000056 constraint_values = [
57 "@platforms//os:linux",
58 "@platforms//cpu:ppc",
59 ],
Adam Vartanianbfcf3a72018-08-10 14:55:24 +010060)
61
62config_setting(
Pete Bentley83b8e972022-02-28 19:23:25 +000063 name = "macos_aarch64",
64 constraint_values = [
65 "@platforms//os:macos",
66 "@platforms//cpu:aarch64",
67 ],
David Benjaminc895d6b2016-08-11 13:26:41 -040068)
69
Robert Sloanfe7cd212017-08-07 09:03:39 -070070config_setting(
Pete Bentley83b8e972022-02-28 19:23:25 +000071 name = "macos_x86_64",
72 constraint_values = [
73 "@platforms//os:macos",
74 "@platforms//cpu:x86_64",
75 ],
Pete Bentley00a7c402021-07-23 17:57:12 +010076)
77
Robert Sloanfe7cd212017-08-07 09:03:39 -070078posix_copts = [
David Benjaminc895d6b2016-08-11 13:26:41 -040079 # Assembler option --noexecstack adds .note.GNU-stack to each object to
80 # ensure that binaries can be built with non-executable stack.
81 "-Wa,--noexecstack",
82
David Benjaminc895d6b2016-08-11 13:26:41 -040083 # This list of warnings should match those in the top-level CMakeLists.txt.
84 "-Wall",
85 "-Werror",
86 "-Wformat=2",
87 "-Wsign-compare",
88 "-Wmissing-field-initializers",
89 "-Wwrite-strings",
90 "-Wshadow",
91 "-fno-common",
Robert Sloanfe7cd212017-08-07 09:03:39 -070092]
93
Benjamin Brittain3d9f2ea2022-01-25 10:11:27 -050094linux_copts = posix_copts + [
95 # This is needed on Linux systems (at least) to get rwlock in pthread, but
96 # it should not be set on Apple platforms, where it instead disables APIs
97 # we use. See compat(5) and sys/cdefs.h.
98 "-D_XOPEN_SOURCE=700",
99]
100
Robert Sloanfe7cd212017-08-07 09:03:39 -0700101boringssl_copts = select({
Pete Bentley83b8e972022-02-28 19:23:25 +0000102 "@platforms//os:linux": linux_copts,
103 "@platforms//os:macos": posix_copts,
104 "@platforms//os:windows": ["-DWIN32_LEAN_AND_MEAN"],
105 "//conditions:default": [],
David Benjaminc895d6b2016-08-11 13:26:41 -0400106})
107
Pete Bentley83b8e972022-02-28 19:23:25 +0000108# These selects must be kept in sync.
David Benjaminc895d6b2016-08-11 13:26:41 -0400109crypto_sources_asm = select({
Pete Bentley00a7c402021-07-23 17:57:12 +0100110 ":linux_aarch64": crypto_sources_linux_aarch64,
Pete Bentley5c2e48f2020-08-27 15:48:43 +0000111 ":linux_ppc64le": crypto_sources_linux_ppc64le,
Pete Bentleyf23caaf2020-09-22 18:02:11 +0100112 ":linux_x86_64": crypto_sources_linux_x86_64,
Pete Bentley83b8e972022-02-28 19:23:25 +0000113 ":macos_aarch64": crypto_sources_apple_aarch64,
114 ":macos_x86_64": crypto_sources_apple_x86_64,
David Benjaminc895d6b2016-08-11 13:26:41 -0400115 "//conditions:default": [],
116})
Pete Bentley83b8e972022-02-28 19:23:25 +0000117boringssl_copts += select({
118 ":linux_aarch64": [],
119 ":linux_ppc64le": [],
120 ":linux_x86_64": [],
121 ":macos_aarch64": [],
122 ":macos_x86_64": [],
123 "//conditions:default": ["-DOPENSSL_NO_ASM"],
124})
David Benjaminc895d6b2016-08-11 13:26:41 -0400125
126# For C targets only (not C++), compile with C11 support.
Robert Sloanfe7cd212017-08-07 09:03:39 -0700127posix_copts_c11 = [
David Benjaminc895d6b2016-08-11 13:26:41 -0400128 "-std=c11",
129 "-Wmissing-prototypes",
130 "-Wold-style-definition",
131 "-Wstrict-prototypes",
132]
133
Robert Sloanfe7cd212017-08-07 09:03:39 -0700134boringssl_copts_c11 = boringssl_copts + select({
Pete Bentley83b8e972022-02-28 19:23:25 +0000135 "@platforms//os:linux": posix_copts_c11,
136 "@platforms//os:macos": posix_copts_c11,
Robert Sloanfe7cd212017-08-07 09:03:39 -0700137 "//conditions:default": [],
138})
139
Pete Bentley235ceeb2022-05-25 13:22:14 +0100140# For C++ targets only (not C), compile with C++14 support.
Robert Sloanfe7cd212017-08-07 09:03:39 -0700141posix_copts_cxx = [
Pete Bentley235ceeb2022-05-25 13:22:14 +0100142 "-std=c++14",
David Benjaminc895d6b2016-08-11 13:26:41 -0400143 "-Wmissing-declarations",
144]
145
Robert Sloanfe7cd212017-08-07 09:03:39 -0700146boringssl_copts_cxx = boringssl_copts + select({
Pete Bentley83b8e972022-02-28 19:23:25 +0000147 "@platforms//os:linux": posix_copts_cxx,
148 "@platforms//os:macos": posix_copts_cxx,
Robert Sloanfe7cd212017-08-07 09:03:39 -0700149 "//conditions:default": [],
150})
151
David Benjaminc895d6b2016-08-11 13:26:41 -0400152cc_library(
153 name = "crypto",
154 srcs = crypto_sources + crypto_internal_headers + crypto_sources_asm,
Robert Sloan8ff03552017-06-14 12:40:58 -0700155 hdrs = crypto_headers + fips_fragments,
David Benjaminc895d6b2016-08-11 13:26:41 -0400156 copts = boringssl_copts_c11,
157 includes = ["src/include"],
158 linkopts = select({
Robert Sloan29c1d2c2017-10-30 14:10:28 -0700159 # Android supports pthreads, but does not provide a libpthread
160 # to link against.
Pete Bentley83b8e972022-02-28 19:23:25 +0000161 "@platforms//os:android": [],
162 "@platforms//os:macos": [],
163 "@platforms//os:windows": ["-defaultlib:advapi32.lib"],
David Benjaminc895d6b2016-08-11 13:26:41 -0400164 "//conditions:default": ["-lpthread"],
165 }),
166 visibility = ["//visibility:public"],
167)
168
169cc_library(
170 name = "ssl",
Robert Sloanfe7cd212017-08-07 09:03:39 -0700171 srcs = ssl_sources + ssl_internal_headers,
David Benjaminc895d6b2016-08-11 13:26:41 -0400172 hdrs = ssl_headers,
Robert Sloanfe7cd212017-08-07 09:03:39 -0700173 copts = boringssl_copts_cxx,
David Benjaminc895d6b2016-08-11 13:26:41 -0400174 includes = ["src/include"],
175 visibility = ["//visibility:public"],
Robert Sloanfe7cd212017-08-07 09:03:39 -0700176 deps = [
177 ":crypto",
178 ],
David Benjaminc895d6b2016-08-11 13:26:41 -0400179)
180
181cc_binary(
182 name = "bssl",
David Benjaminf0c4a6c2016-08-11 13:26:41 -0400183 srcs = tool_sources + tool_headers,
David Benjaminc895d6b2016-08-11 13:26:41 -0400184 copts = boringssl_copts_cxx,
185 visibility = ["//visibility:public"],
186 deps = [":ssl"],
187)