1import("//build/config/c++/c++.gni") 2import("//build/config/chrome_build.gni") 3import("//build/config/chromeos/ui_mode.gni") 4import("//build/config/compiler/compiler.gni") 5import("//build/config/dcheck_always_on.gni") 6import("//buildtools/deps_revisions.gni") 7 8assert(use_custom_libcxx, "should only be used if use_custom_libcxx is set") 9 10# This is included by reference in the //build/config/compiler:runtime_library 11# config that is applied to all targets. It is here to separate out the logic 12# that is specific to libc++. Please see that target for advice on what should 13# go in :runtime_library vs. :compiler. 14config("runtime_library") { 15 cflags = [] 16 cflags_cc = [] 17 defines = [] 18 include_dirs = [] 19 ldflags = [] 20 libs = [] 21 22 # Fixed libc++ configuration macros are in 23 # buildtools/third_party/libc++/__config_site. This config only has defines 24 # that vary depending on gn args, and non-define flags. 25 26 if (!libcxx_is_shared) { 27 # Don't leak any symbols on a static build. 28 defines += [ "_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS" ] 29 if (!export_libcxxabi_from_executables && !is_win) { 30 defines += [ "_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS" ] 31 } 32 } 33 34 include_dirs += [ "//buildtools/third_party/libc++" ] 35 36 # libc++ has two levels of additional checking: 37 # 1. _LIBCPP_ENABLE_ASSERTIONS enables assertions for bounds checking. 38 # We always enable this in __config_site, in all build configurations. 39 # 2. _LIBCPP_ENABLE_DEBUG_MODE enables iterator debugging and other 40 # expensive checks. Enable these only if enable_iterator_debugging is on. 41 if (enable_iterator_debugging) { 42 defines += [ "_LIBCPP_ENABLE_DEBUG_MODE" ] 43 } 44 45 defines += [ "CR_LIBCXX_REVISION=$libcxx_revision" ] 46 47 # Temporarily add a define to force a rebuild when changing 48 # buildtools/third_party/libc++/__config_site which isn't picked up by 49 # dependency tracking (because it's an #include of headers included via 50 # -isysroot). 51 # TODO(thakis): Remove this after a few days. 52 if (is_fuchsia) { 53 defines += [ "TEMP_REBUILD_HACK" ] 54 } 55 56 # Temporarily add a define to force a rebuild when changing 57 # buildtools/third_party/libc++/__assertion_handler which isn't picked up by 58 # dependency tracking (because it's an #include of headers included via 59 # -isysroot). 60 # TODO(crbug.com/40255003): remove after a few days. 61 defines += [ "TEMP_REBUILD_HACK_ASSERTION_HANDLER" ] 62 63 if (is_win) { 64 # Intentionally not using libc++abi on Windows because libc++abi only 65 # implements the Itanium C++ ABI, and not the Microsoft ABI which we use on 66 # Windows (and we need to use in order to interoperate correctly with COM 67 # among other things). 68 assert(!export_libcxxabi_from_executables, 69 "Don't use libcxxabi on Windows.") 70 71 cflags_cc += 72 [ "-I" + rebase_path("$libcxx_prefix/include", root_build_dir) ] 73 74 # Add a debug visualizer for Microsoft's debuggers so that they can display 75 # libc++ types well. 76 if (libcxx_natvis_include) { 77 # chrome.natvis listed as an input in //buildtools/third_party/libc++ to 78 # guarantee relinking on changes. 79 ldflags += [ "/NATVIS:" + rebase_path("libc++.natvis", root_build_dir) ] 80 } 81 } else { 82 cflags_cc += [ 83 "-nostdinc++", 84 "-isystem" + rebase_path("$libcxx_prefix/include", root_build_dir), 85 "-isystem" + rebase_path("$libcxxabi_prefix/include", root_build_dir), 86 ] 87 88 cflags_objcc = cflags_cc 89 90 # Make sure we don't link against the system libstdc++ or libc++. 91 if (is_clang) { 92 ldflags += [ "-nostdlib++" ] 93 } else { 94 # Gcc has a built-in abs() definition with default visibility. 95 # If it was not disabled, it would conflict with libc++'s abs() 96 # with hidden visibility. 97 cflags += [ "-fno-builtin-abs" ] 98 99 ldflags += [ "-nodefaultlibs" ] 100 101 # Unfortunately, there's no way to disable linking against just libc++ 102 # (gcc doesn't have -notstdlib++: 103 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83931); -nodefaultlibs 104 # removes all of the default libraries, so add back the ones that we need. 105 libs += [ 106 "c", 107 "gcc_s", 108 "m", 109 "rt", 110 ] 111 } 112 } 113 114 # In a world without NaCl, the `runtime_library` config would also configure 115 # the `_LIBCPP_ENABLE_ASSERTIONS` define to enable hardening when using the 116 # custom hermetic libc++. However, this is currently added by the `compiler` 117 # config instead, since this hardening define should also be used by the NaCl 118 # saigo toolchain, which uses a prebuilt libc++ that is distinct from the 119 # custom hermetic libc++. 120} 121