flutter-engine.mk 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. ################################################################################
  2. #
  3. # flutter-engine
  4. #
  5. ################################################################################
  6. # Flutter-engine has a release on the GitHub page. However, that release is
  7. # only for Google. Its intended purpose is for the gclient tool provided by
  8. # Google in their depot-tools package. To use the source code, we must use
  9. # gclient to download the flutter-engine source code along with several other
  10. # projects. Unfortunately, the Buildroot download system does not have the
  11. # capability of using gclient, and considering this package is the only
  12. # package that uses gclient, we side-step the entire download process and
  13. # perform the following steps if a tarball does not exist already:
  14. #
  15. # - Copy the pre-made gclient config file to a temporary scratch directory.
  16. # - Run gclient sync to generate a source directory with the proper
  17. # flutter-engine source code in the correct places.
  18. # - Create a source tarball.
  19. # - Copy the source tarball to the $(FLUTTER_ENGINE_DL_DIR) directory.
  20. #
  21. # There is no hash provided for the source tarball, as the gn binary
  22. # (used for configuration) relies on the .git directories. As such, a
  23. # reproducible tarball is not possible.
  24. FLUTTER_ENGINE_VERSION = 3.29.2
  25. # There is nothing for Buildroot to download. This is handled by gclient.
  26. FLUTTER_ENGINE_SITE =
  27. FLUTTER_ENGINE_SOURCE =
  28. FLUTTER_ENGINE_LICENSE = BSD-3-Clause
  29. FLUTTER_ENGINE_LICENSE_FILES = LICENSE
  30. FLUTTER_ENGINE_TARBALL_PATH = $(FLUTTER_ENGINE_DL_DIR)/flutter-$(FLUTTER_ENGINE_VERSION).tar.gz
  31. FLUTTER_ENGINE_INSTALL_STAGING = YES
  32. FLUTTER_ENGINE_DOWNLOAD_DEPENDENCIES = host-depot-tools
  33. FLUTTER_ENGINE_DEPENDENCIES = \
  34. host-flutter-sdk-bin \
  35. host-ninja \
  36. host-pkgconf \
  37. freetype \
  38. zlib
  39. # Dispatch all architectures of flutter
  40. # FLUTTER_ENGINE_TARGET_TRIPPLE must match the directory name found in
  41. # engine/src/buildtools/linux-x64/clang/lib/clang/*/lib
  42. ifeq ($(BR2_aarch64),y)
  43. FLUTTER_ENGINE_TARGET_ARCH = arm64
  44. FLUTTER_ENGINE_TARGET_TRIPPLE = aarch64-unknown-linux-gnu
  45. else ifeq ($(BR2_arm)$(BR2_armeb),y)
  46. FLUTTER_ENGINE_TARGET_ARCH = arm
  47. FLUTTER_ENGINE_TARGET_TRIPPLE = armv7-unknown-linux-gnueabihf
  48. else ifeq ($(BR2_x86_64),y)
  49. FLUTTER_ENGINE_TARGET_ARCH = x64
  50. FLUTTER_ENGINE_TARGET_TRIPPLE = x86_64-unknown-linux-gnu
  51. endif
  52. ifeq ($(FLUTTER_ENGINE_RUNTIME_MODE_PROFILE),y)
  53. FLUTTER_ENGINE_RUNTIME_MODE=profile
  54. else ifeq ($(BR2_ENABLE_RUNTIME_DEBUG),y)
  55. FLUTTER_ENGINE_RUNTIME_MODE=debug
  56. else
  57. FLUTTER_ENGINE_RUNTIME_MODE=release
  58. endif
  59. FLUTTER_ENGINE_BUILD_DIR = \
  60. $(@D)/engine/src/out/linux_$(FLUTTER_ENGINE_RUNTIME_MODE)_$(FLUTTER_ENGINE_TARGET_ARCH)
  61. FLUTTER_ENGINE_INSTALL_FILES = libflutter_engine.so
  62. # Flutter engine includes a bundled patched clang that must be used for
  63. # compiling or else there are linking errors.
  64. FLUTTER_ENGINE_CLANG_PATH = $(@D)/engine/src/flutter/buildtools/linux-x64/clang
  65. FLUTTER_ENGINE_CONF_OPTS = \
  66. --clang \
  67. --embedder-for-target \
  68. --linux-cpu $(FLUTTER_ENGINE_TARGET_ARCH) \
  69. --no-build-embedder-examples \
  70. --no-clang-static-analyzer \
  71. --no-enable-unittests \
  72. --no-goma \
  73. --no-prebuilt-dart-sdk \
  74. --no-stripped \
  75. --runtime-mode $(FLUTTER_ENGINE_RUNTIME_MODE) \
  76. --target-os linux \
  77. --target-sysroot $(STAGING_DIR) \
  78. --target-toolchain $(FLUTTER_ENGINE_CLANG_PATH) \
  79. --target-triple $(FLUTTER_ENGINE_TARGET_TRIPPLE)
  80. ifeq ($(BR2_arm)$(BR2_armeb),y)
  81. FLUTTER_ENGINE_CONF_OPTS += \
  82. --arm-float-abi $(call qstrip,$(BR2_GCC_TARGET_FLOAT_ABI))
  83. endif
  84. # We must specify a full path to ccache and a full path to the flutter-engine
  85. # provided clang in order to use ccache, or else flutter-engine will error out
  86. # attempting to find ccache in the target-toolchain provided path.
  87. ifeq ($(BR2_CCACHE),y)
  88. define FLUTTER_ENGINE_COMPILER_PATH_FIXUP
  89. $(SED) "s%cc =.*%cc = \"$(HOST_DIR)/bin/ccache $(FLUTTER_ENGINE_CLANG_PATH)/bin/clang\""%g \
  90. $(@D)/engine/src/build/toolchain/custom/BUILD.gn
  91. $(SED) "s%cxx =.*%cxx = \"$(HOST_DIR)/bin/ccache $(FLUTTER_ENGINE_CLANG_PATH)/bin/clang++\""%g \
  92. $(@D)/engine/src/build/toolchain/custom/BUILD.gn
  93. endef
  94. FLUTTER_ENGINE_PRE_CONFIGURE_HOOKS += FLUTTER_ENGINE_COMPILER_PATH_FIXUP
  95. endif
  96. ifeq ($(BR2_ENABLE_LTO),y)
  97. FLUTTER_ENGINE_CONF_OPTS += --lto
  98. else
  99. FLUTTER_ENGINE_CONF_OPTS += --no-lto
  100. endif
  101. ifeq ($(BR2_OPTIMIZE_0),y)
  102. FLUTTER_ENGINE_CONF_OPTS += --unoptimized
  103. endif
  104. # There is no --disable-fontconfig option.
  105. ifeq ($(BR2_PACKAGE_FONTCONFIG),y)
  106. FLUTTER_ENGINE_DEPENDENCIES += fontconfig
  107. FLUTTER_ENGINE_CONF_OPTS += --enable-fontconfig
  108. endif
  109. ifeq ($(BR2_PACKAGE_HAS_LIBGL),y)
  110. FLUTTER_ENGINE_DEPENDENCIES += libgl
  111. endif
  112. ifeq ($(BR2_PACKAGE_HAS_LIBGLES),y)
  113. FLUTTER_ENGINE_DEPENDENCIES += libgles
  114. FLUTTER_ENGINE_CONF_OPTS += --enable-impeller-3d
  115. endif
  116. ifeq ($(BR2_PACKAGE_LIBGLFW),y)
  117. FLUTTER_ENGINE_DEPENDENCIES += libglfw
  118. FLUTTER_ENGINE_CONF_OPTS += --build-glfw-shell
  119. else
  120. FLUTTER_ENGINE_CONF_OPTS += --no-build-glfw-shell
  121. endif
  122. ifeq ($(BR2_PACKAGE_LIBGTK3),y)
  123. FLUTTER_ENGINE_DEPENDENCIES += libgtk3
  124. FLUTTER_ENGINE_INSTALL_FILES += libflutter_linux_gtk.so
  125. else
  126. FLUTTER_ENGINE_CONF_OPTS += --disable-desktop-embeddings
  127. endif
  128. # There is no --disable-vulkan option
  129. ifeq ($(BR2_PACKAGE_MESA3D_VULKAN_DRIVER),y)
  130. FLUTTER_ENGINE_CONF_OPTS += --enable-vulkan
  131. endif
  132. ifeq ($(BR2_PACKAGE_XORG7)$(BR2_PACKAGE_LIBXCB),yy)
  133. FLUTTER_ENGINE_DEPENDENCIES += libxcb
  134. else
  135. define FLUTTER_ENGINE_VULKAN_X11_SUPPORT_FIXUP
  136. $(SED) "s%vulkan_use_x11.*%vulkan_use_x11 = false%g" -i \
  137. $(@D)/engine/src/flutter/build_overrides/vulkan_headers.gni
  138. $(SED) "s%ozone_platform_x11.*%ozone_platform_x11 = false%g" \
  139. $(@D)/engine/src/build/config/BUILDCONFIG.gn
  140. endef
  141. FLUTTER_ENGINE_PRE_CONFIGURE_HOOKS += FLUTTER_ENGINE_VULKAN_X11_SUPPORT_FIXUP
  142. endif
  143. ifeq ($(BR2_PACKAGE_WAYLAND),y)
  144. FLUTTER_ENGINE_DEPENDENCIES += wayland
  145. else
  146. define FLUTTER_ENGINE_VULKAN_WAYLAND_SUPPORT_FIXUP
  147. $(SED) "s%vulkan_use_wayland.*%vulkan_use_wayland = false%g" \
  148. $(@D)/engine/src/flutter/build_overrides/vulkan_headers.gni
  149. $(SED) "s%ozone_platform_wayland.*%ozone_platform_wayland = false%g" \
  150. $(@D)/engine/src/build/config/BUILDCONFIG.gn
  151. endef
  152. FLUTTER_ENGINE_PRE_CONFIGURE_HOOKS += FLUTTER_ENGINE_VULKAN_WAYLAND_SUPPORT_FIXUP
  153. endif
  154. # Generate a tarball if one does not already exist.
  155. define FLUTTER_ENGINE_GENERATE_TARBALL
  156. TAR="$(TAR)" \
  157. PATH=$(HOST_DIR)/share/depot_tools:$(BR_PATH) \
  158. PYTHONPATH=$(HOST_DIR)/lib/python$(PYTHON3_VERSION_MAJOR) \
  159. PUB_CACHE=$(FLUTTER_SDK_BIN_PUB_CACHE) \
  160. $(FLUTTER_ENGINE_PKGDIR)/gen-tarball \
  161. --dot-gclient $(TOPDIR)/$(FLUTTER_ENGINE_PKGDIR)/dot-gclient \
  162. --jobs $(PARALLEL_JOBS) \
  163. --scratch-dir $(@D)/dl-tmp \
  164. --tarball-dl-path $(FLUTTER_ENGINE_TARBALL_PATH) \
  165. --version $(FLUTTER_ENGINE_VERSION)
  166. endef
  167. FLUTTER_ENGINE_POST_DOWNLOAD_HOOKS += FLUTTER_ENGINE_GENERATE_TARBALL
  168. define FLUTTER_ENGINE_EXTRACT_CMDS
  169. $(call suitable-extractor,$(FLUTTER_ENGINE_TARBALL_PATH)) $(FLUTTER_ENGINE_TARBALL_PATH) \
  170. | $(TAR) --strip-components=1 -C $(@D) $(TAR_OPTIONS) -
  171. endef
  172. # We must set the home directory to the sdk directory or else flutter will
  173. # place .dart, and .flutter in ~/.
  174. define FLUTTER_ENGINE_CONFIGURE_CMDS
  175. cd $(@D)/engine/src && \
  176. rm -rf $(FLUTTER_ENGINE_BUILD_DIR) && \
  177. PATH=$(HOST_DIR)/share/depot_tools:$(BR_PATH) \
  178. PUB_CACHE=$(FLUTTER_SDK_BIN_PUB_CACHE) \
  179. HOME=$(HOST_FLUTTER_SDK_BIN_SDK) \
  180. ./flutter/tools/gn \
  181. $(FLUTTER_ENGINE_CONF_OPTS)
  182. endef
  183. define FLUTTER_ENGINE_BUILD_CMDS
  184. cd $(@D)/engine/src && \
  185. PATH=$(HOST_DIR)/share/depot_tools:$(BR_PATH) \
  186. PUB_CACHE=$(FLUTTER_SDK_BIN_PUB_CACHE) \
  187. HOME=$(HOST_FLUTTER_SDK_BIN_SDK) \
  188. $(HOST_DIR)/bin/ninja \
  189. -j $(PARALLEL_JOBS) \
  190. -C $(FLUTTER_ENGINE_BUILD_DIR)
  191. endef
  192. # Flutter-engine builds several host applications use for flutter development.
  193. # One of those applications is gen_snapshot, which turns applications into
  194. # usable .so files for the target architecture. Compiling a host version of
  195. # flutter-engine would result in binaries producing host-architecture
  196. # flutter applications .so files. As such, copy gen_snapshot to the host
  197. # directory here and name it flutter_gen_snapshot for clarity.
  198. FLUTTER_ENGINE_GEN_SNAPSHOT = $(HOST_DIR)/bin/flutter_gen_snapshot
  199. define FLUTTER_ENGINE_INSTALL_GEN_SNAPSHOT
  200. $(INSTALL) -D -m 0755 $(FLUTTER_ENGINE_BUILD_DIR)/clang_x64/gen_snapshot \
  201. $(HOST_DIR)/bin/flutter_gen_snapshot
  202. endef
  203. FLUTTER_ENGINE_POST_INSTALL_STAGING_HOOKS += FLUTTER_ENGINE_INSTALL_GEN_SNAPSHOT
  204. define FLUTTER_ENGINE_INSTALL_STAGING_CMDS
  205. $(foreach i,$(FLUTTER_ENGINE_INSTALL_FILES),
  206. $(INSTALL) -D -m 0755 $(FLUTTER_ENGINE_BUILD_DIR)/so.unstripped/$(i) \
  207. $(STAGING_DIR)/usr/lib/$(i); \
  208. )
  209. $(INSTALL) -D -m 0755 $(FLUTTER_ENGINE_BUILD_DIR)/flutter_embedder.h \
  210. $(STAGING_DIR)/usr/include/flutter_embedder.h
  211. $(INSTALL) -D -m 0755 $(FLUTTER_ENGINE_BUILD_DIR)/icudtl.dat \
  212. $(STAGING_DIR)/usr/share/flutter/$(FLUTTER_ENGINE_RUNTIME_MODE)/data/icudtl.dat
  213. endef
  214. define FLUTTER_ENGINE_INSTALL_TARGET_CMDS
  215. $(foreach i,$(FLUTTER_ENGINE_INSTALL_FILES),
  216. $(INSTALL) -D -m 0755 $(FLUTTER_ENGINE_BUILD_DIR)/so.unstripped/$(i) \
  217. $(TARGET_DIR)/usr/lib/$(i); \
  218. )
  219. $(INSTALL) -D -m 0755 $(FLUTTER_ENGINE_BUILD_DIR)/icudtl.dat \
  220. $(TARGET_DIR)/usr/share/flutter/$(FLUTTER_ENGINE_RUNTIME_MODE)/data/icudtl.dat
  221. endef
  222. $(eval $(generic-package))