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## BASE_SRCS 56################################################################################ 57 58# All platform-independent SRCS. 59BASE_SRCS_ALL = struct( 60 include = [ 61 "include/private/**/*.h", 62 "src/**/*.h", 63 "src/**/*.cpp", 64 "src/**/*.inc", 65 66 # Third Party 67 "third_party/etc1/*.cpp", 68 "third_party/etc1/*.h", 69 "third_party/gif/*.cpp", 70 "third_party/gif/*.h", 71 ], 72 exclude = [ 73 # Exclude platform-dependent files. 74 "src/android/*", 75 "src/codec/*", 76 "src/device/xps/*", # Windows-only. Move to ports? 77 "src/doc/*_XPS.cpp", # Windows-only. Move to ports? 78 "src/gpu/gl/android/*", 79 "src/gpu/gl/egl/*", 80 "src/gpu/gl/glfw/*", 81 "src/gpu/gl/glx/*", 82 "src/gpu/gl/iOS/*", 83 "src/gpu/gl/mac/*", 84 "src/gpu/gl/win/*", 85 "src/images/*", 86 "src/jumper/*", 87 "src/opts/**/*", 88 "src/ports/**/*", 89 "src/utils/android/**/*", 90 "src/utils/mac/**/*", 91 "src/utils/SkThreadUtils_win.cpp", # Windows-only. Move to ports? 92 "src/utils/win/**/*", 93 "src/views/sdl/*", 94 "src/views/win/*", 95 "src/views/unix/*", 96 97 # Exclude multiple definitions. 98 # TODO(mtklein): Move to opts? 99 "src/pdf/SkDocument_PDF_None.cpp", # We use src/pdf/SkPDFDocument.cpp. 100 "src/gpu/gl/GrGLCreateNativeInterface_none.cpp", 101 "src/gpu/gl/GrGLDefaultInterface_native.cpp", 102 "src/gpu/gl/GrGLDefaultInterface_none.cpp", 103 104 # Exclude files that don't compile with the current DEFINES. 105 "src/gpu/gl/mesa/*", # Requires SK_MESA define. 106 "src/svg/**/*", # Depends on XML. 107 "src/xml/**/*", 108 109 # Conflicting dependencies among Lua versions. See cl/107087297. 110 "src/utils/SkLua*", 111 112 # Not used. 113 "src/views/**/*", 114 115 # Currently exclude all vulkan specific files 116 "src/gpu/vk/*", 117 118 # Defines main. 119 "src/sksl/SkSLMain.cpp", 120 ], 121) 122 123# Platform-dependent SRCS for google3-default platform. 124BASE_SRCS_UNIX = struct( 125 include = [ 126 "src/android/*", 127 "src/codec/*", 128 "src/gpu/gl/GrGLDefaultInterface_none.cpp", 129 "src/images/*", 130 "src/opts/**/*.cpp", 131 "src/opts/**/*.h", 132 "src/ports/**/*.cpp", 133 "src/ports/**/*.h", 134 ], 135 exclude = [ 136 "src/opts/opts_check_x86.cpp", 137 "src/opts/*arm*", 138 "src/opts/*mips*", 139 "src/opts/*NEON*", 140 "src/opts/*neon*", 141 # Included in :opts_sse2 library. 142 "src/opts/*SSE2*", 143 "src/opts/*sse2*", 144 # Included in :opts_ssse3 library. 145 "src/opts/*SSSE3*", 146 "src/opts/*ssse3*", 147 # Included in :opts_sse4 library. 148 "src/opts/*SSE4*", 149 "src/opts/*sse4*", 150 # Included in :opts_avx or :opts_hsw 151 "src/opts/*avx*", 152 "src/opts/*hsw*", 153 "src/opts/SkBitmapProcState_opts_none.cpp", 154 "src/opts/SkBlitMask_opts_none.cpp", 155 "src/opts/SkBlitRow_opts_none.cpp", 156 "src/ports/*CG*", 157 "src/ports/*WIC*", 158 "src/ports/*android*", 159 "src/ports/*chromium*", 160 "src/ports/*mac*", 161 "src/ports/*mozalloc*", 162 "src/ports/*nacl*", 163 "src/ports/*win*", 164 "src/ports/SkFontMgr_custom_directory_factory.cpp", 165 "src/ports/SkFontMgr_custom_embedded_factory.cpp", 166 "src/ports/SkFontMgr_custom_empty_factory.cpp", 167 "src/ports/SkFontMgr_empty_factory.cpp", 168 "src/ports/SkFontMgr_fontconfig.cpp", 169 "src/ports/SkFontMgr_fontconfig_factory.cpp", 170 "src/ports/SkGlobalInitialization_none.cpp", 171 "src/ports/SkImageEncoder_none.cpp", 172 "src/ports/SkImageGenerator_none.cpp", 173 "src/ports/SkTLS_none.cpp", 174 ], 175) 176 177# Platform-dependent SRCS for google3-default Android. 178BASE_SRCS_ANDROID = struct( 179 include = [ 180 "src/android/*", 181 "src/codec/*", 182 "src/gpu/gl/GrGLDefaultInterface_none.cpp", 183 "src/images/*", 184 # TODO(benjaminwagner): Figure out how to compile with EGL. 185 "src/opts/**/*.cpp", 186 "src/opts/**/*.h", 187 "src/ports/**/*.cpp", 188 "src/ports/**/*.h", 189 ], 190 exclude = [ 191 "src/opts/*mips*", 192 "src/opts/*SSE2*", 193 "src/opts/*SSSE3*", 194 "src/opts/*ssse3*", 195 "src/opts/*SSE4*", 196 "src/opts/*sse4*", 197 "src/opts/*avx*", 198 "src/opts/*hsw*", 199 "src/opts/*x86*", 200 "src/opts/SkBlitMask_opts_none.cpp", 201 "src/opts/SkBlitRow_opts_none.cpp", 202 "src/ports/*CG*", 203 "src/ports/*FontConfig*", 204 "src/ports/*WIC*", 205 "src/ports/*chromium*", 206 "src/ports/*fontconfig*", 207 "src/ports/*mac*", 208 "src/ports/*mozalloc*", 209 "src/ports/*nacl*", 210 "src/ports/*win*", 211 "src/ports/SkDebug_stdio.cpp", 212 "src/ports/SkFontMgr_custom_directory_factory.cpp", 213 "src/ports/SkFontMgr_custom_embedded_factory.cpp", 214 "src/ports/SkFontMgr_custom_empty_factory.cpp", 215 "src/ports/SkFontMgr_empty_factory.cpp", 216 "src/ports/SkGlobalInitialization_none.cpp", 217 "src/ports/SkImageEncoder_none.cpp", 218 "src/ports/SkImageGenerator_none.cpp", 219 "src/ports/SkTLS_none.cpp", 220 ], 221) 222 223# Platform-dependent SRCS for google3-default iOS. 224BASE_SRCS_IOS = struct( 225 include = [ 226 "src/android/*", 227 "src/codec/*", 228 "src/gpu/gl/GrGLDefaultInterface_native.cpp", 229 "src/gpu/gl/iOS/GrGLCreateNativeInterface_iOS.cpp", 230 "src/opts/**/*.cpp", 231 "src/opts/**/*.h", 232 "src/ports/**/*.cpp", 233 "src/ports/**/*.h", 234 "src/utils/mac/*.cpp", 235 ], 236 exclude = [ 237 "src/codec/*Ico*.cpp", 238 "src/codec/*Webp*.cpp", 239 "src/codec/*Png*", 240 "src/codec/*Raw*.cpp", 241 "src/opts/*mips*", 242 "src/opts/*NEON*", 243 "src/opts/*neon*", 244 "src/opts/*SSE2*", 245 "src/opts/*SSSE3*", 246 "src/opts/*ssse3*", 247 "src/opts/*SSE4*", 248 "src/opts/*sse4*", 249 "src/opts/*avx*", 250 "src/opts/*hsw*", 251 "src/opts/*x86*", 252 "src/opts/SkBlitMask_opts_arm*.cpp", 253 "src/opts/SkBlitRow_opts_arm*.cpp", 254 "src/ports/*CG*", 255 "src/ports/*FontConfig*", 256 "src/ports/*FreeType*", 257 "src/ports/*WIC*", 258 "src/ports/*android*", 259 "src/ports/*chromium*", 260 "src/ports/*fontconfig*", 261 "src/ports/*mozalloc*", 262 "src/ports/*nacl*", 263 "src/ports/*win*", 264 "src/ports/SkFontMgr_custom.cpp", 265 "src/ports/SkFontMgr_custom_directory.cpp", 266 "src/ports/SkFontMgr_custom_embedded.cpp", 267 "src/ports/SkFontMgr_custom_empty.cpp", 268 "src/ports/SkFontMgr_custom_directory_factory.cpp", 269 "src/ports/SkFontMgr_custom_embedded_factory.cpp", 270 "src/ports/SkFontMgr_custom_empty_factory.cpp", 271 "src/ports/SkFontMgr_empty_factory.cpp", 272 "src/ports/SkGlobalInitialization_none.cpp", 273 "src/ports/SkImageGenerator_none.cpp", 274 "src/ports/SkTLS_none.cpp", 275 ], 276) 277 278################################################################################ 279## skia_{all,public}_hdrs() 280################################################################################ 281def skia_all_hdrs(): 282 return native.glob(["src/**/*.h", "include/**/*.h"]) 283 284def skia_public_hdrs(): 285 return native.glob(["include/**/*.h"], 286 exclude=[ 287 "include/private/**/*.h", 288 "include/views/**/*", # Not used. 289 ]) 290 291################################################################################ 292## skia_opts_srcs() 293################################################################################ 294# Intel 295SKIA_OPTS_SSE2 = "SSE2" 296 297SKIA_OPTS_SSSE3 = "SSSE3" 298 299SKIA_OPTS_SSE4 = "SSE4" 300 301SKIA_OPTS_AVX = "AVX" 302 303SKIA_OPTS_HSW = "HSW" 304 305# Arm 306SKIA_OPTS_ARMV7 = "ARMV7" 307 308SKIA_OPTS_NEON = "NEON" 309 310SKIA_OPTS_ARM64 = "ARM64" 311 312SKIA_OPTS_CRC32 = "CRC32" # arm64 313 314# Other 315SKIA_OPTS_NONE = "NONE" # not x86, arm, or arm64 316 317def skia_opts_srcs(opts): 318 if opts == SKIA_OPTS_SSE2: 319 return native.glob([ 320 "src/opts/*SSE2*.cpp", 321 "src/opts/*sse2*.cpp", 322 ]) 323 elif opts == SKIA_OPTS_SSSE3: 324 return native.glob([ 325 "src/opts/*SSSE3*.cpp", 326 "src/opts/*ssse3*.cpp", 327 ]) 328 elif opts == SKIA_OPTS_SSE4: 329 return native.glob([ 330 "src/opts/*SSE4*.cpp", 331 "src/opts/*sse4*.cpp", 332 ]) 333 elif opts == SKIA_OPTS_AVX: 334 return native.glob([ 335 "src/opts/*_avx.cpp", 336 ]) 337 elif opts == SKIA_OPTS_HSW: 338 return native.glob([ 339 "src/opts/*_hsw.cpp", 340 ]) 341 elif opts == SKIA_OPTS_ARMV7: 342 return native.glob([ 343 "src/opts/*_arm.cpp", 344 ]) 345 elif opts == SKIA_OPTS_NEON: 346 return native.glob([ 347 "src/opts/*_neon.cpp", 348 ]) 349 elif opts == SKIA_OPTS_CRC32: 350 return native.glob([ 351 "src/opts/*_crc32.cpp", 352 ]) 353 elif opts == SKIA_OPTS_NONE: 354 return native.glob([ 355 "src/opts/*_none.cpp", 356 ]) 357 else: 358 fail("skia_opts_srcs parameter 'opts' must be one of SKIA_OPTS_*.") 359 360def skia_opts_cflags(opts): 361 if opts == SKIA_OPTS_SSE2: 362 return ["-msse2"] 363 elif opts == SKIA_OPTS_SSSE3: 364 return ["-mssse3"] 365 elif opts == SKIA_OPTS_SSE4: 366 return ["-msse4"] 367 elif opts == SKIA_OPTS_AVX: 368 return ["-mavx"] 369 elif opts == SKIA_OPTS_HSW: 370 return ["-mavx2", "-mbmi", "-mbmi2", "-mf16c", "-mfma"] 371 elif opts == SKIA_OPTS_CRC32: 372 return ["-march=armv8-a+crc"] 373 else: 374 return [] 375 376################################################################################ 377## skia_srcs() 378################################################################################ 379SKIA_OS_UNIX = "UNIX" 380 381SKIA_OS_ANDROID = "ANDROID" 382 383SKIA_OS_IOS = "IOS" 384 385SKIA_CPU_UNSPECIFIED = "UNSPECIFIED" 386 387SKIA_CPU_PPC = "PPC" 388 389def skia_srcs(os=SKIA_OS_UNIX, cpu=SKIA_CPU_UNSPECIFIED): 390 """Sources to be compiled into the skia library.""" 391 srcs = skia_glob(BASE_SRCS_ALL) 392 if os == SKIA_OS_IOS: 393 if cpu != SKIA_CPU_UNSPECIFIED: 394 fail("Do not specify IOS and a cpu.") 395 srcs = srcs + skia_glob(BASE_SRCS_IOS) 396 elif os == SKIA_OS_ANDROID: 397 if cpu != SKIA_CPU_UNSPECIFIED: 398 fail("Do not specify ANDROID and a cpu.") 399 srcs = srcs + skia_glob(BASE_SRCS_ANDROID) 400 elif os == SKIA_OS_UNIX: 401 if cpu == SKIA_CPU_UNSPECIFIED: 402 srcs = srcs + ["src/opts/opts_check_x86.cpp"] + skia_glob(BASE_SRCS_UNIX) 403 elif cpu == SKIA_CPU_PPC: 404 srcs = srcs + skia_glob(BASE_SRCS_UNIX) 405 else: 406 fail("cpu must be one of SKIA_CPU_*") 407 else: 408 fail("skia_srcs parameter 'os' must be one of SKIA_OS_{UNIX,ANDROID,IOS}.") 409 return srcs 410 411################################################################################ 412## INCLUDES 413################################################################################ 414 415# Includes needed by Skia implementation. Not public includes. 416INCLUDES = [ 417 "include/android", 418 "include/c", 419 "include/client/android", 420 "include/codec", 421 "include/config", 422 "include/core", 423 "include/effects", 424 "include/gpu", 425 "include/images", 426 "include/pathops", 427 "include/pipe", 428 "include/ports", 429 "include/private", 430 "include/utils", 431 "include/utils/mac", 432 "include/utils/win", 433 "include/svg", 434 "include/xml", 435 "src/codec", 436 "src/core", 437 "src/gpu", 438 "src/image", 439 "src/lazy", 440 "src/opts", 441 "src/ports", 442 "src/pdf", 443 "src/sfnt", 444 "src/sksl", 445 "src/utils", 446 "third_party/etc1", 447 "third_party/gif", 448] 449 450################################################################################ 451## DM_SRCS 452################################################################################ 453 454DM_SRCS_ALL = struct( 455 include = [ 456 "dm/*.cpp", 457 "dm/*.h", 458 "gm/*.c", 459 "gm/*.cpp", 460 "gm/*.h", 461 "tests/*.cpp", 462 "tests/*.h", 463 "tools/BigPathBench.inc", 464 "tools/CrashHandler.cpp", 465 "tools/CrashHandler.h", 466 "tools/ProcStats.cpp", 467 "tools/ProcStats.h", 468 "tools/Resources.cpp", 469 "tools/Resources.h", 470 "tools/SkJSONCPP.h", 471 "tools/UrlDataManager.cpp", 472 "tools/UrlDataManager.h", 473 "tools/debugger/*.cpp", 474 "tools/debugger/*.h", 475 "tools/flags/*.cpp", 476 "tools/flags/*.h", 477 "tools/gpu/**/*.cpp", 478 "tools/gpu/**/*.h", 479 "tools/picture_utils.cpp", 480 "tools/picture_utils.h", 481 "tools/random_parse_path.cpp", 482 "tools/random_parse_path.h", 483 "tools/sk_tool_utils.cpp", 484 "tools/sk_tool_utils.h", 485 "tools/sk_tool_utils_flags.h", 486 "tools/sk_tool_utils_font.cpp", 487 "tools/test_font_monospace.inc", 488 "tools/test_font_sans_serif.inc", 489 "tools/test_font_serif.inc", 490 "tools/test_font_index.inc", 491 "tools/timer/*.cpp", 492 "tools/timer/*.h", 493 ], 494 exclude = [ 495 "tests/FontMgrAndroidParserTest.cpp", # Android-only. 496 "tests/skia_test.cpp", # Old main. 497 "tests/SkpSkGrTest.cpp", # Alternate main. 498 "tests/SVGDeviceTest.cpp", 499 "tools/gpu/gl/angle/*", 500 "tools/gpu/gl/egl/*", 501 "tools/gpu/gl/glx/*", 502 "tools/gpu/gl/iOS/*", 503 "tools/gpu/gl/mac/*", 504 "tools/gpu/gl/mesa/*", 505 "tools/gpu/gl/win/*", 506 "tools/timer/SysTimer_mach.cpp", 507 "tools/timer/SysTimer_windows.cpp", 508 ], 509) 510 511################################################################################ 512## dm_srcs() 513################################################################################ 514# SKIA_OS_* definitions can be found above. 515 516def dm_srcs(os): 517 """Sources for the dm binary for the specified os.""" 518 srcs = skia_glob(DM_SRCS_ALL) 519 # TODO(benjaminwagner): None of the CreatePlatformGLContext_*.cpp files exist. 520 # TODO(jwg): Remove the globs if possible, they only select single files. 521 if os == SKIA_OS_IOS: 522 srcs = srcs + native.glob(["tools/gpu/iOS/CreatePlatformGLContext_iOS.cpp"]) 523 elif os == SKIA_OS_ANDROID: 524 srcs = srcs + native.glob([ 525 "tests/FontMgrAndroidParserTest.cpp", 526 # TODO(benjaminwagner): Figure out how to compile with EGL. 527 "tools/gpu/gl/CreatePlatformGLContext_none.cpp", 528 ]) 529 elif os == SKIA_OS_UNIX: 530 srcs = srcs + native.glob(["tools/gpu/gl/CreatePlatformGLContext_none.cpp"]) 531 else: 532 fail("dm_srcs parameter 'os' must be one of SKIA_OS_{UNIX,ANDROID,IOS}.") 533 return srcs 534 535################################################################################ 536## DM_INCLUDES 537################################################################################ 538 539DM_INCLUDES = [ 540 "dm", 541 "gm", 542 "experimental/svg/model", 543 "src/codec", 544 "src/core", 545 "src/effects", 546 "src/effects/gradients", 547 "src/fonts", 548 "src/images", 549 "src/pathops", 550 "src/pipe/utils", 551 "src/ports", 552 "src/xml", 553 "tests", 554 "tools", 555 "tools/debugger", 556 "tools/flags", 557 "tools/gpu", 558 "tools/timer", 559] 560 561################################################################################ 562## DM_ARGS 563################################################################################ 564 565def DM_ARGS(asan): 566 source = ["tests", "gm", "image"] 567 # TODO(benjaminwagner): f16 and serialize-8888 fail. 568 config = ["565", "8888", "pdf", "srgb", "tiles_rt", "pic"] 569 # TODO(mtklein): maybe investigate why these fail? 570 match = [ 571 "~Canvas", 572 "~Codec", 573 "~Codec_Dimensions", 574 "~Codec_stripes", 575 "~FontMgr", 576 "~PaintBreakText", 577 "~RecordDraw_TextBounds", 578 "~Scalar", 579 "~skps", 580 "~Stream", 581 ] 582 if asan: 583 # The ASAN we use with Bazel has some strict checks, so omit tests that 584 # trigger them. 585 match += [ 586 "~clippedcubic2", 587 "~conicpaths", 588 "~^gradients", 589 "~Math", 590 "~Matrix", 591 "~PathBigCubic", 592 "~PathOpsCubic", 593 "~PathOpsFailOp", 594 "~PathOpsOpCubicsThreaded", 595 "~PathOpsOpLoopsThreaded", 596 "~PathOpsSimplify", 597 "~PathOpsTightBoundsQuads", 598 "~Point", 599 "~sk_linear_to_srgb", 600 "~small_color_stop", 601 ] 602 return ["--src"] + source + ["--config"] + config + ["--match"] + match 603 604################################################################################ 605## COPTS 606################################################################################ 607 608COPTS_UNIX = [ 609 "-Wno-implicit-fallthrough", # Some intentional fallthrough. 610 "-Wno-deprecated-declarations", # Internal use of deprecated methods. :( 611] 612 613COPTS_ANDROID = ["-mfpu=neon"] 614 615COPTS_IOS = [] 616 617COPTS_ALL = [] 618 619################################################################################ 620## DEFINES 621################################################################################ 622 623DEFINES_UNIX = [ 624 "PNG_SKIP_SETJMP_CHECK", 625 "SK_BUILD_FOR_UNIX", 626 "SK_SAMPLES_FOR_X", 627 "SK_PDF_USE_SFNTLY", 628 "SK_CODEC_DECODES_RAW", 629 "SK_HAS_JPEG_LIBRARY", 630 "SK_HAS_PNG_LIBRARY", 631 "SK_HAS_WEBP_LIBRARY", 632] 633 634DEFINES_ANDROID = [ 635 "SK_BUILD_FOR_ANDROID", 636 "SK_CODEC_DECODES_RAW", 637 "SK_HAS_JPEG_LIBRARY", 638 "SK_HAS_PNG_LIBRARY", 639 "SK_HAS_WEBP_LIBRARY", 640] 641 642DEFINES_IOS = [ 643 "SK_BUILD_FOR_IOS", 644 "SK_BUILD_NO_OPTS", 645 "SK_HAS_JPEG_LIBRARY", 646 "SK_IGNORE_ETC1_SUPPORT", 647 "SKNX_NO_SIMD", 648] 649 650DEFINES_ALL = [ 651 # Chrome DEFINES. 652 "SK_USE_FLOATBITS", 653 "SK_USE_FREETYPE_EMBOLDEN", 654 # Turn on a few Google3-specific build fixes. 655 "GOOGLE3", 656 # Staging flags for API changes 657 # Temporarily Disable analytic AA for Google3 658 "SK_NO_ANALYTIC_AA", 659 "SK_SUPPORT_LEGACY_BITMAP_SETPIXELREF", 660] 661 662################################################################################ 663## LINKOPTS 664################################################################################ 665 666LINKOPTS_UNIX = [] 667 668LINKOPTS_ANDROID = [ 669 "-lEGL", 670] 671 672LINKOPTS_IOS = [] 673 674LINKOPTS_ALL = [ 675 "-ldl", 676] 677