• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1load("//bazel:flags.bzl", "bool_flag", "selects", "string_flag_with_values")
2
3package(
4    default_applicable_licenses = ["//:license"],
5)
6
7licenses(["notice"])
8
9# @platforms is found at https://github.com/bazelbuild/platforms
10
11config_setting(
12    name = "linux_x64",
13    constraint_values = [
14        "@platforms//cpu:x86_64",
15        "@platforms//os:linux",
16    ],
17)
18
19# Apple devices with intel processors released before the shift to the M1 chip
20# will use this config setting.
21config_setting(
22    name = "mac_x64",
23    constraint_values = [
24        "@platforms//cpu:x86_64",
25        "@platforms//os:macos",
26    ],
27)
28
29# M1 Macs (and later) will use this setting.
30config_setting(
31    name = "mac_arm64",
32    constraint_values = [
33        "@platforms//cpu:arm64",
34        "@platforms//os:macos",
35    ],
36)
37
38config_setting(
39    name = "windows_x64",
40    constraint_values = [
41        "@platforms//cpu:x86_64",
42        "@platforms//os:windows",
43    ],
44)
45
46config_setting(
47    name = "linux_arm64",
48    constraint_values = [
49        "@platforms//cpu:arm64",
50        "@platforms//os:linux",
51    ],
52)
53
54config_setting(
55    name = "debug_build",
56    values = {"compilation_mode": "dbg"},
57)
58
59config_setting(
60    name = "fast_build",
61    values = {"compilation_mode": "fastbuild"},
62)
63
64config_setting(
65    name = "release_build",
66    values = {"compilation_mode": "opt"},
67)
68
69constraint_value(
70    name = "fuchsia",
71    constraint_setting = "@platforms//os:os",
72)
73
74config_setting(
75    name = "fuchsia_arm64",
76    constraint_values = [
77        "@platforms//cpu:arm64",
78        ":fuchsia",
79    ],
80)
81
82# We define this here because the emscripten toolchain calls the cpu wasm, whereas the
83# bazelbuild/platforms call it wasm32. https://github.com/emscripten-core/emsdk/issues/919
84config_setting(
85    name = "cpu_wasm",
86    values = {
87        "cpu": "wasm",
88    },
89)
90
91selects.config_setting_group(
92    name = "release_build_mac",
93    match_all = [
94        "@platforms//os:macos",
95        ":release_build",
96    ],
97    visibility = ["//:__subpackages__"],
98)
99
100selects.config_setting_group(
101    name = "release_build_linux",
102    match_all = [
103        "@platforms//os:linux",
104        ":release_build",
105    ],
106    visibility = ["//:__subpackages__"],
107)
108
109selects.config_setting_group(
110    name = "fast_build_mac",
111    match_all = [
112        "@platforms//os:macos",
113        ":fast_build",
114    ],
115    visibility = ["//:__subpackages__"],
116)
117
118selects.config_setting_group(
119    name = "fast_build_linux",
120    match_all = [
121        "@platforms//os:linux",
122        ":fast_build",
123    ],
124    visibility = ["//:__subpackages__"],
125)
126
127# =============================================================================
128#                     Configurable Skia Features
129# =============================================================================
130# These are flags that we can specify when invoking bazel build to turn on and
131# off certain features, such as GPU backend, or codec support.
132# https://bazel.build/rules/config#defining-build-settings
133# For example, to enable harfbuzz and icu, one would run
134# bazel build //:skia_public --//bazel/common_config_settings:use_harfbuzz \
135#             --//bazel/common_config_settings:use_icu
136# This is a bit wordy, so we define aliases in the //.bazelrc file that condense this to
137# bazel build //:skia_public --with_harfbuzz --with_icu
138#
139# Developers can specify their own short-hands by making a .bazelrc file in their home
140# directory. https://bazel.build/docs/bazelrc#bazelrc-file-locations
141#
142# We check in some Bazel configs for "blessed builds" in //bazel/buildrc.
143#
144# We can also define flags closer to where they have the most impact. For example
145# //src/pdf:enable_pdf_backend.
146
147string_flag_with_values(
148    name = "fontmgr_factory",
149    default = "empty_fontmgr_factory",
150    values = [
151        "android_fontmgr_factory",
152        # Makes the default SkFontMgr load fonts from a hard-coded directory on disk.
153        "custom_directory_fontmgr_factory",
154        # Makes the default SkFontMgr load fonts from an SkEmbeddedResource that has been compiled
155        # into the binary, e.g. with //tools/embed_resources.py
156        "custom_embedded_fontmgr_factory",
157        # Makes the default SkFontMgr return empty fonts (e.g. SkTypeface_Empty). This is typically
158        # used when someone wants to make their own custom SkFontMgr objects, but does not want the
159        # default SkFontMgr to do anything (e.g. force usage of the custom one).
160        "custom_empty_fontmgr_factory",
161        # Makes the default SkFontMgr return null. Typically used when font support is not desired.
162        "empty_fontmgr_factory",
163        "fontconfig_fontmgr_factory",
164        # Deprecated, do not use.
165        "fci_fontmgr_factory",
166    ],
167)
168
169# These flags need only be set if additional functionality beyond the fontmgr_factory flag is
170# required. For example, the setting fontmgr_factory to custom_embedded_fontmgr_factory does not
171# require setting include_fontmgr to custom_embedded_fontmgr, because those sources and settings
172# will already be compiled in due to the _factory flag.
173string_flag_with_values(
174    name = "include_fontmgr",
175    multiple = True,
176    values = [
177        "android_fontmgr",
178        # Allows the construction of an SkFontMgr that loads files from a programmatically
179        # defined directory on disk.
180        "custom_directory_fontmgr",
181        # Allows the construction of an SkFontMgr which can load fonts from an SkEmbeddedResource
182        # or from another source of raw bytes.
183        "custom_embedded_fontmgr",
184        # Allows the construction of an SkFontMgr which returns empty fonts.
185        "custom_empty_fontmgr",
186        "fontconfig_fontmgr",
187        # Deprecated, do not use.
188        "fci_fontmgr",
189    ],
190)
191
192bool_flag(
193    name = "enable_effect_serialization",
194    default = True,
195)
196
197bool_flag(
198    name = "enable_tracing",
199    # See SkTraceEventCommon.h for more on this type of tracing.
200    default = True,
201)
202
203bool_flag(
204    name = "enable_skvm",
205    default = False,
206)
207
208bool_flag(
209    name = "use_harfbuzz",
210    default = False,
211)
212
213bool_flag(
214    name = "use_fontations",
215    default = False,
216)
217
218bool_flag(
219    name = "use_icu",
220    default = False,
221)
222
223bool_flag(
224    name = "build_for_debugger",
225    default = False,
226)
227
228# These are some helpers to mean "either the fontmgr was enabled or its factory was"
229
230selects.config_setting_group(
231    name = "uses_android_fontmgr",
232    match_any = [
233        ":android_fontmgr",
234        ":android_fontmgr_factory",
235    ],
236)
237
238selects.config_setting_group(
239    name = "uses_custom_directory_fontmgr",
240    match_any = [
241        ":custom_directory_fontmgr",
242        ":custom_directory_fontmgr_factory",
243    ],
244)
245
246selects.config_setting_group(
247    name = "uses_custom_embedded_fontmgr",
248    match_any = [
249        ":custom_embedded_fontmgr",
250        ":custom_embedded_fontmgr_factory",
251    ],
252)
253
254selects.config_setting_group(
255    name = "uses_custom_empty_fontmgr",
256    match_any = [
257        ":custom_empty_fontmgr",
258        ":custom_empty_fontmgr_factory",
259    ],
260)
261
262selects.config_setting_group(
263    name = "uses_fontconfig_fontmgr",
264    match_any = [
265        ":fontconfig_fontmgr",
266        ":fontconfig_fontmgr_factory",
267    ],
268)
269
270selects.config_setting_group(
271    name = "uses_fci_fontmgr",
272    match_any = [
273        ":fci_fontmgr",
274        ":fci_fontmgr_factory",
275    ],
276)
277
278# Convenience condition that is always true. This condition is satisfied if an arbitrarily chosen
279# boolean built-in flag (https://bazel.build/docs/user-manual#stamp) is either true or false.
280#
281# Inspired by
282# https://github.com/bazelbuild/bazel-skylib/blob/2f0bb4cec0297bb38f830a72fa8961bee057c3cd/lib/selects.bzl#L227.
283selects.config_setting_group(
284    name = "always_true",
285    match_any = [
286        ":always_true_0",
287        ":always_true_1",
288    ],
289    visibility = ["//visibility:public"],
290)
291
292config_setting(
293    name = "always_true_0",
294    values = {"stamp": "0"},
295)
296
297config_setting(
298    name = "always_true_1",
299    values = {"stamp": "1"},
300)
301