From 56e4e4a070f1d1c59768c9b3974726eefdc06226 Mon Sep 17 00:00:00 2001 From: Godofredo Contreras Date: Mon, 15 Aug 2022 14:04:43 -0700 Subject: [PATCH 01/20] Archive windows gen_snapshot.exe. This is required to enable engine_v2 recipes for windows platform. Bug: https://github.com/flutter/flutter/issues/81855 --- build/archives/BUILD.gn | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/build/archives/BUILD.gn b/build/archives/BUILD.gn index 7743e1ad911c8..271f8a0e9caf0 100644 --- a/build/archives/BUILD.gn +++ b/build/archives/BUILD.gn @@ -300,3 +300,16 @@ if (is_mac) { ] } } + +if (is_win) { + zip_bundle("archive_win_gen_snapshot") { + deps = [] + output = "$full_platform_name--$flutter_runtime_mode/windows-x64.zip" + files = [ + { + source = "$root_out_dir/gen_snapshot.exe" + destination = "gen_snapshot.exe" + }, + ] + } +} From a420497a2382d9e89f44905c4eae58aa5372c12e Mon Sep 17 00:00:00 2001 From: Godofredo Contreras Date: Mon, 15 Aug 2022 14:27:50 -0700 Subject: [PATCH 02/20] Add dep to generate gen_snapshot.exe. --- build/archives/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/archives/BUILD.gn b/build/archives/BUILD.gn index 271f8a0e9caf0..64c82c8b8e810 100644 --- a/build/archives/BUILD.gn +++ b/build/archives/BUILD.gn @@ -303,7 +303,7 @@ if (is_mac) { if (is_win) { zip_bundle("archive_win_gen_snapshot") { - deps = [] + deps = [ "//third_party/dart/runtime/bin:gen_snapshot" ] output = "$full_platform_name--$flutter_runtime_mode/windows-x64.zip" files = [ { From 6beb5f3b82c2cb5ccb1e186395d90f9eeb93240e Mon Sep 17 00:00:00 2001 From: Godofredo Contreras Date: Mon, 15 Aug 2022 14:44:20 -0700 Subject: [PATCH 03/20] Use target platform name rather than host. --- build/archives/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/archives/BUILD.gn b/build/archives/BUILD.gn index 64c82c8b8e810..43fba3e317327 100644 --- a/build/archives/BUILD.gn +++ b/build/archives/BUILD.gn @@ -304,7 +304,7 @@ if (is_mac) { if (is_win) { zip_bundle("archive_win_gen_snapshot") { deps = [ "//third_party/dart/runtime/bin:gen_snapshot" ] - output = "$full_platform_name--$flutter_runtime_mode/windows-x64.zip" + output = "$full_target_platform_name-$flutter_runtime_mode/windows-x64.zip" files = [ { source = "$root_out_dir/gen_snapshot.exe" From 76c0ed19a99f8112030fecdbc6a56c42e4f55144 Mon Sep 17 00:00:00 2001 From: Godofredo Contreras Date: Mon, 15 Aug 2022 16:48:36 -0700 Subject: [PATCH 04/20] Use prebuilt_arch. --- build/archives/BUILD.gn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/archives/BUILD.gn b/build/archives/BUILD.gn index 43fba3e317327..463d7d7cc65bc 100644 --- a/build/archives/BUILD.gn +++ b/build/archives/BUILD.gn @@ -301,10 +301,10 @@ if (is_mac) { } } -if (is_win) { +if (is_win && is_android) { zip_bundle("archive_win_gen_snapshot") { deps = [ "//third_party/dart/runtime/bin:gen_snapshot" ] - output = "$full_target_platform_name-$flutter_runtime_mode/windows-x64.zip" + output = "$android_prebuilt_arch-$flutter_runtime_mode/windows-x64.zip" files = [ { source = "$root_out_dir/gen_snapshot.exe" From 8c7b9d1003dc0b4df025d518ba13363dc066da04 Mon Sep 17 00:00:00 2001 From: Godofredo Contreras Date: Mon, 15 Aug 2022 17:07:12 -0700 Subject: [PATCH 05/20] Use platform_name instead of is_win. --- build/archives/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/archives/BUILD.gn b/build/archives/BUILD.gn index 463d7d7cc65bc..0ebf5ce381a79 100644 --- a/build/archives/BUILD.gn +++ b/build/archives/BUILD.gn @@ -301,7 +301,7 @@ if (is_mac) { } } -if (is_win && is_android) { +if (platform_name == "windows" && is_android) { zip_bundle("archive_win_gen_snapshot") { deps = [ "//third_party/dart/runtime/bin:gen_snapshot" ] output = "$android_prebuilt_arch-$flutter_runtime_mode/windows-x64.zip" From 1c7c55be334d1a841f8192492a6301e4ce523a6a Mon Sep 17 00:00:00 2001 From: Godofredo Contreras Date: Mon, 15 Aug 2022 17:48:11 -0700 Subject: [PATCH 06/20] Remove android check. --- build/archives/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/archives/BUILD.gn b/build/archives/BUILD.gn index 0ebf5ce381a79..ea594f7719731 100644 --- a/build/archives/BUILD.gn +++ b/build/archives/BUILD.gn @@ -301,7 +301,7 @@ if (is_mac) { } } -if (platform_name == "windows" && is_android) { +if (is_win) { zip_bundle("archive_win_gen_snapshot") { deps = [ "//third_party/dart/runtime/bin:gen_snapshot" ] output = "$android_prebuilt_arch-$flutter_runtime_mode/windows-x64.zip" From 28dde2cd2938acd3ae0fee66a30606c19e41234d Mon Sep 17 00:00:00 2001 From: Godofredo Contreras Date: Mon, 15 Aug 2022 18:39:20 -0700 Subject: [PATCH 07/20] Fix output name. --- build/archives/BUILD.gn | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/build/archives/BUILD.gn b/build/archives/BUILD.gn index ea594f7719731..41f918861f196 100644 --- a/build/archives/BUILD.gn +++ b/build/archives/BUILD.gn @@ -304,7 +304,9 @@ if (is_mac) { if (is_win) { zip_bundle("archive_win_gen_snapshot") { deps = [ "//third_party/dart/runtime/bin:gen_snapshot" ] - output = "$android_prebuilt_arch-$flutter_runtime_mode/windows-x64.zip" + cpu = "arm" + output = + "$target_host_name-$target_cpu-$flutter_runtime_mode/windows-x64.zip" files = [ { source = "$root_out_dir/gen_snapshot.exe" From 58946c405aad0569e099f591098a8b19d9342bf2 Mon Sep 17 00:00:00 2001 From: Godofredo Contreras Date: Mon, 15 Aug 2022 19:04:05 -0700 Subject: [PATCH 08/20] Separate platform and cpu in name. --- build/archives/BUILD.gn | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/build/archives/BUILD.gn b/build/archives/BUILD.gn index 41f918861f196..8234e7c1680f1 100644 --- a/build/archives/BUILD.gn +++ b/build/archives/BUILD.gn @@ -305,8 +305,7 @@ if (is_win) { zip_bundle("archive_win_gen_snapshot") { deps = [ "//third_party/dart/runtime/bin:gen_snapshot" ] cpu = "arm" - output = - "$target_host_name-$target_cpu-$flutter_runtime_mode/windows-x64.zip" + output = "$target_platform_name-$target_cpu-$flutter_runtime_mode/windows-x64.zip" files = [ { source = "$root_out_dir/gen_snapshot.exe" From 6476c1ed7d247193836d1b2451ce03d7416f99e0 Mon Sep 17 00:00:00 2001 From: Godofredo Contreras Date: Mon, 15 Aug 2022 19:36:05 -0700 Subject: [PATCH 09/20] Remove failing line. --- build/archives/BUILD.gn | 1 - 1 file changed, 1 deletion(-) diff --git a/build/archives/BUILD.gn b/build/archives/BUILD.gn index 8234e7c1680f1..4448caf30ee0b 100644 --- a/build/archives/BUILD.gn +++ b/build/archives/BUILD.gn @@ -304,7 +304,6 @@ if (is_mac) { if (is_win) { zip_bundle("archive_win_gen_snapshot") { deps = [ "//third_party/dart/runtime/bin:gen_snapshot" ] - cpu = "arm" output = "$target_platform_name-$target_cpu-$flutter_runtime_mode/windows-x64.zip" files = [ { From 5e8075feae6d043f352f32f00de2c822b07f125c Mon Sep 17 00:00:00 2001 From: Godofredo Contreras Date: Mon, 15 Aug 2022 22:32:20 -0700 Subject: [PATCH 10/20] Use dart_target_arch rather than target_cpu in windows. --- build/archives/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/archives/BUILD.gn b/build/archives/BUILD.gn index 4448caf30ee0b..3e416da2790be 100644 --- a/build/archives/BUILD.gn +++ b/build/archives/BUILD.gn @@ -304,7 +304,7 @@ if (is_mac) { if (is_win) { zip_bundle("archive_win_gen_snapshot") { deps = [ "//third_party/dart/runtime/bin:gen_snapshot" ] - output = "$target_platform_name-$target_cpu-$flutter_runtime_mode/windows-x64.zip" + output = "$target_platform_name-$dart_target_arch-$flutter_runtime_mode/windows-x64.zip" files = [ { source = "$root_out_dir/gen_snapshot.exe" From 34c6458694db1d405104a457127ed9f8b1d7f76d Mon Sep 17 00:00:00 2001 From: Godofredo Contreras Date: Mon, 15 Aug 2022 23:01:51 -0700 Subject: [PATCH 11/20] Add dart_target_arch to scope. --- common/config.gni | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common/config.gni b/common/config.gni index affe61af22dad..06e3662072edf 100644 --- a/common/config.gni +++ b/common/config.gni @@ -23,8 +23,8 @@ declare_args() { # Whether to use a prebuilt Dart SDK instead of building one. flutter_prebuilt_dart_sdk = false - # Whether to build the flutter web sdk outline/DDC artifacts. - flutter_build_web_sdk = false + # The dart target architecture. + dart_target_arch = "arm" } # feature_defines_list --------------------------------------------------------- @@ -117,7 +117,7 @@ if (flutter_prebuilt_dart_sdk) { # There is no prebuilt Dart SDK targeting Fuchsia, but we also don't need # one, so even when the build is targeting Fuchsia, use the prebuilt # Dart SDK for the host. - if (current_toolchain == host_toolchain || is_fuchsia || is_wasm) { + if (current_toolchain == host_toolchain || is_fuchsia) { prebuilt_dart_sdk = host_prebuilt_dart_sdk prebuilt_dart_sdk_config = _host_prebuilt_dart_sdk_config } else { From 74775c8cbf8b68444d906ddeb895055d874e0dc0 Mon Sep 17 00:00:00 2001 From: Godofredo Contreras Date: Tue, 16 Aug 2022 07:13:49 -0700 Subject: [PATCH 12/20] Add support for android_cpu. --- build/archives/BUILD.gn | 2 +- common/config.gni | 4 +- tools/gn | 333 ++++++++++++++-------------------------- 3 files changed, 117 insertions(+), 222 deletions(-) diff --git a/build/archives/BUILD.gn b/build/archives/BUILD.gn index 3e416da2790be..3c1d03e575645 100644 --- a/build/archives/BUILD.gn +++ b/build/archives/BUILD.gn @@ -304,7 +304,7 @@ if (is_mac) { if (is_win) { zip_bundle("archive_win_gen_snapshot") { deps = [ "//third_party/dart/runtime/bin:gen_snapshot" ] - output = "$target_platform_name-$dart_target_arch-$flutter_runtime_mode/windows-x64.zip" + output = "$target_platform_name-$android-cpu-$flutter_runtime_mode/windows-x64.zip" files = [ { source = "$root_out_dir/gen_snapshot.exe" diff --git a/common/config.gni b/common/config.gni index 06e3662072edf..532834dd0c701 100644 --- a/common/config.gni +++ b/common/config.gni @@ -23,8 +23,8 @@ declare_args() { # Whether to use a prebuilt Dart SDK instead of building one. flutter_prebuilt_dart_sdk = false - # The dart target architecture. - dart_target_arch = "arm" + # The android cpu used to generate windows artifacts. + android_cpu = "arm" } # feature_defines_list --------------------------------------------------------- diff --git a/tools/gn b/tools/gn index 27f65988f53b3..f11d6a650ff6e 100755 --- a/tools/gn +++ b/tools/gn @@ -21,8 +21,6 @@ SRC_ROOT = os.path.dirname( def get_out_dir(args): if args.target_os is not None: target_dir = [args.target_os] - elif args.web: - target_dir = ['wasm'] else: target_dir = ['host'] @@ -167,7 +165,7 @@ def get_host_cpu(): if is_rosetta(): return 'arm64' machine = platform.machine() - if machine in ['aarch64', 'arm64', 'ARM64']: + if machine in ['aarch64', 'arm64']: return 'arm64' if machine in ['x86_64', 'AMD64', 'x64']: return 'x64' @@ -179,7 +177,6 @@ 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': @@ -202,9 +199,6 @@ 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' @@ -217,55 +211,13 @@ def to_gn_args(args): gn_args = {} - gn_args['is_debug'] = args.unoptimized - - goma_dir = os.environ.get('GOMA_DIR') - goma_home_dir = os.path.join(os.getenv('HOME', ''), 'goma') - depot_tools_bin_dir = os.path.join(args.depot_tools, '.cipd_bin') - - # GOMA has a different default (home) path on gWindows. - if not os.path.exists(goma_home_dir) and sys.platform.startswith( - ('cygwin', 'win')): - goma_home_dir = os.path.join('c:\\', 'src', 'goma', 'goma-win64') - - if args.target_os == 'wasm' or args.web: - gn_args['use_goma'] = False - gn_args['goma_dir'] = None - print('Disabling GOMA for wasm builds, it is not supported yet.') - elif args.goma and goma_dir: - gn_args['use_goma'] = True - gn_args['goma_dir'] = goma_dir - elif args.goma and os.path.exists(goma_home_dir): - gn_args['use_goma'] = True - gn_args['goma_dir'] = goma_home_dir - elif args.goma and os.path.exists(depot_tools_bin_dir): - gn_args['use_goma'] = True - gn_args['goma_dir'] = depot_tools_bin_dir - else: - if args.goma: - print( - "GOMA usage was specified but can't be found, falling back to local " - 'builds. Set the GOMA_DIR environment variable to fix GOMA.' - ) - gn_args['use_goma'] = False - gn_args['goma_dir'] = None - - if gn_args['use_goma']: - if args.xcode_symlinks or os.getenv('FLUTTER_GOMA_CREATE_XCODE_SYMLINKS', - '0') == '1': - gn_args['create_xcode_symlinks'] = True - - # If building for WASM, set the GN args using 'to_gn_wasm_args' as most - # of the Flutter SDK specific arguments are unused. - if args.target_os == 'wasm' or args.web: - to_gn_wasm_args(args, gn_args) - return gn_args - - gn_args['flutter_build_web_sdk'] = args.build_web_sdk - gn_args['full_dart_sdk'] = args.full_dart_sdk - if args.build_web_sdk or args.full_dart_sdk: - gn_args['build_canvaskit'] = args.build_canvaskit + if args.bitcode: + if args.target_os != 'ios': + raise Exception('Bitcode is only supported for iOS') + if runtime_mode != 'release': + gn_args['bitcode_marker'] = True + gn_args['enable_bitcode'] = args.bitcode if args.enable_unittests: gn_args['enable_unittests'] = args.enable_unittests @@ -280,13 +232,16 @@ def to_gn_args(args): gn_args['skia_use_wuffs'] = True gn_args['skia_use_expat'] = args.target_os == 'android' gn_args['skia_use_fontconfig'] = args.enable_fontconfig - gn_args['skia_use_legacy_layer_bounds' - ] = True # Temporary: See skbug.com/12083, skbug.com/12303. if args.enable_skshaper: gn_args['skia_use_icu'] = True - gn_args['flutter_always_use_skshaper'] = args.always_use_skshaper + if args.target_os != 'wasm': + gn_args['flutter_always_use_skshaper'] = args.always_use_skshaper + else: + gn_args['skia_use_harfbuzz'] = True + gn_args['icu_use_data_file'] = False gn_args['is_official_build'] = True # Disable Skia test utilities. + gn_args['is_debug'] = args.unoptimized gn_args['android_full_debug' ] = args.target_os == 'android' and args.unoptimized if args.clang is None: @@ -296,6 +251,8 @@ def to_gn_args(args): if args.target_os == 'android' or args.target_os == 'ios': gn_args['skia_gl_standard'] = 'gles' + elif args.target_os == 'wasm': + gn_args['skia_gl_standard'] = 'webgl' else: # We explicitly don't want to pick GL because we run GLES tests using SwiftShader. gn_args['skia_gl_standard'] = '' @@ -329,30 +286,19 @@ def to_gn_args(args): gn_args['target_cpu'] = get_target_cpu(args) gn_args['dart_target_arch'] = gn_args['target_cpu'] - # We cannot cross-compile for 32 bit arm on a Windows host. We work around - # this by leaving 'target_cpu' and 'dart_target_arch' set to 'arm' so that - # Dart tools such as gen_snapshot that are built for the host will correctly - # target arm, but we hardcode the 'current_cpu' to always be the host arch - # so that the GN build doesn't go looking for a Windows arm toolchain, which - # does not exist. Further, we set the 'host_cpu' so that it shares the - # bitwidth of the 32-bit arm target. - if sys.platform.startswith( - ('cygwin', 'win') - ) and args.target_os == 'android' and gn_args['target_cpu'] == 'arm': - gn_args['host_cpu'] = 'x86' - gn_args['current_cpu'] = 'x86' + # 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']) + gn_args['android_cpu'] = args.android_cpu + # macOS host builds (whether x64 or arm64) must currently be built under + # Rosetta on Apple Silicon Macs. + # TODO(cbracken): https://github.com/flutter/flutter/issues/103386 if is_host_build(args) and gn_args['host_os'] == 'mac': - # macOS host builds (whether x64 or arm64) must currently be built under - # Rosetta on Apple Silicon Macs. - # TODO(cbracken): https://github.com/flutter/flutter/issues/103386 gn_args['host_cpu'] = 'x64' - # macOS unit tests include Vulkan headers which reference Metal types - # introduced in macOS 10.14. - gn_args['mac_sdk_min'] = '10.14' - gn_args['mac_deployment_target'] = '10.14.0' - # macOS target builds (whether x64 or arm64) must currently be built under # Rosetta on Apple Silicon Macs. # TODO(cbracken): https://github.com/flutter/flutter/issues/103386 @@ -371,33 +317,36 @@ def to_gn_args(args): gn_args['dart_debug'] = True gn_args['dart_debug_optimization_level'] = '0' - gn_args['flutter_use_fontconfig'] = args.enable_fontconfig - gn_args['flutter_enable_skshaper'] = args.enable_skshaper - gn_args['dart_component_kind' - ] = 'static_library' # Always link Dart in statically. - gn_args['embedder_for_target'] = args.embedder_for_target - gn_args['dart_lib_export_symbols'] = False - gn_args['flutter_runtime_mode'] = runtime_mode - gn_args['dart_version_git_info'] = not args.no_dart_version_git_info - - gn_args['dart_lib_export_symbols'] = False - if runtime_mode == 'debug': - gn_args['dart_runtime_mode'] = 'develop' - elif runtime_mode == 'jit_release': - gn_args['dart_runtime_mode'] = 'release' - else: - gn_args['dart_runtime_mode'] = runtime_mode + # Flutter-specific arguments which don't apply for a CanvasKit build. + if args.target_os != 'wasm': + gn_args['flutter_use_fontconfig'] = args.enable_fontconfig + gn_args['flutter_enable_skshaper'] = args.enable_skshaper + gn_args['dart_component_kind' + ] = 'static_library' # Always link Dart in statically. + gn_args['embedder_for_target'] = args.embedder_for_target + gn_args['dart_lib_export_symbols'] = False + gn_args['flutter_runtime_mode'] = runtime_mode + gn_args['full_dart_sdk'] = args.full_dart_sdk + gn_args['dart_version_git_info'] = not args.no_dart_version_git_info + + gn_args['dart_lib_export_symbols'] = False + if runtime_mode == 'debug': + gn_args['dart_runtime_mode'] = 'develop' + elif runtime_mode == 'jit_release': + gn_args['dart_runtime_mode'] = 'release' + else: + gn_args['dart_runtime_mode'] = runtime_mode - # Desktop embeddings can have more dependencies than the engine library, - # which can be problematic in some build environments (e.g., building on - # Linux will bring in pkg-config dependencies at generation time). These - # flags allow preventing those those targets from being part of the build - # tree. - gn_args['enable_desktop_embeddings'] = not args.disable_desktop_embeddings + # Desktop embeddings can have more dependencies than the engine library, + # which can be problematic in some build environments (e.g., building on + # Linux will bring in pkg-config dependencies at generation time). These + # flags allow preventing those those targets from being part of the build + # tree. + gn_args['enable_desktop_embeddings'] = not args.disable_desktop_embeddings - # Overrides whether Boring SSL is compiled with system as. Only meaningful - # on Android. - gn_args['bssl_use_clang_integrated_as'] = True + # Overrides whether Boring SSL is compiled with system as. Only meaningful + # on Android. + gn_args['bssl_use_clang_integrated_as'] = True if args.allow_deprecated_api_calls: gn_args['allow_deprecated_api_calls'] = args.allow_deprecated_api_calls @@ -422,6 +371,38 @@ def to_gn_args(args): if args.target_triple: gn_args['custom_target_triple'] = args.target_triple + goma_dir = os.environ.get('GOMA_DIR') + goma_home_dir = os.path.join(os.getenv('HOME', ''), 'goma') + depot_tools_bin_dir = os.path.join(args.depot_tools, '.cipd_bin') + + # GOMA has a different default (home) path on gWindows. + if not os.path.exists(goma_home_dir) and sys.platform.startswith( + ('cygwin', 'win')): + goma_home_dir = os.path.join('c:\\', 'src', 'goma', 'goma-win64') + + if args.goma and goma_dir: + gn_args['use_goma'] = True + gn_args['goma_dir'] = goma_dir + elif args.goma and os.path.exists(goma_home_dir): + gn_args['use_goma'] = True + gn_args['goma_dir'] = goma_home_dir + elif args.goma and os.path.exists(depot_tools_bin_dir): + gn_args['use_goma'] = True + gn_args['goma_dir'] = depot_tools_bin_dir + else: + if args.goma: + print( + "GOMA usage was specified but can't be found, falling back to local " + 'builds. Set the GOMA_DIR environment variable to fix GOMA.' + ) + gn_args['use_goma'] = False + gn_args['goma_dir'] = None + + if gn_args['use_goma']: + if args.xcode_symlinks or os.getenv('FLUTTER_GOMA_CREATE_XCODE_SYMLINKS', + '0') == '1': + gn_args['create_xcode_symlinks'] = True + # Enable Metal on iOS builds. if args.target_os == 'ios': gn_args['shell_enable_gl'] = False @@ -435,7 +416,8 @@ def to_gn_args(args): else: gn_args['skia_use_gl'] = args.target_os != 'fuchsia' - if sys.platform == 'darwin' and args.target_os not in ['android', 'fuchsia']: + if sys.platform == 'darwin' and args.target_os not in ['android', 'fuchsia', + 'wasm']: # OpenGL is deprecated on macOS > 10.11. # This is not necessarily needed but enabling this until we have a way to # build a macOS metal only shell and a gl only shell. @@ -443,17 +425,18 @@ def to_gn_args(args): gn_args['skia_use_metal'] = True gn_args['shell_enable_metal'] = True - # Enable Vulkan on all platforms except for iOS. This is just + # Enable Vulkan on all platforms except for Android and iOS. This is just # to save on mobile binary size, as there's no reason the Vulkan embedder # features can't work on these platforms. - if args.target_os not in ['ios']: + if args.target_os not in ['android', 'ios', 'wasm']: gn_args['skia_use_vulkan'] = True - gn_args['skia_use_vma'] = False + gn_args['skia_vulkan_memory_allocator_dir' + ] = '//third_party/vulkan_memory_allocator' gn_args['shell_enable_vulkan'] = True # Disable VMA's use of std::shared_mutex in environments where the # standard library doesn't support it. if args.target_os == 'ios' or sys.platform.startswith(('cygwin', 'win')): - gn_args['disable_vma_stl_shared_mutex'] = True + gn_args['skia_disable_vma_stl_shared_mutex'] = True # We should not need a special case for x86, but this seems to introduce text relocations # even with -fPIC everywhere. @@ -554,6 +537,12 @@ def to_gn_args(args): if args.prebuilt_impellerc is not None: gn_args['impeller_use_prebuilt_impellerc'] = args.prebuilt_impellerc + # Vulkan support is WIP, see: https://github.com/flutter/flutter/issues/107357 + if args.enable_impeller_vulkan: + gn_args['impeller_enable_opengles'] = False + gn_args['impeller_enable_vulkan'] = True + gn_args['skia_use_vma'] = False + # ANGLE is exclusively used for: # - Windows at runtime # - Non-fuchsia host unit tests (is_host_build evaluates to false). @@ -566,13 +555,6 @@ def to_gn_args(args): get_host_os() == 'win'): # Do not build unnecessary parts of the ANGLE tree. gn_args['angle_build_all'] = False - gn_args['angle_has_astc_encoder'] = False - # Force ANGLE context checks on Windows to prevent crashes. - # TODO(loic-sharma): Remove this once ANGLE crashes have been fixed. - # https://github.com/flutter/flutter/issues/114107 - if get_host_os() == 'win': - gn_args['angle_force_context_check_every_call'] = True - # Requires RTTI. We may want to build this in debug modes, punting on that # for now. gn_args['angle_enable_vulkan_validation_layers'] = False @@ -586,76 +568,6 @@ def to_gn_args(args): return gn_args -# When building for WASM, almost all GN args used in the Flutter SDK -# build are unused. This method is used instead. -def to_gn_wasm_args(args, gn_args): - gn_args['is_official_build'] = True - gn_args['skia_enable_flutter_defines'] = True - gn_args['is_component_build'] = False - gn_args['use_clang_static_analyzer'] = False - gn_args['is_clang'] = True - gn_args['target_os'] = 'wasm' - gn_args['target_cpu'] = 'wasm' - gn_args['skia_use_angle'] = False - gn_args['skia_use_dng_sdk'] = False - gn_args['skia_use_expat'] = False - gn_args['skia_use_vulkan'] = False - gn_args['skia_use_webgpu'] = False - gn_args['skia_use_libheif'] = False - gn_args['skia_use_libjpeg_turbo_decode'] = True - gn_args['skia_use_libjpeg_turbo_encode'] = False - gn_args['skia_use_libpng_decode'] = True - gn_args['skia_use_libpng_encode'] = True - gn_args['skia_use_libwebp_decode'] = True - gn_args['skia_use_libwebp_encode'] = False - gn_args['skia_use_lua'] = False - gn_args['skia_use_wuffs'] = True - gn_args['skia_use_zlib'] = True - gn_args['skia_gl_standard'] = 'webgl' - gn_args['skia_enable_gpu'] = True - gn_args['skia_enable_sksl_tracing'] = False - gn_args['skia_use_icu'] = True - gn_args['icu_use_data_file'] = False - gn_args['skia_use_freetype'] = True - gn_args['skia_use_harfbuzz'] = True - gn_args['skia_use_fontconfig'] = False - gn_args['skia_use_libheif'] = False - gn_args['skia_enable_fontmgr_custom_directory'] = False - gn_args['skia_enable_fontmgr_custom_embedded'] = True - gn_args['skia_enable_fontmgr_custom_empty'] = True - gn_args['skia_fontmgr_factory' - ] = '//third_party/skia:fontmgr_custom_empty_factory' - gn_args['skia_enable_skshaper'] = True - gn_args['skia_enable_skparagraph'] = True - gn_args['skia_canvaskit_force_tracing'] = False - gn_args['skia_canvaskit_enable_skp_serialization'] = True - gn_args['skia_canvaskit_enable_effects_deserialization'] = False - gn_args['skia_canvaskit_enable_skottie'] = False - gn_args['skia_canvaskit_include_viewer'] = False - gn_args['skia_canvaskit_enable_particles'] = False - gn_args['skia_canvaskit_enable_pathops'] = True - gn_args['skia_canvaskit_enable_rt_shader'] = True - gn_args['skia_canvaskit_enable_matrix_helper'] = False - gn_args['skia_canvaskit_enable_canvas_bindings'] = False - gn_args['skia_canvaskit_enable_font'] = True - gn_args['skia_canvaskit_enable_embedded_font'] = False - gn_args['skia_canvaskit_enable_alias_font'] = True - gn_args['skia_canvaskit_legacy_draw_vertices_blend_mode'] = False - gn_args['skia_canvaskit_enable_debugger'] = False - gn_args['skia_canvaskit_enable_paragraph'] = True - gn_args['skia_canvaskit_enable_webgl'] = True - gn_args['skia_canvaskit_enable_webgpu'] = False - is_profile_build = args.runtime_mode == 'profile' or args.runtime_mode == 'debug' - gn_args['skia_canvaskit_profile_build'] = is_profile_build - gn_args['flutter_prebuilt_dart_sdk'] = True - - # TODO(jacksongardner): Make this based off of the input argument rather - # than forced to true, once the recipes are updated. - # https://github.com/flutter/flutter/issues/113303 - gn_args['build_canvaskit'] = True - gn_args['flutter_build_web_sdk'] = True - - def parse_args(args): args = args[1:] parser = argparse.ArgumentParser(description='A script to run `gn gen`.') @@ -729,7 +641,6 @@ def parse_args(args): parser.add_argument( '--wasm', dest='target_os', action='store_const', const='wasm' ) - parser.add_argument('--web', action='store_true', default=False) parser.add_argument( '--windows', dest='target_os', action='store_const', const='win' ) @@ -853,26 +764,6 @@ def parse_args(args): '--no-full-dart-sdk', dest='full_dart_sdk', action='store_false' ) - parser.add_argument( - '--build-web-sdk', - default=False, - action='store_true', - help='build the flutter web sdk' - ) - parser.add_argument( - '--no-build-web-sdk', dest='build_web_sdk', action='store_false' - ) - - parser.add_argument( - '--build-canvaskit', - default=False, - action='store_true', - help='build canvaskit from source' - ) - parser.add_argument( - '--no-build-canvaskit', dest='build_canvaskit', action='store_false' - ) - parser.add_argument( '--ide', default='', @@ -922,6 +813,13 @@ def parse_args(args): help='Do not build the example embedders using the Embedder API.' ) + parser.add_argument( + '--bitcode', + default=False, + action='store_true', + help='Enable bitcode for iOS targets. On debug runtime modes, this will be a marker only.' + ) + parser.add_argument( '--stripped', default=True, @@ -968,8 +866,6 @@ def parse_args(args): help='Absolute path to a prebuilt impellerc. ' + 'Do not use this outside of CI or with impellerc from a different engine version.' ) - - # This is currently a no-op, will be removed shortly. parser.add_argument( '--enable-impeller-vulkan', default=False, @@ -1018,17 +914,16 @@ def main(argv): '--export-compile-commands', ] - if not args.web: - if args.ide != '': - command.append('--ide=%s' % args.ide) - elif sys.platform == 'darwin': - # On the Mac, generate an Xcode project by default. - command.append('--ide=xcode') - command.append('--xcode-project=flutter_engine') - command.append('--xcode-build-system=new') - elif sys.platform.startswith('win'): - # On Windows, generate a Visual Studio project. - command.append('--ide=vs') + if args.ide != '': + command.append('--ide=%s' % args.ide) + elif sys.platform == 'darwin': + # On the Mac, generate an Xcode project by default. + command.append('--ide=xcode') + command.append('--xcode-project=flutter_engine') + command.append('--xcode-build-system=new') + elif sys.platform.startswith('win'): + # On Windows, generate a Visual Studio project. + command.append('--ide=vs') command.append('--export-compile-commands=default') From fe0447238a6aa4aa72f4674ca9b58c309c2173fa Mon Sep 17 00:00:00 2001 From: Godofredo Contreras Date: Tue, 16 Aug 2022 08:36:40 -0700 Subject: [PATCH 13/20] Fix android_cpu variable name. --- build/archives/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/archives/BUILD.gn b/build/archives/BUILD.gn index 3c1d03e575645..be2377d1aa272 100644 --- a/build/archives/BUILD.gn +++ b/build/archives/BUILD.gn @@ -304,7 +304,7 @@ if (is_mac) { if (is_win) { zip_bundle("archive_win_gen_snapshot") { deps = [ "//third_party/dart/runtime/bin:gen_snapshot" ] - output = "$target_platform_name-$android-cpu-$flutter_runtime_mode/windows-x64.zip" + output = "$target_platform_name-$android_cpu-$flutter_runtime_mode/windows-x64.zip" files = [ { source = "$root_out_dir/gen_snapshot.exe" From 5167ef2d7d0496ef37993a74bd8274a3543719bd Mon Sep 17 00:00:00 2001 From: Godofredo Contreras Date: Wed, 9 Nov 2022 23:05:37 -0800 Subject: [PATCH 14/20] Rebase to ToT --- common/config.gni | 6 +- tools/gn | 333 ++++++++++++++++++++++++++++++---------------- 2 files changed, 222 insertions(+), 117 deletions(-) diff --git a/common/config.gni b/common/config.gni index 532834dd0c701..affe61af22dad 100644 --- a/common/config.gni +++ b/common/config.gni @@ -23,8 +23,8 @@ declare_args() { # Whether to use a prebuilt Dart SDK instead of building one. flutter_prebuilt_dart_sdk = false - # The android cpu used to generate windows artifacts. - android_cpu = "arm" + # Whether to build the flutter web sdk outline/DDC artifacts. + flutter_build_web_sdk = false } # feature_defines_list --------------------------------------------------------- @@ -117,7 +117,7 @@ if (flutter_prebuilt_dart_sdk) { # There is no prebuilt Dart SDK targeting Fuchsia, but we also don't need # one, so even when the build is targeting Fuchsia, use the prebuilt # Dart SDK for the host. - if (current_toolchain == host_toolchain || is_fuchsia) { + if (current_toolchain == host_toolchain || is_fuchsia || is_wasm) { prebuilt_dart_sdk = host_prebuilt_dart_sdk prebuilt_dart_sdk_config = _host_prebuilt_dart_sdk_config } else { diff --git a/tools/gn b/tools/gn index f11d6a650ff6e..27f65988f53b3 100755 --- a/tools/gn +++ b/tools/gn @@ -21,6 +21,8 @@ SRC_ROOT = os.path.dirname( def get_out_dir(args): if args.target_os is not None: target_dir = [args.target_os] + elif args.web: + target_dir = ['wasm'] else: target_dir = ['host'] @@ -165,7 +167,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 +179,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 +202,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' @@ -211,13 +217,55 @@ def to_gn_args(args): gn_args = {} - if args.bitcode: - if args.target_os != 'ios': - raise Exception('Bitcode is only supported for iOS') - if runtime_mode != 'release': - gn_args['bitcode_marker'] = True + gn_args['is_debug'] = args.unoptimized + + goma_dir = os.environ.get('GOMA_DIR') + goma_home_dir = os.path.join(os.getenv('HOME', ''), 'goma') + depot_tools_bin_dir = os.path.join(args.depot_tools, '.cipd_bin') + + # GOMA has a different default (home) path on gWindows. + if not os.path.exists(goma_home_dir) and sys.platform.startswith( + ('cygwin', 'win')): + goma_home_dir = os.path.join('c:\\', 'src', 'goma', 'goma-win64') + + if args.target_os == 'wasm' or args.web: + gn_args['use_goma'] = False + gn_args['goma_dir'] = None + print('Disabling GOMA for wasm builds, it is not supported yet.') + elif args.goma and goma_dir: + gn_args['use_goma'] = True + gn_args['goma_dir'] = goma_dir + elif args.goma and os.path.exists(goma_home_dir): + gn_args['use_goma'] = True + gn_args['goma_dir'] = goma_home_dir + elif args.goma and os.path.exists(depot_tools_bin_dir): + gn_args['use_goma'] = True + gn_args['goma_dir'] = depot_tools_bin_dir + else: + if args.goma: + print( + "GOMA usage was specified but can't be found, falling back to local " + 'builds. Set the GOMA_DIR environment variable to fix GOMA.' + ) + gn_args['use_goma'] = False + gn_args['goma_dir'] = None + + if gn_args['use_goma']: + if args.xcode_symlinks or os.getenv('FLUTTER_GOMA_CREATE_XCODE_SYMLINKS', + '0') == '1': + gn_args['create_xcode_symlinks'] = True + + # If building for WASM, set the GN args using 'to_gn_wasm_args' as most + # of the Flutter SDK specific arguments are unused. + if args.target_os == 'wasm' or args.web: + to_gn_wasm_args(args, gn_args) + return gn_args + + gn_args['flutter_build_web_sdk'] = args.build_web_sdk + gn_args['full_dart_sdk'] = args.full_dart_sdk + if args.build_web_sdk or args.full_dart_sdk: + gn_args['build_canvaskit'] = args.build_canvaskit - gn_args['enable_bitcode'] = args.bitcode if args.enable_unittests: gn_args['enable_unittests'] = args.enable_unittests @@ -232,16 +280,13 @@ def to_gn_args(args): gn_args['skia_use_wuffs'] = True gn_args['skia_use_expat'] = args.target_os == 'android' gn_args['skia_use_fontconfig'] = args.enable_fontconfig + gn_args['skia_use_legacy_layer_bounds' + ] = True # Temporary: See skbug.com/12083, skbug.com/12303. if args.enable_skshaper: gn_args['skia_use_icu'] = True - if args.target_os != 'wasm': - gn_args['flutter_always_use_skshaper'] = args.always_use_skshaper - else: - gn_args['skia_use_harfbuzz'] = True - gn_args['icu_use_data_file'] = False + gn_args['flutter_always_use_skshaper'] = args.always_use_skshaper gn_args['is_official_build'] = True # Disable Skia test utilities. - gn_args['is_debug'] = args.unoptimized gn_args['android_full_debug' ] = args.target_os == 'android' and args.unoptimized if args.clang is None: @@ -251,8 +296,6 @@ def to_gn_args(args): if args.target_os == 'android' or args.target_os == 'ios': gn_args['skia_gl_standard'] = 'gles' - elif args.target_os == 'wasm': - gn_args['skia_gl_standard'] = 'webgl' else: # We explicitly don't want to pick GL because we run GLES tests using SwiftShader. gn_args['skia_gl_standard'] = '' @@ -286,19 +329,30 @@ def to_gn_args(args): gn_args['target_cpu'] = get_target_cpu(args) gn_args['dart_target_arch'] = gn_args['target_cpu'] - # 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']) - gn_args['android_cpu'] = args.android_cpu + # We cannot cross-compile for 32 bit arm on a Windows host. We work around + # this by leaving 'target_cpu' and 'dart_target_arch' set to 'arm' so that + # Dart tools such as gen_snapshot that are built for the host will correctly + # target arm, but we hardcode the 'current_cpu' to always be the host arch + # so that the GN build doesn't go looking for a Windows arm toolchain, which + # does not exist. Further, we set the 'host_cpu' so that it shares the + # bitwidth of the 32-bit arm target. + if sys.platform.startswith( + ('cygwin', 'win') + ) and args.target_os == 'android' and gn_args['target_cpu'] == 'arm': + gn_args['host_cpu'] = 'x86' + gn_args['current_cpu'] = 'x86' - # macOS host builds (whether x64 or arm64) must currently be built under - # Rosetta on Apple Silicon Macs. - # TODO(cbracken): https://github.com/flutter/flutter/issues/103386 if is_host_build(args) and gn_args['host_os'] == 'mac': + # macOS host builds (whether x64 or arm64) must currently be built under + # Rosetta on Apple Silicon Macs. + # TODO(cbracken): https://github.com/flutter/flutter/issues/103386 gn_args['host_cpu'] = 'x64' + # macOS unit tests include Vulkan headers which reference Metal types + # introduced in macOS 10.14. + gn_args['mac_sdk_min'] = '10.14' + gn_args['mac_deployment_target'] = '10.14.0' + # macOS target builds (whether x64 or arm64) must currently be built under # Rosetta on Apple Silicon Macs. # TODO(cbracken): https://github.com/flutter/flutter/issues/103386 @@ -317,36 +371,33 @@ def to_gn_args(args): gn_args['dart_debug'] = True gn_args['dart_debug_optimization_level'] = '0' - # Flutter-specific arguments which don't apply for a CanvasKit build. - if args.target_os != 'wasm': - gn_args['flutter_use_fontconfig'] = args.enable_fontconfig - gn_args['flutter_enable_skshaper'] = args.enable_skshaper - gn_args['dart_component_kind' - ] = 'static_library' # Always link Dart in statically. - gn_args['embedder_for_target'] = args.embedder_for_target - gn_args['dart_lib_export_symbols'] = False - gn_args['flutter_runtime_mode'] = runtime_mode - gn_args['full_dart_sdk'] = args.full_dart_sdk - gn_args['dart_version_git_info'] = not args.no_dart_version_git_info - - gn_args['dart_lib_export_symbols'] = False - if runtime_mode == 'debug': - gn_args['dart_runtime_mode'] = 'develop' - elif runtime_mode == 'jit_release': - gn_args['dart_runtime_mode'] = 'release' - else: - gn_args['dart_runtime_mode'] = runtime_mode + gn_args['flutter_use_fontconfig'] = args.enable_fontconfig + gn_args['flutter_enable_skshaper'] = args.enable_skshaper + gn_args['dart_component_kind' + ] = 'static_library' # Always link Dart in statically. + gn_args['embedder_for_target'] = args.embedder_for_target + gn_args['dart_lib_export_symbols'] = False + gn_args['flutter_runtime_mode'] = runtime_mode + gn_args['dart_version_git_info'] = not args.no_dart_version_git_info + + gn_args['dart_lib_export_symbols'] = False + if runtime_mode == 'debug': + gn_args['dart_runtime_mode'] = 'develop' + elif runtime_mode == 'jit_release': + gn_args['dart_runtime_mode'] = 'release' + else: + gn_args['dart_runtime_mode'] = runtime_mode - # Desktop embeddings can have more dependencies than the engine library, - # which can be problematic in some build environments (e.g., building on - # Linux will bring in pkg-config dependencies at generation time). These - # flags allow preventing those those targets from being part of the build - # tree. - gn_args['enable_desktop_embeddings'] = not args.disable_desktop_embeddings + # Desktop embeddings can have more dependencies than the engine library, + # which can be problematic in some build environments (e.g., building on + # Linux will bring in pkg-config dependencies at generation time). These + # flags allow preventing those those targets from being part of the build + # tree. + gn_args['enable_desktop_embeddings'] = not args.disable_desktop_embeddings - # Overrides whether Boring SSL is compiled with system as. Only meaningful - # on Android. - gn_args['bssl_use_clang_integrated_as'] = True + # Overrides whether Boring SSL is compiled with system as. Only meaningful + # on Android. + gn_args['bssl_use_clang_integrated_as'] = True if args.allow_deprecated_api_calls: gn_args['allow_deprecated_api_calls'] = args.allow_deprecated_api_calls @@ -371,38 +422,6 @@ def to_gn_args(args): if args.target_triple: gn_args['custom_target_triple'] = args.target_triple - goma_dir = os.environ.get('GOMA_DIR') - goma_home_dir = os.path.join(os.getenv('HOME', ''), 'goma') - depot_tools_bin_dir = os.path.join(args.depot_tools, '.cipd_bin') - - # GOMA has a different default (home) path on gWindows. - if not os.path.exists(goma_home_dir) and sys.platform.startswith( - ('cygwin', 'win')): - goma_home_dir = os.path.join('c:\\', 'src', 'goma', 'goma-win64') - - if args.goma and goma_dir: - gn_args['use_goma'] = True - gn_args['goma_dir'] = goma_dir - elif args.goma and os.path.exists(goma_home_dir): - gn_args['use_goma'] = True - gn_args['goma_dir'] = goma_home_dir - elif args.goma and os.path.exists(depot_tools_bin_dir): - gn_args['use_goma'] = True - gn_args['goma_dir'] = depot_tools_bin_dir - else: - if args.goma: - print( - "GOMA usage was specified but can't be found, falling back to local " - 'builds. Set the GOMA_DIR environment variable to fix GOMA.' - ) - gn_args['use_goma'] = False - gn_args['goma_dir'] = None - - if gn_args['use_goma']: - if args.xcode_symlinks or os.getenv('FLUTTER_GOMA_CREATE_XCODE_SYMLINKS', - '0') == '1': - gn_args['create_xcode_symlinks'] = True - # Enable Metal on iOS builds. if args.target_os == 'ios': gn_args['shell_enable_gl'] = False @@ -416,8 +435,7 @@ def to_gn_args(args): else: gn_args['skia_use_gl'] = args.target_os != 'fuchsia' - if sys.platform == 'darwin' and args.target_os not in ['android', 'fuchsia', - 'wasm']: + if sys.platform == 'darwin' and args.target_os not in ['android', 'fuchsia']: # OpenGL is deprecated on macOS > 10.11. # This is not necessarily needed but enabling this until we have a way to # build a macOS metal only shell and a gl only shell. @@ -425,18 +443,17 @@ def to_gn_args(args): gn_args['skia_use_metal'] = True gn_args['shell_enable_metal'] = True - # Enable Vulkan on all platforms except for Android and iOS. This is just + # Enable Vulkan on all platforms except for iOS. This is just # to save on mobile binary size, as there's no reason the Vulkan embedder # features can't work on these platforms. - if args.target_os not in ['android', 'ios', 'wasm']: + if args.target_os not in ['ios']: gn_args['skia_use_vulkan'] = True - gn_args['skia_vulkan_memory_allocator_dir' - ] = '//third_party/vulkan_memory_allocator' + gn_args['skia_use_vma'] = False gn_args['shell_enable_vulkan'] = True # Disable VMA's use of std::shared_mutex in environments where the # standard library doesn't support it. if args.target_os == 'ios' or sys.platform.startswith(('cygwin', 'win')): - gn_args['skia_disable_vma_stl_shared_mutex'] = True + gn_args['disable_vma_stl_shared_mutex'] = True # We should not need a special case for x86, but this seems to introduce text relocations # even with -fPIC everywhere. @@ -537,12 +554,6 @@ def to_gn_args(args): if args.prebuilt_impellerc is not None: gn_args['impeller_use_prebuilt_impellerc'] = args.prebuilt_impellerc - # Vulkan support is WIP, see: https://github.com/flutter/flutter/issues/107357 - if args.enable_impeller_vulkan: - gn_args['impeller_enable_opengles'] = False - gn_args['impeller_enable_vulkan'] = True - gn_args['skia_use_vma'] = False - # ANGLE is exclusively used for: # - Windows at runtime # - Non-fuchsia host unit tests (is_host_build evaluates to false). @@ -555,6 +566,13 @@ def to_gn_args(args): get_host_os() == 'win'): # Do not build unnecessary parts of the ANGLE tree. gn_args['angle_build_all'] = False + gn_args['angle_has_astc_encoder'] = False + # Force ANGLE context checks on Windows to prevent crashes. + # TODO(loic-sharma): Remove this once ANGLE crashes have been fixed. + # https://github.com/flutter/flutter/issues/114107 + if get_host_os() == 'win': + gn_args['angle_force_context_check_every_call'] = True + # Requires RTTI. We may want to build this in debug modes, punting on that # for now. gn_args['angle_enable_vulkan_validation_layers'] = False @@ -568,6 +586,76 @@ def to_gn_args(args): return gn_args +# When building for WASM, almost all GN args used in the Flutter SDK +# build are unused. This method is used instead. +def to_gn_wasm_args(args, gn_args): + gn_args['is_official_build'] = True + gn_args['skia_enable_flutter_defines'] = True + gn_args['is_component_build'] = False + gn_args['use_clang_static_analyzer'] = False + gn_args['is_clang'] = True + gn_args['target_os'] = 'wasm' + gn_args['target_cpu'] = 'wasm' + gn_args['skia_use_angle'] = False + gn_args['skia_use_dng_sdk'] = False + gn_args['skia_use_expat'] = False + gn_args['skia_use_vulkan'] = False + gn_args['skia_use_webgpu'] = False + gn_args['skia_use_libheif'] = False + gn_args['skia_use_libjpeg_turbo_decode'] = True + gn_args['skia_use_libjpeg_turbo_encode'] = False + gn_args['skia_use_libpng_decode'] = True + gn_args['skia_use_libpng_encode'] = True + gn_args['skia_use_libwebp_decode'] = True + gn_args['skia_use_libwebp_encode'] = False + gn_args['skia_use_lua'] = False + gn_args['skia_use_wuffs'] = True + gn_args['skia_use_zlib'] = True + gn_args['skia_gl_standard'] = 'webgl' + gn_args['skia_enable_gpu'] = True + gn_args['skia_enable_sksl_tracing'] = False + gn_args['skia_use_icu'] = True + gn_args['icu_use_data_file'] = False + gn_args['skia_use_freetype'] = True + gn_args['skia_use_harfbuzz'] = True + gn_args['skia_use_fontconfig'] = False + gn_args['skia_use_libheif'] = False + gn_args['skia_enable_fontmgr_custom_directory'] = False + gn_args['skia_enable_fontmgr_custom_embedded'] = True + gn_args['skia_enable_fontmgr_custom_empty'] = True + gn_args['skia_fontmgr_factory' + ] = '//third_party/skia:fontmgr_custom_empty_factory' + gn_args['skia_enable_skshaper'] = True + gn_args['skia_enable_skparagraph'] = True + gn_args['skia_canvaskit_force_tracing'] = False + gn_args['skia_canvaskit_enable_skp_serialization'] = True + gn_args['skia_canvaskit_enable_effects_deserialization'] = False + gn_args['skia_canvaskit_enable_skottie'] = False + gn_args['skia_canvaskit_include_viewer'] = False + gn_args['skia_canvaskit_enable_particles'] = False + gn_args['skia_canvaskit_enable_pathops'] = True + gn_args['skia_canvaskit_enable_rt_shader'] = True + gn_args['skia_canvaskit_enable_matrix_helper'] = False + gn_args['skia_canvaskit_enable_canvas_bindings'] = False + gn_args['skia_canvaskit_enable_font'] = True + gn_args['skia_canvaskit_enable_embedded_font'] = False + gn_args['skia_canvaskit_enable_alias_font'] = True + gn_args['skia_canvaskit_legacy_draw_vertices_blend_mode'] = False + gn_args['skia_canvaskit_enable_debugger'] = False + gn_args['skia_canvaskit_enable_paragraph'] = True + gn_args['skia_canvaskit_enable_webgl'] = True + gn_args['skia_canvaskit_enable_webgpu'] = False + is_profile_build = args.runtime_mode == 'profile' or args.runtime_mode == 'debug' + gn_args['skia_canvaskit_profile_build'] = is_profile_build + gn_args['flutter_prebuilt_dart_sdk'] = True + + # TODO(jacksongardner): Make this based off of the input argument rather + # than forced to true, once the recipes are updated. + # https://github.com/flutter/flutter/issues/113303 + gn_args['build_canvaskit'] = True + gn_args['flutter_build_web_sdk'] = True + + def parse_args(args): args = args[1:] parser = argparse.ArgumentParser(description='A script to run `gn gen`.') @@ -641,6 +729,7 @@ def parse_args(args): parser.add_argument( '--wasm', dest='target_os', action='store_const', const='wasm' ) + parser.add_argument('--web', action='store_true', default=False) parser.add_argument( '--windows', dest='target_os', action='store_const', const='win' ) @@ -764,6 +853,26 @@ def parse_args(args): '--no-full-dart-sdk', dest='full_dart_sdk', action='store_false' ) + parser.add_argument( + '--build-web-sdk', + default=False, + action='store_true', + help='build the flutter web sdk' + ) + parser.add_argument( + '--no-build-web-sdk', dest='build_web_sdk', action='store_false' + ) + + parser.add_argument( + '--build-canvaskit', + default=False, + action='store_true', + help='build canvaskit from source' + ) + parser.add_argument( + '--no-build-canvaskit', dest='build_canvaskit', action='store_false' + ) + parser.add_argument( '--ide', default='', @@ -813,13 +922,6 @@ def parse_args(args): help='Do not build the example embedders using the Embedder API.' ) - parser.add_argument( - '--bitcode', - default=False, - action='store_true', - help='Enable bitcode for iOS targets. On debug runtime modes, this will be a marker only.' - ) - parser.add_argument( '--stripped', default=True, @@ -866,6 +968,8 @@ def parse_args(args): help='Absolute path to a prebuilt impellerc. ' + 'Do not use this outside of CI or with impellerc from a different engine version.' ) + + # This is currently a no-op, will be removed shortly. parser.add_argument( '--enable-impeller-vulkan', default=False, @@ -914,16 +1018,17 @@ def main(argv): '--export-compile-commands', ] - if args.ide != '': - command.append('--ide=%s' % args.ide) - elif sys.platform == 'darwin': - # On the Mac, generate an Xcode project by default. - command.append('--ide=xcode') - command.append('--xcode-project=flutter_engine') - command.append('--xcode-build-system=new') - elif sys.platform.startswith('win'): - # On Windows, generate a Visual Studio project. - command.append('--ide=vs') + if not args.web: + if args.ide != '': + command.append('--ide=%s' % args.ide) + elif sys.platform == 'darwin': + # On the Mac, generate an Xcode project by default. + command.append('--ide=xcode') + command.append('--xcode-project=flutter_engine') + command.append('--xcode-build-system=new') + elif sys.platform.startswith('win'): + # On Windows, generate a Visual Studio project. + command.append('--ide=vs') command.append('--export-compile-commands=default') From 05598a754763a45e3798678b91c5018306dc13c6 Mon Sep 17 00:00:00 2001 From: Godofredo Contreras Date: Wed, 9 Nov 2022 23:08:13 -0800 Subject: [PATCH 15/20] Try to use target cpu directly. --- build/archives/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/archives/BUILD.gn b/build/archives/BUILD.gn index be2377d1aa272..4448caf30ee0b 100644 --- a/build/archives/BUILD.gn +++ b/build/archives/BUILD.gn @@ -304,7 +304,7 @@ if (is_mac) { if (is_win) { zip_bundle("archive_win_gen_snapshot") { deps = [ "//third_party/dart/runtime/bin:gen_snapshot" ] - output = "$target_platform_name-$android_cpu-$flutter_runtime_mode/windows-x64.zip" + output = "$target_platform_name-$target_cpu-$flutter_runtime_mode/windows-x64.zip" files = [ { source = "$root_out_dir/gen_snapshot.exe" From d1862590f16a5545600b424e58c69bc99688ce88 Mon Sep 17 00:00:00 2001 From: Godofredo Contreras Date: Fri, 11 Nov 2022 21:35:01 -0800 Subject: [PATCH 16/20] Use host os instead of is_win. --- build/archives/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/archives/BUILD.gn b/build/archives/BUILD.gn index 4448caf30ee0b..331ae2524fb85 100644 --- a/build/archives/BUILD.gn +++ b/build/archives/BUILD.gn @@ -301,7 +301,7 @@ if (is_mac) { } } -if (is_win) { +if (host_os == "win") { zip_bundle("archive_win_gen_snapshot") { deps = [ "//third_party/dart/runtime/bin:gen_snapshot" ] output = "$target_platform_name-$target_cpu-$flutter_runtime_mode/windows-x64.zip" From 3307d80d40be90a9de01d5000bb3e007a19149d1 Mon Sep 17 00:00:00 2001 From: Godofredo Contreras Date: Fri, 11 Nov 2022 22:44:03 -0800 Subject: [PATCH 17/20] Build engine artifacts for win. --- common/config.gni | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/config.gni b/common/config.gni index affe61af22dad..afb8f0b2b2c92 100644 --- a/common/config.gni +++ b/common/config.gni @@ -132,4 +132,4 @@ if (flutter_prebuilt_dart_sdk) { # see https://github.com/flutter/flutter/issues/74322 build_engine_artifacts = current_toolchain == host_toolchain || - (is_linux && !is_chromeos && current_cpu != "arm") || is_mac + (is_linux && !is_chromeos && current_cpu != "arm") || is_mac || is_win From b05e233f627dacd6e5f078ee61a57a5b367502e7 Mon Sep 17 00:00:00 2001 From: godofredoc Date: Mon, 14 Nov 2022 08:17:07 -0800 Subject: [PATCH 18/20] Update build/archives/BUILD.gn Co-authored-by: Zachary Anderson --- build/archives/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/archives/BUILD.gn b/build/archives/BUILD.gn index 331ae2524fb85..30a1ddab8fd02 100644 --- a/build/archives/BUILD.gn +++ b/build/archives/BUILD.gn @@ -304,7 +304,7 @@ if (is_mac) { if (host_os == "win") { zip_bundle("archive_win_gen_snapshot") { deps = [ "//third_party/dart/runtime/bin:gen_snapshot" ] - output = "$target_platform_name-$target_cpu-$flutter_runtime_mode/windows-x64.zip" + output = "$full_target_platform_name-$flutter_runtime_mode/windows-x64.zip" files = [ { source = "$root_out_dir/gen_snapshot.exe" From 3414a76f77250306da78c4205825846a102b617a Mon Sep 17 00:00:00 2001 From: godofredoc Date: Mon, 14 Nov 2022 08:17:19 -0800 Subject: [PATCH 19/20] Update build/archives/BUILD.gn Co-authored-by: Zachary Anderson --- build/archives/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/archives/BUILD.gn b/build/archives/BUILD.gn index 30a1ddab8fd02..922cb4456a30d 100644 --- a/build/archives/BUILD.gn +++ b/build/archives/BUILD.gn @@ -307,7 +307,7 @@ if (host_os == "win") { output = "$full_target_platform_name-$flutter_runtime_mode/windows-x64.zip" files = [ { - source = "$root_out_dir/gen_snapshot.exe" + source = "$root_out_dir/gen_snapshot/gen_snapshot.exe" destination = "gen_snapshot.exe" }, ] From 2944b799ab6faf9975a6ddea6c4d914d94e2ceac Mon Sep 17 00:00:00 2001 From: godofredoc Date: Mon, 14 Nov 2022 09:55:08 -0800 Subject: [PATCH 20/20] Update build/archives/BUILD.gn Co-authored-by: Zachary Anderson --- build/archives/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/archives/BUILD.gn b/build/archives/BUILD.gn index 922cb4456a30d..90993ddb42793 100644 --- a/build/archives/BUILD.gn +++ b/build/archives/BUILD.gn @@ -303,7 +303,7 @@ if (is_mac) { if (host_os == "win") { zip_bundle("archive_win_gen_snapshot") { - deps = [ "//third_party/dart/runtime/bin:gen_snapshot" ] + deps = [ "//flutter:gen_snapshot" ] output = "$full_target_platform_name-$flutter_runtime_mode/windows-x64.zip" files = [ {