xref: /aosp_15_r20/external/pigweed/third_party/boringssl/BUILD.gn (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1# Copyright 2021 The Pigweed Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4# use this file except in compliance with the License. You may obtain a copy of
5# the License at
6#
7#     https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations under
13# the License.
14
15import("//build_overrides/pigweed.gni")
16import("$dir_pw_build/target_types.gni")
17import("$dir_pw_docgen/docs.gni")
18import("$dir_pw_third_party/boringssl/boringssl.gni")
19import("$dir_pw_unit_test/test.gni")
20
21if (pw_third_party_boringssl_ALIAS != "") {
22  assert(dir_pw_third_party_boringssl == "")
23
24  pw_source_set("boringssl") {
25    public_deps = [ pw_third_party_boringssl_ALIAS ]
26  }
27} else if (dir_pw_third_party_boringssl != "") {
28  import("$dir_pw_third_party_boringssl/BUILD.generated.gni")
29
30  config("public_config") {
31    include_dirs = [
32      "$dir_pw_third_party_boringssl/src/include",
33      "public",
34    ]
35
36    # This can be removed once boringssl threading primitives are implemented,
37    # i.e. using pw_sync, and when we have a posix style socket layer.
38    defines =
39        [ "OPENSSL_NO_THREADS_CORRUPT_MEMORY_AND_LEAK_SECRETS_IF_THREADED" ]
40  }
41
42  config("internal_config") {
43    defines = [
44      # Enable virtual desctructor and compile-time check of pure virtual base class
45      "BORINGSSL_ALLOW_CXX_RUNTIME",
46
47      # Code size optimiaztion
48      "OPENSSL_SMALL",
49
50      # The ARM assembly code is only for cortex-A.
51      "OPENSSL_NO_ASM",
52
53      # socklen_t is not defined
54      "OPENSSL_NO_SOCK",
55
56      # Disable assert, which may additionally link in unwanted binaries via
57      # argument evaluation.
58      "NDEBUG",
59    ]
60    cflags = [
61      "-Wno-unused-function",
62      "-Wno-conversion",
63      "-Wno-unused-parameter",
64      "-Wno-char-subscripts",
65      "-Wno-cast-qual",
66      "-w",
67    ]
68    cflags_cc = [
69      "-fpermissive",
70      "-Wno-error",  # To get through the -Werror=permissive error
71    ]
72    include_dirs = [ "$dir_pw_third_party_boringssl" ]
73  }
74
75  # Remove sources that require file system and posix socket support
76  excluded_sources = [
77    "src/crypto/bio/connect.c",
78    "src/crypto/bio/fd.c",
79    "src/crypto/bio/socket.c",
80    "src/crypto/bio/socket_helper.c",
81  ]
82
83  pw_source_set("boringssl") {
84    sources = []
85    foreach(source, crypto_sources - excluded_sources + ssl_sources) {
86      sources += [ "$dir_pw_third_party_boringssl/$source" ]
87    }
88    public_configs = [ ":public_config" ]
89    configs = [ ":internal_config" ]
90
91    # Contains a faked "sysdeps/sys/socket.h"
92    # Can be removed once posix socket layer in Pigweed is supported.
93    include_dirs = [ "sysdeps" ]
94
95    public_deps = [
96      "$dir_pw_assert",
97      "$dir_pw_tls_client:time",
98    ]
99
100    # Consume //third_party/boringssl via a Pigweed module only.
101    visibility = [
102      ":*",
103      "$dir_pw_bluetooth_sapphire/*",
104      "$dir_pw_tls_client:*",
105      "$dir_pw_tls_client_boringssl:*",
106    ]
107  }
108
109  pw_test_group("tests") {
110    tests = [ ":build_test" ]
111  }
112
113  pw_test("build_test") {
114    sources = [ "build_test.cc" ]
115    deps = [ ":boringssl" ]
116  }
117} else {
118  group("boringssl") {
119  }
120}
121
122pw_doc_group("docs") {
123  sources = [ "docs.rst" ]
124}
125