| # Copyright 2019 The Fuchsia Authors | 
 | # | 
 | # Use of this source code is governed by a MIT-style | 
 | # license that can be found in the LICENSE file or at | 
 | # https://opensource.org/licenses/MIT | 
 |  | 
 | import("//build/cpp/library_headers.gni") | 
 | import("//build/toolchain/toolchain_environment.gni") | 
 |  | 
 | library_headers("headers") { | 
 |   headers = [] | 
 |   public_deps = [ | 
 |     # <stdio.h> has #include <ktl/string_view.h>. | 
 |     "//zircon/kernel/lib/ktl:headers", | 
 |   ] | 
 |  | 
 |   public_configs = [ ":headers.after" ] | 
 | } | 
 |  | 
 | static_library("libc") { | 
 |   complete_static_lib = true | 
 |  | 
 |   public_deps = [ ":headers" ] | 
 |  | 
 |   sources = [ | 
 |     "abort.cc", | 
 |     "atomic.cc", | 
 |     "cxa_pure_virtual.cc", | 
 |     "fprintf.cc", | 
 |     "printf.cc", | 
 |     "rand.cc", | 
 |     "snprintf.cc", | 
 |     "string-file.cc", | 
 |     "strtol.cc", | 
 |     "strtoul.cc", | 
 |   ] | 
 |   deps = [ | 
 |     ":ctype", | 
 |     "string", | 
 |     "//zircon/system/ulib/zircon-internal", | 
 |   ] | 
 |  | 
 |   if (toolchain_environment == "kernel") { | 
 |     deps += [ "//zircon/kernel/lib/heap" ] | 
 |  | 
 |     # In the kernel proper, static constructors that register destructors are | 
 |     # just ignored.  This is deemed safe because all teardown work that matters | 
 |     # is explicit in the shutdown/reboot paths.  But elsewhere, make sure that | 
 |     # a build error results if they are ever emitted.  The other kernel-like | 
 |     # contexts where this libc is used (phys and UEFI) leave their in-memory | 
 |     # state and hand off to another execution context that won't ever run their | 
 |     # destructors.  Such destructors might represent cleanup work that should | 
 |     # happen before that hand-off and is not safe to silently elide. | 
 |     sources += [ "cxa_atexit.cc" ] | 
 |   } | 
 | } | 
 |  | 
 | config("headers.after") { | 
 |   visibility = [ | 
 |     ":*", | 
 |     "//zircon/kernel:headers", | 
 |   ] | 
 |  | 
 |   # libc/include is before toolchain headers because it needs to be able to | 
 |   # override some libc++ headers that won't work in the kernel context. | 
 |   # However, libc/include/limits.h punts to the toolchain via #include_next | 
 |   # <limits.h> and the toolchain's limits.h does the same to get the "system" | 
 |   # libc <limits.h>, so we need another include directory after the toolchain | 
 |   # headers that has a limits.h for that to find, even though in the kernel | 
 |   # there is nothing to add to the toolchain's <limits.h> content. | 
 |   cflags = [ | 
 |     "-idirafter", | 
 |     rebase_path("include-after", root_build_dir), | 
 |   ] | 
 |  | 
 |   # This is propagated by :headers, but that's not used directly by the kernel | 
 |   # toolchain.  It explicitly uses this config, so propagate it separately that | 
 |   # way. | 
 |   configs = [ "//zircon/kernel/lib/ktl:headers.after" ] | 
 | } | 
 |  | 
 | source_set("ctype") { | 
 |   sources = [ "ctype.cc" ] | 
 |   deps = [ ":headers" ] | 
 | } | 
 |  | 
 | group("tests") { | 
 |   testonly = true | 
 | } | 
 |  | 
 | source_set("kernel-tests") { | 
 |   # TODO: testonly = true | 
 |   sources = [ "atomic_tests.cc" ] | 
 |   deps = [ | 
 |     "//zircon/kernel/lib/ktl:headers", | 
 |     "//zircon/kernel/lib/unittest", | 
 |   ] | 
 | } | 
 |  | 
 | group("phys-tests") { | 
 |   testonly = true | 
 | } | 
 |  | 
 | group("boot_tests") { | 
 |   testonly = true | 
 | } |