blob: 32fc42d953a3fd243baccc7fff18030bdbce35b5 [file] [log] [blame] [view]
Artem Titova6178672023-01-30 10:51:011<!-- go/cmark -->
2<!--* freshness: {owner: 'danilchap' reviewed: '2021-05-12'} *-->
Danil Chapovalov46f5c112021-05-12 12:05:483
Artem Titova6178672023-01-30 10:51:014# Using Abseil in WebRTC
Artem Titov0f2ce5c2023-01-26 20:18:465
Karl Wibergc3af97d2018-08-27 02:26:186You 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&rsquo;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
Karl Wiberga667f872020-10-15 23:02:3715
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
Karl Wibergc3af97d2018-08-27 02:26:1826## **Allowed**
27
Danil Chapovalov4b979282022-06-30 08:08:4728* `absl::AnyInvocable`
Per Kjellanderfe2063e2021-05-12 07:02:4329* `absl::bind_front`
Danil Chapovalove6106102022-02-16 11:29:0230* `absl::Cleanup`
Karl Wibergc3af97d2018-08-27 02:26:1831* `absl::InlinedVector`
Mirko Bonadeic128df12019-09-18 05:59:0732* `absl::WrapUnique`
Karl Wibergc3af97d2018-08-27 02:26:1833* `absl::optional` and related stuff from `absl/types/optional.h`.
34* `absl::string_view`
Steve Anton1c9c9fc2019-02-14 23:13:0935* The functions in `absl/strings/ascii.h`, `absl/strings/match.h`,
36 and `absl/strings/str_replace.h`.
Harald Alvestrand666c3332022-10-18 12:32:4037* The functions in `absl/strings/escaping.h`.
Jiawei Oua6e034a2018-11-25 04:59:4138* `absl::is_trivially_copy_constructible`,
39 `absl::is_trivially_copy_assignable`, and
40 `absl::is_trivially_destructible` from `absl/meta/type_traits.h`.
Karl Wibergc3af97d2018-08-27 02:26:1841* `absl::variant` and related stuff from `absl/types/variant.h`.
Steve Antone76ca612019-01-25 20:49:1442* The functions in `absl/algorithm/algorithm.h` and
Elad Alone86af2c2019-06-03 12:37:5043 `absl/algorithm/container.h`.
Markus Handellf70fbc82020-06-03 22:41:2044* `absl/base/const_init.h` for mutex initialization.
Elad Alone86af2c2019-06-03 12:37:5045* The macros in `absl/base/attributes.h`, `absl/base/config.h` and
46 `absl/base/macros.h`.
Danil Chapovalov09fb7872021-08-20 10:46:1447* `absl/numeric/bits.h`
Karl Wibergc3af97d2018-08-27 02:26:1848
Markus Handellf70fbc82020-06-03 22:41:2049
Karl Wibergc3af97d2018-08-27 02:26:1850## **Disallowed**
51
Mirko Bonadeic128df12019-09-18 05:59:0752### `absl::make_unique`
53
54*Use `std::make_unique` instead.*
55
Karl Wibergc3af97d2018-08-27 02:26:1856### `absl::Mutex`
57
Markus Handellf70fbc82020-06-03 22:41:2058*Use `webrtc::Mutex` instead.*
Karl Wibergc3af97d2018-08-27 02:26:1859
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
Rasmus Brandt7ab41e52019-12-18 09:01:5464way that may not be compatible with the rest of WebRTC.
Karl Wibergc3af97d2018-08-27 02:26:1865
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&mdash;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
Karl Wibergbd0deca2019-02-26 00:42:2678### `absl::StrCat`, `absl::StrAppend`, `absl::StrJoin`, `absl::StrSplit`
Karl Wibergc3af97d2018-08-27 02:26:1879
Karl Wibergbd0deca2019-02-26 00:42:2680*Use `rtc::SimpleStringBuilder` to build strings.*
Karl Wibergc3af97d2018-08-27 02:26:1881
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.