1import("//clang/runtimes.gni") 2import("//libcxx/config.gni") 3import("//llvm/utils/gn/build/symlink_or_copy.gni") 4 5declare_args() { 6 # Whether to support libc++ opt-in debug mode via _LIBCPP_DEBUG. 7 libcxx_enable_debug_mode = true 8 9 # Build libc++ with definitions for operator new/delete. 10 libcxx_enable_new_delete_definitions = true 11 12 # Build libc++ as a shared library. 13 libcxx_enable_shared = true 14 15 # Build libc++ as a static library. 16 libcxx_enable_static = true 17 18 # Build filesystem as part of libc++fs.a. 19 libcxx_enable_filesystem = target_os != "win" 20 21 # Build libc++experimental.a. 22 libcxx_enable_experimental = true 23 24 # Use compiler-rt builtins. 25 libcxx_use_compiler_rt = true 26 27 # Use exceptions. 28 libcxx_enable_exceptions = true 29 30 # Use run time type information. 31 libcxx_enable_rtti = true 32 33 # Do not export any symbols from the static library. 34 libcxx_hermetic_static_library = true 35 36 # Use and install a linker script for the given ABI library. 37 libcxx_enable_abi_linker_script = true 38} 39 40config("cxx_config") { 41 include_dirs = [ "//libcxxabi/include" ] 42 cflags = [ 43 "-Wall", 44 "-Wextra", 45 "-W", 46 "-Wwrite-strings", 47 "-Wno-unused-parameter", 48 "-Wno-long-long", 49 "-Werror=return-type", 50 "-Wextra-semi", 51 "-Wno-user-defined-literals", 52 "-Wno-covered-switch-default", 53 ] 54 cflags_cc = [ 55 "-std=c++20", 56 "-nostdinc++", 57 ] 58 defines = [ "_LIBCPP_BUILDING_LIBRARY" ] 59 if (target_os == "win") { 60 cflags += [ "/Zl" ] 61 defines += [ 62 # Ignore the -MSC_VER mismatch, as we may build 63 # with a different compatibility version. 64 "_ALLOW_MSC_VER_MISMATCH", 65 66 # Don't check the msvcprt iterator debug levels 67 # as we will define the iterator types; libc++ 68 # uses a different macro to identify the debug 69 # level. 70 "_ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH", 71 72 # We are building the c++ runtime, don't pull in 73 # msvcprt. 74 "_CRTBLD", 75 76 # Don't warn on the use of "deprecated" 77 # "insecure" functions which are standards 78 # specified. 79 "_CRT_SECURE_NO_WARNINGS", 80 81 # Use the ISO conforming behaviour for conversion 82 # in printf, scanf. 83 "_CRT_STDIO_ISO_WIDE_SPECIFIERS", 84 ] 85 } 86 if (!libcxx_enable_new_delete_definitions) { 87 defines += [ "_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS" ] 88 } 89 if (libcxx_enable_exceptions) { 90 if (current_os == "win") { 91 cflags_cc += [ "/EHsc" ] 92 } 93 } else { 94 if (current_os == "win") { 95 cflags_cc += [ 96 "/EHs-", 97 "/EHa-", 98 ] 99 } else { 100 cflags_cc += [ "-fno-exceptions" ] 101 } 102 } 103 if (!libcxx_enable_rtti) { 104 if (current_os == "win") { 105 cflags_cc += [ "/GR-" ] 106 } else { 107 cflags_cc += [ "-fno-rtti" ] 108 } 109 } 110} 111 112cxx_sources = [ 113 "algorithm.cpp", 114 "any.cpp", 115 "atomic.cpp", 116 "barrier.cpp", 117 "bind.cpp", 118 "charconv.cpp", 119 "chrono.cpp", 120 "condition_variable.cpp", 121 "condition_variable_destructor.cpp", 122 "exception.cpp", 123 "format.cpp", 124 "functional.cpp", 125 "future.cpp", 126 "hash.cpp", 127 "include/apple_availability.h", 128 "include/atomic_support.h", 129 "include/config_elast.h", 130 "include/refstring.h", 131 "include/sso_allocator.h", 132 "ios.cpp", 133 "ios.instantiations.cpp", 134 "iostream.cpp", 135 "locale.cpp", 136 "memory.cpp", 137 "mutex.cpp", 138 "mutex_destructor.cpp", 139 "new.cpp", 140 "optional.cpp", 141 "random.cpp", 142 "random_shuffle.cpp", 143 "regex.cpp", 144 "shared_mutex.cpp", 145 "stdexcept.cpp", 146 "string.cpp", 147 "strstream.cpp", 148 "support/runtime/exception_fallback.ipp", 149 "support/runtime/exception_glibcxx.ipp", 150 "support/runtime/exception_libcxxabi.ipp", 151 "support/runtime/exception_libcxxrt.ipp", 152 "support/runtime/exception_msvc.ipp", 153 "support/runtime/exception_pointer_cxxabi.ipp", 154 "support/runtime/exception_pointer_glibcxx.ipp", 155 "support/runtime/exception_pointer_msvc.ipp", 156 "support/runtime/exception_pointer_unimplemented.ipp", 157 "support/runtime/new_handler_fallback.ipp", 158 "support/runtime/stdexcept_default.ipp", 159 "support/runtime/stdexcept_vcruntime.ipp", 160 "system_error.cpp", 161 "thread.cpp", 162 "typeinfo.cpp", 163 "utility.cpp", 164 "valarray.cpp", 165 "variant.cpp", 166 "vector.cpp", 167] 168if (target_os == "win") { 169 cxx_sources += [ 170 "support/win32/locale_win32.cpp", 171 "support/win32/support.cpp", 172 "support/win32/thread_win32.cpp", 173 ] 174} 175if (target_os == "solaris") { 176 cxx_sources += [ "support/solaris/xlocale.cpp" ] 177} 178if (target_os == "zos") { 179 cxx_sources += [ "support/ibm/xlocale_zos.cpp" ] 180} 181if (libcxx_enable_debug_mode) { 182 cxx_sources += [ "debug.cpp" ] 183} 184if (libcxx_enable_filesystem) { 185 cxx_sources += [ 186 "filesystem/directory_iterator.cpp", 187 "filesystem/filesystem_common.h", 188 "filesystem/operations.cpp", 189 "filesystem/posix_compat.h", 190 ] 191 if (libcxx_use_compiler_rt) { 192 cxx_sources += [ "filesystem/int128_builtins.cpp" ] 193 } 194} 195 196if (libcxx_enable_shared) { 197 shared_library("cxx_shared") { 198 output_dir = runtimes_dir 199 output_name = "c++" 200 if (libcxx_enable_abi_linker_script) { 201 output_extension = "so.0" 202 } 203 if (target_os == "linux" || target_os == "mac") { 204 cflags = [ "-fPIC" ] 205 ldflags = [ "-nostdlib++" ] 206 libs = [ 207 "dl", 208 "pthread", 209 ] 210 } 211 sources = cxx_sources 212 deps = [ 213 "//compiler-rt/lib/builtins", 214 "//libcxx/include", 215 "//libcxxabi/src:cxxabi_shared", 216 "//libunwind/src:unwind_shared", 217 ] 218 configs += [ ":cxx_config" ] 219 configs -= [ 220 "//llvm/utils/gn/build:no_exceptions", 221 "//llvm/utils/gn/build:no_rtti", 222 ] 223 } 224 225 symlink_or_copy("cxx_symlink") { 226 deps = [ ":cxx_shared" ] 227 source = "libc++.so.0" 228 output = "$runtimes_dir/libc++.so" 229 } 230 231 if (libcxx_enable_abi_linker_script) { 232 action("cxx_linker_script") { 233 script = "//llvm/utils/gn/secondary/libcxx/utils/gen_link_script.py" 234 outputs = [ "$runtimes_dir/libc++.so" ] 235 args = [ 236 "--input", 237 rebase_path("$runtimes_dir/libc++.so.0", root_build_dir), 238 "--output", 239 rebase_path("$runtimes_dir/libc++.so", root_build_dir), 240 "c++abi", 241 "unwind", 242 ] 243 deps = [ ":cxx_symlink" ] 244 } 245 } 246} 247 248if (libcxx_enable_static) { 249 static_library("cxx_static") { 250 output_dir = runtimes_dir 251 output_name = "c++" 252 complete_static_lib = true 253 configs -= [ "//llvm/utils/gn/build:thin_archive" ] 254 sources = cxx_sources 255 if (libcxx_hermetic_static_library) { 256 cflags = [ "-fvisibility=hidden" ] 257 if (libcxx_enable_new_delete_definitions) { 258 cflags_cc = [ "-fvisibility-global-new-delete-hidden" ] 259 } 260 defines = [ "_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS" ] 261 } 262 deps = [ 263 "//compiler-rt/lib/builtins", 264 "//libcxx/include", 265 "//libcxxabi/src:cxxabi_static", 266 "//libunwind/src:unwind_static", 267 ] 268 configs += [ ":cxx_config" ] 269 configs -= [ 270 "//llvm/utils/gn/build:no_exceptions", 271 "//llvm/utils/gn/build:no_rtti", 272 ] 273 } 274} 275 276if (libcxx_enable_experimental) { 277 static_library("cxx_experimental") { 278 output_dir = runtimes_dir 279 output_name = "c++experimental" 280 sources = [ "experimental/memory_resource.cpp" ] 281 deps = [ "//libcxx/include" ] 282 configs += [ ":cxx_config" ] 283 configs -= [ 284 "//llvm/utils/gn/build:no_exceptions", 285 "//llvm/utils/gn/build:no_rtti", 286 ] 287 } 288} 289 290group("src") { 291 deps = [] 292 if (libcxx_enable_shared) { 293 if (libcxx_enable_abi_linker_script) { 294 deps += [ ":cxx_linker_script" ] 295 } else { 296 deps += [ ":cxx_shared" ] 297 } 298 } 299 if (libcxx_enable_static) { 300 deps += [ ":cxx_static" ] 301 } 302 if (libcxx_enable_experimental) { 303 deps += [ ":cxx_experimental" ] 304 } 305} 306