forked from revery-ui/esy-skia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BUILD.gn
570 lines (525 loc) · 14.7 KB
/
BUILD.gn
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
# Copyright 2016 Google Inc.
#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
exec_script("xamarin_inject_compat.py", [ rebase_path("..") ])
declare_args() {
extra_asmflags = []
extra_cflags = []
extra_cflags_c = []
extra_cflags_cc = []
extra_ldflags = []
malloc = ""
enable_bitcode = false
if (is_tvos || is_watchos) {
enable_bitcode = true
}
}
if (is_ios) {
if (is_tvos) {
sdk = "appletv"
} else if (is_watchos) {
sdk = "watch"
} else {
sdk = "iphone"
}
if (target_cpu == "x86" || target_cpu == "x64") {
sdk += "simulator"
} else {
sdk += "os"
}
ios_sysroot = exec_script("find_ios_sysroot.py", [ sdk ], "trim string")
}
config("default") {
asmflags = []
cflags = []
cflags_c = []
cflags_cc = []
defines = []
ldflags = []
libs = []
if (is_win) {
cflags += [
"/bigobj", # Some of our files are bigger than the regular limits.
"/utf-8", # Set Source and Executable character sets to UTF-8.
]
if (is_clang) {
cflags += [ "-fms-compatibility-version=19" ] # 2015
}
defines += [
"_CRT_SECURE_NO_WARNINGS", # Disables warnings about sscanf().
"_HAS_EXCEPTIONS=0", # Disables exceptions in MSVC STL.
"WIN32_LEAN_AND_MEAN",
"NOMINMAX",
]
if (msvc == 2015) {
_include_dirs = [ "$win_vc/include" ]
} else { # 2017
_include_dirs = [ "$win_vc/Tools/MSVC/$win_toolchain_version/include" ]
}
_include_dirs += [
"$win_sdk/Include/$win_sdk_version/shared",
"$win_sdk/Include/$win_sdk_version/ucrt",
"$win_sdk/Include/$win_sdk_version/um",
"$win_sdk/Include/$win_sdk_version/winrt",
]
if (is_clang) {
foreach(dir, _include_dirs) {
cflags += [
"-imsvc",
dir,
]
}
} else {
include_dirs = _include_dirs
}
lib_dirs = [
"$win_sdk/Lib/$win_sdk_version/ucrt/$target_cpu",
"$win_sdk/Lib/$win_sdk_version/um/$target_cpu",
]
if (msvc == 2015) {
if (target_cpu == "x86") {
lib_dirs += [ "$win_vc/lib" ]
} else {
lib_dirs += [ "$win_vc/lib/amd64" ]
}
} else { # 2017
_is_store = ""
if (is_winrt) {
_is_store = "/store"
}
lib_dirs +=
[ "$win_vc/Tools/MSVC/$win_toolchain_version/lib/$target_cpu$_is_store" ]
}
} else {
cflags += [
"-fstrict-aliasing",
"-fPIC",
]
cflags_cc += [ "-std=c++11" ]
# The main idea is to slim the exported API, but these flags also improve link time on Mac.
# These would make stack traces worse on Linux, so we don't just set them willy-nilly.
cflags += [ "-fvisibility=hidden" ]
cflags_cc += [ "-fvisibility-inlines-hidden" ]
}
if (current_cpu == "arm" && !is_win) {
cflags += [
"-march=armv7-a",
"-mfpu=neon",
"-mthumb",
]
} else if (current_cpu == "loongson3a" && !is_win) {
asmflags += [ "-march=loongson3a" ]
cflags += [
"-march=loongson3a",
# Causes an internal compiler error.
"-DSKCMS_PORTABLE",
]
} else if (current_cpu == "mips64el" && !is_win) {
asmflags += [ "-march=mips64" ]
cflags += [ "-march=mips64" ]
} else if (current_cpu == "x86" && !is_win) {
asmflags += [ "-m32" ]
cflags += [
"-m32",
"-msse2",
"-mfpmath=sse",
]
ldflags += [ "-m32" ]
}
if (malloc != "" && !is_win) {
cflags += [
"-fno-builtin-malloc",
"-fno-builtin-calloc",
"-fno-builtin-realloc",
"-fno-builtin-free",
]
libs += [ malloc ]
}
if (is_android) {
asmflags += [ "--target=$ndk_target" ]
cflags += [
"--sysroot=$ndk/sysroot",
"-isystem$ndk/sysroot/usr/include/$ndk_target",
"-D__ANDROID_API__=$ndk_api",
"--target=$ndk_target",
]
cflags_cc += [
"-isystem$ndk/sources/cxx-stl/llvm-libc++/include",
"-isystem$ndk/sources/cxx-stl/llvm-libc++abi/include",
"-isystem$ndk/sources/android/support/include",
]
ldflags += [
"--sysroot=$ndk/platforms/$ndk_platform",
"--target=$ndk_target",
"-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
]
lib_dirs = [
"$ndk/sources/cxx-stl/llvm-libc++/libs/$ndk_stdlib",
"$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/lib/gcc/$ndk_target/4.9.x",
]
libs += [
"c++_static",
"c++abi",
]
if (ndk_api < 21) {
libs += [ "android_support" ]
}
}
if (is_tizen) {
asmflags += [
"--target=$ncli_target",
"-B$ncli/tools/$ncli_gccdir/$ncli_target/bin",
]
cflags += [
"--sysroot=$ncli/platforms/$ncli_platform",
"--target=$ncli_target",
"-B$ncli/tools/$ncli_gccdir/$ncli_target/bin",
]
cflags_cc += [
"-isystem$ncli/tools/$ncli_gccdir/$ncli_target/include/c++/6.2.1",
"-isystem$ncli/tools/$ncli_gccdir/$ncli_target/include/c++/6.2.1/$ncli_target",
]
ldflags += [
"--sysroot=$ncli/platforms/$ncli_platform",
"--target=$ncli_target",
"-B$ncli/tools/$ncli_gccdir/$ncli_target/bin",
]
lib_dirs = [
"$ncli/platforms/$ncli_platform/usr/lib",
]
}
if (is_ios) {
_target = target_cpu
if (target_cpu == "arm") {
_target = "armv7"
} else if (target_cpu == "x86") {
_target = "i386"
} else if (target_cpu == "x64") {
_target = "x86_64"
}
if (is_watchos && _target == "armv7") {
_target = "armv7k"
}
asmflags += [
"-isysroot",
ios_sysroot,
"-arch",
_target,
]
cflags += [
"-isysroot",
ios_sysroot,
"-arch",
_target,
]
cflags_cc += [ "-stdlib=libc++" ]
ldflags += [
"-isysroot",
ios_sysroot,
"-arch",
_target,
"-stdlib=libc++",
]
libs += [ "objc" ]
}
if (enable_bitcode) {
cflags += [
"-fembed-bitcode"
]
}
if (is_linux) {
libs += [ "pthread" ]
}
if (is_mac) {
# Disable linker warnings. They're usually just annoyances like,
# ld: warning: text-based stub file
# /System/Library/Frameworks/foo.framework/foo.tbd and library file
# /System/Library/Frameworks/foo.framework/foo are out of sync.
# Falling back to library file for linking.
ldflags += [ "-Wl,-w" ]
}
if (sanitize != "") {
# You can either pass the sanitizers directly, e.g. "address,undefined",
# or pass one of the couple common aliases used by the bots.
sanitizers = sanitize
# fyi_sanitizers only print out stacktraces of their issues
fyi_sanitizers = fyi_sanitize
if (sanitize == "ASAN" || sanitize == "UBSAN") {
# ASAN implicitly runs all UBSAN checks also.
sanitizers = "bool,float-cast-overflow,integer-divide-by-zero,nonnull-attribute,null,return,returns-nonnull-attribute,shift,signed-integer-overflow,unreachable,vla-bound"
if (fyi_sanitize == "" && !is_android) {
fyi_sanitizers = "float-divide-by-zero"
}
if (!is_mac && !is_win) {
sanitizers += ",function" # Not supported on Mac or Win.
}
if (!is_win) {
sanitizers += ",vptr" # Not supported on Win.
}
if (!is_debug && !is_win) {
# No-op with somewhat annoying warning at -O0.
# Seems to be broken on Win.
sanitizers += ",object-size"
}
if (sanitize == "ASAN") {
sanitizers += ",address"
}
if (is_android) {
# Android only easily supports address for now
# UBSAN runs into linking errors
sanitizers = "address"
# recommended by
# https://github.com/google/sanitizers/wiki/AddressSanitizerOnAndroid
cflags += [ "-fno-omit-frame-pointer" ]
}
} else if (sanitize == "TSAN") {
sanitizers = "thread"
} else if (sanitize == "MSAN") {
sanitizers = "memory"
}
cflags += [
"-fsanitize=$sanitizers,$fyi_sanitizers",
"-fno-sanitize-recover=$sanitizers",
]
if (!is_win) {
cflags += [ "-fno-omit-frame-pointer" ]
}
if (is_linux) {
cflags_cc += [ "-stdlib=libc++" ]
ldflags += [ "-stdlib=libc++" ]
}
ldflags += [ "-fsanitize=$sanitizers" ]
if (sanitizers == "memory") {
cflags += [ "-fsanitize-memory-track-origins" ]
}
}
}
config("no_exceptions") {
# Exceptions are disabled by default on Windows. (Use /EHsc to enable them.)
if (!is_win) {
cflags_cc = [ "-fno-exceptions" ]
}
}
config("warnings") {
cflags = []
cflags_cc = []
cflags_objc = []
cflags_objcc = []
if (is_win) {
cflags += [
"/WX", # Treat warnings as errors.
"/W3", # Turn on lots of warnings.
# Disable a bunch of warnings:
"/wd4244", # conversion from 'float' to 'int', possible loss of data
"/wd4267", # conversion from 'size_t' to 'int', possible loss of data
"/wd4800", # forcing value to bool 'true' or 'false' (performance warning)
# Probably only triggers when /EHsc is enabled.
"/wd4291", # no matching operator delete found;
# memory will not be freed if initialization throws an exception
# These only show up in shared builds:
"/wd4251", # class 'type' needs to have dll-interface to be used by clients of class 'type2'
"/wd4275", # non dll-interface class 'base' used as base for dll-interface class 'derived'
]
} else {
cflags += [
"-Werror",
"-Wall",
"-Wextra",
"-Winit-self",
"-Wpointer-arith",
"-Wsign-compare",
"-Wvla",
"-Wno-deprecated-declarations",
"-Wno-maybe-uninitialized",
"-Wno-extra-semi-stmt",
]
cflags_cc += [
"-Wnon-virtual-dtor",
"-Wno-noexcept-type",
]
}
if (is_clang) {
cflags += [
"-Weverything",
"-Wno-unknown-warning-option", # Let older Clangs ignore newer Clangs' warnings.
# clang 10 fixes
"-Wno-anon-enum-enum-conversion",
"-Wno-sizeof-array-div",
# clang 10.2 fixes
"-Wno-psabi",
"-Wno-suggest-destructor-override",
"-Wno-suggest-override",
"-Wno-uninitialized-const-reference",
# macOS cross-compilation fix
"-Wno-poison-system-directories",
]
if (target_cpu == "arm" && is_ios) {
# Clang seems to think new/malloc will only be 4-byte aligned on 32-bit iOS.
# We're pretty sure it's actually 8-byte alignment.
cflags += [ "-Wno-over-aligned" ]
}
if (target_cpu == "x86" && is_android) {
# Clang seems to think new/malloc will only be 4-byte aligned on 32-bit x86 Android builds.
# We're pretty sure it's actually 8-byte alignment. See OverAlignedTest.cpp for more info.
cflags += [ "-Wno-over-aligned" ]
}
# Shouldn't be necessary for local builds. With distributed Windows builds, files may lose
# their case during copy, causing case-sensitivity mismatch on remote machines.
cflags += [
"-Wno-nonportable-include-path",
"-Wno-nonportable-system-include-path",
]
# TODO: These would all be really great warnings to turn on.
cflags += [
"-Wno-cast-align",
"-Wno-cast-qual",
"-Wno-conversion",
"-Wno-disabled-macro-expansion",
"-Wno-documentation",
"-Wno-documentation-unknown-command",
"-Wno-double-promotion",
"-Wno-exit-time-destructors", # TODO: OK outside libskia
"-Wno-float-equal",
"-Wno-format-nonliteral",
"-Wno-global-constructors", # TODO: OK outside libskia
"-Wno-missing-prototypes",
"-Wno-missing-variable-declarations",
"-Wno-pedantic",
"-Wno-reserved-id-macro",
"-Wno-shadow",
"-Wno-shift-sign-overflow",
"-Wno-signed-enum-bitfield",
"-Wno-switch-enum",
"-Wno-undef",
"-Wno-unreachable-code",
"-Wno-unreachable-code-break",
"-Wno-unreachable-code-return",
"-Wno-unused-macros",
"-Wno-unused-member-function",
"-Wno-unused-template",
"-Wno-zero-as-null-pointer-constant",
]
cflags_cc += [
"-Wno-abstract-vbase-init",
"-Wno-weak-vtables",
]
# We are unlikely to want to fix these.
cflags += [
"-Wno-bad-function-cast",
"-Wno-covered-switch-default",
"-Wno-deprecated",
"-Wno-missing-noreturn",
"-Wno-old-style-cast",
"-Wno-padded",
"-Wno-newline-eof",
]
cflags_cc += [
"-Wno-c++98-compat",
"-Wno-c++98-compat-pedantic",
"-Wno-undefined-func-template",
]
cflags_objc += [
"-Wno-direct-ivar-access",
"-Wno-objc-interface-ivars",
]
cflags_objcc += [
"-Wno-direct-ivar-access",
"-Wno-objcc-interface-ivars",
]
}
if (!is_win || is_clang) {
cflags += [ "-Wno-implicit-fallthrough" ]
}
}
config("warnings_except_public_headers") {
if (!is_win || is_clang) {
cflags = [ "-Wno-unused-parameter" ]
}
}
config("extra_flags") {
asmflags = extra_asmflags
cflags = extra_cflags
cflags_c = extra_cflags_c
cflags_cc = extra_cflags_cc
ldflags = extra_ldflags
}
config("debug_symbols") {
# It's annoying to wait for full debug symbols to push over
# to Android devices. -gline-tables-only is a lot slimmer.
if (is_android) {
cflags = [
"-gline-tables-only",
"-funwind-tables", # Helps make in-process backtraces fuller.
]
} else if (is_win) {
cflags = [ "/Z7" ]
ldflags = [ "/DEBUG:FASTLINK" ]
} else {
cflags = [ "-g" ]
}
}
config("no_rtti") {
if (sanitize != "ASAN") { # -fsanitize=vptr requires RTTI
if (is_win) {
cflags_cc = [ "/GR-" ]
} else {
cflags_cc = [ "-fno-rtti" ]
}
}
}
config("release") {
if (is_win) {
cflags = [
"/O2",
"/Zc:inline",
]
ldflags = [
"/OPT:ICF",
"/OPT:REF",
]
} else {
cflags = [
"-O3",
]
if (!enable_bitcode) {
cflags += [
"-fdata-sections",
"-ffunction-sections",
]
}
if (is_mac || is_ios) {
ldflags = [ "-dead_strip" ]
} else {
ldflags = [ "-s", "-Wl,--gc-sections" ]
}
if (target_cpu == "wasm") {
# The compiler asks us to add an optimization flag to both cflags
# and ldflags to cut down on the local variables,
# for performance reasons.
# The "linking" step is the conversion to javascript.
ldflags += [ "-O3" ]
}
}
defines = [ "NDEBUG" ]
}
config("executable") {
if (is_android) {
ldflags = [
"-pie",
"-rdynamic",
]
} else if (is_mac) {
ldflags = [ "-Wl,-rpath,@loader_path/." ]
} else if (is_linux) {
ldflags = [
"-rdynamic",
"-Wl,-rpath,\$ORIGIN",
]
} else if (is_win) {
ldflags = [
"/SUBSYSTEM:CONSOLE", # Quiet "no subsystem specified; CONSOLE assumed".
"/INCREMENTAL:NO", # Quiet warnings about failing to incrementally link by never trying to.
]
}
}