blob: 034f6c2fb4108e31bdec36e4d538f3e427d6fba6 [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`
Tommifd3b3462023-10-27 20:38:3332* `absl::Nonnull` and `absl::Nullable`
Mirko Bonadeic128df12019-09-18 05:59:0733* `absl::WrapUnique`
Karl Wibergc3af97d2018-08-27 02:26:1834* `absl::optional` and related stuff from `absl/types/optional.h`.
35* `absl::string_view`
Steve Anton1c9c9fc2019-02-14 23:13:0936* The functions in `absl/strings/ascii.h`, `absl/strings/match.h`,
37 and `absl/strings/str_replace.h`.
Harald Alvestrand666c3332022-10-18 12:32:4038* The functions in `absl/strings/escaping.h`.
Jiawei Oua6e034a2018-11-25 04:59:4139* `absl::is_trivially_copy_constructible`,
40 `absl::is_trivially_copy_assignable`, and
41 `absl::is_trivially_destructible` from `absl/meta/type_traits.h`.
Karl Wibergc3af97d2018-08-27 02:26:1842* `absl::variant` and related stuff from `absl/types/variant.h`.
Steve Antone76ca612019-01-25 20:49:1443* The functions in `absl/algorithm/algorithm.h` and
Elad Alone86af2c2019-06-03 12:37:5044 `absl/algorithm/container.h`.
Markus Handellf70fbc82020-06-03 22:41:2045* `absl/base/const_init.h` for mutex initialization.
Elad Alone86af2c2019-06-03 12:37:5046* The macros in `absl/base/attributes.h`, `absl/base/config.h` and
47 `absl/base/macros.h`.
Danil Chapovalov09fb7872021-08-20 10:46:1448* `absl/numeric/bits.h`
Karl Wibergc3af97d2018-08-27 02:26:1849
Markus Handellf70fbc82020-06-03 22:41:2050
Karl Wibergc3af97d2018-08-27 02:26:1851## **Disallowed**
52
Mirko Bonadeic128df12019-09-18 05:59:0753### `absl::make_unique`
54
55*Use `std::make_unique` instead.*
56
Karl Wibergc3af97d2018-08-27 02:26:1857### `absl::Mutex`
58
Markus Handellf70fbc82020-06-03 22:41:2059*Use `webrtc::Mutex` instead.*
Karl Wibergc3af97d2018-08-27 02:26:1860
61Chromium has a ban on new static initializers, and `absl::Mutex` uses
62one. To make `absl::Mutex` available, we would need to nicely ask the
63Abseil team to remove that initializer (like they already did for a
64spinlock initializer). Additionally, `absl::Mutex` handles time in a
Rasmus Brandt7ab41e52019-12-18 09:01:5465way that may not be compatible with the rest of WebRTC.
Karl Wibergc3af97d2018-08-27 02:26:1866
67### `absl::Span`
68
69*Use `rtc::ArrayView` instead.*
70
71`absl::Span` differs from `rtc::ArrayView` on several points, and both
72of them differ from the `std::span` that was voted into
73C++20&mdash;and `std::span` is likely to undergo further changes
74before C++20 is finalized. We should just keep using `rtc::ArrayView`
75and avoid `absl::Span` until C++20 is finalized and the Abseil team
76has decided if they will change `absl::Span` to match.
77[Bug](https://bugs.webrtc.org/9214).
78
Karl Wibergbd0deca2019-02-26 00:42:2679### `absl::StrCat`, `absl::StrAppend`, `absl::StrJoin`, `absl::StrSplit`
Karl Wibergc3af97d2018-08-27 02:26:1880
Karl Wibergbd0deca2019-02-26 00:42:2681*Use `rtc::SimpleStringBuilder` to build strings.*
Karl Wibergc3af97d2018-08-27 02:26:1882
83These are optimized for speed, not binary size. Even `StrCat` calls
84with a modest number of arguments can easily add several hundred bytes
85to the binary.