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