llvm.org GIT mirror llvm / e1e3e97
[gn] Support for building libc++ This change introduces support for building libc++. The library build should be complete, but not all CMake options have been replicated in GN. We also don't support tests yet. We only support two stage build at the moment. Differential Revision: https://reviews.llvm.org/D61143 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359806 91177308-0d34-0410-b5e6-96231b3b80d8 Petr Hosek 5 months ago
4 changed file(s) with 584 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
1212 if (current_os == "linux") {
1313 deps += [
1414 "//compiler-rt",
15 "//libcxx",
1516 "//libcxxabi",
1617 "//libunwind",
1718 ]
0 group("libcxx") {
1 deps = [
2 "include",
3 "src(//llvm/utils/gn/build/toolchain:stage2_unix)",
4 ]
5 }
0 import("//clang/resource_dir.gni")
1 import("//libcxx/config.gni")
2 import("//llvm/utils/gn/build/write_cmake_config.gni")
3
4 declare_args() {
5 # Install libc++ support headers.
6 libcxx_install_support_headers = true
7 }
8
9 libcxx_needs_site_config =
10 libcxx_abi_version != 1 || libcxx_abi_namespace != "" || libcxx_abi_unstable
11
12 if (libcxx_needs_site_config) {
13 write_cmake_config("write_config") {
14 input = "__config_site.in"
15 output = "$target_gen_dir/__config_site"
16
17 values = []
18 if (libcxx_abi_version != 1) {
19 values += [ "_LIBCPP_ABI_VERSION=$libcxx_abi_version" ]
20 }
21 if (libcxx_abi_namespace != "") {
22 values += [ "_LIBCPP_ABI_NAMESPACE=$libcxx_abi_namespace" ]
23 }
24 if (libcxx_abi_unstable) {
25 values += [ "_LIBCPP_ABI_UNSTABLE=" ]
26 }
27 }
28
29 # Generate a custom __config header. The new header is created
30 # by prepending __config_site to the current __config header.
31 action("concat_config") {
32 script = "//libcxx/utils/cat_files.py"
33 inputs = [
34 "$target_gen_dir/__config_site",
35 "__config",
36 ]
37 outputs = [
38 "$target_gen_dir/__config",
39 ]
40 args = [
41 "$target_gen_dir/__config_site",
42 "__config",
43 "-o",
44 "$target_gen_dir/__config",
45 ]
46 deps = [
47 ":write_config",
48 ]
49 }
50
51 copy("copy_config") {
52 sources = [
53 "$target_gen_dir/__config",
54 ]
55 outputs = [
56 "$clang_resource_dir/include/c++/v1/{{source_file_part}}",
57 ]
58 deps = [
59 ":concat_config",
60 ]
61 }
62 }
63
64 copy("include") {
65 sources = [
66 "__bit_reference",
67 "__bsd_locale_defaults.h",
68 "__bsd_locale_fallbacks.h",
69 "__debug",
70 "__errc",
71 "__functional_03",
72 "__functional_base",
73 "__functional_base_03",
74 "__hash_table",
75 "__libcpp_version",
76 "__locale",
77 "__mutex_base",
78 "__node_handle",
79 "__nullptr",
80 "__split_buffer",
81 "__sso_allocator",
82 "__std_stream",
83 "__string",
84 "__threading_support",
85 "__tree",
86 "__tuple",
87 "__undef_macros",
88 "algorithm",
89 "any",
90 "array",
91 "atomic",
92 "bit",
93 "bitset",
94 "cassert",
95 "ccomplex",
96 "cctype",
97 "cerrno",
98 "cfenv",
99 "cfloat",
100 "charconv",
101 "chrono",
102 "cinttypes",
103 "ciso646",
104 "climits",
105 "clocale",
106 "cmath",
107 "codecvt",
108 "compare",
109 "complex",
110 "complex.h",
111 "condition_variable",
112 "csetjmp",
113 "csignal",
114 "cstdarg",
115 "cstdbool",
116 "cstddef",
117 "cstdint",
118 "cstdio",
119 "cstdlib",
120 "cstring",
121 "ctgmath",
122 "ctime",
123 "ctype.h",
124 "cwchar",
125 "cwctype",
126 "deque",
127 "errno.h",
128 "exception",
129 "experimental/__config",
130 "experimental/__memory",
131 "experimental/algorithm",
132 "experimental/any",
133 "experimental/chrono",
134 "experimental/coroutine",
135 "experimental/deque",
136 "experimental/filesystem",
137 "experimental/forward_list",
138 "experimental/functional",
139 "experimental/iterator",
140 "experimental/list",
141 "experimental/map",
142 "experimental/memory_resource",
143 "experimental/numeric",
144 "experimental/optional",
145 "experimental/propagate_const",
146 "experimental/ratio",
147 "experimental/regex",
148 "experimental/set",
149 "experimental/simd",
150 "experimental/string",
151 "experimental/string_view",
152 "experimental/system_error",
153 "experimental/tuple",
154 "experimental/type_traits",
155 "experimental/unordered_map",
156 "experimental/unordered_set",
157 "experimental/utility",
158 "experimental/vector",
159 "ext/__hash",
160 "ext/hash_map",
161 "ext/hash_set",
162 "fenv.h",
163 "filesystem",
164 "float.h",
165 "forward_list",
166 "fstream",
167 "functional",
168 "future",
169 "initializer_list",
170 "inttypes.h",
171 "iomanip",
172 "ios",
173 "iosfwd",
174 "iostream",
175 "istream",
176 "iterator",
177 "limits",
178 "limits.h",
179 "list",
180 "locale",
181 "locale.h",
182 "map",
183 "math.h",
184 "memory",
185 "module.modulemap",
186 "mutex",
187 "new",
188 "numeric",
189 "optional",
190 "ostream",
191 "queue",
192 "random",
193 "ratio",
194 "regex",
195 "scoped_allocator",
196 "set",
197 "setjmp.h",
198 "shared_mutex",
199 "span",
200 "sstream",
201 "stack",
202 "stdbool.h",
203 "stddef.h",
204 "stdexcept",
205 "stdint.h",
206 "stdio.h",
207 "stdlib.h",
208 "streambuf",
209 "string",
210 "string.h",
211 "string_view",
212 "strstream",
213 "system_error",
214 "tgmath.h",
215 "thread",
216 "tuple",
217 "type_traits",
218 "typeindex",
219 "typeinfo",
220 "unordered_map",
221 "unordered_set",
222 "utility",
223 "valarray",
224 "variant",
225 "vector",
226 "version",
227 "wchar.h",
228 "wctype.h",
229 ]
230 deps = [
231 "//libcxxabi/include",
232 ]
233 if (!libcxx_needs_site_config) {
234 sources += [ "__config" ]
235 } else {
236 deps += [ ":copy_config" ]
237 }
238 if (libcxx_install_support_headers) {
239 sources += [
240 "support/android/locale_bionic.h",
241 "support/fuchsia/xlocale.h",
242 "support/ibm/limits.h",
243 "support/ibm/locale_mgmt_aix.h",
244 "support/ibm/support.h",
245 "support/ibm/xlocale.h",
246 "support/musl/xlocale.h",
247 "support/newlib/xlocale.h",
248 "support/solaris/floatingpoint.h",
249 "support/solaris/wchar.h",
250 "support/solaris/xlocale.h",
251 "support/xlocale/__nop_locale_mgmt.h",
252 "support/xlocale/__posix_l_fallback.h",
253 "support/xlocale/__strtonum_fallback.h",
254 ]
255 if (target_os == "win") {
256 sources += [
257 "support/win32/limits_msvc_win32.h",
258 "support/win32/locale_win32.h",
259 ]
260 }
261 }
262 outputs = [
263 "$clang_resource_dir/include/c++/v1/{{source_target_relative}}",
264 ]
265 }
266
267 copy("cxxabi_include") {
268 sources = [
269 "//libcxxabi/include/__cxxabi_config.h", # ignore for sync script
270 "//libcxxabi/include/cxxabi.h", # ignore for sync script
271 ]
272 outputs = [
273 "$clang_resource_dir/include/c++/v1/{{source_target_relative}}",
274 ]
275 }
0 import("//clang/runtimes.gni")
1 import("//llvm/utils/gn/build/symlink_or_copy.gni")
2
3 declare_args() {
4 # Build libc++ with definitions for operator new/delete.
5 libcxx_enable_new_delete_definitions = true
6
7 # Build libc++ as a shared library.
8 libcxx_enable_shared = true
9
10 # Build libc++ as a static library.
11 libcxx_enable_static = true
12
13 # Build filesystem as part of libc++fs.a.
14 libcxx_enable_filesystem = target_os != "win"
15
16 # Build libc++experimental.a.
17 libcxx_enable_experimental = true
18
19 # Use compiler-rt builtins.
20 libcxx_use_compiler_rt = true
21
22 # Use exceptions.
23 libcxx_enable_exceptions = true
24
25 # Use run time type information.
26 libcxx_enable_rtti = true
27
28 # Do not export any symbols from the static library.
29 libcxx_hermetic_static_library = true
30
31 # Use and install a linker script for the given ABI library.
32 libcxx_enable_abi_linker_script = true
33 }
34
35 config("cxx_config") {
36 include_dirs = [
37 "//libcxxabi/include",
38 "//libcxx/include",
39 ]
40 cflags = [
41 "-Wall",
42 "-Wextra",
43 "-W",
44 "-Wwrite-strings",
45 "-Wno-unused-parameter",
46 "-Wno-long-long",
47 "-Werror=return-type",
48 "-Wextra-semi",
49 "-Wno-user-defined-literals",
50 "-Wno-covered-switch-default",
51 ]
52 cflags_cc = [ "-nostdinc++" ]
53 if (target_os == "win") {
54 cflags_cc += [ "/std:c++11" ]
55 } else {
56 cflags_cc += [ "-std=c++11" ]
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_exceptions) {
87 if (current_os == "win") {
88 cflags_cc += [ "/EHsc" ]
89 }
90 } else {
91 if (current_os == "win") {
92 cflags_cc += [
93 "/EHs-",
94 "/EHa-",
95 ]
96 } else {
97 cflags_cc += [ "-fno-exceptions" ]
98 }
99 defines += [ "-D_LIBCPP_NO_EXCEPTIONS" ]
100 }
101 if (!libcxx_enable_rtti) {
102 if (current_os == "win") {
103 cflags_cc += [ "/GR-" ]
104 } else {
105 cflags_cc += [ "-fno-rtti" ]
106 }
107 defines += [ "-D_LIBCPP_NO_RTTI" ]
108 }
109 }
110
111 cxx_sources = [
112 "algorithm.cpp",
113 "string.cpp",
114 "ios.cpp",
115 "condition_variable.cpp",
116 "hash.cpp",
117 "random.cpp",
118 "new.cpp",
119 "functional.cpp",
120 "exception.cpp",
121 "support/runtime/exception_msvc.ipp",
122 "support/runtime/exception_libcxxabi.ipp",
123 "support/runtime/exception_glibcxx.ipp",
124 "support/runtime/new_handler_fallback.ipp",
125 "support/runtime/exception_libcxxrt.ipp",
126 "support/runtime/exception_pointer_unimplemented.ipp",
127 "support/runtime/exception_pointer_cxxabi.ipp",
128 "support/runtime/exception_pointer_msvc.ipp",
129 "support/runtime/exception_fallback.ipp",
130 "support/runtime/exception_pointer_glibcxx.ipp",
131 "variant.cpp",
132 "shared_mutex.cpp",
133 "optional.cpp",
134 "strstream.cpp",
135 "include/apple_availability.h",
136 "include/refstring.h",
137 "include/config_elast.h",
138 "include/atomic_support.h",
139 "future.cpp",
140 "system_error.cpp",
141 "bind.cpp",
142 "iostream.cpp",
143 "stdexcept.cpp",
144 "valarray.cpp",
145 "chrono.cpp",
146 "typeinfo.cpp",
147 "locale.cpp",
148 "debug.cpp",
149 "charconv.cpp",
150 "utility.cpp",
151 "regex.cpp",
152 "mutex.cpp",
153 "any.cpp",
154 "thread.cpp",
155 "vector.cpp",
156 "memory.cpp",
157 ]
158 if (target_os == "win") {
159 cxx_sources += [
160 "support/win32/locale_win32.cpp",
161 "support/win32/support.cpp",
162 "support/win32/thread_win32.cpp",
163 ]
164 }
165 if (target_os == "solaris") {
166 cxx_sources += [
167 # This comment prevents `gn format` from putting the file on the same line
168 # as `sources +=`, for sync_source_lists_from_cmake.py.
169 "support/solaris/xlocale.cpp",
170 ]
171 }
172 if (libcxx_enable_filesystem) {
173 cxx_sources += [
174 "filesystem/directory_iterator.cpp",
175 "filesystem/filesystem_common.h",
176 "filesystem/operations.cpp",
177 ]
178 if (libcxx_use_compiler_rt) {
179 cxx_sources += [
180 # This comment prevents `gn format` from putting the file on the same line
181 # as `sources +=`, for sync_source_lists_from_cmake.py.
182 "filesystem/int128_builtins.cpp",
183 ]
184 }
185 }
186
187 if (libcxx_enable_shared) {
188 shared_library("cxx_shared") {
189 output_dir = runtimes_dir
190 output_name = "c++"
191 if (libcxx_enable_abi_linker_script) {
192 output_extension = "so.0"
193 }
194 if (target_os == "linux" || target_os == "mac") {
195 cflags = [ "-fPIC" ]
196 ldflags = [ "-nostdlib++" ]
197 libs = [
198 "dl",
199 "pthread",
200 ]
201 }
202 sources = cxx_sources
203 deps = [
204 "//compiler-rt/lib/builtins",
205 "//libcxxabi/src:cxxabi_shared",
206 "//libunwind/src:unwind_shared",
207 ]
208 configs += [ ":cxx_config" ]
209 configs -= [
210 "//llvm/utils/gn/build:no_exceptions",
211 "//llvm/utils/gn/build:no_rtti",
212 ]
213 }
214
215 symlink_or_copy("cxx_symlink") {
216 deps = [
217 ":cxx_shared",
218 ]
219 source = "libc++.so.0"
220 output = "$runtimes_dir/libc++.so"
221 }
222
223 if (libcxx_enable_abi_linker_script) {
224 action("cxx_linker_script") {
225 script = "//libcxx/utils/gen_link_script.py"
226 outputs = [
227 "$runtimes_dir/libc++.so",
228 ]
229 args = [
230 "--input",
231 "$runtimes_dir/libc++.so.0",
232 "--output",
233 "$runtimes_dir/libc++.so",
234 "c++abi",
235 "unwind",
236 ]
237 deps = [
238 ":cxx_symlink",
239 ]
240 }
241 }
242 }
243
244 if (libcxx_enable_static) {
245 static_library("cxx_static") {
246 output_dir = runtimes_dir
247 output_name = "c++"
248 complete_static_lib = true
249 configs -= [ "//llvm/utils/gn/build:thin_archive" ]
250 sources = cxx_sources
251 if (libcxx_hermetic_static_library) {
252 cflags = [ "-fvisibility=hidden" ]
253 cflags_cc = [ "-fvisibility-global-new-delete-hidden" ]
254 defines = [ "_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS" ]
255 }
256 deps = [
257 "//compiler-rt/lib/builtins",
258 "//libcxxabi/src:cxxabi_static",
259 "//libunwind/src:unwind_static",
260 ]
261 configs += [ ":cxx_config" ]
262 configs -= [
263 "//llvm/utils/gn/build:no_exceptions",
264 "//llvm/utils/gn/build:no_rtti",
265 ]
266 }
267 }
268
269 if (libcxx_enable_experimental) {
270 static_library("cxx_experimental") {
271 output_dir = runtimes_dir
272 output_name = "c++experimental"
273 cflags_cc = [ "-std=c++14" ]
274 sources = [
275 "experimental/memory_resource.cpp",
276 ]
277 configs += [ ":cxx_config" ]
278 configs -= [
279 "//llvm/utils/gn/build:no_exceptions",
280 "//llvm/utils/gn/build:no_rtti",
281 ]
282 }
283 }
284
285 group("src") {
286 deps = []
287 if (libcxx_enable_shared) {
288 if (libcxx_enable_abi_linker_script) {
289 deps += [ ":cxx_linker_script" ]
290 } else {
291 deps += [ ":cxx_shared" ]
292 }
293 }
294 if (libcxx_enable_static) {
295 deps += [ ":cxx_static" ]
296 }
297 if (libcxx_enable_experimental) {
298 deps += [ ":cxx_experimental" ]
299 }
300 }