diff --git a/engine/src/flutter/tools/gn b/engine/src/flutter/tools/gn index 11d7cf63323..8db9728ed2a 100755 --- a/engine/src/flutter/tools/gn +++ b/engine/src/flutter/tools/gn @@ -120,6 +120,37 @@ def can_use_prebuilt_dart(args): prebuilts_dir = os.path.join(SRC_ROOT, 'flutter', 'prebuilts', prebuilt) return prebuilts_dir != None and os.path.isdir(prebuilts_dir) + +def get_target_cpu(args): + if args.target_os == 'android': + target_cpu = args.android_cpu + elif args.target_os == 'ios': + if args.simulator: + target_cpu = args.simulator_cpu + else: + target_cpu = args.ios_cpu + elif args.target_os == 'mac': + target_cpu = args.mac_cpu + elif args.target_os == 'linux': + target_cpu = args.linux_cpu + elif args.target_os == 'fuchsia': + target_cpu = args.fuchsia_cpu + elif args.target_os == 'wasm': + target_cpu = 'wasm' + elif args.target_os == 'win': + target_cpu = args.windows_cpu + else: + # Building host artifacts + target_cpu = 'x64' + + # No cross-compilation on Windows (for now). + # See: https://github.com/flutter/engine/pull/3883 + if sys.platform.startswith(('cygwin', 'win')) and args.target_os != 'win': + target_cpu = cpu_for_target_arch(target_cpu) + + return target_cpu + + def to_gn_args(args): if args.simulator: if args.target_os != 'ios': @@ -189,20 +220,14 @@ def to_gn_args(args): # The GN arg is not available in the windows toolchain. gn_args['enable_lto'] = enable_lto - if args.target_os == 'android': - gn_args['target_os'] = 'android' - elif args.target_os == 'ios': - gn_args['target_os'] = 'ios' - gn_args['use_ios_simulator'] = args.simulator + if args.target_os: + gn_args['target_os'] = args.target_os + gn_args['target_cpu'] = get_target_cpu(args) + + if args.target_os == 'ios': + gn_args['use_ios_simulator'] = args.simulator elif args.target_os == 'mac': - gn_args['target_os'] = 'mac' - gn_args['use_ios_simulator'] = False - elif args.target_os == 'fuchsia': - gn_args['target_os'] = 'fuchsia' - elif args.target_os == 'wasm': - gn_args['target_os'] = 'wasm' - elif args.target_os is not None: - gn_args['target_os'] = args.target_os + gn_args['use_ios_simulator'] = False if args.dart_debug: gn_args['dart_debug'] = True @@ -211,27 +236,6 @@ def to_gn_args(args): gn_args['dart_debug'] = True gn_args['dart_debug_optimization_level'] = '0' - if args.target_os == 'android': - gn_args['target_cpu'] = args.android_cpu - elif args.target_os == 'ios': - if args.simulator: - gn_args['target_cpu'] = args.simulator_cpu - else: - gn_args['target_cpu'] = args.ios_cpu - elif args.target_os == 'mac': - gn_args['target_cpu'] = args.mac_cpu - elif args.target_os == 'linux': - gn_args['target_cpu'] = args.linux_cpu - elif args.target_os == 'fuchsia': - gn_args['target_cpu'] = args.fuchsia_cpu - elif args.target_os == 'wasm': - gn_args['target_cpu'] = 'wasm' - elif args.target_os == 'win': - gn_args['target_cpu'] = args.windows_cpu - else: - # Building host artifacts - gn_args['target_cpu'] = 'x64' - # Flutter-specific arguments which don't apply for a CanvasKit build. if args.target_os != 'wasm': gn_args['flutter_use_fontconfig'] = args.enable_fontconfig @@ -270,10 +274,6 @@ def to_gn_args(args): if args.interpreter: raise Exception('--interpreter is no longer needed on any supported platform.') - if sys.platform.startswith(('cygwin', 'win')) and args.target_os != 'win': - if 'target_cpu' in gn_args: - gn_args['target_cpu'] = cpu_for_target_arch(gn_args['target_cpu']) - if args.target_os is None: if sys.platform.startswith(('cygwin', 'win')): gn_args['dart_use_fallback_root_certificates'] = True