flutter-engine.mk 8.6 KB

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