aboutsummaryrefslogtreecommitdiff
path: root/pw_libc/BUILD.gn
blob: d9fd80be7b2e319ec0e05a51486fff5c03cc6fe8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# Copyright 2023 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

import("//build_overrides/pigweed.gni")

import("$dir_pw_build/target_types.gni")
import("$dir_pw_docgen/docs.gni")
import("$dir_pw_third_party/llvm_libc/llvm_libc.gni")
import("$dir_pw_toolchain/generate_toolchain.gni")
import("$dir_pw_unit_test/test.gni")

config("default_config") {
  include_dirs = [ "public" ]
}

pw_test_group("tests") {
  tests = [
    ":llvm_libc_tests",
    ":memset_test",
  ]
}

pw_test("memset_test") {
  sources = [ "memset_test.cc" ]
  deps = [ "$dir_pw_containers" ]
}

# Clang has __attribute__(("no-builtin")), but gcc doesn't support it so we
# need this flag instead.
config("no-builtin") {
  cflags = [ "-fno-builtin" ]
}

# Downstream projects sometimes build with -Wshadow, which on gcc also warns
# about constructor arguments shadowing struct members. This is too pedantic
# and not reasonable to change upstream llvm-libc.
config("no-shadow") {
  cflags = [ "-Wno-shadow" ]
}

# If dir_pw_third_party_llvm_libc is defined, use that directory to create a
# pw_libc.a from llvm-libc. Otherwise, we create an empty pw_libc.a.
if (dir_pw_third_party_llvm_libc != "") {
  pw_libc_source_set("stdlib") {
    functions = [
      "abs",
      "rand",
      "srand",
    ]
    additional_srcs = [
      "baremetal/abort.cpp",
      "rand_util.cpp",
    ]

    # srand and rand are both tested in rand_test.cpp.
    no_test_functions = [ "srand" ]
  }

  pw_libc_source_set("string") {
    defines = [ "LIBC_COPT_MEMCPY_USE_EMBEDDED_TINY" ]
    functions = [
      "strcmp",
      "strcpy",
      "strstr",
      "strnlen",
      "memcpy",
      "memset",
      "memmove",
    ]

    # memmove tests use gtest matchers which pw_unit_test doesn't support.
    no_test_functions = [ "memmove" ]

    configs = [
      ":no-builtin",
      ":no-shadow",
    ]
  }

  pw_libc_source_set("ctype") {
    functions = [ "isprint" ]
  }

  pw_libc_source_set("time") {
    functions = [ "gmtime" ]
    additional_srcs = [ "time_utils.cpp" ]

    # gmtime requires gtest matchers which pw_unit_test doesn't support.
    # Moreover, the matches in llvm-libc don't have the same internal API that
    # gtest does, so it isn't possible to enable this tests when using gtest
    # either.
    no_test_functions = [ "gmtime" ]
  }

  pw_libc_source_set("math") {
    non_cpu_dir = "generic"

    functions = [
      "modff",
      "roundf",
    ]

    # Math tests require the MPFR library, which is not available.
    no_test_functions = functions
  }

  pw_libc_source_set("stdio") {
    functions = [ "snprintf" ]

    additional_srcs = [
      "printf_core/printf_main.cpp",
      "printf_core/writer.cpp",
      "printf_core/parser.cpp",
      "printf_core/converter.cpp",
    ]

    defines = [
      "LIBC_COPT_PRINTF_DISABLE_FLOAT",
      "LIBC_COPT_PRINTF_DISABLE_WRITE_INT",
      "LIBC_COPT_PRINTF_DISABLE_INDEX_MODE",
    ]

    # This config includes -Wshadow. On gcc, this warns even for constructor
    # arguments which shadow members. This is too pedantic and shouldn't be
    # changed upstream.
    remove_configs = [ "//pw_build:extra_strict_warnings" ]
  }

  pw_static_library("pw_libc") {
    complete_static_lib = true
    add_global_link_deps = false
    deps = [
      ":ctype",
      ":math",
      ":stdio",
      ":stdlib",
      ":string",
      ":time",
    ]
  }

  pw_test_group("llvm_libc_tests") {
    tests = [
      ":ctype_tests",
      ":math_tests",
      ":stdio_tests",
      ":stdlib_tests",
      ":string_tests",
      ":time_tests",
    ]
  }
} else {
  pw_static_library("pw_libc") {
    add_global_link_deps = false
  }

  pw_test_group("llvm_libc_tests") {
  }
}

pw_doc_group("docs") {
  sources = [ "docs.rst" ]
}