Skip to content

Commit 9e41dcb

Browse files
Engine build setup for Android RISCV64.
Bug: #117973
1 parent b0c8612 commit 9e41dcb

File tree

14 files changed

+213
-6
lines changed

14 files changed

+213
-6
lines changed

engine/src/build/config/android/config.gni

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ if (is_android) {
6767

6868
zipalign_path = "$android_sdk_build_tools/zipalign"
6969

70-
if (current_cpu != "x64" && current_cpu != "arm64") {
70+
if (current_cpu == "riscv64") {
71+
android_api_level = 35
72+
} else if (current_cpu != "x64" && current_cpu != "arm64") {
7173
android_api_level = 21
7274
}
7375

@@ -101,6 +103,9 @@ if (is_android) {
101103
} else if (current_cpu == "arm64") {
102104
android_app_abi = "arm64-v8a"
103105
_android_lib_dir = "aarch64-linux-android"
106+
} else if (current_cpu == "riscv64") {
107+
android_app_abi = "riscv64"
108+
_android_lib_dir = "riscv64-linux-android"
104109
} else {
105110
assert(false, "Unknown Android ABI: " + current_cpu)
106111
}

engine/src/build/config/compiler/BUILD.gn

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ declare_args() {
3333

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

3839
# This flag is deprecated and will be removed. The value will be ignored.
3940
use_fstack_protector = false
@@ -464,6 +465,9 @@ config("compiler") {
464465
} else if (current_cpu == "x64") {
465466
cflags += [ "--target=x86_64-linux-androideabi${android_api_level}" ]
466467
ldflags += [ "--target=x86_64-linux-androideabi${android_api_level}" ]
468+
} else if (current_cpu == "riscv64") {
469+
cflags += [ "--target=riscv64-linux-androideabi${android_api_level}" ]
470+
ldflags += [ "--target=riscv64-linux-androideabi${android_api_level}" ]
467471
}
468472
}
469473

engine/src/build/toolchain/android/BUILD.gn

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,7 @@ android_toolchains_helper("arm64_apilevel26") {
152152
android_api_level = 26
153153
}
154154
}
155+
156+
android_toolchains_helper("riscv64") {
157+
toolchain_cpu = "riscv64"
158+
}

engine/src/flutter/assets/native_assets.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ namespace flutter {
1717
#define kTargetArchitectureName "ia32"
1818
#elif defined(FML_ARCH_CPU_X86_64)
1919
#define kTargetArchitectureName "x64"
20+
#elif defined(FML_ARCH_CPU_RISCV32)
21+
#define kTargetArchitectureName "riscv32"
22+
#elif defined(FML_ARCH_CPU_RISCV64)
23+
#define kTargetArchitectureName "riscv64"
2024
#else
2125
#error Target architecture detection failed.
2226
#endif

engine/src/flutter/ci/builders/linux_android_aot_engine.json

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,98 @@
301301
"flutter/shell/platform/android:analyze_snapshot"
302302
]
303303
}
304+
},
305+
{
306+
"archives": [
307+
{
308+
"name": "ci/android_profile_riscv64",
309+
"type": "gcs",
310+
"base_path": "out/ci/android_profile_riscv64/zip_archives/",
311+
"include_paths": [
312+
"out/ci/android_profile_riscv64/zip_archives/android-riscv64-profile/artifacts.zip",
313+
"out/ci/android_profile_riscv64/zip_archives/android-riscv64-profile/linux-x64.zip",
314+
"out/ci/android_profile_riscv64/zip_archives/android-riscv64-profile/symbols.zip",
315+
"out/ci/android_profile_riscv64/zip_archives/android-riscv64-profile/analyze-snapshot-linux-x64.zip",
316+
"out/ci/android_profile_riscv64/zip_archives/download.flutter.io"
317+
],
318+
"realm": "production"
319+
}
320+
],
321+
"drone_dimensions": [
322+
"device_type=none",
323+
"os=Linux"
324+
],
325+
"gclient_variables": {
326+
"use_rbe": true
327+
},
328+
"gn": [
329+
"--target-dir",
330+
"ci/android_profile_riscv64",
331+
"--runtime-mode",
332+
"profile",
333+
"--android",
334+
"--android-cpu",
335+
"riscv64",
336+
"--rbe",
337+
"--no-goma"
338+
],
339+
"name": "ci/android_profile_riscv64",
340+
"description": "Produces profile mode artifacts to target riscv64 Android from a Linux host.",
341+
"ninja": {
342+
"config": "ci/android_profile_riscv64",
343+
"targets": [
344+
"default",
345+
"clang_x64/gen_snapshot",
346+
"flutter/shell/platform/android:abi_jars",
347+
"flutter/shell/platform/android:analyze_snapshot"
348+
]
349+
}
350+
},
351+
{
352+
"archives": [
353+
{
354+
"name": "ci/android_release_riscv64",
355+
"type": "gcs",
356+
"base_path": "out/ci/android_release_riscv64/zip_archives/",
357+
"include_paths": [
358+
"out/ci/android_release_riscv64/zip_archives/android-riscv64-release/artifacts.zip",
359+
"out/ci/android_release_riscv64/zip_archives/android-riscv64-release/linux-x64.zip",
360+
"out/ci/android_release_riscv64/zip_archives/android-riscv64-release/symbols.zip",
361+
"out/ci/android_release_riscv64/zip_archives/android-riscv64-release/analyze-snapshot-linux-x64.zip",
362+
"out/ci/android_release_riscv64/zip_archives/download.flutter.io"
363+
],
364+
"realm": "production"
365+
}
366+
],
367+
"drone_dimensions": [
368+
"device_type=none",
369+
"os=Linux"
370+
],
371+
"gclient_variables": {
372+
"use_rbe": true
373+
},
374+
"gn": [
375+
"--target-dir",
376+
"ci/android_release_riscv64",
377+
"--runtime-mode",
378+
"release",
379+
"--android",
380+
"--android-cpu",
381+
"riscv64",
382+
"--rbe",
383+
"--no-goma"
384+
],
385+
"name": "ci/android_release_riscv64",
386+
"description": "Produces release mode artifacts to target riscv64 Android from a Linux host.",
387+
"ninja": {
388+
"config": "ci/android_release_riscv64",
389+
"targets": [
390+
"default",
391+
"clang_x64/gen_snapshot",
392+
"flutter/shell/platform/android:abi_jars",
393+
"flutter/shell/platform/android:analyze_snapshot"
394+
]
395+
}
304396
}
305397
],
306398
"generators": {

engine/src/flutter/ci/builders/linux_android_debug_engine.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,50 @@
194194
"flutter/impeller/toolkit/interop:sdk"
195195
]
196196
}
197+
},
198+
{
199+
"archives": [
200+
{
201+
"name": "ci/android_debug_riscv64",
202+
"type": "gcs",
203+
"base_path": "out/ci/android_debug_riscv64/zip_archives/",
204+
"include_paths": [
205+
"out/ci/android_debug_riscv64/zip_archives/android-riscv64/artifacts.zip",
206+
"out/ci/android_debug_riscv64/zip_archives/android-riscv64/android-riscv64-embedder.zip",
207+
"out/ci/android_debug_riscv64/zip_archives/android-riscv64/impeller_sdk.zip",
208+
"out/ci/android_debug_riscv64/zip_archives/android-riscv64/symbols.zip",
209+
"out/ci/android_debug_riscv64/zip_archives/download.flutter.io"
210+
],
211+
"realm": "production"
212+
}
213+
],
214+
"drone_dimensions": [
215+
"device_type=none",
216+
"os=Linux"
217+
],
218+
"gclient_variables": {
219+
"use_rbe": true
220+
},
221+
"gn": [
222+
"--target-dir",
223+
"ci/android_debug_riscv64",
224+
"--android",
225+
"--android-cpu=riscv64",
226+
"--no-lto",
227+
"--rbe",
228+
"--no-goma"
229+
],
230+
"name": "ci/android_debug_riscv64",
231+
"description": "Produces debug mode artifacts to target riscv64 Android from a Linux host.",
232+
"ninja": {
233+
"config": "ci/android_debug_riscv64",
234+
"targets": [
235+
"flutter",
236+
"flutter/shell/platform/android:abi_jars",
237+
"flutter/shell/platform/embedder:embedder-archive",
238+
"flutter/impeller/toolkit/interop:sdk"
239+
]
240+
}
197241
}
198242
],
199243
"generators": {

engine/src/flutter/ci/builders/local_engine.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,32 @@
261261
"targets": []
262262
}
263263
},
264+
{
265+
"cas_archive": false,
266+
"drone_dimensions": [
267+
"os=Linux",
268+
"device_type=none"
269+
],
270+
"gclient_variables": {
271+
"use_rbe": true
272+
},
273+
"gn": [
274+
"--runtime-mode",
275+
"debug",
276+
"--android",
277+
"--android-cpu=riscv64",
278+
"--no-stripped",
279+
"--no-lto",
280+
"--rbe",
281+
"--no-goma"
282+
],
283+
"name": "linux/android_debug_riscv64",
284+
"description": "Builds a debug mode engine that targets riscv64 Android from a Linux host.",
285+
"ninja": {
286+
"config": "android_debug_riscv64",
287+
"targets": []
288+
}
289+
},
264290
{
265291
"cas_archive": false,
266292
"drone_dimensions": [

engine/src/flutter/fml/build_config.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@
9393
#define FML_ARCH_CPU_ARM64 1
9494
#define FML_ARCH_CPU_64_BITS 1
9595
#define FML_ARCH_CPU_LITTLE_ENDIAN 1
96+
#elif defined(__riscv) && __SIZEOF_POINTER__ == 4
97+
#define FML_ARCH_CPU_RISCV_FAMILY 1
98+
#define FML_ARCH_CPU_RISCV32 1
99+
#define FML_ARCH_CPU_32_BITS 1
100+
#define FML_ARCH_CPU_LITTLE_ENDIAN 1
101+
#elif defined(__riscv) && __SIZEOF_POINTER__ == 8
102+
#define FML_ARCH_CPU_RISCV_FAMILY 1
103+
#define FML_ARCH_CPU_RISCV64 1
104+
#define FML_ARCH_CPU_64_BITS 1
105+
#define FML_ARCH_CPU_LITTLE_ENDIAN 1
96106
#elif defined(__pnacl__)
97107
#define FML_ARCH_CPU_32_BITS 1
98108
#define FML_ARCH_CPU_LITTLE_ENDIAN 1

engine/src/flutter/lib/snapshot/BUILD.gn

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,14 @@ group("generate_snapshot_bins") {
4141
# For iOS, Android target builds: all AOT target CPUs are arm/arm64.
4242
public_deps += [ ":create_arm_gen_snapshot" ]
4343
} else if (target_cpu == "arm" || target_cpu == "arm64" ||
44-
target_cpu == "x64") {
44+
target_cpu == "x64" || target_cpu == "riscv64") {
4545
# For other host OSes, build gen_snapshot directly.
4646
public_deps = [ "$dart_src/runtime/bin:gen_snapshot($host_toolchain)" ]
4747
}
4848

4949
# Build analyze_snapshot for 64-bit target CPUs.
50-
if (host_os == "linux" && (target_cpu == "x64" || target_cpu == "arm64")) {
50+
if (host_os == "linux" && (target_cpu == "x64" || target_cpu == "arm64" ||
51+
target_cpu == "riscv64")) {
5152
public_deps += [ "$dart_src/runtime/bin:analyze_snapshot($host_toolchain)" ]
5253
}
5354
}

engine/src/flutter/shell/platform/android/BUILD.gn

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,8 @@ if (target_cpu != "x86") {
796796
}
797797
}
798798

799-
if (host_os == "linux" && (target_cpu == "x64" || target_cpu == "arm64")) {
799+
if (host_os == "linux" &&
800+
(target_cpu == "x64" || target_cpu == "arm64" || target_cpu == "riscv64")) {
800801
zip_bundle("analyze_snapshot") {
801802
deps = [ "$dart_src/runtime/bin:analyze_snapshot($host_toolchain)" ]
802803

0 commit comments

Comments
 (0)