Merge pull request #24 from google/chrome/m54
[platform/upstream/libSkiaSharp.git] / public.bzl
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 ## PRIVATE_HDRS
56 ################################################################################
57
58 PRIVATE_HDRS_INCLUDE_LIST = [
59     "include/private/**/*.h",
60     "src/**/*.inc",
61 ]
62
63 PRIVATE_HDRS = struct(
64     include = PRIVATE_HDRS_INCLUDE_LIST,
65 )
66
67 ALL_HDRS = struct(
68     include = [
69         "src/**/*.h",
70         "include/**/*.h",
71     ],
72 )
73
74 ################################################################################
75 ## BASE_SRCS
76 ################################################################################
77
78 # All platform-independent SRCS.
79 BASE_SRCS_ALL = struct(
80     include = [
81         "src/**/*.h",
82         "src/**/*.cpp",
83
84         # Third Party
85         "third_party/etc1/*.cpp",
86         "third_party/etc1/*.h",
87         "third_party/ktx/*.cpp",
88         "third_party/ktx/*.h",
89     ],
90     # Note: PRIVATE_HDRS_INCLUDE_LIST is excluded from BASE_SRCS_ALL here
91     # because they are required to appear in srcs for some rules but hdrs for
92     # other rules. See internal cl/119566959.
93     exclude = PRIVATE_HDRS_INCLUDE_LIST + [
94         # Exclude platform-dependent files.
95         "src/android/*",
96         "src/codec/*",
97         "src/device/xps/*",  # Windows-only. Move to ports?
98         "src/doc/*_XPS.cpp",  # Windows-only. Move to ports?
99         "src/gpu/gl/android/*",
100         "src/gpu/gl/egl/*",
101         "src/gpu/gl/glfw/*",
102         "src/gpu/gl/glx/*",
103         "src/gpu/gl/iOS/*",
104         "src/gpu/gl/mac/*",
105         "src/gpu/gl/win/*",
106         "src/images/*",
107         "src/opts/**/*",
108         "src/ports/**/*",
109         "src/utils/android/**/*",
110         "src/utils/mac/**/*",
111         "src/utils/SkThreadUtils_win.cpp",  # Windows-only. Move to ports?
112         "src/utils/win/**/*",
113         "src/views/sdl/*",
114         "src/views/win/*",
115         "src/views/unix/*",
116
117         # Exclude multiple definitions.
118         # TODO(mtklein): Move to opts?
119         "src/pdf/SkDocument_PDF_None.cpp",  # We use src/pdf/SkPDFDocument.cpp.
120         "src/gpu/gl/GrGLCreateNativeInterface_none.cpp",
121         "src/gpu/gl/GrGLDefaultInterface_native.cpp",
122         "src/gpu/gl/GrGLDefaultInterface_none.cpp",
123
124         # Exclude files that don't compile with the current DEFINES.
125         "src/gpu/gl/mesa/*",  # Requires SK_MESA define.
126         "src/svg/**/*",  # Depends on XML.
127         "src/xml/**/*",
128
129         # Conflicting dependencies among Lua versions. See cl/107087297.
130         "src/utils/SkLua*",
131
132         # Not used.
133         "src/views/**/*",
134
135         # Currently exclude all vulkan specific files
136         "src/gpu/vk/*",
137         "src/sksl/**/*",
138     ],
139 )
140
141 # Platform-dependent SRCS for google3-default platform.
142 BASE_SRCS_UNIX = struct(
143     include = [
144         "src/android/*",
145         "src/codec/*",
146         "src/gpu/gl/GrGLDefaultInterface_none.cpp",
147         "src/images/*",
148         "src/opts/**/*.cpp",
149         "src/opts/**/*.h",
150         "src/ports/**/*.cpp",
151         "src/ports/**/*.h",
152     ],
153     exclude = [
154         "src/opts/*arm*",
155         "src/opts/*mips*",
156         "src/opts/*NEON*",
157         "src/opts/*neon*",
158         # Included in :opts_ssse3 library.
159         "src/opts/*SSSE3*",
160         "src/opts/*ssse3*",
161         # Included in :opts_sse4 library.
162         "src/opts/*SSE4*",
163         "src/opts/*sse4*",
164         # Included in :opts_avx or :opts_avx2
165         "src/opts/*avx*",
166         "src/opts/SkBitmapProcState_opts_none.cpp",
167         "src/opts/SkBlitMask_opts_none.cpp",
168         "src/opts/SkBlitRow_opts_none.cpp",
169         "src/ports/*CG*",
170         "src/ports/*WIC*",
171         "src/ports/*android*",
172         "src/ports/*chromium*",
173         "src/ports/*mac*",
174         "src/ports/*mozalloc*",
175         "src/ports/*nacl*",
176         "src/ports/*win*",
177         "src/ports/SkFontConfigInterface_direct_factory.cpp",
178         "src/ports/SkFontMgr_custom_directory_factory.cpp",
179         "src/ports/SkFontMgr_custom_embedded_factory.cpp",
180         "src/ports/SkFontMgr_custom_empty_factory.cpp",
181         "src/ports/SkFontMgr_empty_factory.cpp",
182         "src/ports/SkFontMgr_fontconfig.cpp",
183         "src/ports/SkFontMgr_fontconfig_factory.cpp",
184         "src/ports/SkImageEncoder_none.cpp",
185         "src/ports/SkImageGenerator_none.cpp",
186         "src/ports/SkTLS_none.cpp",
187     ],
188 )
189
190 # Platform-dependent SRCS for google3-default Android.
191 BASE_SRCS_ANDROID = struct(
192     include = [
193         "src/android/*",
194         "src/codec/*",
195         "src/gpu/gl/GrGLDefaultInterface_none.cpp",
196         "src/images/*",
197         # TODO(benjaminwagner): Figure out how to compile with EGL.
198         "src/opts/**/*.cpp",
199         "src/opts/**/*.h",
200         "src/ports/**/*.cpp",
201         "src/ports/**/*.h",
202     ],
203     exclude = [
204         "src/opts/*mips*",
205         "src/opts/*SSE2*",
206         "src/opts/*SSSE3*",
207         "src/opts/*ssse3*",
208         "src/opts/*SSE4*",
209         "src/opts/*sse4*",
210         "src/opts/*avx*",
211         "src/opts/*x86*",
212         "src/opts/SkBitmapProcState_opts_none.cpp",
213         "src/opts/SkBlitMask_opts_none.cpp",
214         "src/opts/SkBlitRow_opts_none.cpp",
215         "src/ports/*CG*",
216         "src/ports/*FontConfig*",
217         "src/ports/*WIC*",
218         "src/ports/*chromium*",
219         "src/ports/*fontconfig*",
220         "src/ports/*mac*",
221         "src/ports/*mozalloc*",
222         "src/ports/*nacl*",
223         "src/ports/*win*",
224         "src/ports/SkDebug_stdio.cpp",
225         "src/ports/SkFontMgr_custom_directory_factory.cpp",
226         "src/ports/SkFontMgr_custom_embedded_factory.cpp",
227         "src/ports/SkFontMgr_custom_empty_factory.cpp",
228         "src/ports/SkFontMgr_empty_factory.cpp",
229         "src/ports/SkImageEncoder_none.cpp",
230         "src/ports/SkImageGenerator_none.cpp",
231         "src/ports/SkTLS_none.cpp",
232     ],
233 )
234
235 # Platform-dependent SRCS for google3-default iOS.
236 BASE_SRCS_IOS = struct(
237     include = [
238         "src/android/*",
239         "src/codec/*",
240         "src/gpu/gl/GrGLDefaultInterface_native.cpp",
241         "src/gpu/gl/iOS/GrGLCreateNativeInterface_iOS.cpp",
242         "src/opts/**/*.cpp",
243         "src/opts/**/*.h",
244         "src/ports/**/*.cpp",
245         "src/ports/**/*.h",
246         "src/utils/mac/*.cpp",
247     ],
248     exclude = [
249         "src/codec/*Gif*.cpp",
250         "src/codec/*Ico*.cpp",
251         "src/codec/*Jpeg*.cpp",
252         "src/codec/*Webp*.cpp",
253         "src/codec/*Png*",
254         "src/codec/*Raw*.cpp",
255         "src/opts/*mips*",
256         "src/opts/*NEON*",
257         "src/opts/*neon*",
258         "src/opts/*SSE2*",
259         "src/opts/*SSSE3*",
260         "src/opts/*ssse3*",
261         "src/opts/*SSE4*",
262         "src/opts/*sse4*",
263         "src/opts/*avx*",
264         "src/opts/*x86*",
265         "src/opts/SkBitmapProcState_opts_none.cpp",
266         "src/opts/SkBlitMask_opts_arm*.cpp",
267         "src/opts/SkBlitRow_opts_arm*.cpp",
268         "src/ports/*CG*",
269         "src/ports/*FontConfig*",
270         "src/ports/*FreeType*",
271         "src/ports/*WIC*",
272         "src/ports/*android*",
273         "src/ports/*chromium*",
274         "src/ports/*fontconfig*",
275         "src/ports/*mozalloc*",
276         "src/ports/*nacl*",
277         "src/ports/*win*",
278         "src/ports/SkFontMgr_custom.cpp",
279         "src/ports/SkFontMgr_custom_directory_factory.cpp",
280         "src/ports/SkFontMgr_custom_embedded_factory.cpp",
281         "src/ports/SkFontMgr_custom_empty_factory.cpp",
282         "src/ports/SkFontMgr_empty_factory.cpp",
283         "src/ports/SkImageGenerator_none.cpp",
284         "src/ports/SkTLS_none.cpp",
285     ],
286 )
287
288 ################################################################################
289 ## SSSE3/SSE4/AVX/AVX2 SRCS
290 ################################################################################
291
292 SSSE3_SRCS = struct(
293     include = [
294         "src/opts/*SSSE3*.cpp",
295         "src/opts/*ssse3*.cpp",
296     ],
297 )
298
299 SSE4_SRCS = struct(
300     include = [
301         "src/opts/*SSE4*.cpp",
302         "src/opts/*sse4*.cpp",
303     ],
304 )
305
306 AVX_SRCS = struct(
307     include = [
308         "src/opts/*_avx.cpp",
309     ],
310 )
311
312 AVX2_SRCS = struct(
313     include = [
314         "src/opts/*_avx2.cpp",
315     ],
316 )
317
318 ################################################################################
319 ## BASE_HDRS
320 ################################################################################
321
322 BASE_HDRS = struct(
323     include = [
324         "include/**/*.h",
325     ],
326     exclude = PRIVATE_HDRS_INCLUDE_LIST + [
327         # Not used.
328         "include/animator/**/*",
329         "include/views/**/*",
330     ],
331 )
332
333 ################################################################################
334 ## BASE_DEPS
335 ################################################################################
336
337 BASE_DEPS_ALL = []
338
339 BASE_DEPS_UNIX = [
340     ":opts_ssse3",
341     ":opts_sse4",
342     ":opts_avx",
343     ":opts_avx2",
344 ]
345
346 BASE_DEPS_ANDROID = []
347
348 BASE_DEPS_IOS = []
349
350 ################################################################################
351 ## INCLUDES
352 ################################################################################
353
354 # Includes needed by Skia implementation.  Not public includes.
355 INCLUDES = [
356     "include/android",
357     "include/c",
358     "include/client/android",
359     "include/codec",
360     "include/config",
361     "include/core",
362     "include/effects",
363     "include/gpu",
364     "include/images",
365     "include/pathops",
366     "include/pipe",
367     "include/ports",
368     "include/private",
369     "include/utils",
370     "include/utils/mac",
371     "include/utils/win",
372     "include/svg",
373     "include/xml",
374     "src/codec",
375     "src/core",
376     "src/gpu",
377     "src/image",
378     "src/lazy",
379     "src/opts",
380     "src/ports",
381     "src/pdf",
382     "src/sfnt",
383     "src/utils",
384     "third_party/etc1",
385     "third_party/ktx",
386 ]
387
388 ################################################################################
389 ## DM_SRCS
390 ################################################################################
391
392 DM_SRCS_ALL = struct(
393     include = [
394         "dm/*.cpp",
395         "dm/*.h",
396         "gm/*.c",
397         "gm/*.cpp",
398         "gm/*.h",
399         "tests/*.cpp",
400         "tests/*.h",
401         "tools/BigPathBench.inc",
402         "tools/CrashHandler.cpp",
403         "tools/CrashHandler.h",
404         "tools/ProcStats.cpp",
405         "tools/ProcStats.h",
406         "tools/Resources.cpp",
407         "tools/Resources.h",
408         "tools/SkJSONCPP.h",
409         "tools/UrlDataManager.cpp",
410         "tools/UrlDataManager.h",
411         "tools/debugger/*.cpp",
412         "tools/debugger/*.h",
413         "tools/flags/*.cpp",
414         "tools/flags/*.h",
415         "tools/gpu/**/*.cpp",
416         "tools/gpu/**/*.h",
417         "tools/picture_utils.cpp",
418         "tools/picture_utils.h",
419         "tools/random_parse_path.cpp",
420         "tools/random_parse_path.h",
421         "tools/sk_tool_utils.cpp",
422         "tools/sk_tool_utils.h",
423         "tools/sk_tool_utils_flags.h",
424         "tools/sk_tool_utils_font.cpp",
425         "tools/test_font_monospace.inc",
426         "tools/test_font_sans_serif.inc",
427         "tools/test_font_serif.inc",
428         "tools/test_font_index.inc",
429         "tools/timer/*.cpp",
430         "tools/timer/*.h",
431     ],
432     exclude = [
433         "dm/DMSrcSinkAndroid.cpp",  # Android-only.
434         "tests/FontMgrAndroidParserTest.cpp",  # Android-only.
435         "tests/PathOpsSkpClipTest.cpp",  # Alternate main.
436         "tests/skia_test.cpp",  # Old main.
437         "tests/SkpSkGrTest.cpp",  # Alternate main.
438         "tests/SkSL*.cpp",  # Excluded along with Vulkan.
439         "tests/SVGDeviceTest.cpp",
440         "tools/gpu/gl/angle/*",
441         "tools/gpu/gl/command_buffer/*",
442         "tools/gpu/gl/egl/*",
443         "tools/gpu/gl/glx/*",
444         "tools/gpu/gl/iOS/*",
445         "tools/gpu/gl/mac/*",
446         "tools/gpu/gl/mesa/*",
447         "tools/gpu/gl/win/*",
448         "tools/timer/SysTimer_mach.cpp",
449         "tools/timer/SysTimer_windows.cpp",
450     ],
451 )
452
453 DM_SRCS_UNIX = struct(
454     include = [
455         "tools/gpu/gl/CreatePlatformGLContext_none.cpp",
456     ],
457 )
458
459 DM_SRCS_ANDROID = struct(
460     include = [
461         # Depends on Android HWUI library that is not available in google3.
462         #"dm/DMSrcSinkAndroid.cpp",
463         "tests/FontMgrAndroidParserTest.cpp",
464         # TODO(benjaminwagner): Figure out how to compile with EGL.
465         "tools/gpu/gl/CreatePlatformGLContext_none.cpp",
466     ],
467 )
468
469 DM_SRCS_IOS = struct(
470     include = [
471         "tools/gpu/iOS/CreatePlatformGLContext_iOS.cpp",
472     ],
473 )
474
475 ################################################################################
476 ## DM_INCLUDES
477 ################################################################################
478
479 DM_INCLUDES = [
480     "dm",
481     "gm",
482     "src/codec",
483     "src/effects",
484     "src/effects/gradients",
485     "src/fonts",
486     "src/pathops",
487     "src/pipe/utils",
488     "src/ports",
489     "tests",
490     "tools",
491     "tools/debugger",
492     "tools/flags",
493     "tools/gpu",
494     "tools/timer",
495 ]
496
497 ################################################################################
498 ## DM_ARGS
499 ################################################################################
500
501 def DM_ARGS(base_dir, asan):
502   source = ["tests", "gm", "image"]
503   # TODO(benjaminwagner): f16 and serialize-8888 fail.
504   config = ["565", "8888", "pdf", "srgb", "tiles_rt", "pic"]
505   # TODO(mtklein): maybe investigate why these fail?
506   match = [
507       "~Canvas",
508       "~Codec",
509       "~Codec_Dimensions",
510       "~Codec_stripes",
511       "~FontMgr",
512       "~PaintBreakText",
513       "~RecordDraw_TextBounds",
514       "~Scalar",
515       "~skps",
516       "~Stream",
517   ]
518   if asan:
519     # Running all sources and configs under ASAN causes the test to exceed
520     # "large" size and time out.
521     source = ["tests", "gm"]
522     config = ["8888"]
523     match += [
524         "~clippedcubic2",
525         "~conicpaths",
526         "~gradients_2pt_conical",
527         "~Math",
528         "~Matrix",
529         "~PathOpsCubic",
530         "~PathOpsFailOp",
531         "~PathOpsOpCubicsThreaded",
532         "~PathOpsOpLoopsThreaded",
533         "~PathOpsSimplify",
534         "~PathOpsTightBoundsQuads",
535         "~Point",
536         "~sk_linear_to_srgb",
537     ]
538   return [
539       "--src %s" % " ".join(source),
540       "--config %s" % " ".join(config),
541       "--verbose",
542       "--match %s" % " ".join(match),
543       "--resourcePath %s/resources" % base_dir,
544       "--images %s/resources" % base_dir,
545   ]
546
547 ################################################################################
548 ## COPTS
549 ################################################################################
550
551 COPTS_UNIX = [
552     "-Wno-implicit-fallthrough",  # Some intentional fallthrough.
553     "-Wno-deprecated-declarations",  # Internal use of deprecated methods. :(
554 ]
555
556 COPTS_ANDROID = ["-mfpu=neon"]
557
558 COPTS_IOS = []
559
560 COPTS_ALL = []
561
562 ################################################################################
563 ## DEFINES
564 ################################################################################
565
566 DEFINES_UNIX = [
567     "PNG_SKIP_SETJMP_CHECK",
568     "SK_BUILD_FOR_UNIX",
569     "SK_SAMPLES_FOR_X",
570     "SK_SFNTLY_SUBSETTER",
571     "SK_CODEC_DECODES_RAW",
572     "SK_HAS_GIF_LIBRARY",
573     "SK_HAS_JPEG_LIBRARY",
574     "SK_HAS_PNG_LIBRARY",
575     "SK_HAS_WEBP_LIBRARY",
576 ]
577
578 DEFINES_ANDROID = [
579     "SK_BUILD_FOR_ANDROID",
580     "SK_CODEC_DECODES_RAW",
581     "SK_HAS_GIF_LIBRARY",
582     "SK_HAS_JPEG_LIBRARY",
583     "SK_HAS_PNG_LIBRARY",
584     "SK_HAS_WEBP_LIBRARY",
585 ]
586
587 DEFINES_IOS = [
588     "SK_BUILD_FOR_IOS",
589     "SK_BUILD_NO_OPTS",
590     "SK_IGNORE_ETC1_SUPPORT",
591     "SKNX_NO_SIMD",
592 ]
593
594 DEFINES_ALL = [
595     # Chrome DEFINES.
596     "SK_USE_FLOATBITS",
597     "SK_USE_FREETYPE_EMBOLDEN",
598     # Turn on a few Google3-specific build fixes.
599     "GOOGLE3",
600     # Staging flags for API changes
601     "SK_SUPPORT_LEGACY_ACCESSBITMAP",
602     "SK_SUPPORT_LEGACY_BITMAP_GETTEXTURE",
603     "SK_SUPPORT_LEGACY_COLORFILTER_PTR",
604     "SK_SUPPORT_LEGACY_CREATESHADER_PTR",
605     "SK_SUPPORT_LEGACY_IMAGEFACTORY",
606     "SK_SUPPORT_LEGACY_IMAGEFILTER_PTR",
607     "SK_SUPPORT_LEGACY_MASKFILTER_PTR",
608     "SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR",
609     "SK_SUPPORT_LEGACY_NEW_SURFACE_API",
610     "SK_SUPPORT_LEGACY_PATHEFFECT_PTR",
611     "SK_SUPPORT_LEGACY_PICTURE_PTR",
612     "SK_SUPPORT_LEGACY_TYPEFACE_PTR",
613     "SK_SUPPORT_LEGACY_XFERMODE_PTR",
614     "SK_SUPPORT_LEGACY_PICTUREINSTALLPIXELREF",
615 ]
616
617 ################################################################################
618 ## LINKOPTS
619 ################################################################################
620
621 LINKOPTS_UNIX = []
622
623 LINKOPTS_ANDROID = [
624     "-lEGL",
625 ]
626
627 LINKOPTS_IOS = []
628
629 LINKOPTS_ALL = [
630     "-ldl",
631 ]