From ca037ac2d7de6c271ff7386f6bc08729c943b43a Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Thu, 29 Jul 2021 09:57:05 +0900 Subject: [PATCH] Add arm64 Linux host support (#29) Fixed https://github.com/sony/flutter-elinux/issues/2 --- lib/commands/build.dart | 7 ++++++- lib/commands/run.dart | 14 +++++++++++++- lib/elinux_builder.dart | 17 +++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/lib/commands/build.dart b/lib/commands/build.dart index 4571daf..e22986e 100644 --- a/lib/commands/build.dart +++ b/lib/commands/build.dart @@ -67,7 +67,12 @@ class BuildPackageCommand extends BuildSubCommand with ELinuxExtension { @override Future> get requiredArtifacts async => { - DevelopmentArtifact.androidGenSnapshot, + // Use gensnapshot for Arm64 Linux when the host is arm64 because + // the artifacts for arm64 host don't support self-building now. + if (_getCurrentHostPlatformArchName() == 'arm64') + DevelopmentArtifact.linux, + if (_getCurrentHostPlatformArchName() == 'x64') + DevelopmentArtifact.androidGenSnapshot, ELinuxDevelopmentArtifact.elinux, }; diff --git a/lib/commands/run.dart b/lib/commands/run.dart index b40b480..ee6456c 100644 --- a/lib/commands/run.dart +++ b/lib/commands/run.dart @@ -5,6 +5,8 @@ // @dart = 2.8 +import 'package:flutter_tools/src/base/os.dart'; +import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/commands/run.dart'; @@ -18,7 +20,17 @@ class ELinuxRunCommand extends RunCommand with ELinuxExtension { @override Future> get requiredArtifacts async => { - DevelopmentArtifact.androidGenSnapshot, + // Use gensnapshot for Arm64 Linux when the host is arm64 because + // the artifacts for arm64 host don't support self-building now. + if (_getCurrentHostPlatformArchName() == 'arm64') + DevelopmentArtifact.linux, + if (_getCurrentHostPlatformArchName() == 'x64') + DevelopmentArtifact.androidGenSnapshot, ELinuxDevelopmentArtifact.elinux, }; + + String _getCurrentHostPlatformArchName() { + final HostPlatform hostPlatform = getCurrentHostPlatform(); + return getNameForHostPlatformArch(hostPlatform); + } } diff --git a/lib/elinux_builder.dart b/lib/elinux_builder.dart index 5a203c8..38cc365 100644 --- a/lib/elinux_builder.dart +++ b/lib/elinux_builder.dart @@ -12,6 +12,7 @@ import 'package:flutter_tools/src/android/gradle.dart'; import 'package:flutter_tools/src/base/analyze_size.dart'; import 'package:flutter_tools/src/base/common.dart'; import 'package:flutter_tools/src/base/logger.dart'; +import 'package:flutter_tools/src/base/os.dart'; import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/build_system/build_system.dart'; import 'package:flutter_tools/src/cache.dart'; @@ -145,10 +146,26 @@ class ELinuxBuilder { /// See: [getTargetPlatformForName] in `build_info.dart` TargetPlatform _getTargetPlatformForArch(String arch) { + final String hostArch = _getCurrentHostPlatformArchName(); switch (arch) { case 'arm64': + // Use gensnapshot for Arm64 Linux when the host is arm64 because + // the artifacts for arm64 host don't support self-building now. + if (hostArch == 'arm64') { + return TargetPlatform.linux_arm64; + } return TargetPlatform.android_arm64; default: + // Use gensnapshot for Arm64 Linux when the host is arm64 because + // the artifacts for arm64 host don't support self-building now. + if (hostArch == 'arm64') { + return TargetPlatform.linux_x64; + } return TargetPlatform.android_x64; } } + +String _getCurrentHostPlatformArchName() { + final HostPlatform hostPlatform = getCurrentHostPlatform(); + return getNameForHostPlatformArch(hostPlatform); +}