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