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