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