2021-11-16 19:09:44 +00:00
|
|
|
"""
|
|
|
|
This file contains helpers for defining build flags and options that are used to
|
|
|
|
configure the Skia build.
|
|
|
|
"""
|
|
|
|
|
[infra] Add initial Bazel rules and files
These rules can be used to build our GMs on WASM+WebGL and
libskia.a with just the CPU backend (and most other features
turned off).
This can be done with the following commands:
- bazel build //modules/canvaskit:gm-bindings-wasm --gpu_backend=gl_backend --with_gl_standard=webgl_standard
- bazel build :skia-core --config clang
This pivots slightly from http://review.skia.org/463517
by using config_settings [1] instead of platforms for
the optional features that we control. This pivot was
suggested in [2]
We have BUILD.bazel files in many of the subdirectories
that specify filegroups for the appropriate files. In
an effort to make //BUILD.bazel more readable, it is
the responsibility of these subfolders to deal with
conditionally including certain .h or .cpp files.
This is done using select statements and config_settings
or platform constraints as necessary.
For example, src/gpu/BUILD.bazel will different private
filegroups for each of the supported gpu backends [3]
and a more-visible filegroup called "srcs" that has
the right selection of the private files to be used
for compilation.
An effort has been made to avoid using glob() in our
BUILD.bazel files. These file lists were made by using
`ls -1` and some regex to add in quotes. We might want
to make a helper script to assist with that, if necessary.
To specify which options we have, the settings in
//bazel/common_config_settings/BUILD.bazel have been
redesigned. They make use of a macro `string_flag_with_values`
that removes the boilerplate. Patchset 36 shows what the
file looks like w/o the macro.
The top level BUILD.bazel file will still need to use
some logic to handle defines, because local_defines is
a list of strings, not a list of labels [4].
Suggested Review Order:
- WORKSPACE.bazel to see the new dependencies on the
emsdk toolchain and bazel_skylib
- bazel/common_config_settings/* to see the few settings
defined (we have more to define, see BUILD.gn and
//gn/skia.gni for ideas)
- BUILD.bazel to see the "skia-core" cc_library rule.
See also "gms" and "tests"
- modules/canvaskit/BUILD.bazel to see the use of
the emscripten "wasm_cc_binary" rule, which depends
on the "skia-core", "gms", and "tests" rule. Note that
it only builds some of the gms as a proof of concept.
- The other BUILD.bazel files. Some of these are not
platform or feature dependent (e.g. pathops). Others
are (e.g. gpu).
- All other files.
[1] https://docs.bazel.build/versions/4.2.1/skylark/config.html#user-defined-build-settings
[2] https://github.com/emscripten-core/emsdk/pull/920
[3] In this CL, that's just the webgl one.
[4] https://docs.bazel.build/versions/main/be/c-cpp.html#cc_library.local_defines
Change-Id: Ieecf9c106d5e3a6ae97d13d66be06b4b3c207089
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/458637
Reviewed-by: Ben Wagner <bungeman@google.com>
Reviewed-by: Leandro Lovisolo <lovisolo@google.com>
Owners-Override: Kevin Lubick <kjlubick@google.com>
2021-11-08 20:26:09 +00:00
|
|
|
# https://github.com/bazelbuild/bazel-skylib/blob/main/rules/common_settings.bzl
|
2021-11-16 19:09:44 +00:00
|
|
|
load("@bazel_skylib//rules:common_settings.bzl", "string_flag", skylib_bool_flag = "bool_flag")
|
[infra] Add initial Bazel rules and files
These rules can be used to build our GMs on WASM+WebGL and
libskia.a with just the CPU backend (and most other features
turned off).
This can be done with the following commands:
- bazel build //modules/canvaskit:gm-bindings-wasm --gpu_backend=gl_backend --with_gl_standard=webgl_standard
- bazel build :skia-core --config clang
This pivots slightly from http://review.skia.org/463517
by using config_settings [1] instead of platforms for
the optional features that we control. This pivot was
suggested in [2]
We have BUILD.bazel files in many of the subdirectories
that specify filegroups for the appropriate files. In
an effort to make //BUILD.bazel more readable, it is
the responsibility of these subfolders to deal with
conditionally including certain .h or .cpp files.
This is done using select statements and config_settings
or platform constraints as necessary.
For example, src/gpu/BUILD.bazel will different private
filegroups for each of the supported gpu backends [3]
and a more-visible filegroup called "srcs" that has
the right selection of the private files to be used
for compilation.
An effort has been made to avoid using glob() in our
BUILD.bazel files. These file lists were made by using
`ls -1` and some regex to add in quotes. We might want
to make a helper script to assist with that, if necessary.
To specify which options we have, the settings in
//bazel/common_config_settings/BUILD.bazel have been
redesigned. They make use of a macro `string_flag_with_values`
that removes the boilerplate. Patchset 36 shows what the
file looks like w/o the macro.
The top level BUILD.bazel file will still need to use
some logic to handle defines, because local_defines is
a list of strings, not a list of labels [4].
Suggested Review Order:
- WORKSPACE.bazel to see the new dependencies on the
emsdk toolchain and bazel_skylib
- bazel/common_config_settings/* to see the few settings
defined (we have more to define, see BUILD.gn and
//gn/skia.gni for ideas)
- BUILD.bazel to see the "skia-core" cc_library rule.
See also "gms" and "tests"
- modules/canvaskit/BUILD.bazel to see the use of
the emscripten "wasm_cc_binary" rule, which depends
on the "skia-core", "gms", and "tests" rule. Note that
it only builds some of the gms as a proof of concept.
- The other BUILD.bazel files. Some of these are not
platform or feature dependent (e.g. pathops). Others
are (e.g. gpu).
- All other files.
[1] https://docs.bazel.build/versions/4.2.1/skylark/config.html#user-defined-build-settings
[2] https://github.com/emscripten-core/emsdk/pull/920
[3] In this CL, that's just the webgl one.
[4] https://docs.bazel.build/versions/main/be/c-cpp.html#cc_library.local_defines
Change-Id: Ieecf9c106d5e3a6ae97d13d66be06b4b3c207089
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/458637
Reviewed-by: Ben Wagner <bungeman@google.com>
Reviewed-by: Leandro Lovisolo <lovisolo@google.com>
Owners-Override: Kevin Lubick <kjlubick@google.com>
2021-11-08 20:26:09 +00:00
|
|
|
|
2021-11-11 17:50:02 +00:00
|
|
|
# Forked from https://github.com/bazelbuild/bazel-skylib/blob/main/rules/common_settings.bzl
|
2021-11-16 19:09:44 +00:00
|
|
|
BuildSettingInfo = provider(
|
|
|
|
doc = "A singleton provider that contains the raw value of a multi-string build setting",
|
|
|
|
fields = ["values"],
|
|
|
|
)
|
2021-11-11 17:50:02 +00:00
|
|
|
|
|
|
|
def _multi_string_impl(ctx):
|
|
|
|
allowed_values = ctx.attr.values
|
|
|
|
values = ctx.build_setting_value
|
|
|
|
for v in values:
|
|
|
|
if v not in ctx.attr.values:
|
|
|
|
fail("Error setting " + str(ctx.label) + ": invalid value '" + v + "'. Allowed values are " + str(allowed_values))
|
|
|
|
return BuildSettingInfo(values = values)
|
|
|
|
|
|
|
|
multi_string_flag = rule(
|
|
|
|
implementation = _multi_string_impl,
|
|
|
|
build_setting = config.string(flag = True, allow_multiple = True),
|
|
|
|
attrs = {
|
|
|
|
"values": attr.string_list(
|
|
|
|
doc = "The list of allowed values for this setting. An error is raised if any other values are given.",
|
|
|
|
),
|
|
|
|
},
|
|
|
|
doc = "A string-typed build setting that can be set multiple times on the command line",
|
|
|
|
)
|
|
|
|
|
2022-04-05 18:21:56 +00:00
|
|
|
# buildifier: disable=unnamed-macro
|
|
|
|
def string_flag_with_values(flag_name, values, default = "", multiple = False):
|
2021-11-16 19:09:44 +00:00
|
|
|
"""Create a string flag and corresponding config_settings.
|
|
|
|
|
|
|
|
string_flag_with_values is a Bazel Macro that defines a flag with the given name and a set
|
|
|
|
of valid values for that flag. For each value, a config_setting is defined with the name
|
|
|
|
of the value, associated with the created flag.
|
|
|
|
This is defined to make the BUILD.bazel file easier to read w/o the boilerplate of defining
|
|
|
|
a string_flag rule and n config_settings
|
|
|
|
https://docs.bazel.build/versions/main/skylark/macros.html
|
|
|
|
|
|
|
|
Args:
|
|
|
|
flag_name: string, the name of the flag to create and use for the config_settings
|
|
|
|
values: list of strings, the valid values for this flag to be set to.
|
|
|
|
default: string, whatever the default value should be if the flag is not set. Can be
|
|
|
|
empty string for both a string_flag and a multi_string flag.
|
|
|
|
multiple: boolean, True if the flag should be able to be set multiple times on the CLI.
|
|
|
|
"""
|
2021-11-11 17:50:02 +00:00
|
|
|
if multiple:
|
|
|
|
multi_string_flag(
|
|
|
|
name = flag_name,
|
|
|
|
# We have to specify a default value, even if that value is empty string.
|
|
|
|
# https://docs.bazel.build/versions/main/skylark/config.html#instantiating-build-settings
|
|
|
|
build_setting_default = default,
|
|
|
|
# If empty string is the default, we need to make sure it is in the list
|
|
|
|
# of acceptable values. If the default is not empty string, we don't want
|
|
|
|
# to make empty string a valid value. Having duplicate values in the list
|
|
|
|
# does not cause any issues, so we can just add the default to achieve
|
|
|
|
# this affect.
|
|
|
|
values = values + [default],
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
string_flag(
|
|
|
|
name = flag_name,
|
|
|
|
# We have to specify a default value, even if that value is empty string.
|
|
|
|
# https://docs.bazel.build/versions/main/skylark/config.html#instantiating-build-settings
|
|
|
|
build_setting_default = default,
|
|
|
|
# If empty string is the default, we need to make sure it is in the list
|
|
|
|
# of acceptable values. If the default is not empty string, we don't want
|
|
|
|
# to make empty string a valid value. Having duplicate values in the list
|
|
|
|
# does not cause any issues, so we can just add the default to achieve
|
|
|
|
# this affect.
|
|
|
|
values = values + [default],
|
|
|
|
)
|
[infra] Add initial Bazel rules and files
These rules can be used to build our GMs on WASM+WebGL and
libskia.a with just the CPU backend (and most other features
turned off).
This can be done with the following commands:
- bazel build //modules/canvaskit:gm-bindings-wasm --gpu_backend=gl_backend --with_gl_standard=webgl_standard
- bazel build :skia-core --config clang
This pivots slightly from http://review.skia.org/463517
by using config_settings [1] instead of platforms for
the optional features that we control. This pivot was
suggested in [2]
We have BUILD.bazel files in many of the subdirectories
that specify filegroups for the appropriate files. In
an effort to make //BUILD.bazel more readable, it is
the responsibility of these subfolders to deal with
conditionally including certain .h or .cpp files.
This is done using select statements and config_settings
or platform constraints as necessary.
For example, src/gpu/BUILD.bazel will different private
filegroups for each of the supported gpu backends [3]
and a more-visible filegroup called "srcs" that has
the right selection of the private files to be used
for compilation.
An effort has been made to avoid using glob() in our
BUILD.bazel files. These file lists were made by using
`ls -1` and some regex to add in quotes. We might want
to make a helper script to assist with that, if necessary.
To specify which options we have, the settings in
//bazel/common_config_settings/BUILD.bazel have been
redesigned. They make use of a macro `string_flag_with_values`
that removes the boilerplate. Patchset 36 shows what the
file looks like w/o the macro.
The top level BUILD.bazel file will still need to use
some logic to handle defines, because local_defines is
a list of strings, not a list of labels [4].
Suggested Review Order:
- WORKSPACE.bazel to see the new dependencies on the
emsdk toolchain and bazel_skylib
- bazel/common_config_settings/* to see the few settings
defined (we have more to define, see BUILD.gn and
//gn/skia.gni for ideas)
- BUILD.bazel to see the "skia-core" cc_library rule.
See also "gms" and "tests"
- modules/canvaskit/BUILD.bazel to see the use of
the emscripten "wasm_cc_binary" rule, which depends
on the "skia-core", "gms", and "tests" rule. Note that
it only builds some of the gms as a proof of concept.
- The other BUILD.bazel files. Some of these are not
platform or feature dependent (e.g. pathops). Others
are (e.g. gpu).
- All other files.
[1] https://docs.bazel.build/versions/4.2.1/skylark/config.html#user-defined-build-settings
[2] https://github.com/emscripten-core/emsdk/pull/920
[3] In this CL, that's just the webgl one.
[4] https://docs.bazel.build/versions/main/be/c-cpp.html#cc_library.local_defines
Change-Id: Ieecf9c106d5e3a6ae97d13d66be06b4b3c207089
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/458637
Reviewed-by: Ben Wagner <bungeman@google.com>
Reviewed-by: Leandro Lovisolo <lovisolo@google.com>
Owners-Override: Kevin Lubick <kjlubick@google.com>
2021-11-08 20:26:09 +00:00
|
|
|
|
|
|
|
# For each of the values given, we define a config_setting. This allows us to use
|
|
|
|
# select statements, on the given setting, e.g. referencing
|
|
|
|
# //bazel/common_config_settings:some_valid_value_for_a_flag
|
|
|
|
for v in values:
|
|
|
|
native.config_setting(
|
|
|
|
name = v,
|
|
|
|
flag_values = {
|
|
|
|
":" + flag_name: v,
|
|
|
|
},
|
|
|
|
)
|
2021-11-16 19:09:44 +00:00
|
|
|
|
2022-04-05 18:21:56 +00:00
|
|
|
# buildifier: disable=unnamed-macro
|
|
|
|
def bool_flag(flag_name, default = True, public = True):
|
2021-11-16 19:09:44 +00:00
|
|
|
"""Create a boolean flag and corresponding config_settings.
|
|
|
|
|
|
|
|
bool_flag is a Bazel Macro that defines a boolean flag with the given name two config_settings,
|
|
|
|
one for True, one for False. Reminder that Bazel has special syntax for unsetting boolean flags,
|
|
|
|
but this does not work well with aliases.
|
|
|
|
https://docs.bazel.build/versions/main/skylark/config.html#using-build-settings-on-the-command-line
|
|
|
|
Thus it is best to define both an "enabled" alias and a "disabled" alias.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
flag_name: string, the name of the flag to create and use for the config_settings
|
|
|
|
default: boolean, if the flag should default to on or off.
|
2022-04-05 18:21:56 +00:00
|
|
|
public: boolean, if the flag should be usable from other packages or if it is meant to be
|
|
|
|
combined with some other constraint.
|
2021-11-16 19:09:44 +00:00
|
|
|
"""
|
|
|
|
skylib_bool_flag(name = flag_name, build_setting_default = default)
|
2022-04-05 18:21:56 +00:00
|
|
|
vis = ["//:__subpackages__"]
|
|
|
|
if not public:
|
|
|
|
vis = ["//visibility:private"]
|
2021-11-16 19:09:44 +00:00
|
|
|
|
|
|
|
native.config_setting(
|
|
|
|
name = flag_name + "_true",
|
|
|
|
flag_values = {
|
|
|
|
# The value must be a string, but it will be parsed to a boolean
|
|
|
|
# https://docs.bazel.build/versions/main/skylark/config.html#build-settings-and-select
|
|
|
|
":" + flag_name: "True",
|
|
|
|
},
|
2022-04-05 18:21:56 +00:00
|
|
|
visibility = vis,
|
2021-11-16 19:09:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
native.config_setting(
|
|
|
|
name = flag_name + "_false",
|
|
|
|
flag_values = {
|
|
|
|
":" + flag_name: "False",
|
|
|
|
},
|
2022-04-05 18:21:56 +00:00
|
|
|
visibility = vis,
|
2021-11-16 19:09:44 +00:00
|
|
|
)
|