blob: da03af07b1aa2d642e7d6cd4547d5d9cdd7dd33c [file] [log] [blame] [view]
Karl Wibergc3af97d2018-08-27 02:26:181# 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`
Mirko Bonadeic128df12019-09-18 05:59:0715* `absl::WrapUnique`
Karl Wibergc3af97d2018-08-27 02:26:1816* `absl::optional` and related stuff from `absl/types/optional.h`.
17* `absl::string_view`
Steve Anton1c9c9fc2019-02-14 23:13:0918* The functions in `absl/strings/ascii.h`, `absl/strings/match.h`,
19 and `absl/strings/str_replace.h`.
Jiawei Oua6e034a2018-11-25 04:59:4120* `absl::is_trivially_copy_constructible`,
21 `absl::is_trivially_copy_assignable`, and
22 `absl::is_trivially_destructible` from `absl/meta/type_traits.h`.
Karl Wibergc3af97d2018-08-27 02:26:1823* `absl::variant` and related stuff from `absl/types/variant.h`.
Steve Antone76ca612019-01-25 20:49:1424* The functions in `absl/algorithm/algorithm.h` and
Elad Alone86af2c2019-06-03 12:37:5025 `absl/algorithm/container.h`.
Markus Handellf70fbc82020-06-03 22:41:2026* `absl/base/const_init.h` for mutex initialization.
Elad Alone86af2c2019-06-03 12:37:5027* The macros in `absl/base/attributes.h`, `absl/base/config.h` and
28 `absl/base/macros.h`.
Karl Wibergc3af97d2018-08-27 02:26:1829
Markus Handellf70fbc82020-06-03 22:41:2030
Karl Wibergc3af97d2018-08-27 02:26:1831## **Disallowed**
32
Mirko Bonadeic128df12019-09-18 05:59:0733### `absl::make_unique`
34
35*Use `std::make_unique` instead.*
36
Karl Wibergc3af97d2018-08-27 02:26:1837### `absl::Mutex`
38
Markus Handellf70fbc82020-06-03 22:41:2039*Use `webrtc::Mutex` instead.*
Karl Wibergc3af97d2018-08-27 02:26:1840
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
Rasmus Brandt7ab41e52019-12-18 09:01:5445way that may not be compatible with the rest of WebRTC.
Karl Wibergc3af97d2018-08-27 02:26:1846
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
Karl Wibergbd0deca2019-02-26 00:42:2659### `absl::StrCat`, `absl::StrAppend`, `absl::StrJoin`, `absl::StrSplit`
Karl Wibergc3af97d2018-08-27 02:26:1860
Karl Wibergbd0deca2019-02-26 00:42:2661*Use `rtc::SimpleStringBuilder` to build strings.*
Karl Wibergc3af97d2018-08-27 02:26:1862
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.
Mirko Bonadei2dcf3482020-06-05 12:30:4166
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.