• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2023 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")
16
17import("$dir_pw_build/target_types.gni")
18import("$dir_pw_docgen/docs.gni")
19import("$dir_pw_third_party/llvm_libc/llvm_libc.gni")
20import("$dir_pw_toolchain/generate_toolchain.gni")
21import("$dir_pw_unit_test/test.gni")
22
23config("default_config") {
24  include_dirs = [ "public" ]
25}
26
27pw_test_group("tests") {
28  tests = [
29    ":llvm_libc_tests",
30    ":logf_test",
31    ":memset_test",
32  ]
33}
34
35pw_test("memset_test") {
36  sources = [ "memset_test.cc" ]
37  deps = [ "$dir_pw_containers" ]
38}
39
40pw_test("logf_test") {
41  sources = [ "logf_test.cc" ]
42}
43
44# Clang has __attribute__(("no-builtin")), but gcc doesn't support it so we
45# need this flag instead.
46config("no-builtin") {
47  cflags = [ "-fno-builtin" ]
48}
49
50# Downstream projects sometimes build with -Wshadow, which on gcc also warns
51# about constructor arguments shadowing struct members. This is too pedantic
52# and not reasonable to change upstream llvm-libc.
53config("no-shadow") {
54  cflags = [ "-Wno-shadow" ]
55}
56
57# If dir_pw_third_party_llvm_libc is defined, use that directory to create a
58# pw_libc.a from llvm-libc. Otherwise, we create an empty pw_libc.a.
59if (dir_pw_third_party_llvm_libc != "") {
60  pw_libc_source_set("stdlib") {
61    functions = [
62      "abs",
63      "rand",
64      "srand",
65    ]
66    additional_srcs = [
67      "baremetal/abort.cpp",
68      "rand_util.cpp",
69    ]
70
71    # srand and rand are both tested in rand_test.cpp.
72    no_test_functions = [ "srand" ]
73  }
74
75  pw_libc_source_set("string") {
76    defines = [ "LIBC_COPT_MEMCPY_USE_EMBEDDED_TINY" ]
77    functions = [
78      "strcmp",
79      "strcpy",
80      "strstr",
81      "strncpy",
82      "strnlen",
83      "memcpy",
84      "memset",
85      "memmove",
86    ]
87
88    # memmove tests use gtest matchers which pw_unit_test doesn't support.
89    no_test_functions = [ "memmove" ]
90
91    configs = [
92      ":no-builtin",
93      ":no-shadow",
94    ]
95  }
96
97  pw_libc_source_set("ctype") {
98    functions = [ "isprint" ]
99  }
100
101  pw_libc_source_set("time") {
102    functions = [ "gmtime" ]
103    additional_srcs = [ "time_utils.cpp" ]
104
105    # gmtime requires gtest matchers which pw_unit_test doesn't support.
106    # Moreover, the matches in llvm-libc don't have the same internal API that
107    # gtest does, so it isn't possible to enable this tests when using gtest
108    # either.
109    no_test_functions = [ "gmtime" ]
110  }
111
112  pw_libc_source_set("math") {
113    non_cpu_dir = "generic"
114
115    functions = [
116      "modff",
117      "roundf",
118    ]
119
120    # Math tests require the MPFR library, which is not available.
121    no_test_functions = functions
122  }
123
124  pw_libc_source_set("stdio") {
125    functions = [
126      "snprintf",
127      "vsnprintf",
128    ]
129
130    additional_srcs = [
131      "printf_core/printf_main.cpp",
132      "printf_core/writer.cpp",
133      "printf_core/converter.cpp",
134    ]
135
136    # If we happen to be using pw_libc for host, let's keep all the normal features.
137    if (current_os != host_os) {
138      defines = [
139        "LIBC_COPT_PRINTF_DISABLE_FLOAT",
140        "LIBC_COPT_PRINTF_DISABLE_WRITE_INT",
141        "LIBC_COPT_PRINTF_DISABLE_INDEX_MODE",
142      ]
143    }
144
145    # This config includes -Wshadow. On gcc, this warns even for constructor
146    # arguments which shadow members. This is too pedantic and shouldn't be
147    # changed upstream.
148    remove_configs = [ "$dir_pw_build:extra_strict_warnings" ]
149    configs = [ ":no-shadow" ]
150  }
151
152  pw_libc_source_set("stdfix") {
153    functions = [
154      "expk",
155      "roundlk",
156      "sqrtulr",
157      "sqrtur",
158      "uksqrtui",
159    ]
160    defines = [ "LIBC_FAST_MATH=1" ]
161  }
162
163  pw_static_library("pw_libc") {
164    complete_static_lib = true
165    add_global_link_deps = false
166    deps = [
167      ":ctype",
168      ":math",
169      ":stdio",
170      ":stdlib",
171      ":string",
172      ":time",
173    ]
174  }
175
176  pw_test_group("llvm_libc_tests") {
177    tests = [
178      ":ctype_tests",
179      ":math_tests",
180      ":stdio_tests",
181      ":stdlib_tests",
182      ":string_tests",
183      ":time_tests",
184    ]
185  }
186
187  pw_static_library("pw_libc_stdfix") {
188    complete_static_lib = true
189    add_global_link_deps = false
190    deps = [
191      ":stdfix",
192      ":stdio",
193    ]
194  }
195} else {
196  pw_static_library("pw_libc") {
197    add_global_link_deps = false
198  }
199
200  pw_static_library("pw_libc_stdfix") {
201    add_global_link_deps = false
202  }
203
204  pw_test_group("llvm_libc_tests") {
205  }
206}
207
208pw_doc_group("docs") {
209  sources = [ "docs.rst" ]
210}
211