tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

c++.gni (6450B)


      1 # Copyright 2017 The Chromium Authors
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 import("//chromium/build/config/nacl/config.gni")
      6 import("//chromium/build/config/sanitizers/sanitizers.gni")
      7 import("//chromium/build/toolchain/rbe.gni")
      8 import("//build_overrides/build.gni")
      9 
     10 declare_args() {
     11   # Use in-tree libc++ (buildtools/third_party/libc++ and
     12   # buildtools/third_party/libc++abi) instead of the system C++ library for C++
     13   # standard library support.
     14   #
     15   # WARNING: Bringing your own C++ standard library is deprecated and will not
     16   # be supported in the future. This flag will be removed.
     17   use_custom_libcxx = true
     18 
     19   # Use libc++ instead of stdlibc++ when using the host_cpu toolchain, even if
     20   # use_custom_libcxx is false. This is useful for cross-compiles where a custom
     21   # toolchain for the target_cpu has been set as the default toolchain, but
     22   # use_custom_libcxx should still be true when building for the host.  The
     23   # expected usage is to set use_custom_libcxx=false and
     24   # use_custom_libcxx_for_host=true in the passed in buildargs.
     25   #
     26   # WARNING: Bringing your own C++ standard library is deprecated and will not
     27   # be supported in the future. This flag will be removed.
     28   use_custom_libcxx_for_host = true
     29 
     30   # Builds libcxx Natvis into the symbols for type visualization.
     31   # Set to false to workaround http://crbug.com/966676 and
     32   # http://crbug.com/966687.
     33   libcxx_natvis_include = true
     34 
     35   # When set, enables libc++ debug mode with iterator debugging.
     36   #
     37   # Iterator debugging is generally useful for catching bugs. But it can
     38   # introduce extra locking to check the state of an iterator against the state
     39   # of the current object. For iterator- and thread-heavy code, this can
     40   # significantly slow execution - two orders of magnitude slowdown has been
     41   # seen (crbug.com/903553) and iterator debugging also slows builds by making
     42   # generation of snapshot_blob.bin take ~40-60 s longer. Therefore this
     43   # defaults to off.
     44   enable_iterator_debugging = false
     45 
     46   # Use explicit Clang header modules for libc++.
     47   # This is experimental only (see crbug.com/543704).
     48   # For details on the current state of modules in Chromium see
     49   # https://chromium.googlesource.com/chromium/src/+/main/docs/modules.md
     50   use_libcxx_modules = false
     51 
     52   # Use implicit Clang header modules for libc++.
     53   # This is experimental only (see crbug.com/543704).
     54   # For details on the current state of modules in Chromium see
     55   # https://chromium.googlesource.com/chromium/src/+/main/docs/modules.md
     56   use_implicit_libcxx_modules = false
     57 }
     58 
     59 if (use_implicit_libcxx_modules) {
     60   use_libcxx_modules = true
     61 }
     62 
     63 use_explicit_libcxx_modules = use_libcxx_modules && !use_implicit_libcxx_modules
     64 
     65 assert(!use_implicit_libcxx_modules || !use_remoteexec,
     66        "Implicit Clang header modules don't work with remote execution.")
     67 
     68 use_custom_libcxx =
     69     use_custom_libcxx || (use_custom_libcxx_for_host && !is_a_target_toolchain)
     70 use_custom_libcxx = use_custom_libcxx && !is_nacl
     71 
     72 declare_args() {
     73   # WARNING: Setting this to a non-default value is highly discouraged.
     74   # If true, libc++ will be built as a shared library; otherwise libc++ will be
     75   # linked statically. Setting this to something other than the default is
     76   # unsupported and can be broken by libc++ rolls. Note that if this is set to
     77   # true, you must also set libcxx_abi_unstable=false, which is bad for
     78   # performance and memory use.
     79   libcxx_is_shared = use_custom_libcxx && is_component_build
     80 
     81   # In case the C++ standard library implementation used is libstdc++, then
     82   # enable its own hardening checks. As we cannot determine in GN if libstdc++
     83   # is used or not, by default enable it for Linux without the custom libc++.
     84   #
     85   # WARNING: Bringing your own C++ standard library is deprecated and will not
     86   # be supported in the future. This flag will be removed.
     87   use_safe_libstdcxx = is_linux && !use_custom_libcxx
     88 }
     89 
     90 # The saigo libc++ is distinct from the custom hermetic libc++. However, since
     91 # the Chrome team controls the saigo toolchain, it is safe to unconditionally
     92 # enable libc++ hardening there as well.
     93 use_safe_libcxx = (use_custom_libcxx && enable_safe_libcxx) || is_nacl_saigo
     94 
     95 # libc++abi needs to be exported from executables to be picked up by shared
     96 # libraries on certain instrumented builds.
     97 export_libcxxabi_from_executables =
     98     use_custom_libcxx && !is_apple && !is_win && !is_component_build &&
     99     (is_asan || is_ubsan_vptr)
    100 
    101 # On Android, many shared libraries get loaded from the context of a JRE.  In
    102 # this case, there's no "main executable" to export libc++abi from.  We could
    103 # export libc++abi from each "toplevel" shared library instead, but that would
    104 # require adding an explicit dependency for each one, and might introduce
    105 # subtle, hard-to-fix problems down the line if the dependency is missing.
    106 #
    107 # export_libcxxabi_from_executables was added to avoid having an RPATH set in
    108 # static sanitizer builds just for executables to find libc++.  But on Android,
    109 # the Bionic dynamic loader doesn't even look at RPATH; instead, LD_LIBRARY_PATH
    110 # is set for tests. Because of this, we make libc++ a shared library on android
    111 # since it should get loaded properly.
    112 if (is_android && export_libcxxabi_from_executables) {
    113   export_libcxxabi_from_executables = false
    114   libcxx_is_shared = true
    115 }
    116 
    117 libcxx_prefix = "//third_party/libc++/src"
    118 libcxxabi_prefix = "//third_party/libc++abi/src"
    119 libcxx_module_prefix = "$root_gen_dir/libcxx"
    120 
    121 assert(!(is_ios && libcxx_is_shared),
    122        "Can't build libc++ as a shared library on iOS.")
    123 
    124 # Chromium will require using its libc++ library implementation. Warn if the
    125 # current configuration is not using it.
    126 if ((!use_custom_libcxx || !use_custom_libcxx_for_host) &&
    127     # Standalone use of //build outside of Chromium can disable libc++.
    128     build_with_chromium &&
    129     # Try to avoid spamming the console lots. It's not actually
    130     # toolchain-specific.
    131     current_toolchain == default_toolchain) {
    132   print("*********************************************************************")
    133   print("WARNING: Support for linking against a C++ standard library other ")
    134   print("  than the one in-tree (buildtools/third_party/libc++) is deprecated")
    135   print("  and support for this will end. We plan to remove this option in ")
    136   print("  M138.")
    137   print("*********************************************************************")
    138 }