363 lines · plain
1import("//clang/runtimes.gni")2import("//libcxx/config.gni")3import("//llvm/utils/gn/build/symlink_or_copy.gni")4 5declare_args() {6 # Build libc++ with definitions for operator new/delete.7 libcxx_enable_new_delete_definitions = true8 9 # Build libc++ as a shared library.10 libcxx_enable_shared = true11 12 # Build libc++ as a static library.13 libcxx_enable_static = true14 15 # Build filesystem as part of libc++.16 libcxx_enable_filesystem = target_os != "win"17 18 # Build libc++experimental.a.19 libcxx_enable_experimental = true20 21 # Use compiler-rt builtins.22 libcxx_use_compiler_rt = true23 24 # Use exceptions.25 libcxx_enable_exceptions = true26 27 # Use run time type information.28 libcxx_enable_rtti = true29 30 # Do not export any symbols from the static library.31 libcxx_hermetic_static_library = true32 33 # Use and install a linker script for the given ABI library.34 libcxx_enable_abi_linker_script = true35}36 37config("cxx_config") {38 include_dirs = [ "//libcxxabi/include" ]39 cflags = [40 "-Wall",41 "-Wextra",42 "-W",43 "-Wwrite-strings",44 "-Wno-unused-parameter",45 "-Wno-long-long",46 "-Werror=return-type",47 "-Wextra-semi",48 "-Wno-user-defined-literals",49 "-Wno-covered-switch-default",50 "-Wno-nullability-completeness",51 ]52 cflags_cc = [53 "-std=c++23",54 "-nostdinc++",55 ]56 defines = [57 "_LIBCPP_BUILDING_LIBRARY",58 "_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER",59 ]60 if (current_os != "win") {61 defines += [ "LIBCXX_BUILDING_LIBCXXABI" ]62 }63 if (target_os == "win") {64 cflags += [ "/Zl" ]65 defines += [66 # Ignore the -MSC_VER mismatch, as we may build67 # with a different compatibility version.68 "_ALLOW_MSC_VER_MISMATCH",69 70 # Don't check the msvcprt iterator debug levels71 # as we will define the iterator types; libc++72 # uses a different macro to identify the debug73 # level.74 "_ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH",75 76 # We are building the c++ runtime, don't pull in77 # msvcprt.78 "_CRTBLD",79 80 # Don't warn on the use of "deprecated"81 # "insecure" functions which are standards82 # specified.83 "_CRT_SECURE_NO_WARNINGS",84 85 # Use the ISO conforming behaviour for conversion86 # in printf, scanf.87 "_CRT_STDIO_ISO_WIDE_SPECIFIERS",88 ]89 }90 if (!libcxx_enable_new_delete_definitions) {91 defines += [ "_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS" ]92 }93 if (libcxx_enable_exceptions) {94 if (current_os == "win") {95 cflags_cc += [ "/EHsc" ]96 }97 } else {98 if (current_os == "win") {99 cflags_cc += [100 "/EHs-",101 "/EHa-",102 ]103 } else {104 cflags_cc += [ "-fno-exceptions" ]105 }106 }107 if (!libcxx_enable_rtti) {108 if (current_os == "win") {109 cflags_cc += [ "/GR-" ]110 } else {111 cflags_cc += [ "-fno-rtti" ]112 }113 }114}115 116cxx_sources = [117 "algorithm.cpp",118 "any.cpp",119 "atomic.cpp",120 "barrier.cpp",121 "bind.cpp",122 "call_once.cpp",123 "charconv.cpp",124 "chrono.cpp",125 "condition_variable.cpp",126 "condition_variable_destructor.cpp",127 "error_category.cpp",128 "exception.cpp",129 "expected.cpp",130 "fstream.cpp",131 "functional.cpp",132 "future.cpp",133 "hash.cpp",134 "include/apple_availability.h",135 "include/atomic_support.h",136 "include/config_elast.h",137 "include/from_chars_floating_point.h",138 "include/refstring.h",139 "include/ryu/common.h",140 "include/ryu/d2fixed.h",141 "include/ryu/d2fixed_full_table.h",142 "include/ryu/d2s.h",143 "include/ryu/d2s_full_table.h",144 "include/ryu/d2s_intrinsics.h",145 "include/ryu/digit_table.h",146 "include/ryu/f2s.h",147 "include/ryu/ryu.h",148 "include/sso_allocator.h",149 "include/to_chars_floating_point.h",150 "ios.cpp",151 "ios.instantiations.cpp",152 "iostream.cpp",153 "locale.cpp",154 "memory.cpp",155 "memory_resource.cpp",156 "mutex.cpp",157 "mutex_destructor.cpp",158 "new.cpp",159 "new_handler.cpp",160 "new_helpers.cpp",161 "optional.cpp",162 "ostream.cpp",163 "print.cpp",164 "random.cpp",165 "random_shuffle.cpp",166 "regex.cpp",167 "ryu/d2fixed.cpp",168 "ryu/d2s.cpp",169 "ryu/f2s.cpp",170 "shared_mutex.cpp",171 "stdexcept.cpp",172 "string.cpp",173 "strstream.cpp",174 "support/runtime/exception_fallback.ipp",175 "support/runtime/exception_glibcxx.ipp",176 "support/runtime/exception_libcxxabi.ipp",177 "support/runtime/exception_libcxxrt.ipp",178 "support/runtime/exception_msvc.ipp",179 "support/runtime/exception_pointer_cxxabi.ipp",180 "support/runtime/exception_pointer_glibcxx.ipp",181 "support/runtime/exception_pointer_msvc.ipp",182 "support/runtime/exception_pointer_unimplemented.ipp",183 "support/runtime/new_handler_fallback.ipp",184 "support/runtime/stdexcept_default.ipp",185 "support/runtime/stdexcept_vcruntime.ipp",186 "system_error.cpp",187 "thread.cpp",188 "typeinfo.cpp",189 "valarray.cpp",190 "variant.cpp",191 "vector.cpp",192 "verbose_abort.cpp",193]194if (target_os == "win") {195 cxx_sources += [196 "support/win32/compiler_rt_shims.cpp",197 "support/win32/locale_win32.cpp",198 "support/win32/support.cpp",199 "support/win32/thread_win32.cpp",200 ]201}202if (target_os == "zos") {203 cxx_sources += [204 "support/ibm/mbsnrtowcs.cpp",205 "support/ibm/wcsnrtombs.cpp",206 "support/ibm/xlocale_zos.cpp",207 ]208}209if (libcxx_enable_filesystem) {210 cxx_sources += [211 "filesystem/directory_entry.cpp",212 "filesystem/directory_iterator.cpp",213 "filesystem/file_descriptor.h",214 "filesystem/filesystem_clock.cpp",215 "filesystem/filesystem_error.cpp",216 "filesystem/operations.cpp",217 "filesystem/path.cpp",218 "filesystem/path_parser.h",219 "filesystem/posix_compat.h",220 "filesystem/time_utils.h",221 ]222 if (libcxx_use_compiler_rt) {223 cxx_sources += [ "filesystem/int128_builtins.cpp" ]224 }225}226 227# FIXME: Put this behind an arg, or enable it by default on macOS.228if (false) {229 cxx_sources += [ "pstl/libdispatch.cpp" ]230}231 232if (libcxx_enable_shared) {233 shared_library("cxx_shared") {234 output_dir = runtimes_dir235 output_name = "c++"236 if (libcxx_enable_abi_linker_script) {237 output_extension = "so.0"238 }239 if (target_os == "linux" || target_os == "mac") {240 cflags = [ "-fPIC" ]241 ldflags = [ "-nostdlib++" ]242 libs = [243 "dl",244 "pthread",245 ]246 }247 sources = cxx_sources248 include_dirs = [ "." ]249 deps = [250 "//compiler-rt/lib/builtins",251 "//libc:common_utils",252 "//libcxx/include",253 "//libcxxabi/src:cxxabi_shared",254 "//libunwind/src:unwind_shared",255 ]256 configs += [ ":cxx_config" ]257 configs -= [258 "//llvm/utils/gn/build:no_exceptions",259 "//llvm/utils/gn/build:no_rtti",260 ]261 }262 263 symlink_or_copy("cxx_symlink") {264 deps = [ ":cxx_shared" ]265 source = "libc++.so.0"266 output = "$runtimes_dir/libc++.so"267 }268 269 if (libcxx_enable_abi_linker_script) {270 action("cxx_linker_script") {271 script = "//llvm/utils/gn/secondary/libcxx/utils/gen_link_script.py"272 outputs = [ "$runtimes_dir/libc++.so" ]273 args = [274 "--input",275 rebase_path("$runtimes_dir/libc++.so.0", root_build_dir),276 "--output",277 rebase_path("$runtimes_dir/libc++.so", root_build_dir),278 "c++abi",279 "unwind",280 ]281 deps = [ ":cxx_symlink" ]282 }283 }284}285 286if (libcxx_enable_static) {287 static_library("cxx_static") {288 output_dir = runtimes_dir289 output_name = "c++"290 complete_static_lib = true291 configs -= [ "//llvm/utils/gn/build:thin_archive" ]292 sources = cxx_sources293 include_dirs = [ "." ]294 if (libcxx_hermetic_static_library) {295 cflags = [ "-fvisibility=hidden" ]296 if (libcxx_enable_new_delete_definitions) {297 cflags_cc = [ "-fvisibility-global-new-delete=force-hidden" ]298 }299 defines = [ "_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS" ]300 }301 deps = [302 "//compiler-rt/lib/builtins",303 "//libc:common_utils",304 "//libcxx/include",305 "//libcxxabi/src:cxxabi_static",306 "//libunwind/src:unwind_static",307 ]308 configs += [ ":cxx_config" ]309 configs -= [310 "//llvm/utils/gn/build:no_exceptions",311 "//llvm/utils/gn/build:no_rtti",312 ]313 }314}315 316if (libcxx_enable_experimental) {317 static_library("cxx_experimental") {318 output_dir = runtimes_dir319 output_name = "c++experimental"320 sources = [321 "experimental/keep.cpp",322 "experimental/log_hardening_failure.cpp",323 ]324 if (libcxx_enable_filesystem && libcxx_enable_time_zone_database) {325 sources += [326 # TODO TZDB The exception could be moved in chrono once the TZDB library327 # is no longer experimental.328 "experimental/chrono_exception.cpp",329 "experimental/include/tzdb/time_zone_private.h",330 "experimental/include/tzdb/types_private.h",331 "experimental/include/tzdb/tzdb_list_private.h",332 "experimental/include/tzdb/tzdb_private.h",333 "experimental/time_zone.cpp",334 "experimental/tzdb.cpp",335 "experimental/tzdb_list.cpp",336 ]337 }338 deps = [ "//libcxx/include" ]339 configs += [ ":cxx_config" ]340 configs -= [341 "//llvm/utils/gn/build:no_exceptions",342 "//llvm/utils/gn/build:no_rtti",343 ]344 }345}346 347group("src") {348 deps = []349 if (libcxx_enable_shared) {350 if (libcxx_enable_abi_linker_script) {351 deps += [ ":cxx_linker_script" ]352 } else {353 deps += [ ":cxx_shared" ]354 }355 }356 if (libcxx_enable_static) {357 deps += [ ":cxx_static" ]358 }359 if (libcxx_enable_experimental) {360 deps += [ ":cxx_experimental" ]361 }362}363