mirror of
https://fuchsia.googlesource.com/third_party/pigweed.googlesource.com/pigweed/pigweed
synced 2024-07-12 01:23:34 +00:00
pw_build_android: Enable function dynamic alloc
Set the PW_FUNCTION_ENABLE_DYNAMIC_ALLOCATION define for Android builds. This allows `pw::Function`s to exceed the inline size. The motivation for setting this across the board is that components built with dynamic allocation disabled (i.e. PW_FUNCTION_ENABLE_DYNAMIC_ALLOCATION unset or set to 0) cannot be linked against components with dynamic allocation enabled. Since even the smallest Android environment is not nearly as constrained as a typical embedded environment, the solution is to always set this flag on Android. Bug: 349352849 Test: Built Android locally. Change-Id: I7209151c2508026258c23f931a5c12c64c733a1e Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/218219 Reviewed-by: Eli Lipsitz <elipsitz@google.com> Reviewed-by: Carlos Chinchilla <cachinchilla@google.com> Reviewed-by: Jonathon Reinhart <jrreinhart@google.com> Commit-Queue: Andrew Harper <aharp@google.com> Lint: Lint 🤖 <android-build-ayeaye@system.gserviceaccount.com>
This commit is contained in:
parent
e6cbfd477a
commit
51ed6ec520
|
@ -16,13 +16,21 @@ package {
|
|||
default_applicable_licenses: ["external_pigweed_license"],
|
||||
}
|
||||
|
||||
// List of Common Android backends used by Pigweed modules.
|
||||
// List of Common Android backends and build flags used by Pigweed modules.
|
||||
// Do not modify this to swap a different backend. Instead see the
|
||||
// pw_build_android documentation for how to use custom backends.
|
||||
cc_defaults {
|
||||
name: "pw_android_common_backends",
|
||||
cpp_std: "c++20",
|
||||
|
||||
// Note for maintainers:
|
||||
// Update the build flags in the documentation when updating this list.
|
||||
cflags: [
|
||||
// Allow `pw::Function`s to exceed the inline size. This assumes all
|
||||
// targets built with this backend can use dynamic allocation.
|
||||
"-DPW_FUNCTION_ENABLE_DYNAMIC_ALLOCATION=1",
|
||||
],
|
||||
|
||||
// Note for maintainers:
|
||||
// Update the common backends list in the documentation when updating this
|
||||
// list.
|
||||
|
|
|
@ -376,3 +376,20 @@ Backends are defined the same way as
|
|||
:ref:`module-pw_build_android-module-libraries`. They must follow the
|
||||
``pw_<MODULE_NAME>.<FACADE_NAME>_<BACKEND_NAME>`` name format or
|
||||
``pw_<MODULE_NAME>_<BACKEND_NAME>`` if applicable.
|
||||
|
||||
-----------
|
||||
Build flags
|
||||
-----------
|
||||
Some build flags should be set for all Android targets; these flags are
|
||||
specified in ``pw_android_common_backends``. These flags are as follows:
|
||||
|
||||
``PW_FUNCTION_ENABLE_DYNAMIC_ALLOCATION``
|
||||
-----------------------------------------
|
||||
As discussed in :ref:`module-pw_function-dynamic-allocation`, this flag enables
|
||||
dynamic allocation of :cpp:type:`pw::Function`, allowing it to exceed the
|
||||
inline size limit.
|
||||
|
||||
Android targets support dynamic allocation since the Android environment is not
|
||||
memory constrained. Thus, ``PW_FUNCTION_ENABLE_DYNAMIC_ALLOCATION`` is enabled
|
||||
in ``pw_android_common_backends``. Components built with dynamic allocation
|
||||
disabled cannot be linked against components with dynamic allocation enabled.
|
||||
|
|
|
@ -327,6 +327,8 @@ is a compile-time error unless dynamic allocation is enabled.
|
|||
// Compiler error: sizeof(MyCallable) exceeds function's inline storage size.
|
||||
pw::Function<int(int)> function((MyCallable()));
|
||||
|
||||
.. _module-pw_function-dynamic-allocation:
|
||||
|
||||
Dynamic allocation
|
||||
==================
|
||||
You can configure the inline allocation size of ``pw::Function`` and whether it
|
||||
|
|
Loading…
Reference in New Issue
Block a user