1*61c4878aSAndroid Build Coastguard Worker# Copyright 2023 The Pigweed Authors 2*61c4878aSAndroid Build Coastguard Worker# 3*61c4878aSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4*61c4878aSAndroid Build Coastguard Worker# use this file except in compliance with the License. You may obtain a copy of 5*61c4878aSAndroid Build Coastguard Worker# the License at 6*61c4878aSAndroid Build Coastguard Worker# 7*61c4878aSAndroid Build Coastguard Worker# https://www.apache.org/licenses/LICENSE-2.0 8*61c4878aSAndroid Build Coastguard Worker# 9*61c4878aSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software 10*61c4878aSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11*61c4878aSAndroid Build Coastguard Worker# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12*61c4878aSAndroid Build Coastguard Worker# License for the specific language governing permissions and limitations under 13*61c4878aSAndroid Build Coastguard Worker# the License. 14*61c4878aSAndroid Build Coastguard Worker 15*61c4878aSAndroid Build Coastguard Workerimport("//build_overrides/pigweed.gni") 16*61c4878aSAndroid Build Coastguard Worker 17*61c4878aSAndroid Build Coastguard Workerimport("$dir_pw_build/target_types.gni") 18*61c4878aSAndroid Build Coastguard Workerimport("$dir_pw_docgen/docs.gni") 19*61c4878aSAndroid Build Coastguard Workerimport("$dir_pw_third_party/llvm_libc/llvm_libc.gni") 20*61c4878aSAndroid Build Coastguard Workerimport("$dir_pw_toolchain/generate_toolchain.gni") 21*61c4878aSAndroid Build Coastguard Workerimport("$dir_pw_unit_test/test.gni") 22*61c4878aSAndroid Build Coastguard Worker 23*61c4878aSAndroid Build Coastguard Workerconfig("default_config") { 24*61c4878aSAndroid Build Coastguard Worker include_dirs = [ "public" ] 25*61c4878aSAndroid Build Coastguard Worker} 26*61c4878aSAndroid Build Coastguard Worker 27*61c4878aSAndroid Build Coastguard Workerpw_test_group("tests") { 28*61c4878aSAndroid Build Coastguard Worker tests = [ 29*61c4878aSAndroid Build Coastguard Worker ":llvm_libc_tests", 30*61c4878aSAndroid Build Coastguard Worker ":memset_test", 31*61c4878aSAndroid Build Coastguard Worker ] 32*61c4878aSAndroid Build Coastguard Worker} 33*61c4878aSAndroid Build Coastguard Worker 34*61c4878aSAndroid Build Coastguard Workerpw_test("memset_test") { 35*61c4878aSAndroid Build Coastguard Worker sources = [ "memset_test.cc" ] 36*61c4878aSAndroid Build Coastguard Worker deps = [ "$dir_pw_containers" ] 37*61c4878aSAndroid Build Coastguard Worker} 38*61c4878aSAndroid Build Coastguard Worker 39*61c4878aSAndroid Build Coastguard Worker# Clang has __attribute__(("no-builtin")), but gcc doesn't support it so we 40*61c4878aSAndroid Build Coastguard Worker# need this flag instead. 41*61c4878aSAndroid Build Coastguard Workerconfig("no-builtin") { 42*61c4878aSAndroid Build Coastguard Worker cflags = [ "-fno-builtin" ] 43*61c4878aSAndroid Build Coastguard Worker} 44*61c4878aSAndroid Build Coastguard Worker 45*61c4878aSAndroid Build Coastguard Worker# Downstream projects sometimes build with -Wshadow, which on gcc also warns 46*61c4878aSAndroid Build Coastguard Worker# about constructor arguments shadowing struct members. This is too pedantic 47*61c4878aSAndroid Build Coastguard Worker# and not reasonable to change upstream llvm-libc. 48*61c4878aSAndroid Build Coastguard Workerconfig("no-shadow") { 49*61c4878aSAndroid Build Coastguard Worker cflags = [ "-Wno-shadow" ] 50*61c4878aSAndroid Build Coastguard Worker} 51*61c4878aSAndroid Build Coastguard Worker 52*61c4878aSAndroid Build Coastguard Worker# If dir_pw_third_party_llvm_libc is defined, use that directory to create a 53*61c4878aSAndroid Build Coastguard Worker# pw_libc.a from llvm-libc. Otherwise, we create an empty pw_libc.a. 54*61c4878aSAndroid Build Coastguard Workerif (dir_pw_third_party_llvm_libc != "") { 55*61c4878aSAndroid Build Coastguard Worker pw_libc_source_set("stdlib") { 56*61c4878aSAndroid Build Coastguard Worker functions = [ 57*61c4878aSAndroid Build Coastguard Worker "abs", 58*61c4878aSAndroid Build Coastguard Worker "rand", 59*61c4878aSAndroid Build Coastguard Worker "srand", 60*61c4878aSAndroid Build Coastguard Worker ] 61*61c4878aSAndroid Build Coastguard Worker additional_srcs = [ 62*61c4878aSAndroid Build Coastguard Worker "baremetal/abort.cpp", 63*61c4878aSAndroid Build Coastguard Worker "rand_util.cpp", 64*61c4878aSAndroid Build Coastguard Worker ] 65*61c4878aSAndroid Build Coastguard Worker 66*61c4878aSAndroid Build Coastguard Worker # srand and rand are both tested in rand_test.cpp. 67*61c4878aSAndroid Build Coastguard Worker no_test_functions = [ "srand" ] 68*61c4878aSAndroid Build Coastguard Worker } 69*61c4878aSAndroid Build Coastguard Worker 70*61c4878aSAndroid Build Coastguard Worker pw_libc_source_set("string") { 71*61c4878aSAndroid Build Coastguard Worker defines = [ "LIBC_COPT_MEMCPY_USE_EMBEDDED_TINY" ] 72*61c4878aSAndroid Build Coastguard Worker functions = [ 73*61c4878aSAndroid Build Coastguard Worker "strcmp", 74*61c4878aSAndroid Build Coastguard Worker "strcpy", 75*61c4878aSAndroid Build Coastguard Worker "strstr", 76*61c4878aSAndroid Build Coastguard Worker "strncpy", 77*61c4878aSAndroid Build Coastguard Worker "strnlen", 78*61c4878aSAndroid Build Coastguard Worker "memcpy", 79*61c4878aSAndroid Build Coastguard Worker "memset", 80*61c4878aSAndroid Build Coastguard Worker "memmove", 81*61c4878aSAndroid Build Coastguard Worker ] 82*61c4878aSAndroid Build Coastguard Worker 83*61c4878aSAndroid Build Coastguard Worker # memmove tests use gtest matchers which pw_unit_test doesn't support. 84*61c4878aSAndroid Build Coastguard Worker no_test_functions = [ "memmove" ] 85*61c4878aSAndroid Build Coastguard Worker 86*61c4878aSAndroid Build Coastguard Worker configs = [ 87*61c4878aSAndroid Build Coastguard Worker ":no-builtin", 88*61c4878aSAndroid Build Coastguard Worker ":no-shadow", 89*61c4878aSAndroid Build Coastguard Worker ] 90*61c4878aSAndroid Build Coastguard Worker } 91*61c4878aSAndroid Build Coastguard Worker 92*61c4878aSAndroid Build Coastguard Worker pw_libc_source_set("ctype") { 93*61c4878aSAndroid Build Coastguard Worker functions = [ "isprint" ] 94*61c4878aSAndroid Build Coastguard Worker } 95*61c4878aSAndroid Build Coastguard Worker 96*61c4878aSAndroid Build Coastguard Worker pw_libc_source_set("time") { 97*61c4878aSAndroid Build Coastguard Worker functions = [ "gmtime" ] 98*61c4878aSAndroid Build Coastguard Worker additional_srcs = [ "time_utils.cpp" ] 99*61c4878aSAndroid Build Coastguard Worker 100*61c4878aSAndroid Build Coastguard Worker # gmtime requires gtest matchers which pw_unit_test doesn't support. 101*61c4878aSAndroid Build Coastguard Worker # Moreover, the matches in llvm-libc don't have the same internal API that 102*61c4878aSAndroid Build Coastguard Worker # gtest does, so it isn't possible to enable this tests when using gtest 103*61c4878aSAndroid Build Coastguard Worker # either. 104*61c4878aSAndroid Build Coastguard Worker no_test_functions = [ "gmtime" ] 105*61c4878aSAndroid Build Coastguard Worker } 106*61c4878aSAndroid Build Coastguard Worker 107*61c4878aSAndroid Build Coastguard Worker pw_libc_source_set("math") { 108*61c4878aSAndroid Build Coastguard Worker non_cpu_dir = "generic" 109*61c4878aSAndroid Build Coastguard Worker 110*61c4878aSAndroid Build Coastguard Worker functions = [ 111*61c4878aSAndroid Build Coastguard Worker "modff", 112*61c4878aSAndroid Build Coastguard Worker "roundf", 113*61c4878aSAndroid Build Coastguard Worker ] 114*61c4878aSAndroid Build Coastguard Worker 115*61c4878aSAndroid Build Coastguard Worker # Math tests require the MPFR library, which is not available. 116*61c4878aSAndroid Build Coastguard Worker no_test_functions = functions 117*61c4878aSAndroid Build Coastguard Worker } 118*61c4878aSAndroid Build Coastguard Worker 119*61c4878aSAndroid Build Coastguard Worker pw_libc_source_set("stdio") { 120*61c4878aSAndroid Build Coastguard Worker functions = [ 121*61c4878aSAndroid Build Coastguard Worker "snprintf", 122*61c4878aSAndroid Build Coastguard Worker "vsnprintf", 123*61c4878aSAndroid Build Coastguard Worker ] 124*61c4878aSAndroid Build Coastguard Worker 125*61c4878aSAndroid Build Coastguard Worker additional_srcs = [ 126*61c4878aSAndroid Build Coastguard Worker "printf_core/printf_main.cpp", 127*61c4878aSAndroid Build Coastguard Worker "printf_core/writer.cpp", 128*61c4878aSAndroid Build Coastguard Worker "printf_core/converter.cpp", 129*61c4878aSAndroid Build Coastguard Worker ] 130*61c4878aSAndroid Build Coastguard Worker 131*61c4878aSAndroid Build Coastguard Worker defines = [ 132*61c4878aSAndroid Build Coastguard Worker "LIBC_COPT_PRINTF_DISABLE_FLOAT", 133*61c4878aSAndroid Build Coastguard Worker "LIBC_COPT_PRINTF_DISABLE_WRITE_INT", 134*61c4878aSAndroid Build Coastguard Worker "LIBC_COPT_PRINTF_DISABLE_INDEX_MODE", 135*61c4878aSAndroid Build Coastguard Worker ] 136*61c4878aSAndroid Build Coastguard Worker 137*61c4878aSAndroid Build Coastguard Worker # This config includes -Wshadow. On gcc, this warns even for constructor 138*61c4878aSAndroid Build Coastguard Worker # arguments which shadow members. This is too pedantic and shouldn't be 139*61c4878aSAndroid Build Coastguard Worker # changed upstream. 140*61c4878aSAndroid Build Coastguard Worker remove_configs = [ "//pw_build:extra_strict_warnings" ] 141*61c4878aSAndroid Build Coastguard Worker } 142*61c4878aSAndroid Build Coastguard Worker 143*61c4878aSAndroid Build Coastguard Worker pw_libc_source_set("stdfix") { 144*61c4878aSAndroid Build Coastguard Worker functions = [ 145*61c4878aSAndroid Build Coastguard Worker "expk", 146*61c4878aSAndroid Build Coastguard Worker "roundlk", 147*61c4878aSAndroid Build Coastguard Worker "sqrtulr", 148*61c4878aSAndroid Build Coastguard Worker "sqrtur", 149*61c4878aSAndroid Build Coastguard Worker "uksqrtui", 150*61c4878aSAndroid Build Coastguard Worker ] 151*61c4878aSAndroid Build Coastguard Worker defines = [ "LIBC_FAST_MATH=1" ] 152*61c4878aSAndroid Build Coastguard Worker } 153*61c4878aSAndroid Build Coastguard Worker 154*61c4878aSAndroid Build Coastguard Worker pw_static_library("pw_libc") { 155*61c4878aSAndroid Build Coastguard Worker complete_static_lib = true 156*61c4878aSAndroid Build Coastguard Worker add_global_link_deps = false 157*61c4878aSAndroid Build Coastguard Worker deps = [ 158*61c4878aSAndroid Build Coastguard Worker ":ctype", 159*61c4878aSAndroid Build Coastguard Worker ":math", 160*61c4878aSAndroid Build Coastguard Worker ":stdio", 161*61c4878aSAndroid Build Coastguard Worker ":stdlib", 162*61c4878aSAndroid Build Coastguard Worker ":string", 163*61c4878aSAndroid Build Coastguard Worker ":time", 164*61c4878aSAndroid Build Coastguard Worker ] 165*61c4878aSAndroid Build Coastguard Worker } 166*61c4878aSAndroid Build Coastguard Worker 167*61c4878aSAndroid Build Coastguard Worker pw_test_group("llvm_libc_tests") { 168*61c4878aSAndroid Build Coastguard Worker tests = [ 169*61c4878aSAndroid Build Coastguard Worker ":ctype_tests", 170*61c4878aSAndroid Build Coastguard Worker ":math_tests", 171*61c4878aSAndroid Build Coastguard Worker ":stdio_tests", 172*61c4878aSAndroid Build Coastguard Worker ":stdlib_tests", 173*61c4878aSAndroid Build Coastguard Worker ":string_tests", 174*61c4878aSAndroid Build Coastguard Worker ":time_tests", 175*61c4878aSAndroid Build Coastguard Worker ] 176*61c4878aSAndroid Build Coastguard Worker } 177*61c4878aSAndroid Build Coastguard Worker 178*61c4878aSAndroid Build Coastguard Worker pw_static_library("pw_libc_stdfix") { 179*61c4878aSAndroid Build Coastguard Worker complete_static_lib = true 180*61c4878aSAndroid Build Coastguard Worker add_global_link_deps = false 181*61c4878aSAndroid Build Coastguard Worker deps = [ 182*61c4878aSAndroid Build Coastguard Worker ":stdfix", 183*61c4878aSAndroid Build Coastguard Worker ":stdio", 184*61c4878aSAndroid Build Coastguard Worker ] 185*61c4878aSAndroid Build Coastguard Worker } 186*61c4878aSAndroid Build Coastguard Worker} else { 187*61c4878aSAndroid Build Coastguard Worker pw_static_library("pw_libc") { 188*61c4878aSAndroid Build Coastguard Worker add_global_link_deps = false 189*61c4878aSAndroid Build Coastguard Worker } 190*61c4878aSAndroid Build Coastguard Worker 191*61c4878aSAndroid Build Coastguard Worker pw_static_library("pw_libc_stdfix") { 192*61c4878aSAndroid Build Coastguard Worker add_global_link_deps = false 193*61c4878aSAndroid Build Coastguard Worker } 194*61c4878aSAndroid Build Coastguard Worker 195*61c4878aSAndroid Build Coastguard Worker pw_test_group("llvm_libc_tests") { 196*61c4878aSAndroid Build Coastguard Worker } 197*61c4878aSAndroid Build Coastguard Worker} 198*61c4878aSAndroid Build Coastguard Worker 199*61c4878aSAndroid Build Coastguard Workerpw_doc_group("docs") { 200*61c4878aSAndroid Build Coastguard Worker sources = [ "docs.rst" ] 201*61c4878aSAndroid Build Coastguard Worker} 202