diff --git a/DEPS b/DEPS index d9411a52e57..a6e90a2efb0 100644 --- a/DEPS +++ b/DEPS @@ -605,6 +605,17 @@ Var("dart_root") + "/third_party/pkg/tar": "dep_type": "cipd", }, + Var("dart_root") + "/third_party/canary_ndk": { + "packages": [ + { + "package": "flutter/android/ndk/${{os}}-amd64", + "version": "version:r27.0.10869015" + } + ], + "condition": "download_android_deps", + "dep_type": "cipd", + }, + Var("dart_root") + "/third_party/android_tools": { "packages": [ { diff --git a/build/config/android/config.gni b/build/config/android/config.gni index cf91e85eeb7..b5501357f42 100644 --- a/build/config/android/config.gni +++ b/build/config/android/config.gni @@ -55,6 +55,9 @@ if (is_android) { # Path to the Android NDK and SDK. android_ndk_root = "//third_party/android_tools/ndk" + if (current_cpu == "riscv64") { + android_ndk_root = "//third_party/canary_ndk" + } android_ndk_include_dir = "$android_ndk_root/usr/include" android_sdk = "${android_sdk_root}/platforms/android-${android_sdk_version}" @@ -70,7 +73,9 @@ if (is_android) { # Subdirectories inside android_ndk_root that contain the sysroot for the # associated platform. - 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 = 22 } else { android_api_level = 19 @@ -86,11 +91,13 @@ if (is_android) { arm_android_toolchain_root = "$android_ndk_root/toolchains/arm-linux-androideabi-${_android_toolchain_version}/prebuilt/${android_host_os}-${android_host_arch}" x86_64_android_toolchain_root = "$android_ndk_root/toolchains/x86_64-${_android_toolchain_version}/prebuilt/${android_host_os}-${android_host_arch}" arm64_android_toolchain_root = "$android_ndk_root/toolchains/aarch64-linux-android-${_android_toolchain_version}/prebuilt/${android_host_os}-${android_host_arch}" + riscv64_android_toolchain_root = "$android_ndk_root/toolchains/llvm/prebuilt/${android_host_os}-${android_host_arch}" x86_android_lib = "$llvm_android_toolchain_root/sysroot/usr/lib/i686-linux-android/${android_api_level}" arm_android_lib = "$llvm_android_toolchain_root/sysroot/usr/lib/arm-linux-androideabi/${android_api_level}" x86_64_android_lib = "$llvm_android_toolchain_root/sysroot/usr/lib/x86_64-linux-android/${android_api_level}" arm64_android_lib = "$llvm_android_toolchain_root/sysroot/usr/lib/aarch64-linux-android/${android_api_level}" + riscv64_android_lib = "$llvm_android_toolchain_root/sysroot/usr/lib/riscv64-linux-android/${android_api_level}" # Location of libgcc. This is only needed for the current GN toolchain, so we # only need to define the current one, rather than one for every platform @@ -115,6 +122,11 @@ if (is_android) { android_target_triple = "aarch64-linux-android" android_toolchain_root = "$arm64_android_toolchain_root" android_lib = "$arm64_android_lib" + } else if (current_cpu == "riscv64") { + android_prebuilt_arch = "android-riscv64" + android_target_triple = "riscv64-linux-android" + android_toolchain_root = "$riscv64_android_toolchain_root" + android_lib = "$riscv64_android_lib" } else { assert(false, "Need android libgcc support for your target arch.") } @@ -157,6 +169,8 @@ if (is_android) { android_app_abi = "x86_64" } else if (current_cpu == "arm64") { android_app_abi = "arm64-v8a" + } else if (current_cpu == "riscv64") { + android_app_abi = "riscv64" } else { assert(false, "Unknown Android ABI: " + current_cpu) } diff --git a/build/config/compiler/BUILD.gn b/build/config/compiler/BUILD.gn index 19f4ffe1af5..4f367d4fe1f 100644 --- a/build/config/compiler/BUILD.gn +++ b/build/config/compiler/BUILD.gn @@ -415,6 +415,9 @@ config("compiler") { } else if (current_cpu == "x64") { cflags += [ "--target=x86_64-linux-androideabi" ] ldflags += [ "--target=x86_64-linux-androideabi" ] + } else if (current_cpu == "riscv64") { + cflags += [ "--target=riscv64-linux-android" ] + ldflags += [ "--target=riscv64-linux-android" ] } } } @@ -600,11 +603,6 @@ config("runtime_library") { lib_dirs += [ "$android_libcpp_root/libs/$android_app_abi" ] - libs += [ - "$android_libcpp_library", - "c++abi", - ] - if (android_api_level < 21) { libs += [ "android_support" ] } @@ -619,6 +617,11 @@ config("runtime_library") { "dl", "m", ] + if (current_cpu == "riscv64") { + libs -= [ "gcc" ] + lib_dirs += [ "//third_party/canary_ndk/toolchains/llvm/prebuilt/${android_host_os}-${android_host_arch}/lib/clang/17/lib/linux/" ] + libs += [ "clang_rt.builtins-riscv64-android" ] + } # Clang with libc++ does not require an explicit atomic library reference. if (!is_clang) { diff --git a/build/toolchain/android/BUILD.gn b/build/toolchain/android/BUILD.gn index cdb82ff5e4d..5d12dcf07e0 100644 --- a/build/toolchain/android/BUILD.gn +++ b/build/toolchain/android/BUILD.gn @@ -45,6 +45,11 @@ template("android_gcc_toolchain") { not_needed([ "tool_prefix" ]) prefix = rebase_path("//buildtools/${host_os}-x64/clang/bin", root_build_dir) + if (current_cpu == "riscv64") { + prefix = rebase_path( + "//third_party/canary_ndk/toolchains/llvm/prebuilt/${android_host_os}-${android_host_arch}/bin", + root_build_dir) + } cc = compiler_prefix + prefix + "/clang" cxx = compiler_prefix + prefix + "/clang++" @@ -130,3 +135,10 @@ android_gcc_toolchains_helper("arm64") { tool_prefix = "$llvm_android_toolchain_root/bin/aarch64-linux-android-" toolchain_cpu = "aarch64" } + +android_gcc_toolchains_helper("riscv64") { + android_ndk_lib_dir = riscv64_android_lib + + tool_prefix = "$llvm_android_toolchain_root/bin/riscv64-linux-android-" + toolchain_cpu = "riscv64" +} diff --git a/tools/gn.py b/tools/gn.py index be7fedf36f5..bf76924498d 100755 --- a/tools/gn.py +++ b/tools/gn.py @@ -384,6 +384,7 @@ def ProcessOptions(args): 'arm64', 'x64c', 'arm64c', + 'riscv64', ]: print( "Cross-compilation to %s is not supported for architecture %s."