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