import("//build/config/c++/c++.gni") import("//build/config/chrome_build.gni") import("//build/config/chromeos/ui_mode.gni") import("//build/config/compiler/compiler.gni") import("//build/config/dcheck_always_on.gni") import("//buildtools/deps_revisions.gni") assert(use_custom_libcxx, "should only be used if use_custom_libcxx is set") # This is included by reference in the //build/config/compiler:runtime_library # config that is applied to all targets. It is here to separate out the logic # that is specific to libc++. Please see that target for advice on what should # go in :runtime_library vs. :compiler. config("runtime_library") { cflags = [] cflags_cc = [] defines = [] include_dirs = [] ldflags = [] libs = [] # Fixed libc++ configuration macros are in # buildtools/third_party/libc++/__config_site. This config only has defines # that vary depending on gn args, and non-define flags. if (!libcxx_is_shared) { # Don't leak any symbols on a static build. defines += [ "_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS" ] if (!export_libcxxabi_from_executables && !is_win) { defines += [ "_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS" ] } } include_dirs += [ "//buildtools/third_party/libc++" ] # libc++ has two levels of additional checking: # 1. _LIBCPP_ENABLE_ASSERTIONS enables assertions for bounds checking. # We always enable this in __config_site, in all build configurations. # 2. _LIBCPP_ENABLE_DEBUG_MODE enables iterator debugging and other # expensive checks. Enable these only if enable_iterator_debugging is on. if (enable_iterator_debugging) { defines += [ "_LIBCPP_ENABLE_DEBUG_MODE" ] } # Fuzzers build parts of the code with asan enabled and some with it # disabled. That's incompatible with _LIBCPP_INSTRUMENTED_WITH_ASAN, see # https://crbug.com/347026228#comment25 # TODO(thakis): Enable on apple if https://llvm.org/PR96099 gets fixed. if (is_asan && !use_fuzzing_engine && !is_apple) { defines += [ "_LIBCPP_INSTRUMENTED_WITH_ASAN" ] } defines += [ "CR_LIBCXX_REVISION=$libcxx_revision" ] # Temporarily add a define to force a rebuild when changing # buildtools/third_party/libc++/__config_site which isn't picked up by # dependency tracking (because it's an #include of headers included via # -isysroot). # TODO(thakis): Remove this after a few days. defines += [ "TEMP_REBUILD_HACK" ] if (is_win) { # Intentionally not using libc++abi on Windows because libc++abi only # implements the Itanium C++ ABI, and not the Microsoft ABI which we use on # Windows (and we need to use in order to interoperate correctly with COM # among other things). assert(!export_libcxxabi_from_executables, "Don't use libcxxabi on Windows.") cflags_cc += [ "-I" + rebase_path("$libcxx_prefix/include", root_build_dir) ] # Add a debug visualizer for Microsoft's debuggers so that they can display # libc++ types well. if (libcxx_natvis_include) { # chrome.natvis listed as an input in //buildtools/third_party/libc++ to # guarantee relinking on changes. ldflags += [ "/NATVIS:" + rebase_path("libc++.natvis", root_build_dir) ] } } else { cflags_cc += [ "-nostdinc++", "-isystem" + rebase_path("$libcxx_prefix/include", root_build_dir), "-isystem" + rebase_path("$libcxxabi_prefix/include", root_build_dir), ] cflags_objcc = cflags_cc # Make sure we don't link against the system libstdc++ or libc++. if (is_clang) { ldflags += [ "-nostdlib++" ] } else { # Gcc has a built-in abs() definition with default visibility. # If it was not disabled, it would conflict with libc++'s abs() # with hidden visibility. cflags += [ "-fno-builtin-abs" ] ldflags += [ "-nodefaultlibs" ] # Unfortunately, there's no way to disable linking against just libc++ # (gcc doesn't have -notstdlib++: # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83931); -nodefaultlibs # removes all of the default libraries, so add back the ones that we need. libs += [ "c", "gcc_s", "m", "rt", ] } } # In a world without NaCl, the `runtime_library` config would also configure # the `_LIBCPP_ENABLE_ASSERTIONS` define to enable hardening when using the # custom hermetic libc++. However, this is currently added by the `compiler` # config instead, since this hardening define should also be used by the NaCl # saigo toolchain, which uses a prebuilt libc++ that is distinct from the # custom hermetic libc++. }