The Abseil C++ Library (source) is a collection of useful C++ utilities that are elusive in the C++ standard library. Why adopt Abseil?
The official repository supports using Bazel or CMake as the build system. But I want to make it usable with GN, a build system developed by and for the Chromium projects with cross-platform and conditional builds in mind, and which I think is more light-weight and syntactically elegant than Bazel (GN vs Bazel).
This project generates GN build files so that Abseil can serve as a library
embedded in another GN-managed project. Therefore, it does not transpile Bazel
build settings stored in WORKSPACE
and *.bzl
files etc.
- Python 3.8+,
- Git 2.21+,
- (optional) Bazel 3.4.1+
This requires Bazel.
Working directory: at root of this repository.
# Fetch Abseil source and update *.gn files
$ ./update.sh # add "-r" to skip fetching the Abseil source.
What if the program "hangs"?
On first execution, Bazel may decide to download JDK (yeah, it doesn't do this step during installation), which may take a long time and it appears the program hangs. This peculiar behavior of Bazel is annoying (GitHub issue).
This doesn't require Bazel.
Working directory: at root of this repository.
# This will automatically "git checkout" the corresponding Abseil commit.
$ ./inject.sh path/to/abseil-cpp
$ ./gen.py --help
It controls how Bazel build files are converted to GN build files. Boradly speaking, the JSON file serves two purposes:
- Controls the generation of GN files.
- Circumvents complex configuration computation in Bazel.
The profile could be auto-generated by a GN target so its content can depend on how GN handles conditionals.
Type: dict[str, str]
(key: apparent Bazel target type, value: apparent GN
target type). Default: empty.
Controls what Bazel target types get transpiled into what GN target types (for
example, cc_library
can correspond to source_set
, shared_library
,
static_library
, or even a custom GN target template name like absl_source_set
).
Bazel targets whose type doesn't appear in this map are ignored.
hidden_target_labels
Type: list[str]
(elements: regular expressions). Default: empty.
If a target's full label (i.e. path/to/build/file:target_name
) is matched with
any of the regular expressions, the target's visibility is private to the Bazel
project itself. Otherwise, the target is publicly visible.
Indeed, Bazel targets have their own visibility annotations the grammar is too
complicated (e.g. special names like __pkg__
, __subpackages__
, or a package
group), and isn't particularly useful to retain this fine-grained control in the use case where the Bazel project serves as a library - what really matters is whether clients can refer to a target or not.
Type: bool
. Default: false
.
Whether to skip Bazel targets which have testonly = 1
.
Type: dict[str, str]
(key: root path in Bazel syntax, value: paths in GN
syntax). Default: empty.
Bazel can handle foreign packages but GN was designed with mono-repo in mind.
Therefore, users may need to replace package root path symbols with symbols
understandable by GN. For example, @com_google_googletest//
can be replaced
with $googletest/
, and the user need to specify in their GN setup what
path string the variable googletest
is mapped to.
Type: list[str]
. Default: empty.
Bazel build options to control how to evaluate config_setting
targets, which
in turn affect how select()
is evaluated.
Type: dict[str, Any]
. Default: empty.
Controls what values Bazel variables should represent. In Bazel files, their
values are determined by the context - the assignment statement may appear
elsewhere, even in other files via a load
statement. This is complex.
bazel_variable_expansions
provides a way for user to directly specify their
values.
Type: list[str]
. Default: empty.
Controls what GN attributes should be left out if their values are empty lists.
It serves a cosmetic purpose, in that lots of empty attributes like cflags = []
is ugly.
Type Dict[str, List[str]]
. Default: empty.
Remove list elements in the corresponding any target's GN attribute.
MIT License, except the Abseil source (noted in files) are licensed under this license.
■