Bringing Flutter to RISC-V

From Engine Patches to Running Apps on RISC-V Devices

Sep 10, 2025

Hannes Winkler

$ gclient sync
...

$ pushd engine/src && ./flutter/tools/gn \
	--linux --linux-cpu arm64 \
	--runtime-mode release \
	--embedder-for-target --disable-desktop-embeddings \
	--no-enable-unittests --no-build-glfw-shell \
	--no-build-embedder-examples
Generating GN files in: out/linux_release_arm64
Generating compile_commands took 77ms
Done. Made 1178 targets from 345 files in 433ms

$ ninja -C out/linux_release_arm64
--- a/engine/src/build/config/sysroot.gni
+++ b/engine/src/build/config/sysroot.gni
@@ -21,7 +21,16 @@ if (current_toolchain == default_toolchain && target_sysroot != "") {diff
   import("//build/config/android/config.gni")
   sysroot = rebase_path("$android_toolchain_root/sysroot", root_build_dir)
 } else if (is_linux && !is_chromeos) {
-  if (use_default_linux_sysroot && !is_fuchsia) {
+  # install-sysroot.py doesn't provide a RISC-V 64 sysroot, which means
+  # we can't provide a default sysroot.
+  # 
+  # If we make this fail here, when use_default_linux_sysroot == true and 
+  # current_cpu == "riscv64", the sysroot choosing for arm/arm64/x64
+  # will fail as well, so we wouldn't be able to cross-compile the gen_snapshots
+  # and build the libflutter_engine.so in one build anymore.
+  #
+  # Instead we just silently use no sysroot for riscv64 at all.
+  if (use_default_linux_sysroot && !is_fuchsia && current_cpu != "riscv64") {
     if (current_cpu == "x64") {
       sysroot =
           rebase_path("//build/linux/debian_sid_amd64-sysroot", root_build_dir)
--- a/engine/src/build/config/compiler/BUILD.gn
+++ b/engine/src/build/config/compiler/BUILD.gn
@@ -288,6 +288,11 @@ config("compiler") {
       if (arm_tune != "") {
         cflags += [ "-mtune=$arm_tune" ]
       }
+    } else if (current_cpu == "riscv64") {
+      assert(is_clang)
+
+      cflags += [ "--target=riscv64-linux-gnu" ]
+      ldflags += [ "--target=riscv64-linux-gnu" ]
     }
 
     if (!is_android) {
--- a/engine/src/build/config/linux/BUILD.gn
+++ b/engine/src/build/config/linux/BUILD.gn
@@ -27,9 +27,9 @@ config("fontconfig") {
   libs = [ "fontconfig" ]
 }
 
-pkg_config("freetype2") {
-  packages = [ "freetype2" ]
-}
+#pkg_config("freetype2") {
+#  packages = [ "freetype2" ]
+#}
 
 config("x11") {
   libs = [
--- a/engine/src/flutter/assets/native_assets.cc
+++ b/engine/src/flutter/assets/native_assets.cc
@@ -17,6 +17,8 @@ namespace flutter {
 #define kTargetArchitectureName "ia32"
 #elif defined(FML_ARCH_CPU_X86_64)
 #define kTargetArchitectureName "x64"
+#elif defined(FML_ARCH_CPU_RISCV64)
+#define kTargetArchitectureName "riscv64"
 #else
 #error Target architecture detection failed.
 #endif
--- a/engine/src/flutter/fml/build_config.h
+++ b/engine/src/flutter/fml/build_config.h
@@ -96,6 +96,11 @@
 #elif defined(__pnacl__)
 #define FML_ARCH_CPU_32_BITS 1
 #define FML_ARCH_CPU_LITTLE_ENDIAN 1
+#elif defined(__riscv) && __riscv_xlen == 64 && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+#define FML_ARCH_CPU_RISCV_FAMILY 1
+#define FML_ARCH_CPU_RISCV64 1
+#define FML_ARCH_CPU_64_BITS 1
+#define FML_ARCH_CPU_LITTLE_ENDIAN 1
 #else
 #error Please add support for your architecture in flutter/fml/build_config.h
 #endif
--- a/engine/src/flutter/third_party/tonic/common/build_config.h
+++ b/engine/src/flutter/third_party/tonic/common/build_config.h
@@ -103,6 +103,11 @@
 #define ARCH_CPU_32_BITS 1
 #define ARCH_CPU_LITTLE_ENDIAN 1
 #endif
+#elif defined(__riscv) && __riscv_xlen == 64 && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+#define ARCH_CPU_RISCV_FAMILY 1
+#define ARCH_CPU_RISCV64 1
+#define ARCH_CPU_64_BITS 1
+#define ARCH_CPU_LITTLE_ENDIAN 1
 #else
 #error Please add support for your architecture in build/build_config.h
 #endif

This content can not be viewed with respect to your privacy. Allow statistics and marketing in your or view on YouTube.

Tags:

Leave a Comment

Your Email address will not be published