1################################################################################ 2# Skylark macros 3################################################################################ 4 5is_bazel = not hasattr(native, "genmpm") 6 7def portable_select(select_dict, bazel_condition, default_condition): 8 """Replaces select() with a Bazel-friendly wrapper. 9 10 Args: 11 select_dict: Dictionary in the same format as select(). 12 Returns: 13 If Blaze platform, returns select() using select_dict. 14 If Bazel platform, returns dependencies for condition 15 bazel_condition, or empty list if none specified. 16 """ 17 if is_bazel: 18 return select_dict.get(bazel_condition, select_dict[default_condition]) 19 else: 20 return select(select_dict) 21 22def skia_select(conditions, results): 23 """Replaces select() for conditions [UNIX, ANDROID, IOS] 24 25 Args: 26 conditions: [CONDITION_UNIX, CONDITION_ANDROID, CONDITION_IOS] 27 results: [RESULT_UNIX, RESULT_ANDROID, RESULT_IOS] 28 Returns: 29 The result matching the platform condition. 30 """ 31 if len(conditions) != 3 or len(results) != 3: 32 fail("Must provide exactly 3 conditions and 3 results") 33 34 selector = {} 35 for i in range(3): 36 selector[conditions[i]] = results[i] 37 return portable_select(selector, conditions[2], conditions[0]) 38 39def skia_glob(srcs): 40 """Replaces glob() with a version that accepts a struct. 41 42 Args: 43 srcs: struct(include=[], exclude=[]) 44 Returns: 45 Equivalent of glob(srcs.include, exclude=srcs.exclude) 46 """ 47 if hasattr(srcs, "include"): 48 if hasattr(srcs, "exclude"): 49 return native.glob(srcs.include, exclude = srcs.exclude) 50 else: 51 return native.glob(srcs.include) 52 return [] 53 54################################################################################ 55## skia_{all,public}_hdrs() 56################################################################################ 57def skia_all_hdrs(): 58 return native.glob([ 59 "src/**/*.h", 60 "include/**/*.h", 61 "third_party/**/*.h", 62 ]) 63 64def skia_public_hdrs(): 65 return native.glob( 66 ["include/**/*.h"], 67 exclude = [ 68 "include/private/**/*", 69 ], 70 ) 71 72################################################################################ 73## skia_opts_srcs() 74################################################################################ 75# Intel 76SKIA_OPTS_SSE2 = "SSE2" 77 78SKIA_OPTS_SSSE3 = "SSSE3" 79 80SKIA_OPTS_SSE41 = "SSE41" 81 82SKIA_OPTS_SSE42 = "SSE42" 83 84SKIA_OPTS_AVX = "AVX" 85 86SKIA_OPTS_HSW = "HSW" 87 88# Arm 89SKIA_OPTS_NEON = "NEON" 90 91SKIA_OPTS_CRC32 = "CRC32" # arm64 92 93def opts_srcs(opts): 94 if opts == SKIA_OPTS_SSE2: 95 return native.glob([ 96 "src/opts/*_SSE2.cpp", 97 "src/opts/*_sse2.cpp", # No matches currently. 98 ]) 99 elif opts == SKIA_OPTS_SSSE3: 100 return native.glob([ 101 "src/opts/*_SSSE3.cpp", 102 "src/opts/*_ssse3.cpp", 103 ]) 104 elif opts == SKIA_OPTS_SSE41: 105 return native.glob([ 106 "src/opts/*_sse41.cpp", 107 ]) 108 elif opts == SKIA_OPTS_SSE42: 109 return native.glob([ 110 "src/opts/*_sse42.cpp", 111 ]) 112 elif opts == SKIA_OPTS_AVX: 113 return native.glob([ 114 "src/opts/*_avx.cpp", 115 ]) 116 elif opts == SKIA_OPTS_HSW: 117 return native.glob([ 118 "src/opts/*_hsw.cpp", 119 ]) 120 elif opts == SKIA_OPTS_NEON: 121 return native.glob([ 122 "src/opts/*_neon.cpp", 123 ]) 124 elif opts == SKIA_OPTS_CRC32: 125 return native.glob([ 126 "src/opts/*_crc32.cpp", 127 ]) 128 else: 129 fail("skia_opts_srcs parameter 'opts' must be one of SKIA_OPTS_*.") 130 131def opts_cflags(opts): 132 if opts == SKIA_OPTS_SSE2: 133 return ["-msse2"] 134 elif opts == SKIA_OPTS_SSSE3: 135 return ["-mssse3"] 136 elif opts == SKIA_OPTS_SSE41: 137 return ["-msse4.1"] 138 elif opts == SKIA_OPTS_SSE42: 139 return ["-msse4.2"] 140 elif opts == SKIA_OPTS_AVX: 141 return ["-mavx"] 142 elif opts == SKIA_OPTS_HSW: 143 return ["-mavx2", "-mf16c", "-mfma"] 144 elif opts == SKIA_OPTS_NEON: 145 return ["-mfpu=neon"] 146 elif opts == SKIA_OPTS_CRC32: 147 # NDK r11's Clang (3.8) doesn't pass along this -march setting correctly to an external 148 # assembler, so we do it manually with -Wa. This is just a bug, fixed in later Clangs. 149 return ["-march=armv8-a+crc", "-Wa,-march=armv8-a+crc"] 150 else: 151 return [] 152 153SKIA_CPU_ARM = "ARM" 154 155SKIA_CPU_ARM64 = "ARM64" 156 157SKIA_CPU_X86 = "X86" 158 159SKIA_CPU_OTHER = "OTHER" 160 161def opts_rest_srcs(cpu): 162 srcs = [] 163 if cpu == SKIA_CPU_ARM or cpu == SKIA_CPU_ARM64: 164 srcs += native.glob([ 165 "src/opts/*_arm.cpp", 166 "src/opts/SkBitmapProcState_opts_none.cpp", 167 ]) 168 if cpu == SKIA_CPU_ARM64: 169 # NEON doesn't need special flags to compile on ARM64. 170 srcs += native.glob([ 171 "src/opts/*_neon.cpp", 172 ]) 173 elif cpu == SKIA_CPU_X86: 174 srcs += native.glob([ 175 "src/opts/*_x86.cpp", 176 ]) 177 elif cpu == SKIA_CPU_OTHER: 178 srcs += native.glob([ 179 "src/opts/*_none.cpp", 180 ]) 181 else: 182 fail("opts_rest_srcs parameter 'cpu' must be one of " + 183 "SKIA_CPU_{ARM,ARM64,X86,OTHER}.") 184 return srcs 185 186def skia_opts_deps(cpu): 187 res = [":opts_rest"] 188 189 if cpu == SKIA_CPU_ARM: 190 res += [":opts_neon"] 191 192 if cpu == SKIA_CPU_ARM64: 193 res += [":opts_crc32"] 194 195 if cpu == SKIA_CPU_X86: 196 res += [ 197 ":opts_sse2", 198 ":opts_ssse3", 199 ":opts_sse41", 200 ":opts_sse42", 201 ":opts_avx", 202 ":opts_hsw", 203 ] 204 205 return res 206 207################################################################################ 208## BASE_SRCS 209################################################################################ 210 211# All platform-independent SRCS. 212BASE_SRCS_ALL = struct( 213 include = [ 214 "include/private/**/*.h", 215 "src/**/*.h", 216 "src/**/*.cpp", 217 "src/**/*.inc", 218 ], 219 exclude = [ 220 # Exclude platform-dependent files. 221 "src/codec/*", 222 "src/device/xps/*", # Windows-only. Move to ports? 223 "src/doc/*_XPS.cpp", # Windows-only. Move to ports? 224 "src/gpu/gl/android/*", 225 "src/gpu/gl/egl/*", 226 "src/gpu/gl/glfw/*", 227 "src/gpu/gl/glx/*", 228 "src/gpu/gl/iOS/*", 229 "src/gpu/gl/mac/*", 230 "src/gpu/gl/win/*", 231 "src/opts/**/*", 232 "src/ports/**/*", 233 "src/utils/android/**/*", 234 "src/utils/mac/**/*", 235 "src/utils/win/**/*", 236 237 # Exclude multiple definitions. 238 "src/core/SkPicture_none.cpp", 239 "src/gpu/GrPathRendering_none.cpp", 240 "src/gpu/ccpr/GrCoverageCountingPathRenderer_none.cpp", 241 "src/gpu/gl/GrGLMakeNativeInterface_none.cpp", 242 "src/pdf/SkDocument_PDF_None.cpp", # We use src/pdf/SkPDFDocument.cpp. 243 244 # Exclude files that don't compile everywhere. 245 "src/svg/**/*", # Depends on xml, SkJpegCodec, and SkPngCodec. 246 "src/xml/**/*", # Avoid dragging in expat when not needed. 247 248 # Conflicting dependencies among Lua versions. See cl/107087297. 249 "src/utils/SkLua*", 250 251 # Currently exclude all vulkan specific files 252 "src/gpu/vk/*", 253 254 # Defines main. 255 "src/sksl/SkSLMain.cpp", 256 257 # Only used to regenerate the lexer 258 "src/sksl/lex/*", 259 260 # Atlas text 261 "src/atlastext/*", 262 263 # Compute backend not yet even hooked into Skia. 264 "src/compute/**/*", 265 ], 266) 267 268def codec_srcs(limited): 269 """Sources for the codecs. Excludes Raw, and Ico, Webp, and Png if limited.""" 270 271 # TODO: Enable wuffs in Google3 272 exclude = ["src/codec/SkWuffsCodec.cpp", "src/codec/*Raw*.cpp"] 273 if limited: 274 exclude += [ 275 "src/codec/*Ico*.cpp", 276 "src/codec/*Webp*.cpp", 277 "src/codec/*Png*", 278 ] 279 return native.glob(["src/codec/*.cpp", "third_party/etc1/*.cpp", "third_party/gif/*.cpp"], exclude = exclude) 280 281# Platform-dependent SRCS for google3-default platform. 282BASE_SRCS_UNIX = struct( 283 include = [ 284 "src/gpu/gl/GrGLMakeNativeInterface_none.cpp", 285 "src/ports/**/*.cpp", 286 "src/ports/**/*.h", 287 ], 288 exclude = [ 289 "src/ports/*CG*", 290 "src/ports/*WIC*", 291 "src/ports/*android*", 292 "src/ports/*chromium*", 293 "src/ports/*mac*", 294 "src/ports/*mozalloc*", 295 "src/ports/*nacl*", 296 "src/ports/*win*", 297 "src/ports/SkFontMgr_custom_directory_factory.cpp", 298 "src/ports/SkFontMgr_custom_embedded_factory.cpp", 299 "src/ports/SkFontMgr_custom_empty_factory.cpp", 300 "src/ports/SkFontMgr_empty_factory.cpp", 301 "src/ports/SkFontMgr_fontconfig.cpp", 302 "src/ports/SkFontMgr_fontconfig_factory.cpp", 303 "src/ports/SkFontMgr_fuchsia.cpp", 304 "src/ports/SkImageGenerator_none.cpp", 305 "src/ports/SkTLS_none.cpp", 306 ], 307) 308 309# Platform-dependent SRCS for google3-default Android. 310BASE_SRCS_ANDROID = struct( 311 include = [ 312 "src/gpu/gl/android/*.cpp", 313 "src/ports/**/*.cpp", 314 "src/ports/**/*.h", 315 ], 316 exclude = [ 317 "src/ports/*CG*", 318 "src/ports/*FontConfig*", 319 "src/ports/*WIC*", 320 "src/ports/*chromium*", 321 "src/ports/*fontconfig*", 322 "src/ports/*mac*", 323 "src/ports/*mozalloc*", 324 "src/ports/*nacl*", 325 "src/ports/*win*", 326 "src/ports/SkDebug_stdio.cpp", 327 "src/ports/SkFontMgr_custom_directory_factory.cpp", 328 "src/ports/SkFontMgr_custom_embedded_factory.cpp", 329 "src/ports/SkFontMgr_custom_empty_factory.cpp", 330 "src/ports/SkFontMgr_empty_factory.cpp", 331 "src/ports/SkFontMgr_fuchsia.cpp", 332 "src/ports/SkImageGenerator_none.cpp", 333 "src/ports/SkTLS_none.cpp", 334 ], 335) 336 337# Platform-dependent SRCS for google3-default iOS. 338BASE_SRCS_IOS = struct( 339 include = [ 340 "src/gpu/gl/iOS/GrGLMakeNativeInterface_iOS.cpp", 341 "src/ports/**/*.cpp", 342 "src/ports/**/*.h", 343 "src/utils/mac/*.cpp", 344 ], 345 exclude = [ 346 "src/ports/*FontConfig*", 347 "src/ports/*FreeType*", 348 "src/ports/*WIC*", 349 "src/ports/*android*", 350 "src/ports/*chromium*", 351 "src/ports/*fontconfig*", 352 "src/ports/*mozalloc*", 353 "src/ports/*nacl*", 354 "src/ports/*win*", 355 "src/ports/SkFontMgr_custom.cpp", 356 "src/ports/SkFontMgr_custom_directory.cpp", 357 "src/ports/SkFontMgr_custom_embedded.cpp", 358 "src/ports/SkFontMgr_custom_empty.cpp", 359 "src/ports/SkFontMgr_custom_directory_factory.cpp", 360 "src/ports/SkFontMgr_custom_embedded_factory.cpp", 361 "src/ports/SkFontMgr_custom_empty_factory.cpp", 362 "src/ports/SkFontMgr_empty_factory.cpp", 363 "src/ports/SkFontMgr_fuchsia.cpp", 364 "src/ports/SkImageGenerator_none.cpp", 365 "src/ports/SkTLS_none.cpp", 366 ], 367) 368 369################################################################################ 370## skia_srcs() 371################################################################################ 372def skia_srcs(os_conditions): 373 """Sources to be compiled into the skia library.""" 374 return skia_glob(BASE_SRCS_ALL) + skia_select( 375 os_conditions, 376 [ 377 skia_glob(BASE_SRCS_UNIX), 378 skia_glob(BASE_SRCS_ANDROID), 379 skia_glob(BASE_SRCS_IOS), 380 ], 381 ) 382 383################################################################################ 384## INCLUDES 385################################################################################ 386 387# Includes needed by Skia implementation. Not public includes. 388INCLUDES = [ 389 "include/android", 390 "include/c", 391 "include/codec", 392 "include/config", 393 "include/core", 394 "include/docs", 395 "include/effects", 396 "include/encode", 397 "include/gpu", 398 "include/pathops", 399 "include/ports", 400 "include/private", 401 "include/utils", 402 "include/utils/mac", 403 "src/codec", 404 "src/core", 405 "src/gpu", 406 "src/image", 407 "src/images", 408 "src/lazy", 409 "src/opts", 410 "src/pdf", 411 "src/ports", 412 "src/sfnt", 413 "src/shaders", 414 "src/shaders/gradients", 415 "src/sksl", 416 "src/utils", 417 "third_party/etc1", 418 "third_party/gif", 419] 420 421################################################################################ 422## DM_SRCS 423################################################################################ 424 425DM_SRCS_ALL = struct( 426 include = [ 427 "dm/*.cpp", 428 "dm/*.h", 429 "experimental/pipe/*.cpp", 430 "experimental/pipe/*.h", 431 "experimental/svg/model/*.cpp", 432 "experimental/svg/model/*.h", 433 "gm/*.cpp", 434 "gm/*.h", 435 "src/xml/*.cpp", 436 "tests/*.cpp", 437 "tests/*.h", 438 "tools/ios_utils.h", 439 "tools/BinaryAsset.h", 440 "tools/BigPathBench.inc", 441 "tools/CrashHandler.cpp", 442 "tools/CrashHandler.h", 443 "tools/DDLPromiseImageHelper.cpp", 444 "tools/DDLPromiseImageHelper.h", 445 "tools/DDLTileHelper.cpp", 446 "tools/DDLTileHelper.h", 447 "tools/ProcStats.cpp", 448 "tools/ProcStats.h", 449 "tools/Registry.h", 450 "tools/ResourceFactory.h", 451 "tools/Resources.cpp", 452 "tools/Resources.h", 453 "tools/UrlDataManager.cpp", 454 "tools/UrlDataManager.h", 455 "tools/debugger/*.cpp", 456 "tools/debugger/*.h", 457 "tools/flags/*.cpp", 458 "tools/flags/*.h", 459 "tools/fonts/SkRandomScalerContext.cpp", 460 "tools/fonts/SkRandomScalerContext.h", 461 "tools/fonts/SkTestFontMgr.cpp", 462 "tools/fonts/SkTestFontMgr.h", 463 "tools/fonts/SkTestSVGTypeface.cpp", 464 "tools/fonts/SkTestSVGTypeface.h", 465 "tools/fonts/SkTestTypeface.cpp", 466 "tools/fonts/SkTestTypeface.h", 467 "tools/fonts/sk_tool_utils_font.cpp", 468 "tools/fonts/test_font_monospace.inc", 469 "tools/fonts/test_font_sans_serif.inc", 470 "tools/fonts/test_font_serif.inc", 471 "tools/fonts/test_font_index.inc", 472 "tools/gpu/**/*.cpp", 473 "tools/gpu/**/*.h", 474 "tools/random_parse_path.cpp", 475 "tools/random_parse_path.h", 476 "tools/sk_pixel_iter.h", 477 "tools/sk_tool_utils.cpp", 478 "tools/sk_tool_utils.h", 479 "tools/timer/*.cpp", 480 "tools/timer/*.h", 481 "tools/trace/*.cpp", 482 "tools/trace/*.h", 483 ], 484 exclude = [ 485 "gm/cgms.cpp", 486 "tests/FontMgrAndroidParserTest.cpp", # Android-only. 487 "tests/FontMgrFontConfigTest.cpp", # FontConfig-only. 488 "tests/skia_test.cpp", # Old main. 489 "tools/gpu/atlastext/*", 490 "tools/gpu/gl/angle/*", 491 "tools/gpu/gl/egl/*", 492 "tools/gpu/gl/glx/*", 493 "tools/gpu/gl/iOS/*", 494 "tools/gpu/gl/mac/*", 495 "tools/gpu/gl/win/*", 496 "tools/timer/SysTimer_mach.cpp", 497 "tools/timer/SysTimer_windows.cpp", 498 ], 499) 500 501################################################################################ 502## dm_srcs() 503################################################################################ 504 505def dm_srcs(os_conditions): 506 """Sources for the dm binary for the specified os.""" 507 return skia_glob(DM_SRCS_ALL) + skia_select( 508 os_conditions, 509 [ 510 [], 511 ["tests/FontMgrAndroidParserTest.cpp"], 512 [], 513 ], 514 ) 515 516################################################################################ 517## DM_INCLUDES 518################################################################################ 519 520DM_INCLUDES = [ 521 "dm", 522 "gm", 523 "experimental/pipe", 524 "experimental/svg/model", 525 "src/codec", 526 "src/core", 527 "src/effects", 528 "src/fonts", 529 "src/images", 530 "src/pathops", 531 "src/pipe/utils", 532 "src/ports", 533 "src/shaders", 534 "src/shaders/gradients", 535 "src/xml", 536 "tests", 537 "tools", 538 "tools/debugger", 539 "tools/flags", 540 "tools/fonts", 541 "tools/gpu", 542 "tools/timer", 543 "tools/trace", 544] 545 546################################################################################ 547## DM_ARGS 548################################################################################ 549 550def DM_ARGS(asan): 551 source = ["gm", "image", "lottie"] 552 553 # TODO(benjaminwagner): f16, pic-8888, serialize-8888, and tiles_rt-8888 fail. 554 config = ["565", "8888", "pdf"] 555 match = ["~Codec_78329453"] 556 return (["--src"] + source + ["--config"] + config + ["--nonativeFonts"] + 557 ["--match"] + match) 558 559################################################################################ 560## COPTS 561################################################################################ 562 563def base_copts(os_conditions): 564 return skia_select( 565 os_conditions, 566 [ 567 # UNIX 568 [ 569 "-Wno-implicit-fallthrough", # Some intentional fallthrough. 570 # Internal use of deprecated methods. :( 571 "-Wno-deprecated-declarations", 572 # TODO(kjlubick) 573 "-Wno-self-assign", # Spurious warning in tests/PathOpsDVectorTest.cpp? 574 ], 575 # ANDROID 576 [ 577 "-Wno-implicit-fallthrough", # Some intentional fallthrough. 578 # 'GrResourceCache' declared with greater visibility than the 579 # type of its field 'GrResourceCache::fPurgeableQueue'... bogus. 580 "-Wno-error=attributes", 581 ], 582 # IOS 583 [ 584 "-Wno-implicit-fallthrough", # Some intentional fallthrough. 585 ], 586 ], 587 ) 588 589################################################################################ 590## DEFINES 591################################################################################ 592 593def base_defines(os_conditions): 594 return [ 595 # Chrome DEFINES. 596 "SK_USE_FREETYPE_EMBOLDEN", 597 # Turn on a few Google3-specific build fixes. 598 "SK_BUILD_FOR_GOOGLE3", 599 # Required for building dm. 600 "GR_TEST_UTILS", 601 # Staging flags for API changes 602 # Should remove after we update golden images 603 "SK_WEBP_ENCODER_USE_DEFAULT_METHOD", 604 # Experiment to diagnose image diffs in Google3 605 "SK_DISABLE_LOWP_RASTER_PIPELINE", 606 # JPEG is in codec_limited 607 "SK_HAS_JPEG_LIBRARY", 608 ] + skia_select( 609 os_conditions, 610 [ 611 # UNIX 612 [ 613 "PNG_SKIP_SETJMP_CHECK", 614 "SK_BUILD_FOR_UNIX", 615 "SK_SAMPLES_FOR_X", 616 "SK_PDF_USE_SFNTLY", 617 "SK_HAS_PNG_LIBRARY", 618 "SK_HAS_WEBP_LIBRARY", 619 ], 620 # ANDROID 621 [ 622 "SK_BUILD_FOR_ANDROID", 623 "SK_HAS_PNG_LIBRARY", 624 "SK_HAS_WEBP_LIBRARY", 625 ], 626 # IOS 627 [ 628 "SK_BUILD_FOR_IOS", 629 "SK_BUILD_NO_OPTS", 630 "SKNX_NO_SIMD", 631 ], 632 ], 633 ) 634 635################################################################################ 636## LINKOPTS 637################################################################################ 638 639def base_linkopts(os_conditions): 640 return [ 641 "-ldl", 642 ] + skia_select( 643 os_conditions, 644 [ 645 # UNIX 646 [], 647 # ANDROID 648 [ 649 "-lEGL", 650 "-lGLESv2", 651 ], 652 # IOS 653 [ 654 "-framework CoreFoundation", 655 "-framework CoreGraphics", 656 "-framework CoreText", 657 "-framework ImageIO", 658 "-framework MobileCoreServices", 659 ], 660 ], 661 ) 662 663################################################################################ 664## skottie_tool 665################################################################################ 666 667SKOTTIE_TOOL_INCLUDES = [ 668 "modules/skottie/utils", 669 "tools/flags", 670] 671 672SKOTTIE_TOOL_SRCS = [ 673 "modules/skottie/src/SkottieTool.cpp", 674 "modules/skottie/utils/SkottieUtils.cpp", 675 "modules/skottie/utils/SkottieUtils.h", 676 # TODO(benjaminwagner): Add "flags" target. 677 "tools/flags/SkCommandLineFlags.cpp", 678 "tools/flags/SkCommandLineFlags.h", 679] 680 681################################################################################ 682## SkShaper 683################################################################################ 684 685SKSHAPER_INCLUDES = [ 686 "modules/skshaper/include", 687] 688 689SKSHAPER_HARFBUZZ_SRCS = [ 690 "modules/skshaper/include/SkShaper.h", 691 "modules/skshaper/src/SkShaper.cpp", 692 "modules/skshaper/src/SkShaper_harfbuzz.cpp", 693 "modules/skshaper/src/SkShaper_primitive.cpp", 694] 695 696SKSHAPER_PRIMITIVE_SRCS = [ 697 "modules/skshaper/include/SkShaper.h", 698 "modules/skshaper/src/SkShaper.cpp", 699 "modules/skshaper/src/SkShaper_primitive.cpp", 700] 701