From 1c09d84078035b404df60516e4dd4518dcbfe381 Mon Sep 17 00:00:00 2001 From: Pierrick Bouvier <101587250+pbo-linaro@users.noreply.github.com> Date: Thu, 22 Sep 2022 21:44:26 +0200 Subject: [PATCH] Enable native Windows on Arm build (flutter/engine#35962) Linaro [Windows on Arm](https://www.linaro.org/windows-on-arm/) team is working to enable projects for this new platform. Lately, we have been interested in Dart/Flutter. This PR enables building natively flutter components (exe + dll) for windows on arm. It solves this issue (https://github.com/flutter/flutter/issues/62597) partially, by starting with native build. --- engine/src/flutter/tools/gn | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/tools/gn b/engine/src/flutter/tools/gn index 87c379fb6c..a2b365c097 100755 --- a/engine/src/flutter/tools/gn +++ b/engine/src/flutter/tools/gn @@ -165,7 +165,7 @@ def get_host_cpu(): if is_rosetta(): return 'arm64' machine = platform.machine() - if machine in ['aarch64', 'arm64']: + if machine in ['aarch64', 'arm64', 'ARM64']: return 'arm64' if machine in ['x86_64', 'AMD64', 'x64']: return 'x64' @@ -177,6 +177,7 @@ def get_host_cpu(): # Returns the target CPU architecture. # # For macOS host builds where --mac-cpu is specified, returns that value. +# For windows host builds where --windows-cpu is specified, returns that value. # For all other host builds, assumes 'x64'. def get_target_cpu(args): if args.target_os == 'android': @@ -199,6 +200,9 @@ def get_target_cpu(args): # Host build. Default to x64 unless overridden. if get_host_os() == 'mac' and args.mac_cpu: return args.mac_cpu + if get_host_os() == 'win' and args.windows_cpu: + return args.windows_cpu + return 'x64' @@ -324,8 +328,12 @@ def to_gn_args(args): # No cross-compilation on Windows (for now). Use host toolchain that # matches the bit-width of the target architecture. if sys.platform.startswith(('cygwin', 'win')) and args.target_os != 'win': - gn_args['host_cpu'] = cpu_for_target_arch(gn_args['target_cpu']) - gn_args['target_cpu'] = cpu_for_target_arch(gn_args['target_cpu']) + cpu = cpu_for_target_arch(gn_args['target_cpu']) + # We explicitly allow arm64 native build. 'host_cpu' key may not exist. + if gn_args.get('host_cpu') == 'arm64' and gn_args['target_cpu'] == 'arm64': + cpu = 'arm64' + gn_args['host_cpu'] = cpu + gn_args['target_cpu'] = cpu # macOS host builds (whether x64 or arm64) must currently be built under # Rosetta on Apple Silicon Macs.