xref: /aosp_15_r20/external/cronet/build/config/c++/BUILD.gn (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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  if (is_win) {
57    # Intentionally not using libc++abi on Windows because libc++abi only
58    # implements the Itanium C++ ABI, and not the Microsoft ABI which we use on
59    # Windows (and we need to use in order to interoperate correctly with COM
60    # among other things).
61    assert(!export_libcxxabi_from_executables,
62           "Don't use libcxxabi on Windows.")
63
64    cflags_cc +=
65        [ "-I" + rebase_path("$libcxx_prefix/include", root_build_dir) ]
66
67    # Add a debug visualizer for Microsoft's debuggers so that they can display
68    # libc++ types well.
69    if (libcxx_natvis_include) {
70      # chrome.natvis listed as an input in //buildtools/third_party/libc++ to
71      # guarantee relinking on changes.
72      ldflags += [ "/NATVIS:" + rebase_path("libc++.natvis", root_build_dir) ]
73    }
74  } else {
75    cflags_cc += [
76      "-nostdinc++",
77      "-isystem" + rebase_path("$libcxx_prefix/include", root_build_dir),
78      "-isystem" + rebase_path("$libcxxabi_prefix/include", root_build_dir),
79    ]
80
81    cflags_objcc = cflags_cc
82
83    # Make sure we don't link against the system libstdc++ or libc++.
84    if (is_clang) {
85      ldflags += [ "-nostdlib++" ]
86    } else {
87      # Gcc has a built-in abs() definition with default visibility.
88      # If it was not disabled, it would conflict with libc++'s abs()
89      # with hidden visibility.
90      cflags += [ "-fno-builtin-abs" ]
91
92      ldflags += [ "-nodefaultlibs" ]
93
94      # Unfortunately, there's no way to disable linking against just libc++
95      # (gcc doesn't have -notstdlib++:
96      # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83931); -nodefaultlibs
97      # removes all of the default libraries, so add back the ones that we need.
98      libs += [
99        "c",
100        "gcc_s",
101        "m",
102        "rt",
103      ]
104    }
105  }
106
107  # In a world without NaCl, the `runtime_library` config would also configure
108  # the `_LIBCPP_ENABLE_ASSERTIONS` define to enable hardening when using the
109  # custom hermetic libc++. However, this is currently added by the `compiler`
110  # config instead, since this hardening define should also be used by the NaCl
111  # saigo toolchain, which uses a prebuilt libc++ that is distinct from the
112  # custom hermetic libc++.
113}
114