Home | History | Annotate | Download | only in skqp
      1 ################################################################################
      2 # Skylark macros
      3 ################################################################################
      4 
      5 is_bazel = not hasattr(native, "genmpm")
      6 
      7 def 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 
     22 def 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 
     39 def 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 ################################################################################
     57 def skia_all_hdrs():
     58   return native.glob([
     59       "src/**/*.h",
     60       "include/**/*.h",
     61       "third_party/**/*.h",
     62   ])
     63 
     64 def skia_public_hdrs():
     65   return native.glob(["include/**/*.h"],
     66                      exclude=[
     67                          "include/private/**/*",
     68                          "include/views/**/*",  # Not used.
     69                      ])
     70 
     71 ################################################################################
     72 ## skia_opts_srcs()
     73 ################################################################################
     74 # Intel
     75 SKIA_OPTS_SSE2 = "SSE2"
     76 
     77 SKIA_OPTS_SSSE3 = "SSSE3"
     78 
     79 SKIA_OPTS_SSE41 = "SSE41"
     80 
     81 SKIA_OPTS_SSE42 = "SSE42"
     82 
     83 SKIA_OPTS_AVX = "AVX"
     84 
     85 # Arm
     86 SKIA_OPTS_NEON = "NEON"
     87 
     88 SKIA_OPTS_CRC32 = "CRC32"  # arm64
     89 
     90 def opts_srcs(opts):
     91   if opts == SKIA_OPTS_SSE2:
     92     return native.glob([
     93         "src/opts/*_SSE2.cpp",
     94         "src/opts/*_sse2.cpp",  # No matches currently.
     95     ])
     96   elif opts == SKIA_OPTS_SSSE3:
     97     return native.glob([
     98         "src/opts/*_SSSE3.cpp",
     99         "src/opts/*_ssse3.cpp",
    100     ])
    101   elif opts == SKIA_OPTS_SSE41:
    102     return native.glob([
    103         "src/opts/*_sse41.cpp",
    104     ])
    105   elif opts == SKIA_OPTS_SSE42:
    106     return native.glob([
    107         "src/opts/*_sse42.cpp",
    108     ])
    109   elif opts == SKIA_OPTS_AVX:
    110     return native.glob([
    111         "src/opts/*_avx.cpp",
    112     ])
    113   elif opts == SKIA_OPTS_NEON:
    114     return native.glob([
    115         "src/opts/*_neon.cpp",
    116     ])
    117   elif opts == SKIA_OPTS_CRC32:
    118     return native.glob([
    119         "src/opts/*_crc32.cpp",
    120     ])
    121   else:
    122     fail("skia_opts_srcs parameter 'opts' must be one of SKIA_OPTS_*.")
    123 
    124 def opts_cflags(opts):
    125   if opts == SKIA_OPTS_SSE2:
    126     return ["-msse2"]
    127   elif opts == SKIA_OPTS_SSSE3:
    128     return ["-mssse3"]
    129   elif opts == SKIA_OPTS_SSE41:
    130     return ["-msse4.1"]
    131   elif opts == SKIA_OPTS_SSE42:
    132     return ["-msse4.2"]
    133   elif opts == SKIA_OPTS_AVX:
    134     return ["-mavx"]
    135   elif opts == SKIA_OPTS_NEON:
    136     return ["-mfpu=neon"]
    137   elif opts == SKIA_OPTS_CRC32:
    138     # NDK r11's Clang (3.8) doesn't pass along this -march setting correctly to an external
    139     # assembler, so we do it manually with -Wa.  This is just a bug, fixed in later Clangs.
    140     return ["-march=armv8-a+crc", "-Wa,-march=armv8-a+crc"]
    141   else:
    142     return []
    143 
    144 SKIA_CPU_ARM = "ARM"
    145 
    146 SKIA_CPU_ARM64 = "ARM64"
    147 
    148 SKIA_CPU_X86 = "X86"
    149 
    150 SKIA_CPU_OTHER = "OTHER"
    151 
    152 def opts_rest_srcs(cpu):
    153   srcs = []
    154   if cpu == SKIA_CPU_ARM or cpu == SKIA_CPU_ARM64:
    155     srcs += native.glob([
    156         "src/opts/*_arm.cpp",
    157         "src/opts/SkBitmapProcState_opts_none.cpp",
    158     ])
    159     if cpu == SKIA_CPU_ARM64:
    160       # NEON doesn't need special flags to compile on ARM64.
    161       srcs += native.glob([
    162           "src/opts/*_neon.cpp",
    163       ])
    164   elif cpu == SKIA_CPU_X86:
    165     srcs += native.glob([
    166         "src/opts/*_x86.cpp",
    167     ])
    168   elif cpu == SKIA_CPU_OTHER:
    169     srcs += native.glob([
    170         "src/opts/*_none.cpp",
    171     ])
    172   else:
    173     fail("opts_rest_srcs parameter 'cpu' must be one of " +
    174          "SKIA_CPU_{ARM,ARM64,X86,OTHER}.")
    175   return srcs
    176 
    177 def skia_opts_deps(cpu):
    178   res = [":opts_rest"]
    179 
    180   if cpu == SKIA_CPU_ARM:
    181     res += [":opts_neon"]
    182 
    183   if cpu == SKIA_CPU_ARM64:
    184     res += [":opts_crc32"]
    185 
    186   if cpu == SKIA_CPU_X86:
    187     res += [
    188         ":opts_sse2",
    189         ":opts_ssse3",
    190         ":opts_sse41",
    191         ":opts_sse42",
    192         ":opts_avx",
    193     ]
    194 
    195   return res
    196 
    197 ################################################################################
    198 ## BASE_SRCS
    199 ################################################################################
    200 
    201 # All platform-independent SRCS.
    202 BASE_SRCS_ALL = struct(
    203     include = [
    204         "include/private/**/*.h",
    205         "src/**/*.h",
    206         "src/**/*.cpp",
    207         "src/**/*.inc",
    208         "src/jumper/SkJumper_generated.S",
    209 
    210         # Third Party
    211         "third_party/etc1/*.cpp",
    212         "third_party/etc1/*.h",
    213         "third_party/gif/*.cpp",
    214         "third_party/gif/*.h",
    215     ],
    216     exclude = [
    217         # Exclude platform-dependent files.
    218         "src/codec/*",
    219         "src/device/xps/*",  # Windows-only. Move to ports?
    220         "src/doc/*_XPS.cpp",  # Windows-only. Move to ports?
    221         "src/gpu/gl/android/*",
    222         "src/gpu/gl/egl/*",
    223         "src/gpu/gl/glfw/*",
    224         "src/gpu/gl/glx/*",
    225         "src/gpu/gl/iOS/*",
    226         "src/gpu/gl/mac/*",
    227         "src/gpu/gl/win/*",
    228         "src/opts/**/*",
    229         "src/ports/**/*",
    230         "src/utils/android/**/*",
    231         "src/utils/mac/**/*",
    232         "src/utils/win/**/*",
    233         "src/views/sdl/*",
    234         "src/views/win/*",
    235         "src/views/unix/*",
    236 
    237         # Exclude multiple definitions.
    238         # TODO(mtklein): Move to opts?
    239         "src/pdf/SkDocument_PDF_None.cpp",  # We use src/pdf/SkPDFDocument.cpp.
    240         "src/gpu/gl/GrGLMakeNativeInterface_none.cpp",
    241 
    242         # Exclude files that don't compile with the current DEFINES.
    243         "src/svg/**/*",  # Depends on XML.
    244         "src/xml/**/*",
    245 
    246         # Conflicting dependencies among Lua versions. See cl/107087297.
    247         "src/utils/SkLua*",
    248 
    249         # Not used.
    250         "src/views/**/*",
    251 
    252         # Currently exclude all vulkan specific files
    253         "src/gpu/vk/*",
    254 
    255         # Defines main.
    256         "src/sksl/SkSLMain.cpp",
    257 
    258         # Only used to regenerate the lexer
    259         "src/sksl/lex/*",
    260 
    261         # Atlas text
    262         "src/atlastext/*",
    263     ],
    264 )
    265 
    266 def codec_srcs(limited):
    267   """Sources for the codecs. Excludes Ico, Webp, Png, and Raw if limited."""
    268   exclude = []
    269   if limited:
    270     exclude += [
    271         "src/codec/*Ico*.cpp",
    272         "src/codec/*Webp*.cpp",
    273         "src/codec/*Png*",
    274         "src/codec/*Raw*.cpp",
    275     ]
    276   return native.glob(["src/codec/*.cpp"], exclude = exclude)
    277 
    278 # Platform-dependent SRCS for google3-default platform.
    279 BASE_SRCS_UNIX = struct(
    280     include = [
    281         "src/gpu/gl/GrGLMakeNativeInterface_none.cpp",
    282         "src/ports/**/*.cpp",
    283         "src/ports/**/*.h",
    284     ],
    285     exclude = [
    286         "src/ports/*CG*",
    287         "src/ports/*WIC*",
    288         "src/ports/*android*",
    289         "src/ports/*chromium*",
    290         "src/ports/*mac*",
    291         "src/ports/*mozalloc*",
    292         "src/ports/*nacl*",
    293         "src/ports/*win*",
    294         "src/ports/SkFontMgr_custom_directory_factory.cpp",
    295         "src/ports/SkFontMgr_custom_embedded_factory.cpp",
    296         "src/ports/SkFontMgr_custom_empty_factory.cpp",
    297         "src/ports/SkFontMgr_empty_factory.cpp",
    298         "src/ports/SkFontMgr_fontconfig.cpp",
    299         "src/ports/SkFontMgr_fontconfig_factory.cpp",
    300         "src/ports/SkGlobalInitialization_none.cpp",
    301         "src/ports/SkImageGenerator_none.cpp",
    302         "src/ports/SkTLS_none.cpp",
    303     ],
    304 )
    305 
    306 # Platform-dependent SRCS for google3-default Android.
    307 BASE_SRCS_ANDROID = struct(
    308     include = [
    309         "src/gpu/gl/GrGLMakeNativeInterface_none.cpp",
    310         # TODO(benjaminwagner): Figure out how to compile with EGL.
    311         "src/ports/**/*.cpp",
    312         "src/ports/**/*.h",
    313     ],
    314     exclude = [
    315         "src/ports/*CG*",
    316         "src/ports/*FontConfig*",
    317         "src/ports/*WIC*",
    318         "src/ports/*chromium*",
    319         "src/ports/*fontconfig*",
    320         "src/ports/*mac*",
    321         "src/ports/*mozalloc*",
    322         "src/ports/*nacl*",
    323         "src/ports/*win*",
    324         "src/ports/SkDebug_stdio.cpp",
    325         "src/ports/SkFontMgr_custom_directory_factory.cpp",
    326         "src/ports/SkFontMgr_custom_embedded_factory.cpp",
    327         "src/ports/SkFontMgr_custom_empty_factory.cpp",
    328         "src/ports/SkFontMgr_empty_factory.cpp",
    329         "src/ports/SkGlobalInitialization_none.cpp",
    330         "src/ports/SkImageGenerator_none.cpp",
    331         "src/ports/SkTLS_none.cpp",
    332     ],
    333 )
    334 
    335 # Platform-dependent SRCS for google3-default iOS.
    336 BASE_SRCS_IOS = struct(
    337     include = [
    338         "src/gpu/gl/iOS/GrGLMakeNativeInterface_iOS.cpp",
    339         "src/ports/**/*.cpp",
    340         "src/ports/**/*.h",
    341         "src/utils/mac/*.cpp",
    342     ],
    343     exclude = [
    344         "src/ports/*FontConfig*",
    345         "src/ports/*FreeType*",
    346         "src/ports/*WIC*",
    347         "src/ports/*android*",
    348         "src/ports/*chromium*",
    349         "src/ports/*fontconfig*",
    350         "src/ports/*mozalloc*",
    351         "src/ports/*nacl*",
    352         "src/ports/*win*",
    353         "src/ports/SkFontMgr_custom.cpp",
    354         "src/ports/SkFontMgr_custom_directory.cpp",
    355         "src/ports/SkFontMgr_custom_embedded.cpp",
    356         "src/ports/SkFontMgr_custom_empty.cpp",
    357         "src/ports/SkFontMgr_custom_directory_factory.cpp",
    358         "src/ports/SkFontMgr_custom_embedded_factory.cpp",
    359         "src/ports/SkFontMgr_custom_empty_factory.cpp",
    360         "src/ports/SkFontMgr_empty_factory.cpp",
    361         "src/ports/SkGlobalInitialization_none.cpp",
    362         "src/ports/SkImageGenerator_none.cpp",
    363         "src/ports/SkTLS_none.cpp",
    364     ],
    365 )
    366 
    367 ################################################################################
    368 ## skia_srcs()
    369 ################################################################################
    370 def skia_srcs(os_conditions):
    371   """Sources to be compiled into the skia library."""
    372   return skia_glob(BASE_SRCS_ALL) + skia_select(
    373       os_conditions,
    374       [
    375           skia_glob(BASE_SRCS_UNIX),
    376           skia_glob(BASE_SRCS_ANDROID),
    377           skia_glob(BASE_SRCS_IOS),
    378       ],
    379   )
    380 
    381 ################################################################################
    382 ## INCLUDES
    383 ################################################################################
    384 
    385 # Includes needed by Skia implementation.  Not public includes.
    386 INCLUDES = [
    387     "include/android",
    388     "include/c",
    389     "include/client/android",
    390     "include/codec",
    391     "include/config",
    392     "include/core",
    393     "include/effects",
    394     "include/encode",
    395     "include/gpu",
    396     "include/images",
    397     "include/pathops",
    398     "include/pipe",
    399     "include/ports",
    400     "include/private",
    401     "include/utils",
    402     "include/utils/mac",
    403     "include/utils/win",
    404     "include/svg",
    405     "include/xml",
    406     "src/codec",
    407     "src/core",
    408     "src/gpu",
    409     "src/image",
    410     "src/images",
    411     "src/lazy",
    412     "src/opts",
    413     "src/ports",
    414     "src/pdf",
    415     "src/sfnt",
    416     "src/shaders",
    417     "src/sksl",
    418     "src/utils",
    419     "third_party/etc1",
    420     "third_party/gif",
    421 ]
    422 
    423 ################################################################################
    424 ## DM_SRCS
    425 ################################################################################
    426 
    427 DM_SRCS_ALL = struct(
    428     include = [
    429         "dm/*.cpp",
    430         "dm/*.h",
    431         "gm/*.c",
    432         "gm/*.cpp",
    433         "gm/*.h",
    434         "tests/*.cpp",
    435         "tests/*.h",
    436         "tools/BigPathBench.inc",
    437         "tools/CrashHandler.cpp",
    438         "tools/CrashHandler.h",
    439         "tools/ProcStats.cpp",
    440         "tools/ProcStats.h",
    441         "tools/Resources.cpp",
    442         "tools/Resources.h",
    443         "tools/SkJSONCPP.h",
    444         "tools/SkRandomScalerContext.cpp",
    445         "tools/SkRandomScalerContext.h",
    446         "tools/SkTestScalerContext.cpp",
    447         "tools/SkTestScalerContext.h",
    448         "tools/UrlDataManager.cpp",
    449         "tools/UrlDataManager.h",
    450         "tools/debugger/*.cpp",
    451         "tools/debugger/*.h",
    452         "tools/flags/*.cpp",
    453         "tools/flags/*.h",
    454         "tools/gpu/**/*.cpp",
    455         "tools/gpu/**/*.h",
    456         "tools/picture_utils.cpp",
    457         "tools/picture_utils.h",
    458         "tools/random_parse_path.cpp",
    459         "tools/random_parse_path.h",
    460         "tools/sk_tool_utils.cpp",
    461         "tools/sk_tool_utils.h",
    462         "tools/sk_tool_utils_font.cpp",
    463         "tools/test_font_monospace.inc",
    464         "tools/test_font_sans_serif.inc",
    465         "tools/test_font_serif.inc",
    466         "tools/test_font_index.inc",
    467         "tools/timer/*.cpp",
    468         "tools/timer/*.h",
    469         "tools/trace/*.cpp",
    470         "tools/trace/*.h",
    471     ],
    472     exclude = [
    473         "tests/FontMgrAndroidParserTest.cpp",  # Android-only.
    474         "tests/skia_test.cpp",  # Old main.
    475         "tests/SkpSkGrTest.cpp",  # Alternate main.
    476         "tests/SVGDeviceTest.cpp",
    477         "tools/gpu/atlastext/*",
    478         "tools/gpu/gl/angle/*",
    479         "tools/gpu/gl/egl/*",
    480         "tools/gpu/gl/glx/*",
    481         "tools/gpu/gl/iOS/*",
    482         "tools/gpu/gl/mac/*",
    483         "tools/gpu/gl/win/*",
    484         "tools/timer/SysTimer_mach.cpp",
    485         "tools/timer/SysTimer_windows.cpp",
    486     ],
    487 )
    488 
    489 ################################################################################
    490 ## dm_srcs()
    491 ################################################################################
    492 
    493 def dm_srcs(os_conditions):
    494   """Sources for the dm binary for the specified os."""
    495   return skia_glob(DM_SRCS_ALL) + skia_select(
    496       os_conditions,
    497       [
    498           [],
    499           ["tests/FontMgrAndroidParserTest.cpp"],
    500           [],
    501       ],
    502   )
    503 
    504 ################################################################################
    505 ## DM_INCLUDES
    506 ################################################################################
    507 
    508 DM_INCLUDES = [
    509     "dm",
    510     "gm",
    511     "experimental/svg/model",
    512     "src/codec",
    513     "src/core",
    514     "src/effects",
    515     "src/fonts",
    516     "src/images",
    517     "src/pathops",
    518     "src/pipe/utils",
    519     "src/ports",
    520     "src/shaders",
    521     "src/shaders/gradients",
    522     "src/xml",
    523     "tests",
    524     "tools",
    525     "tools/debugger",
    526     "tools/flags",
    527     "tools/gpu",
    528     "tools/timer",
    529     "tools/trace",
    530 ]
    531 
    532 ################################################################################
    533 ## DM_ARGS
    534 ################################################################################
    535 
    536 def DM_ARGS(asan):
    537   source = ["tests", "gm", "image"]
    538   # TODO(benjaminwagner): f16, pic-8888, serialize-8888, and tiles_rt-8888 fail.
    539   config = ["565", "8888", "pdf", "srgb"]
    540   # TODO(mtklein): maybe investigate why these fail?
    541   match = [
    542       "~^FontHostStream$$",
    543       "~^FontMgr$$",
    544       "~^PaintBreakText$$",
    545       "~^RecordDraw_TextBounds$$",
    546   ]
    547   return ["--src"] + source + ["--config"] + config + ["--match"] + match
    548 
    549 ################################################################################
    550 ## COPTS
    551 ################################################################################
    552 
    553 def base_copts(os_conditions):
    554   return skia_select(
    555       os_conditions,
    556       [
    557           # UNIX
    558           [
    559               "-Wno-implicit-fallthrough",  # Some intentional fallthrough.
    560               # Internal use of deprecated methods. :(
    561               "-Wno-deprecated-declarations",
    562           ],
    563           # ANDROID
    564           [
    565               # 'GrResourceCache' declared with greater visibility than the
    566               # type of its field 'GrResourceCache::fPurgeableQueue'... bogus.
    567               "-Wno-error=attributes",
    568           ],
    569           # IOS
    570           [],
    571       ],
    572   )
    573 
    574 ################################################################################
    575 ## DEFINES
    576 ################################################################################
    577 
    578 def base_defines(os_conditions):
    579   return [
    580       # Chrome DEFINES.
    581       "SK_USE_FREETYPE_EMBOLDEN",
    582       # Turn on a few Google3-specific build fixes.
    583       "SK_BUILD_FOR_GOOGLE3",
    584       # Required for building dm.
    585       "GR_TEST_UTILS",
    586       # Staging flags for API changes
    587       # Should remove after we update golden images
    588       "SK_WEBP_ENCODER_USE_DEFAULT_METHOD",
    589       # Experiment to diagnose image diffs in Google3
    590       "SK_JUMPER_DISABLE_8BIT",
    591       # JPEG is in codec_limited
    592       "SK_HAS_JPEG_LIBRARY",
    593   ] + skia_select(
    594       os_conditions,
    595       [
    596           # UNIX
    597           [
    598               "PNG_SKIP_SETJMP_CHECK",
    599               "SK_BUILD_FOR_UNIX",
    600               "SK_SAMPLES_FOR_X",
    601               "SK_PDF_USE_SFNTLY",
    602               "SK_CODEC_DECODES_RAW",
    603               "SK_HAS_PNG_LIBRARY",
    604               "SK_HAS_WEBP_LIBRARY",
    605           ],
    606           # ANDROID
    607           [
    608               "SK_BUILD_FOR_ANDROID",
    609               "SK_CODEC_DECODES_RAW",
    610               "SK_HAS_PNG_LIBRARY",
    611               "SK_HAS_WEBP_LIBRARY",
    612           ],
    613           # IOS
    614           [
    615               "SK_BUILD_FOR_IOS",
    616               "SK_BUILD_NO_OPTS",
    617               "SKNX_NO_SIMD",
    618           ],
    619       ],
    620   )
    621 
    622 ################################################################################
    623 ## LINKOPTS
    624 ################################################################################
    625 
    626 def base_linkopts(os_conditions):
    627   return [
    628       "-ldl",
    629   ] + skia_select(
    630       os_conditions,
    631       [
    632           # UNIX
    633           [],
    634           # ANDROID
    635           [
    636               "-lEGL",
    637           ],
    638           # IOS
    639           [
    640               "-framework CoreFoundation",
    641               "-framework CoreGraphics",
    642               "-framework CoreText",
    643               "-framework ImageIO",
    644               "-framework MobileCoreServices",
    645           ],
    646       ]
    647   )
    648