Skip to content

Engine build setup for Android RISCV64. #173672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion engine/src/build/config/android/config.gni
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ if (is_android) {

zipalign_path = "$android_sdk_build_tools/zipalign"

if (current_cpu != "x64" && current_cpu != "arm64") {
if (current_cpu == "riscv64") {
android_api_level = 35
} else if (current_cpu != "x64" && current_cpu != "arm64") {
android_api_level = 21
}

Expand Down Expand Up @@ -101,6 +103,9 @@ if (is_android) {
} else if (current_cpu == "arm64") {
android_app_abi = "arm64-v8a"
_android_lib_dir = "aarch64-linux-android"
} else if (current_cpu == "riscv64") {
android_app_abi = "riscv64"
_android_lib_dir = "riscv64-linux-android"
} else {
assert(false, "Unknown Android ABI: " + current_cpu)
}
Expand Down
6 changes: 5 additions & 1 deletion engine/src/build/config/compiler/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ declare_args() {

# By default, API calls to deprecated methods are errors. While prototyping,
# this flag may be set to allow such calls.
allow_deprecated_api_calls = false
# riscv64: https://github.com/flutter/flutter/issues/173656
allow_deprecated_api_calls = target_cpu == "riscv64"

# This flag is deprecated and will be removed. The value will be ignored.
use_fstack_protector = false
Expand Down Expand Up @@ -464,6 +465,9 @@ config("compiler") {
} else if (current_cpu == "x64") {
cflags += [ "--target=x86_64-linux-androideabi${android_api_level}" ]
ldflags += [ "--target=x86_64-linux-androideabi${android_api_level}" ]
} else if (current_cpu == "riscv64") {
cflags += [ "--target=riscv64-linux-androideabi${android_api_level}" ]
ldflags += [ "--target=riscv64-linux-androideabi${android_api_level}" ]
}
}

Expand Down
4 changes: 4 additions & 0 deletions engine/src/build/toolchain/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,7 @@ android_toolchains_helper("arm64_apilevel26") {
android_api_level = 26
}
}

android_toolchains_helper("riscv64") {
toolchain_cpu = "riscv64"
}
4 changes: 4 additions & 0 deletions engine/src/flutter/assets/native_assets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ namespace flutter {
#define kTargetArchitectureName "ia32"
#elif defined(FML_ARCH_CPU_X86_64)
#define kTargetArchitectureName "x64"
#elif defined(FML_ARCH_CPU_RISCV32)
#define kTargetArchitectureName "riscv32"
#elif defined(FML_ARCH_CPU_RISCV64)
#define kTargetArchitectureName "riscv64"
#else
#error Target architecture detection failed.
#endif
Expand Down
92 changes: 92 additions & 0 deletions engine/src/flutter/ci/builders/linux_android_aot_engine.json
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,98 @@
"flutter/shell/platform/android:analyze_snapshot"
]
}
},
{
"archives": [
{
"name": "ci/android_profile_riscv64",
"type": "gcs",
"base_path": "out/ci/android_profile_riscv64/zip_archives/",
"include_paths": [
"out/ci/android_profile_riscv64/zip_archives/android-riscv64-profile/artifacts.zip",
"out/ci/android_profile_riscv64/zip_archives/android-riscv64-profile/linux-x64.zip",
"out/ci/android_profile_riscv64/zip_archives/android-riscv64-profile/symbols.zip",
"out/ci/android_profile_riscv64/zip_archives/android-riscv64-profile/analyze-snapshot-linux-x64.zip",
"out/ci/android_profile_riscv64/zip_archives/download.flutter.io"
],
"realm": "production"
}
],
"drone_dimensions": [
"device_type=none",
"os=Linux"
],
"gclient_variables": {
"use_rbe": true
},
"gn": [
"--target-dir",
"ci/android_profile_riscv64",
"--runtime-mode",
"profile",
"--android",
"--android-cpu",
"riscv64",
"--rbe",
"--no-goma"
],
"name": "ci/android_profile_riscv64",
"description": "Produces profile mode artifacts to target riscv64 Android from a Linux host.",
"ninja": {
"config": "ci/android_profile_riscv64",
"targets": [
"default",
"clang_x64/gen_snapshot",
"flutter/shell/platform/android:abi_jars",
"flutter/shell/platform/android:analyze_snapshot"
]
}
},
{
"archives": [
{
"name": "ci/android_release_riscv64",
"type": "gcs",
"base_path": "out/ci/android_release_riscv64/zip_archives/",
"include_paths": [
"out/ci/android_release_riscv64/zip_archives/android-riscv64-release/artifacts.zip",
"out/ci/android_release_riscv64/zip_archives/android-riscv64-release/linux-x64.zip",
"out/ci/android_release_riscv64/zip_archives/android-riscv64-release/symbols.zip",
"out/ci/android_release_riscv64/zip_archives/android-riscv64-release/analyze-snapshot-linux-x64.zip",
"out/ci/android_release_riscv64/zip_archives/download.flutter.io"
],
"realm": "production"
}
],
"drone_dimensions": [
"device_type=none",
"os=Linux"
],
"gclient_variables": {
"use_rbe": true
},
"gn": [
"--target-dir",
"ci/android_release_riscv64",
"--runtime-mode",
"release",
"--android",
"--android-cpu",
"riscv64",
"--rbe",
"--no-goma"
],
"name": "ci/android_release_riscv64",
"description": "Produces release mode artifacts to target riscv64 Android from a Linux host.",
"ninja": {
"config": "ci/android_release_riscv64",
"targets": [
"default",
"clang_x64/gen_snapshot",
"flutter/shell/platform/android:abi_jars",
"flutter/shell/platform/android:analyze_snapshot"
]
}
}
],
"generators": {
Expand Down
44 changes: 44 additions & 0 deletions engine/src/flutter/ci/builders/linux_android_debug_engine.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,50 @@
"flutter/impeller/toolkit/interop:sdk"
]
}
},
{
"archives": [
{
"name": "ci/android_debug_riscv64",
"type": "gcs",
"base_path": "out/ci/android_debug_riscv64/zip_archives/",
"include_paths": [
"out/ci/android_debug_riscv64/zip_archives/android-riscv64/artifacts.zip",
"out/ci/android_debug_riscv64/zip_archives/android-riscv64/android-riscv64-embedder.zip",
"out/ci/android_debug_riscv64/zip_archives/android-riscv64/impeller_sdk.zip",
"out/ci/android_debug_riscv64/zip_archives/android-riscv64/symbols.zip",
"out/ci/android_debug_riscv64/zip_archives/download.flutter.io"
],
"realm": "production"
}
],
"drone_dimensions": [
"device_type=none",
"os=Linux"
],
"gclient_variables": {
"use_rbe": true
},
"gn": [
"--target-dir",
"ci/android_debug_riscv64",
"--android",
"--android-cpu=riscv64",
"--no-lto",
"--rbe",
"--no-goma"
],
"name": "ci/android_debug_riscv64",
"description": "Produces debug mode artifacts to target riscv64 Android from a Linux host.",
"ninja": {
"config": "ci/android_debug_riscv64",
"targets": [
"flutter",
"flutter/shell/platform/android:abi_jars",
"flutter/shell/platform/embedder:embedder-archive",
"flutter/impeller/toolkit/interop:sdk"
]
}
}
],
"generators": {
Expand Down
26 changes: 26 additions & 0 deletions engine/src/flutter/ci/builders/local_engine.json
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,32 @@
"targets": []
}
},
{
"cas_archive": false,
"drone_dimensions": [
"os=Linux",
"device_type=none"
],
"gclient_variables": {
"use_rbe": true
},
"gn": [
"--runtime-mode",
"debug",
"--android",
"--android-cpu=riscv64",
"--no-stripped",
"--no-lto",
"--rbe",
"--no-goma"
],
"name": "linux/android_debug_riscv64",
"description": "Builds a debug mode engine that targets riscv64 Android from a Linux host.",
"ninja": {
"config": "android_debug_riscv64",
"targets": []
}
},
{
"cas_archive": false,
"drone_dimensions": [
Expand Down
10 changes: 10 additions & 0 deletions engine/src/flutter/fml/build_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@
#define FML_ARCH_CPU_ARM64 1
#define FML_ARCH_CPU_64_BITS 1
#define FML_ARCH_CPU_LITTLE_ENDIAN 1
#elif defined(__riscv) && __SIZEOF_POINTER__ == 4
#define FML_ARCH_CPU_RISCV_FAMILY 1
#define FML_ARCH_CPU_RISCV32 1
#define FML_ARCH_CPU_32_BITS 1
#define FML_ARCH_CPU_LITTLE_ENDIAN 1
#elif defined(__riscv) && __SIZEOF_POINTER__ == 8
#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
#elif defined(__pnacl__)
#define FML_ARCH_CPU_32_BITS 1
#define FML_ARCH_CPU_LITTLE_ENDIAN 1
Expand Down
5 changes: 3 additions & 2 deletions engine/src/flutter/lib/snapshot/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ group("generate_snapshot_bins") {
# For iOS, Android target builds: all AOT target CPUs are arm/arm64.
public_deps += [ ":create_arm_gen_snapshot" ]
} else if (target_cpu == "arm" || target_cpu == "arm64" ||
target_cpu == "x64") {
target_cpu == "x64" || target_cpu == "riscv64") {
# For other host OSes, build gen_snapshot directly.
public_deps = [ "$dart_src/runtime/bin:gen_snapshot($host_toolchain)" ]
}

# Build analyze_snapshot for 64-bit target CPUs.
if (host_os == "linux" && (target_cpu == "x64" || target_cpu == "arm64")) {
if (host_os == "linux" && (target_cpu == "x64" || target_cpu == "arm64" ||
target_cpu == "riscv64")) {
public_deps += [ "$dart_src/runtime/bin:analyze_snapshot($host_toolchain)" ]
}
}
Expand Down
3 changes: 2 additions & 1 deletion engine/src/flutter/shell/platform/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,8 @@ if (target_cpu != "x86") {
}
}

if (host_os == "linux" && (target_cpu == "x64" || target_cpu == "arm64")) {
if (host_os == "linux" &&
(target_cpu == "x64" || target_cpu == "arm64" || target_cpu == "riscv64")) {
zip_bundle("analyze_snapshot") {
deps = [ "$dart_src/runtime/bin:analyze_snapshot($host_toolchain)" ]

Expand Down
10 changes: 10 additions & 0 deletions engine/src/flutter/third_party/tonic/common/build_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@
#define ARCH_CPU_ARM64 1
#define ARCH_CPU_64_BITS 1
#define ARCH_CPU_LITTLE_ENDIAN 1
#elif defined(__riscv) && __SIZEOF_POINTER__ == 4
#define ARCH_CPU_RISCV_FAMILY 1
#define ARCH_CPU_RISCV32 1
#define ARCH_CPU_32_BITS 1
#define ARCH_CPU_LITTLE_ENDIAN 1
#elif defined(__riscv) && __SIZEOF_POINTER__ == 8
#define ARCH_CPU_RISCV_FAMILY 1
#define ARCH_CPU_RISCV64 1
#define ARCH_CPU_64_BITS 1
#define ARCH_CPU_LITTLE_ENDIAN 1
#elif defined(__pnacl__)
#define ARCH_CPU_32_BITS 1
#define ARCH_CPU_LITTLE_ENDIAN 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ final class RunTarget {
TargetPlatform.androidX86 => 'android_${mode}_x86',
TargetPlatform.androidX64 => 'android_${mode}_x64',
TargetPlatform.androidArm64 => 'android_${mode}_arm64',
TargetPlatform.androidRiscv64 => 'android_${mode}_riscv64',

// DESKTOP (MacOS, Linux, Windows)
// We do not support cross-builds, so implicitly assume the host platform.
Expand Down Expand Up @@ -291,6 +292,7 @@ final class RunTarget {
TargetPlatform.androidUnspecified ||
TargetPlatform.androidX86 ||
TargetPlatform.androidX64 ||
TargetPlatform.androidRiscv64 ||
TargetPlatform.androidArm64 => [
Label.parseGn('//flutter/shell/platform/android:android_jar'),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ final class TargetPlatform {
/// Android ARM64.
static const androidArm64 = TargetPlatform._('android-arm64');

/// Android RISCV64.
static const androidRiscv64 = TargetPlatform._('android-riscv64');

/// Android x64.
static const androidX64 = TargetPlatform._('android-x64');

Expand Down Expand Up @@ -87,6 +90,7 @@ final class TargetPlatform {
androidUnspecified,
androidArm,
androidArm64,
androidRiscv64,
androidX64,
androidX86,
linuxArm64,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ void main() {
TargetPlatform.androidX86: 'android_debug_x86',
TargetPlatform.androidX64: 'android_debug_x64',
TargetPlatform.androidArm64: 'android_debug_arm64',
TargetPlatform.androidRiscv64: 'android_debug_riscv64',
TargetPlatform.darwinUnspecified: 'host_debug',
TargetPlatform.darwinX64: 'host_debug',
TargetPlatform.darwinArm64: 'host_debug_arm64',
Expand Down Expand Up @@ -100,6 +101,9 @@ void main() {
TargetPlatform.androidX86: [Label.parseGn('//flutter/shell/platform/android:android_jar')],
TargetPlatform.androidX64: [Label.parseGn('//flutter/shell/platform/android:android_jar')],
TargetPlatform.androidArm64: [Label.parseGn('//flutter/shell/platform/android:android_jar')],
TargetPlatform.androidRiscv64: [
Label.parseGn('//flutter/shell/platform/android:android_jar'),
],
TargetPlatform.iOSUnspecified: [
Label.parseGn('//flutter/shell/platform/darwin/ios:flutter_framework'),
],
Expand Down
2 changes: 1 addition & 1 deletion engine/src/flutter/tools/gn
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ def parse_args(args):
)
parser.add_argument('--android', dest='target_os', action='store_const', const='android')
parser.add_argument(
'--android-cpu', type=str, choices=['arm', 'x64', 'x86', 'arm64'], default='arm'
'--android-cpu', type=str, choices=['arm', 'x64', 'x86', 'arm64', 'riscv64'], default='arm'
)
parser.add_argument('--ios', dest='target_os', action='store_const', const='ios')
parser.add_argument('--mac', dest='target_os', action='store_const', const='mac')
Expand Down