1################################################################################
2# Skylark macros
3################################################################################
4
5is_bazel = not hasattr(native, "genmpm")
6
7def 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
22def 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
39def 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## BASE_SRCS
56################################################################################
57
58# All platform-independent SRCS.
59BASE_SRCS_ALL = struct(
60    include = [
61        "include/private/*.h",
62        "src/**/*.h",
63        "src/**/*.cpp",
64
65        # Third Party
66        "third_party/etc1/*.cpp",
67        "third_party/etc1/*.h",
68        "third_party/ktx/*.cpp",
69        "third_party/ktx/*.h",
70    ],
71    exclude = [
72        # Exclude platform-dependent files.
73        "src/android/*",
74        "src/codec/*",
75        "src/device/xps/*",  # Windows-only. Move to ports?
76        "src/doc/*_XPS.cpp",  # Windows-only. Move to ports?
77        "src/fonts/SkFontMgr_fontconfig.cpp",
78        "src/gpu/gl/android/*",
79        "src/gpu/gl/egl/*",
80        "src/gpu/gl/glx/*",
81        "src/gpu/gl/iOS/*",
82        "src/gpu/gl/mac/*",
83        "src/gpu/gl/win/*",
84        "src/images/*",
85        "src/opts/**/*",
86        "src/ports/**/*",
87        "src/utils/android/**/*",
88        "src/utils/mac/**/*",
89        "src/utils/SkThreadUtils_win.cpp",  # Windows-only. Move to ports?
90        "src/utils/win/**/*",
91        "src/views/sdl/*",
92        "src/views/win/*",
93        "src/views/unix/*",
94
95        # Exclude multiple definitions.
96        # TODO(mtklein): Move to opts?
97        "src/doc/SkDocument_PDF_None.cpp",  # We use SkDocument_PDF.cpp.
98        "src/gpu/gl/GrGLCreateNativeInterface_none.cpp",
99        "src/gpu/gl/GrGLDefaultInterface_native.cpp",
100        "src/gpu/gl/GrGLDefaultInterface_none.cpp",
101
102        # Exclude files that don't compile with the current DEFINES.
103        "src/gpu/gl/angle/*",  # Requires SK_ANGLE define.
104        "src/gpu/gl/command_buffer/*",  # unknown type name 'HMODULE'
105        "src/gpu/gl/mesa/*",  # Requires SK_MESA define.
106        "src/svg/parser/*",  # Missing SkSVG.h.
107
108        # Conflicting dependencies among Lua versions. See cl/107087297.
109        "src/utils/SkLua*",
110
111        # Not used.
112        "src/animator/**/*",
113        "src/views/**/*",
114        "src/xml/SkBML_Verbs.h",
115        "src/xml/SkBML_XMLParser.cpp",
116        "src/xml/SkXMLPullParser.cpp",
117
118        # Currently exclude all vulkan specific files
119        "src/gpu/vk/*",
120    ],
121)
122
123# Platform-dependent SRCS for google3-default platform.
124BASE_SRCS_UNIX = struct(
125    include = [
126        "src/android/*",
127        "src/codec/*",
128        "src/fonts/SkFontMgr_fontconfig.cpp",
129        "src/gpu/gl/GrGLDefaultInterface_none.cpp",
130        "src/images/*",
131        "src/opts/**/*.cpp",
132        "src/opts/**/*.h",
133        "src/ports/**/*.cpp",
134        "src/ports/**/*.h",
135    ],
136    exclude = [
137        "src/opts/*arm*",
138        "src/opts/*mips*",
139        "src/opts/*NEON*",
140        "src/opts/*neon*",
141        # Included in :opts_ssse3 library.
142        "src/opts/*SSSE3*",
143        "src/opts/*ssse3*",
144        # Included in :opts_sse4 library.
145        "src/opts/*SSE4*",
146        "src/opts/*sse4*",
147        # Included in :opts_avx or :opts_avx2
148        "src/opts/*avx*",
149        "src/opts/SkBitmapProcState_opts_none.cpp",
150        "src/opts/SkBlitMask_opts_none.cpp",
151        "src/opts/SkBlitRow_opts_none.cpp",
152        "src/ports/*android*",
153        "src/ports/*chromium*",
154        "src/ports/*mac*",
155        "src/ports/*mozalloc*",
156        "src/ports/*nacl*",
157        "src/ports/*win*",
158        "src/ports/SkFontConfigInterface_direct_factory.cpp",
159        "src/ports/SkFontMgr_custom_directory_factory.cpp",
160        "src/ports/SkFontMgr_custom_embedded_factory.cpp",
161        "src/ports/SkFontMgr_empty_factory.cpp",
162        "src/ports/SkFontMgr_fontconfig.cpp",
163        "src/ports/SkImageDecoder_CG.cpp",
164        "src/ports/SkFontMgr_fontconfig_factory.cpp",
165        "src/ports/SkImageDecoder_WIC.cpp",
166        "src/ports/SkImageDecoder_empty.cpp",
167        "src/ports/SkImageGenerator_none.cpp",
168        "src/ports/SkTLS_none.cpp",
169    ],
170)
171
172# Platform-dependent SRCS for google3-default Android.
173BASE_SRCS_ANDROID = struct(
174    include = [
175        "src/android/*",
176        "src/codec/*",
177        "src/gpu/gl/GrGLDefaultInterface_none.cpp",
178        "src/images/*",
179        # TODO(benjaminwagner): Figure out how to compile with EGL.
180        "src/opts/**/*.cpp",
181        "src/opts/**/*.h",
182        "src/ports/**/*.cpp",
183        "src/ports/**/*.h",
184    ],
185    exclude = [
186        "src/opts/*mips*",
187        "src/opts/*SSE2*",
188        "src/opts/*SSSE3*",
189        "src/opts/*ssse3*",
190        "src/opts/*SSE4*",
191        "src/opts/*sse4*",
192        "src/opts/*avx*",
193        "src/opts/*x86*",
194        "src/opts/SkBitmapProcState_opts_none.cpp",
195        "src/opts/SkBlitMask_opts_none.cpp",
196        "src/opts/SkBlitRow_opts_none.cpp",
197        "src/ports/*chromium*",
198        "src/ports/*fontconfig*",
199        "src/ports/*FontConfig*",
200        "src/ports/*mac*",
201        "src/ports/*mozalloc*",
202        "src/ports/*nacl*",
203        "src/ports/*win*",
204        "src/ports/SkDebug_stdio.cpp",
205        "src/ports/SkFontConfigInterface_direct_factory.cpp",
206        "src/ports/SkFontConfigInterface_direct_google3_factory.cpp",
207        "src/ports/SkFontMgr_custom_directory_factory.cpp",
208        "src/ports/SkFontMgr_custom_embedded_factory.cpp",
209        "src/ports/SkFontMgr_empty_factory.cpp",
210        "src/ports/SkImageDecoder_CG.cpp",
211        "src/ports/SkImageDecoder_WIC.cpp",
212        "src/ports/SkImageDecoder_empty.cpp",
213        "src/ports/SkImageGenerator_none.cpp",
214        "src/ports/SkTLS_none.cpp",
215    ],
216)
217
218# Platform-dependent SRCS for google3-default iOS.
219BASE_SRCS_IOS = struct(
220    include = [
221        "src/android/*",
222        "src/codec/*",
223        "src/gpu/gl/GrGLDefaultInterface_native.cpp",
224        "src/gpu/gl/iOS/GrGLCreateNativeInterface_iOS.cpp",
225        "src/opts/**/*.cpp",
226        "src/opts/**/*.h",
227        "src/ports/**/*.cpp",
228        "src/ports/**/*.h",
229        "src/utils/mac/*.cpp",
230    ],
231    exclude = [
232        "src/codec/*Gif*.cpp",
233        "src/codec/*Ico*.cpp",
234        "src/codec/*Jpeg*.cpp",
235        "src/codec/*Webp*.cpp",
236        "src/codec/*Png*",
237        "src/codec/*Raw*.cpp",
238        "src/opts/*mips*",
239        "src/opts/*NEON*",
240        "src/opts/*neon*",
241        "src/opts/*SSE2*",
242        "src/opts/*SSSE3*",
243        "src/opts/*ssse3*",
244        "src/opts/*SSE4*",
245        "src/opts/*sse4*",
246        "src/opts/*avx*",
247        "src/opts/*x86*",
248        "src/opts/SkBitmapProcState_opts_none.cpp",
249        "src/opts/SkBlitMask_opts_arm*.cpp",
250        "src/opts/SkBlitRow_opts_arm*.cpp",
251        "src/ports/*android*",
252        "src/ports/*chromium*",
253        "src/ports/*fontconfig*",
254        "src/ports/*FontConfig*",
255        "src/ports/*FreeType*",
256        "src/ports/*mozalloc*",
257        "src/ports/*nacl*",
258        "src/ports/*win*",
259        "src/ports/SkFontMgr_custom.cpp",
260        "src/ports/SkFontConfigInterface_direct_factory.cpp",
261        "src/ports/SkFontConfigInterface_direct_google3_factory.cpp",
262        "src/ports/SkFontMgr_custom_directory_factory.cpp",
263        "src/ports/SkFontMgr_custom_embedded_factory.cpp",
264        "src/ports/SkFontMgr_empty_factory.cpp",
265        "src/ports/SkImageDecoder_CG.cpp",
266        "src/ports/SkImageDecoder_WIC.cpp",
267        "src/ports/SkImageGenerator_none.cpp",
268        "src/ports/SkTLS_none.cpp",
269    ],
270)
271
272################################################################################
273## SSSE3/SSE4/AVX/AVX2 SRCS
274################################################################################
275
276SSSE3_SRCS = struct(
277    include = [
278        "src/opts/*SSSE3*.cpp",
279        "src/opts/*ssse3*.cpp",
280    ],
281)
282
283SSE4_SRCS = struct(
284    include = [
285        "src/opts/*SSE4*.cpp",
286        "src/opts/*sse4*.cpp",
287    ],
288)
289
290AVX_SRCS = struct(
291    include = [
292        "src/opts/*_avx.cpp",
293    ],
294)
295
296AVX2_SRCS = struct(
297    include = [
298        "src/opts/*_avx2.cpp",
299    ],
300)
301
302################################################################################
303## BASE_HDRS
304################################################################################
305
306BASE_HDRS = struct(
307    include = [
308        "include/**/*.h",
309        "src/utils/SkWhitelistChecksums.cpp",
310    ],
311    exclude = [
312        "include/private/**/*",
313
314        # Not used.
315        "include/animator/**/*",
316        "include/views/**/*",
317        "include/xml/SkBML_WXMLParser.h",
318        "include/xml/SkBML_XMLParser.h",
319    ],
320)
321
322################################################################################
323## BASE_DEPS
324################################################################################
325
326BASE_DEPS_ALL = []
327
328BASE_DEPS_UNIX = [
329    ":opts_ssse3",
330    ":opts_sse4",
331    ":opts_avx",
332    ":opts_avx2",
333]
334
335BASE_DEPS_ANDROID = []
336
337BASE_DEPS_IOS = []
338
339################################################################################
340## INCLUDES
341################################################################################
342
343# Includes needed by Skia implementation.  Not public includes.
344INCLUDES = [
345    "include/android",
346    "include/c",
347    "include/client/android",
348    "include/codec",
349    "include/config",
350    "include/core",
351    "include/effects",
352    "include/gpu",
353    "include/images",
354    "include/pathops",
355    "include/pipe",
356    "include/ports",
357    "include/private",
358    "include/utils",
359    "include/utils/mac",
360    "include/utils/win",
361    "include/svg",
362    "include/xml",
363    "src/codec",
364    "src/core",
365    "src/gpu",
366    "src/image",
367    "src/lazy",
368    "src/opts",
369    "src/ports",
370    "src/pdf",
371    "src/sfnt",
372    "src/utils",
373    "third_party/etc1",
374    "third_party/ktx",
375]
376
377################################################################################
378## DM_SRCS
379################################################################################
380
381DM_SRCS_ALL = struct(
382    include = [
383        "dm/*.cpp",
384        "dm/*.h",
385        "gm/*.c",
386        "gm/*.cpp",
387        "gm/*.h",
388        "tests/*.cpp",
389        "tests/*.h",
390        "tools/CrashHandler.cpp",
391        "tools/CrashHandler.h",
392        "tools/ProcStats.cpp",
393        "tools/ProcStats.h",
394        "tools/Resources.cpp",
395        "tools/Resources.h",
396        "tools/SkBitmapRegionCanvas.cpp",
397        "tools/SkBitmapRegionCanvas.h",
398        "tools/SkBitmapRegionCodec.cpp",
399        "tools/SkBitmapRegionCodec.h",
400        "tools/SkBitmapRegionDecoder.cpp",
401        "tools/SkBitmapRegionDecoder.h",
402        "tools/SkBitmapRegionSampler.cpp",
403        "tools/SkBitmapRegionSampler.h",
404        "tools/flags/*.cpp",
405        "tools/flags/*.h",
406        "tools/random_parse_path.cpp",
407        "tools/random_parse_path.h",
408        "tools/sk_tool_utils.cpp",
409        "tools/sk_tool_utils.h",
410        "tools/sk_tool_utils_font.cpp",
411        "tools/timer/*.cpp",
412        "tools/timer/*.h",
413    ],
414    exclude = [
415        "dm/DMSrcSinkAndroid.cpp",  # Android-only.
416        "tests/FontMgrAndroidParserTest.cpp",  # Android-only.
417        "tests/PathOpsSkpClipTest.cpp",  # Alternate main.
418        "tests/skia_test.cpp",  # Old main.
419        "tests/SkpSkGrTest.cpp",  # Alternate main.
420        "tools/timer/SysTimer_mach.cpp",
421        "tools/timer/SysTimer_windows.cpp",
422    ],
423)
424
425DM_SRCS_UNIX = struct()
426
427DM_SRCS_ANDROID = struct(
428    include = [
429        # Depends on Android HWUI library that is not available in google3.
430        #"dm/DMSrcSinkAndroid.cpp",
431        "tests/FontMgrAndroidParserTest.cpp",
432    ],
433)
434
435DM_SRCS_IOS = struct()
436
437################################################################################
438## DM_INCLUDES
439################################################################################
440
441DM_INCLUDES = [
442    "dm",
443    "gm",
444    "src/codec",
445    "src/effects",
446    "src/effects/gradients",
447    "src/fonts",
448    "src/pathops",
449    "src/pipe/utils",
450    "src/ports",
451    "tools/debugger",
452    "tests",
453    "tools",
454    "tools/flags",
455    "tools/timer",
456]
457
458################################################################################
459## DM_ARGS
460################################################################################
461
462def DM_ARGS(base_dir):
463    return [
464        "--nogpu",
465        "--verbose",
466        # TODO(mtklein): maybe investigate why these fail?
467        "--match ~FontMgr ~Scalar ~Canvas ~Codec_stripes ~Codec_Dimensions ~Codec ~Stream ~skps ~RecordDraw_TextBounds ~PaintBreakText",
468        "--resourcePath %s/resources" % base_dir,
469        "--images %s/resources" % base_dir,
470    ]
471
472################################################################################
473## COPTS
474################################################################################
475
476COPTS_UNIX = [
477    "-Wno-implicit-fallthrough",  # Some intentional fallthrough.
478    "-Wno-deprecated-declarations",  # Internal use of deprecated methods. :(
479]
480
481COPTS_ANDROID = ["-mfpu=neon"]
482
483COPTS_IOS = []
484
485COPTS_ALL = []
486
487################################################################################
488## DEFINES
489################################################################################
490
491DEFINES_UNIX = [
492    "PNG_SKIP_SETJMP_CHECK",
493    "SK_BUILD_FOR_UNIX",
494    "SK_SAMPLES_FOR_X",
495    "SK_SFNTLY_SUBSETTER",
496    "SK_CODEC_DECODES_GIF",
497    "SK_CODEC_DECODES_JPEG",
498    "SK_CODEC_DECODES_PNG",
499    "SK_CODEC_DECODES_RAW",
500    "SK_CODEC_DECODES_WEBP",
501]
502
503DEFINES_ANDROID = [
504    "SK_BUILD_FOR_ANDROID",
505    "SK_CODEC_DECODES_GIF",
506    "SK_CODEC_DECODES_JPEG",
507    "SK_CODEC_DECODES_PNG",
508    "SK_CODEC_DECODES_RAW",
509    "SK_CODEC_DECODES_WEBP",
510]
511
512DEFINES_IOS = [
513    "SK_BUILD_FOR_IOS",
514    "SK_IGNORE_ETC1_SUPPORT",
515    "SKNX_NO_SIMD",
516]
517
518DEFINES_ALL = [
519    # Chrome DEFINES.
520    "SK_USE_FLOATBITS",
521    "SK_USE_FREETYPE_EMBOLDEN",
522    # Turn on a few Google3-specific build fixes.
523    "GOOGLE3",
524]
525
526################################################################################
527## LINKOPTS
528################################################################################
529
530LINKOPTS_UNIX = []
531
532LINKOPTS_ANDROID = [
533    "-lEGL",
534]
535
536LINKOPTS_IOS = []
537
538LINKOPTS_ALL = [
539    "-ldl",
540]
541