Skip to content

Commit e1373de

Browse files
Engine build setup for Android RISCV64.
Bug: #117973
1 parent 78df185 commit e1373de

File tree

15 files changed

+217
-6
lines changed

15 files changed

+217
-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
@@ -299,6 +299,98 @@
299299
"flutter/shell/platform/android:analyze_snapshot"
300300
]
301301
}
302+
},
303+
{
304+
"archives": [
305+
{
306+
"name": "ci/android_profile_riscv64",
307+
"type": "gcs",
308+
"base_path": "out/ci/android_profile_riscv64/zip_archives/",
309+
"include_paths": [
310+
"out/ci/android_profile_riscv64/zip_archives/android-riscv64-profile/artifacts.zip",
311+
"out/ci/android_profile_riscv64/zip_archives/android-riscv64-profile/linux-x64.zip",
312+
"out/ci/android_profile_riscv64/zip_archives/android-riscv64-profile/symbols.zip",
313+
"out/ci/android_profile_riscv64/zip_archives/android-riscv64-profile/analyze-snapshot-linux-x64.zip",
314+
"out/ci/android_profile_riscv64/zip_archives/download.flutter.io"
315+
],
316+
"realm": "production"
317+
}
318+
],
319+
"drone_dimensions": [
320+
"device_type=none",
321+
"os=Linux"
322+
],
323+
"gclient_variables": {
324+
"use_rbe": true
325+
},
326+
"gn": [
327+
"--target-dir",
328+
"ci/android_profile_riscv64",
329+
"--runtime-mode",
330+
"profile",
331+
"--android",
332+
"--android-cpu",
333+
"riscv64",
334+
"--rbe",
335+
"--no-goma"
336+
],
337+
"name": "ci/android_profile_riscv64",
338+
"description": "Produces profile mode artifacts to target riscv64 Android from a Linux host.",
339+
"ninja": {
340+
"config": "ci/android_profile_riscv64",
341+
"targets": [
342+
"default",
343+
"clang_x64/gen_snapshot",
344+
"flutter/shell/platform/android:abi_jars",
345+
"flutter/shell/platform/android:analyze_snapshot"
346+
]
347+
}
348+
},
349+
{
350+
"archives": [
351+
{
352+
"name": "ci/android_release_riscv64",
353+
"type": "gcs",
354+
"base_path": "out/ci/android_release_riscv64/zip_archives/",
355+
"include_paths": [
356+
"out/ci/android_release_riscv64/zip_archives/android-riscv64-release/artifacts.zip",
357+
"out/ci/android_release_riscv64/zip_archives/android-riscv64-release/linux-x64.zip",
358+
"out/ci/android_release_riscv64/zip_archives/android-riscv64-release/symbols.zip",
359+
"out/ci/android_release_riscv64/zip_archives/android-riscv64-release/analyze-snapshot-linux-x64.zip",
360+
"out/ci/android_release_riscv64/zip_archives/download.flutter.io"
361+
],
362+
"realm": "production"
363+
}
364+
],
365+
"drone_dimensions": [
366+
"device_type=none",
367+
"os=Linux"
368+
],
369+
"gclient_variables": {
370+
"use_rbe": true
371+
},
372+
"gn": [
373+
"--target-dir",
374+
"ci/android_release_riscv64",
375+
"--runtime-mode",
376+
"release",
377+
"--android",
378+
"--android-cpu",
379+
"riscv64",
380+
"--rbe",
381+
"--no-goma"
382+
],
383+
"name": "ci/android_release_riscv64",
384+
"description": "Produces release mode artifacts to target riscv64 Android from a Linux host.",
385+
"ninja": {
386+
"config": "ci/android_release_riscv64",
387+
"targets": [
388+
"default",
389+
"clang_x64/gen_snapshot",
390+
"flutter/shell/platform/android:abi_jars",
391+
"flutter/shell/platform/android:analyze_snapshot"
392+
]
393+
}
302394
}
303395
],
304396
"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
@@ -192,6 +192,50 @@
192192
"flutter/impeller/toolkit/interop:sdk"
193193
]
194194
}
195+
},
196+
{
197+
"archives": [
198+
{
199+
"name": "ci/android_debug_riscv64",
200+
"type": "gcs",
201+
"base_path": "out/ci/android_debug_riscv64/zip_archives/",
202+
"include_paths": [
203+
"out/ci/android_debug_riscv64/zip_archives/android-riscv64/artifacts.zip",
204+
"out/ci/android_debug_riscv64/zip_archives/android-riscv64/android-riscv64-embedder.zip",
205+
"out/ci/android_debug_riscv64/zip_archives/android-riscv64/impeller_sdk.zip",
206+
"out/ci/android_debug_riscv64/zip_archives/android-riscv64/symbols.zip",
207+
"out/ci/android_debug_riscv64/zip_archives/download.flutter.io"
208+
],
209+
"realm": "production"
210+
}
211+
],
212+
"drone_dimensions": [
213+
"device_type=none",
214+
"os=Linux"
215+
],
216+
"gclient_variables": {
217+
"use_rbe": true
218+
},
219+
"gn": [
220+
"--target-dir",
221+
"ci/android_debug_riscv64",
222+
"--android",
223+
"--android-cpu=riscv64",
224+
"--no-lto",
225+
"--rbe",
226+
"--no-goma"
227+
],
228+
"name": "ci/android_debug_riscv64",
229+
"description": "Produces debug mode artifacts to target riscv64 Android from a Linux host.",
230+
"ninja": {
231+
"config": "ci/android_debug_riscv64",
232+
"targets": [
233+
"flutter",
234+
"flutter/shell/platform/android:abi_jars",
235+
"flutter/shell/platform/embedder:embedder-archive",
236+
"flutter/impeller/toolkit/interop:sdk"
237+
]
238+
}
195239
}
196240
],
197241
"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)