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_apple_aarch64", 22 "crypto_sources_apple_x86_64", 23 "crypto_sources_linux_aarch64", 24 "crypto_sources_linux_ppc64le", 25 "crypto_sources_linux_x86_64", 26 "fips_fragments", 27 "ssl_headers", 28 "ssl_internal_headers", 29 "ssl_sources", 30 "tool_headers", 31 "tool_sources", 32) 33 34licenses(["notice"]) 35 36exports_files(["LICENSE"]) 37 38config_setting( 39 name = "linux_aarch64", 40 constraint_values = [ 41 "@platforms//os:linux", 42 "@platforms//cpu:aarch64", 43 ], 44) 45 46config_setting( 47 name = "linux_x86_64", 48 constraint_values = [ 49 "@platforms//os:linux", 50 "@platforms//cpu:x86_64", 51 ], 52) 53 54config_setting( 55 name = "linux_ppc64le", 56 constraint_values = [ 57 "@platforms//os:linux", 58 "@platforms//cpu:ppc", 59 ], 60) 61 62config_setting( 63 name = "macos_aarch64", 64 constraint_values = [ 65 "@platforms//os:macos", 66 "@platforms//cpu:aarch64", 67 ], 68) 69 70config_setting( 71 name = "macos_x86_64", 72 constraint_values = [ 73 "@platforms//os:macos", 74 "@platforms//cpu:x86_64", 75 ], 76) 77 78posix_copts = [ 79 # 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 83 # 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", 92] 93 94linux_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 101boringssl_copts = select({ 102 "@platforms//os:linux": linux_copts, 103 "@platforms//os:macos": posix_copts, 104 "@platforms//os:windows": ["-DWIN32_LEAN_AND_MEAN"], 105 "//conditions:default": [], 106}) 107 108# These selects must be kept in sync. 109crypto_sources_asm = select({ 110 ":linux_aarch64": crypto_sources_linux_aarch64, 111 ":linux_ppc64le": crypto_sources_linux_ppc64le, 112 ":linux_x86_64": crypto_sources_linux_x86_64, 113 ":macos_aarch64": crypto_sources_apple_aarch64, 114 ":macos_x86_64": crypto_sources_apple_x86_64, 115 "//conditions:default": [], 116}) 117boringssl_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}) 125 126# For C targets only (not C++), compile with C11 support. 127posix_copts_c11 = [ 128 "-std=c11", 129 "-Wmissing-prototypes", 130 "-Wold-style-definition", 131 "-Wstrict-prototypes", 132] 133 134boringssl_copts_c11 = boringssl_copts + select({ 135 "@platforms//os:linux": posix_copts_c11, 136 "@platforms//os:macos": posix_copts_c11, 137 "//conditions:default": [], 138}) 139 140# For C++ targets only (not C), compile with C++14 support. 141posix_copts_cxx = [ 142 "-std=c++14", 143 "-Wmissing-declarations", 144] 145 146boringssl_copts_cxx = boringssl_copts + select({ 147 "@platforms//os:linux": posix_copts_cxx, 148 "@platforms//os:macos": posix_copts_cxx, 149 "//conditions:default": [], 150}) 151 152cc_library( 153 name = "crypto", 154 srcs = crypto_sources + crypto_internal_headers + crypto_sources_asm, 155 hdrs = crypto_headers + fips_fragments, 156 copts = boringssl_copts_c11, 157 includes = ["src/include"], 158 linkopts = select({ 159 # Android supports pthreads, but does not provide a libpthread 160 # to link against. 161 "@platforms//os:android": [], 162 "@platforms//os:macos": [], 163 "@platforms//os:windows": ["-defaultlib:advapi32.lib"], 164 "//conditions:default": ["-lpthread"], 165 }), 166 visibility = ["//visibility:public"], 167) 168 169cc_library( 170 name = "ssl", 171 srcs = ssl_sources + ssl_internal_headers, 172 hdrs = ssl_headers, 173 copts = boringssl_copts_cxx, 174 includes = ["src/include"], 175 visibility = ["//visibility:public"], 176 deps = [ 177 ":crypto", 178 ], 179) 180 181cc_binary( 182 name = "bssl", 183 srcs = tool_sources + tool_headers, 184 copts = boringssl_copts_cxx, 185 visibility = ["//visibility:public"], 186 deps = [":ssl"], 187) 188