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