xref: /aosp_15_r20/external/cronet/base/allocator/partition_allocator/external_builds.md (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1# Chrome-External Builds
2
3Work is ongoing to make PartitionAlloc a standalone library. The
4standalone repository for PartitionAlloc is hosted
5[here][standalone-PA-repo].
6
7## GN Args
8
9External clients should examine the args described in
10`build_overrides/partition_alloc.gni` and add them in their own source
11tree. PartitionAlloc's build will expect them at
12`//build_overrides/partition_alloc.gni`.
13
14In addition, something must provide `build_with_chromium = false` to
15the PA build system.
16
17## `use_partition_alloc`
18
19The `use_partition_alloc` GN arg, described in
20[`build_config.md`](./build_config.md), provides a GN-level seam that
21embedders
22
231.  can set in their GN args and
242.  should  observe in their GN recipes to conditionally pull in
25    PartitionAlloc.
26
27I.E. if you have any reason to disable PartitionAlloc, you should do so
28with this GN arg. Avoid pulling in PartitionAlloc headers when the
29corresponding buildflag is false.
30
31Setting `use_partition_alloc` false will also implicitly disable other
32features, e.g. nixing the compilation of BackupRefPtr as the
33implementation of `raw_ptr<T>`.
34
35## Periodic Memory Reduction Routines
36
37PartitionAlloc provides APIs to
38
39* reclaim memory (see `memory_reclaimer.h`) and
40
41* purge thread caches (see `thread_cache.h`).
42
43Both of these must be called by the embedder external to PartitionAlloc.
44PA provides neither an event loop nor timers of its own, delegating this
45to its clients.
46
47## Build Considerations
48
49External clients create constraints on PartitionAlloc's implementation.
50
51### C++17
52
53PartitionAlloc targets C++17. This is aligned with our first external
54client, PDFium, and may be further constrained by other clients. These
55impositions prevent us from moving in lockstep with Chrome's target
56C++ version.
57
58We do not even have guarantees of backported future features, e.g.
59C++20's designated initializers. Therefore, these cannot ship with
60PartitionAlloc.
61
62### MSVC Support
63
64PDFium supports MSVC. PartitionAlloc will have to match it.
65
66### MSVC Constraint: No Inline Assembly
67
68MSVC's syntax for `asm` blocks differs from the one widely adopted in
69parts of Chrome. But more generally,
70[MSVC doesn't support inline assembly on ARM and x64 processors][msvc-inline-assembly].
71Assembly blocks should be gated behind compiler-specific flags and
72replaced with intrinsics in the presence of `COMPILER_MSVC` (absent
73`__clang__`).
74
75[standalone-PA-repo]: https://chromium.googlesource.com/chromium/src/base/allocator/partition_allocator.git
76[msvc-inline-assembly]: https://docs.microsoft.com/en-us/cpp/assembler/inline/inline-assembler?view=msvc-170
77