diff --git a/pw_build_android/Android.bp b/pw_build_android/Android.bp index 6fa4d1d58..31cc9510f 100644 --- a/pw_build_android/Android.bp +++ b/pw_build_android/Android.bp @@ -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. diff --git a/pw_build_android/docs.rst b/pw_build_android/docs.rst index ef2d4c0e6..84b205671 100644 --- a/pw_build_android/docs.rst +++ b/pw_build_android/docs.rst @@ -376,3 +376,20 @@ Backends are defined the same way as :ref:`module-pw_build_android-module-libraries`. They must follow the ``pw_._`` name format or ``pw__`` 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. diff --git a/pw_function/docs.rst b/pw_function/docs.rst index 3d2539a96..f9a171290 100644 --- a/pw_function/docs.rst +++ b/pw_function/docs.rst @@ -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 function((MyCallable())); +.. _module-pw_function-dynamic-allocation: + Dynamic allocation ================== You can configure the inline allocation size of ``pw::Function`` and whether it