flutter-engine.mk 8.9 KB

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