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