1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
buildtools / third_party / libc++ / BUILD.gn [blame]
# Copyright 2015 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/config/c++/c++.gni")
import("//build/config/sanitizers/sanitizers.gni")
import("//build/toolchain/toolchain.gni")
# Used by libc++ and libc++abi.
# See //build/config/c++:runtime_library for the config used by users of libc++.
config("config") {
cflags = [
"-fstrict-aliasing",
"-Wundef",
]
if (is_win) {
cflags += [
# libc++ wants to redefine the macros WIN32_LEAN_AND_MEAN and _CRT_RAND_S
# in its implementation.
"-Wno-macro-redefined",
]
cflags_cc = [
# We want to use a uniform C++ version across all of chromium, but
# upstream libc++ requires C++20 so we have to make an exception here.
# No other target should override the default -std= flag.
"-std:c++20",
]
} else {
cflags += [ "-fPIC" ]
cflags_cc = [ "-std=c++20" ]
}
defines = [ "_LIBCPP_BUILDING_LIBRARY" ]
}
# Explicitly set version macros to Windows 7 to prevent libc++ from adding a
# hard dependency on GetSystemTimePreciseAsFileTime, which was introduced in
# Windows 8.
config("winver") {
defines = [
"NTDDI_VERSION=NTDDI_WIN7",
"_WIN32_WINNT=_WIN32_WINNT_WIN7",
"WINVER=_WIN32_WINNT_WIN7",
]
}
if (libcxx_is_shared) {
_libcxx_target_type = "shared_library"
} else {
_libcxx_target_type = "source_set"
}
target(_libcxx_target_type, "libc++") {
# Most things that need to depend on libc++ should do so via the implicit
# 'common_deps' dependency below. Some targets that package libc++.so may
# need to explicitly depend on libc++.
visibility = [
"//build/config:common_deps",
"//third_party/catapult/devil:devil",
]
if (is_linux) {
# This target packages libc++.so, so must have an explicit dependency on
# libc++.
visibility +=
[ "//remoting/host/linux:remoting_me2me_host_copy_user_session" ]
}
if (build_with_chromium && is_win && is_component_build) {
# PartitionAlloc uses no_default_deps=true when is_win && is_component_build
# but it depends on libc++. So need to add an explicit dependency on
# libc++.
visibility +=
[ "//base/allocator/partition_allocator/src/partition_alloc:*" ]
}
if (libcxx_is_shared) {
no_default_deps = true
}
if (is_linux && !is_clang) {
libs = [ "atomic" ]
}
inputs = [
"__assertion_handler",
"__config_site",
]
# TODO(crbug.com/40273848): Move this build file to third_party/libc++/BUILD.gn
# once submodule migration is done.
sources = [
"//third_party/libc++/src/src/algorithm.cpp",
"//third_party/libc++/src/src/any.cpp",
"//third_party/libc++/src/src/atomic.cpp",
"//third_party/libc++/src/src/barrier.cpp",
"//third_party/libc++/src/src/bind.cpp",
"//third_party/libc++/src/src/call_once.cpp",
"//third_party/libc++/src/src/charconv.cpp",
"//third_party/libc++/src/src/chrono.cpp",
"//third_party/libc++/src/src/condition_variable.cpp",
"//third_party/libc++/src/src/condition_variable_destructor.cpp",
"//third_party/libc++/src/src/error_category.cpp",
"//third_party/libc++/src/src/exception.cpp",
"//third_party/libc++/src/src/filesystem/directory_iterator.cpp",
"//third_party/libc++/src/src/filesystem/filesystem_error.cpp",
"//third_party/libc++/src/src/filesystem/operations.cpp",
"//third_party/libc++/src/src/filesystem/path.cpp",
"//third_party/libc++/src/src/functional.cpp",
"//third_party/libc++/src/src/future.cpp",
"//third_party/libc++/src/src/hash.cpp",
"//third_party/libc++/src/src/ios.cpp",
"//third_party/libc++/src/src/ios.instantiations.cpp",
"//third_party/libc++/src/src/iostream.cpp",
"//third_party/libc++/src/src/locale.cpp",
"//third_party/libc++/src/src/memory.cpp",
"//third_party/libc++/src/src/mutex.cpp",
"//third_party/libc++/src/src/mutex_destructor.cpp",
"//third_party/libc++/src/src/new_handler.cpp",
"//third_party/libc++/src/src/new_helpers.cpp",
"//third_party/libc++/src/src/optional.cpp",
"//third_party/libc++/src/src/random.cpp",
"//third_party/libc++/src/src/random_shuffle.cpp",
"//third_party/libc++/src/src/regex.cpp",
"//third_party/libc++/src/src/ryu/d2fixed.cpp",
"//third_party/libc++/src/src/ryu/d2s.cpp",
"//third_party/libc++/src/src/ryu/f2s.cpp",
"//third_party/libc++/src/src/shared_mutex.cpp",
"//third_party/libc++/src/src/stdexcept.cpp",
"//third_party/libc++/src/src/string.cpp",
"//third_party/libc++/src/src/strstream.cpp",
"//third_party/libc++/src/src/system_error.cpp",
"//third_party/libc++/src/src/thread.cpp",
"//third_party/libc++/src/src/typeinfo.cpp",
"//third_party/libc++/src/src/valarray.cpp",
"//third_party/libc++/src/src/variant.cpp",
"//third_party/libc++/src/src/vector.cpp",
"//third_party/libc++/src/src/verbose_abort.cpp",
]
if (is_apple || (!is_asan && !is_tsan && !is_msan)) {
# In {a,t,m}san configurations, operator new and operator delete will be
# provided by the sanitizer runtime library. Since libc++ defines these
# symbols with weak linkage, and the *san runtime uses strong linkage, it
# should technically be OK to include this file, but it's removed to be
# explicit.
sources += [ "//third_party/libc++/src/src/new.cpp" ]
}
if (is_linux) {
# These sources are necessary for the Centipede fuzzer,
# which currently only needs to run on Linux.
sources += [
"//third_party/libc++/src/src/filesystem/directory_entry.cpp",
"//third_party/libc++/src/src/filesystem/filesystem_clock.cpp",
]
}
include_dirs = [ "//third_party/libc++/src/src" ]
if (is_win) {
sources += [
"//third_party/libc++/src/src/support/win32/locale_win32.cpp",
"//third_party/libc++/src/src/support/win32/support.cpp",
"//third_party/libc++/src/src/support/win32/thread_win32.cpp",
]
configs -= [ "//build/config/win:winver" ]
configs += [ ":winver" ]
if (libcxx_natvis_include) {
inputs += [
# libc++.natvis listed as an input here instead of in
# //build/config/c++:runtime_library to prevent unnecessary size
# increase in generated build files.
"//build/config/c++/libc++.natvis",
]
}
}
configs -= [
"//build/config/compiler:chromium_code",
"//build/config/compiler:no_exceptions",
"//build/config/compiler:no_rtti",
"//build/config/coverage:default_coverage",
]
if (use_libcxx_modules) {
configs -= [ "//build/config/compiler:libcxx_module" ]
}
if ((is_android || is_apple) && libcxx_is_shared) {
# Use libc++_chrome to avoid conflicting with system libc++
output_name = "libc++_chrome"
if (is_android) {
# See crbug.com/1076244#c11 for more detail.
configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
}
}
configs += [
":config",
"//build/config/compiler:no_chromium_code",
"//build/config/compiler:exceptions",
"//build/config/compiler:rtti",
]
if (libcxx_is_shared && !is_win) {
configs -= [ "//build/config/gcc:symbol_visibility_hidden" ]
configs += [ "//build/config/gcc:symbol_visibility_default" ]
}
defines = []
if (!libcxx_is_shared && !is_win) {
if (is_apple && is_clang) {
# We want operator new/delete to be private on Mac, but these functions
# are implicitly created by the compiler for each translation unit, as
# specified in the C++ spec 3.7.4p2, which makes them always have default
# visibility. This option is needed to force hidden visibility since
# -fvisibility=hidden doesn't have the desired effect.
cflags = [ "-fvisibility-global-new-delete=force-hidden" ]
} else {
# This resets the visibility to default only for the various
# flavors of operator new and operator delete. These symbols
# are weak and get overriden by Chromium-provided ones, but if
# these symbols had hidden visibility, this would make the
# Chromium symbols hidden too because elf visibility rules
# require that linkers use the least visible form when merging.
# We want operator new to be public, so that our allocator is
# able to intercept allocations from other shared libraries.
# TODO(lld): Ask lld for a --force-public-visibility flag or
# similar to that overrides the default elf merging rules, and
# make the allocator's gn config pass that to all its dependencies,
# then remove this override here.
defines += [ "_LIBCPP_OVERRIDABLE_FUNC_VIS=__attribute__((__visibility__(\"default\")))" ]
}
}
deps = [ "//third_party/llvm-libc:llvm-libc-shared" ]
if (!is_win) {
defines += [ "LIBCXX_BUILDING_LIBCXXABI" ]
if (!export_libcxxabi_from_executables) {
deps += [ "//buildtools/third_party/libc++abi" ]
}
}
}