1# Using Abseil in WebRTC 2 3You may use a subset of the utilities provided by the [Abseil][abseil] 4library when writing WebRTC C++ code. Below, we list the explicitly 5*allowed* and the explicitly *disallowed* subsets of Abseil; if you 6find yourself in need of something that isn’t in either subset, 7please add it to the *allowed* subset in this doc in the same CL that 8adds the first use. 9 10[abseil]: https://abseil.io/about/ 11 12## **Allowed** 13 14* `absl::InlinedVector` 15* `absl::WrapUnique` 16* `absl::optional` and related stuff from `absl/types/optional.h`. 17* `absl::string_view` 18* The functions in `absl/strings/ascii.h`, `absl/strings/match.h`, 19 and `absl/strings/str_replace.h`. 20* `absl::is_trivially_copy_constructible`, 21 `absl::is_trivially_copy_assignable`, and 22 `absl::is_trivially_destructible` from `absl/meta/type_traits.h`. 23* `absl::variant` and related stuff from `absl/types/variant.h`. 24* The functions in `absl/algorithm/algorithm.h` and 25 `absl/algorithm/container.h`. 26* `absl/base/const_init.h` for mutex initialization. 27* The macros in `absl/base/attributes.h`, `absl/base/config.h` and 28 `absl/base/macros.h`. 29 30 31## **Disallowed** 32 33### `absl::make_unique` 34 35*Use `std::make_unique` instead.* 36 37### `absl::Mutex` 38 39*Use `webrtc::Mutex` instead.* 40 41Chromium has a ban on new static initializers, and `absl::Mutex` uses 42one. To make `absl::Mutex` available, we would need to nicely ask the 43Abseil team to remove that initializer (like they already did for a 44spinlock initializer). Additionally, `absl::Mutex` handles time in a 45way that may not be compatible with the rest of WebRTC. 46 47### `absl::Span` 48 49*Use `rtc::ArrayView` instead.* 50 51`absl::Span` differs from `rtc::ArrayView` on several points, and both 52of them differ from the `std::span` that was voted into 53C++20—and `std::span` is likely to undergo further changes 54before C++20 is finalized. We should just keep using `rtc::ArrayView` 55and avoid `absl::Span` until C++20 is finalized and the Abseil team 56has decided if they will change `absl::Span` to match. 57[Bug](https://bugs.webrtc.org/9214). 58 59### `absl::StrCat`, `absl::StrAppend`, `absl::StrJoin`, `absl::StrSplit` 60 61*Use `rtc::SimpleStringBuilder` to build strings.* 62 63These are optimized for speed, not binary size. Even `StrCat` calls 64with a modest number of arguments can easily add several hundred bytes 65to the binary. 66 67## How to depend on Abseil 68 69For build targets `rtc_library`, `rtc_source_set` and `rtc_static_library`, 70dependencies on Abseil need to be listed in `absl_deps` instead of `deps`. 71 72This is needed in order to support the Abseil component build in Chromium. In 73such build mode, WebRTC will depend on a unique Abseil build target what will 74generate a shared library. 75