diff --git a/BUILD.gn b/BUILD.gn index 23de5f02a861d..e8e8699be07ed 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -12,6 +12,8 @@ import("//third_party/dart/build/dart/copy_tree.gni") # Whether to build the dartdevc sdk, libraries, and source files # required for the flutter web sdk. +# TODO(jacksongardner): remove this poorly named argument once the recipes stop +# using it. https://github.com/flutter/flutter/issues/113303 declare_args() { full_dart_sdk = false } @@ -44,30 +46,6 @@ config("export_dynamic_symbols") { } } -if (flutter_prebuilt_dart_sdk) { - copy_trees("_copy_trees") { - sources = [ - { - target = "copy_dart_sdk" - visibility = [ ":dart_sdk" ] - source = prebuilt_dart_sdk - dest = "$root_out_dir/dart-sdk" - ignore_patterns = "{}" - }, - ] - } -} - -group("dart_sdk") { - if (build_engine_artifacts) { - if (flutter_prebuilt_dart_sdk) { - public_deps = [ ":copy_dart_sdk" ] - } else { - public_deps = [ "//third_party/dart:create_sdk" ] - } - } -} - group("flutter") { testonly = true @@ -96,7 +74,7 @@ group("flutter") { if (build_engine_artifacts) { public_deps += [ - ":dart_sdk", + "//flutter/build/dart:dart_sdk", "//flutter/flutter_frontend_server:frontend_server", # This must be listed explicitly for desktop cross-builds since diff --git a/build/archives/BUILD.gn b/build/archives/BUILD.gn index dbe31d4af91b6..d9b785b9bd536 100644 --- a/build/archives/BUILD.gn +++ b/build/archives/BUILD.gn @@ -220,13 +220,6 @@ if (build_engine_artifacts && !flutter_prebuilt_dart_sdk) { } } -# Archives Flutter Web SDK -if (!is_fuchsia) { - group("flutter_web_sdk") { - deps = [ "//flutter/web_sdk:flutter_web_sdk_archive" ] - } -} - # Archives Flutter Windows Artifacts if (host_os == "win") { zip_bundle("windows_flutter") { diff --git a/build/dart/BUILD.gn b/build/dart/BUILD.gn index a52bb11e409d7..0a2b6a3a6c155 100644 --- a/build/dart/BUILD.gn +++ b/build/dart/BUILD.gn @@ -3,6 +3,8 @@ # found in the LICENSE file. import("//flutter/build/concurrent_jobs.gni") +import("//flutter/common/config.gni") +import("//third_party/dart/build/dart/copy_tree.gni") declare_args() { # Maximum number of Dart processes to run in parallel. @@ -14,3 +16,25 @@ declare_args() { pool("dart_pool") { depth = concurrent_dart_jobs } + +if (flutter_prebuilt_dart_sdk) { + copy_trees("_copy_trees") { + sources = [ + { + target = "copy_dart_sdk" + visibility = [ ":dart_sdk" ] + source = prebuilt_dart_sdk + dest = "$root_out_dir/dart-sdk" + ignore_patterns = "{}" + }, + ] + } +} + +group("dart_sdk") { + if (flutter_prebuilt_dart_sdk) { + public_deps = [ ":copy_dart_sdk" ] + } else { + public_deps = [ "//third_party/dart:create_sdk" ] + } +} diff --git a/ci/builders/linux_host_engine.json b/ci/builders/linux_host_engine.json index adc349d77e1fb..1c1f621464363 100644 --- a/ci/builders/linux_host_engine.json +++ b/ci/builders/linux_host_engine.json @@ -64,7 +64,7 @@ "flutter/build/archives:embedder", "flutter/build/archives:flutter_patched_sdk", "flutter/build/archives:dart_sdk_archive", - "flutter/build/archives:flutter_web_sdk", + "flutter/web_sdk", "flutter/tools/font-subset", "flutter/shell/platform/linux:flutter_gtk" ] @@ -151,8 +151,7 @@ "targets": [ "flutter:unittests", "flutter/build/archives:flutter_patched_sdk", - "flutter/shell/platform/linux:flutter_gtk", - "flutter/build/archives:flutter_web_sdk" + "flutter/shell/platform/linux:flutter_gtk" ] }, "tests": [ diff --git a/ci/builders/mac_host_engine.json b/ci/builders/mac_host_engine.json index d5288a222cda4..834563eeb142a 100644 --- a/ci/builders/mac_host_engine.json +++ b/ci/builders/mac_host_engine.json @@ -37,7 +37,7 @@ "flutter/shell/platform/darwin/macos:zip_macos_flutter_framework", "flutter/build/archives:artifacts", "flutter/build/archives:dart_sdk_archive", - "flutter/build/archives:flutter_web_sdk", + "flutter/web_sdk", "flutter/build/archives:archive_gen_snapshot", "flutter/build/archives:flutter_embedder_framework" ] diff --git a/ci/builders/windows_host_engine.json b/ci/builders/windows_host_engine.json index 27de7be80d8cc..a22943aae63db 100644 --- a/ci/builders/windows_host_engine.json +++ b/ci/builders/windows_host_engine.json @@ -41,7 +41,7 @@ "flutter/build/archives:dart_sdk_archive", "flutter/shell/platform/windows/client_wrapper:client_wrapper_archive", "flutter/build/archives:windows_flutter", - "flutter/build/archives:flutter_web_sdk" + "flutter/web_sdk" ] }, "tests": [ diff --git a/common/config.gni b/common/config.gni index 9354bfb784ad5..affe61af22dad 100644 --- a/common/config.gni +++ b/common/config.gni @@ -22,6 +22,9 @@ 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 } # feature_defines_list --------------------------------------------------------- @@ -114,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/lib/web_ui/dev/build.dart b/lib/web_ui/dev/build.dart index e5334fe17630b..b36d3035e2899 100644 --- a/lib/web_ui/dev/build.dart +++ b/lib/web_ui/dev/build.dart @@ -3,7 +3,7 @@ // found in the LICENSE file. import 'dart:async'; -import 'dart:io' show Directory, Platform; +import 'dart:io' show Directory; import 'package:args/command_runner.dart'; import 'package:path/path.dart' as path; @@ -25,6 +25,12 @@ class BuildCommand extends Command with ArgUtils { 'build-canvaskit', help: 'Build CanvasKit locally instead of getting it from CIPD. Disabled ' 'by default.', + defaultsTo: true + ); + argParser.addFlag( + 'host', + help: 'Build the host build instead of the wasm build, which is currently' + 'needed for `flutter run --local-engine` to work' ); } @@ -38,19 +44,15 @@ class BuildCommand extends Command with ArgUtils { bool get buildCanvasKit => boolArg('build-canvaskit'); + bool get host => boolArg('host'); + @override FutureOr run() async { final FilePath libPath = FilePath.fromWebUi('lib'); final List steps = [ - GnPipelineStep(), - NinjaPipelineStep(target: environment.engineBuildDir), + GnPipelineStep(buildCanvasKit: buildCanvasKit, host: host), + NinjaPipelineStep(target: host ? environment.hostDebugUnoptDir : environment.wasmReleaseOutDir), ]; - if (buildCanvasKit) { - steps.addAll([ - GnPipelineStep(target: 'canvaskit'), - NinjaPipelineStep(target: environment.wasmReleaseOutDir), - ]); - } final Pipeline buildPipeline = Pipeline(steps: steps); await buildPipeline.run(); @@ -73,8 +75,10 @@ class BuildCommand extends Command with ArgUtils { /// Not safe to interrupt as it may leave the `out/` directory in a corrupted /// state. GN is pretty quick though, so it's OK to not support interruption. class GnPipelineStep extends ProcessStep { - GnPipelineStep({this.target = 'engine'}) - : assert(target == 'engine' || target == 'canvaskit'); + GnPipelineStep({required this.buildCanvasKit, required this.host}); + + final bool buildCanvasKit; + final bool host; @override String get description => 'gn'; @@ -82,33 +86,27 @@ class GnPipelineStep extends ProcessStep { @override bool get isSafeToInterrupt => false; - /// The target to build with gn. - /// - /// Acceptable values: engine, canvaskit - final String target; - - @override - Future createProcess() { - print('Running gn for $target...'); - final List gnArgs = []; - if (target == 'engine') { - gnArgs.addAll([ - '--unopt', - if (Platform.isMacOS) '--xcode-symlinks', + List get _gnArgs { + if (host) { + return [ + '--unoptimized', '--full-dart-sdk', - if (environment.isMacosArm) '--mac-cpu=arm64', - ]); - } else if (target == 'canvaskit') { - gnArgs.addAll([ - '--wasm', - '--runtime-mode=release', - ]); + ]; } else { - throw StateError('Target was not engine or canvaskit: $target'); + return [ + '--web', + '--runtime-mode=release', + if (buildCanvasKit) '--build-canvaskit', + ]; } + } + + @override + Future createProcess() { + print('Running gn...'); return startProcess( path.join(environment.flutterDirectory.path, 'tools', 'gn'), - gnArgs, + _gnArgs, ); } } diff --git a/lib/web_ui/dev/environment.dart b/lib/web_ui/dev/environment.dart index 8cdac3e6598a7..08822a39dac56 100644 --- a/lib/web_ui/dev/environment.dart +++ b/lib/web_ui/dev/environment.dart @@ -20,21 +20,19 @@ Environment? _environment; class Environment { factory Environment() { final bool isMacosArm = ffi.Abi.current() == ffi.Abi.macosArm64; + final io.File dartExecutable = io.File(io.Platform.resolvedExecutable); final io.File self = io.File.fromUri(io.Platform.script); + final io.Directory engineSrcDir = self.parent.parent.parent.parent.parent; final io.Directory engineToolsDir = io.Directory(pathlib.join(engineSrcDir.path, 'flutter', 'tools')); final io.Directory outDir = io.Directory(pathlib.join(engineSrcDir.path, 'out')); - final io.Directory engineBuildDir = - io.Directory(pathlib.join( - outDir.path, - isMacosArm ? 'host_debug_unopt_arm64' : 'host_debug_unopt' - )); final io.Directory wasmReleaseOutDir = io.Directory(pathlib.join(outDir.path, 'wasm_release')); - final io.Directory dartSdkDir = - io.Directory(pathlib.join(engineBuildDir.path, 'dart-sdk')); + final io.Directory hostDebugUnoptDir = + io.Directory(pathlib.join(outDir.path, 'host_debug_unopt')); + final io.Directory dartSdkDir = dartExecutable.parent.parent; final io.Directory webUiRootDir = io.Directory( pathlib.join(engineSrcDir.path, 'flutter', 'lib', 'web_ui')); @@ -55,8 +53,8 @@ class Environment { engineSrcDir: engineSrcDir, engineToolsDir: engineToolsDir, outDir: outDir, - engineBuildDir: engineBuildDir, wasmReleaseOutDir: wasmReleaseOutDir, + hostDebugUnoptDir: hostDebugUnoptDir, dartSdkDir: dartSdkDir, ); } @@ -68,8 +66,8 @@ class Environment { required this.engineSrcDir, required this.engineToolsDir, required this.outDir, - required this.engineBuildDir, required this.wasmReleaseOutDir, + required this.hostDebugUnoptDir, required this.dartSdkDir, }); @@ -93,14 +91,14 @@ class Environment { /// This is where you'll find the ninja output, such as the Dart SDK. final io.Directory outDir; - /// The output directory for the host_debug_unopt build. - final io.Directory engineBuildDir; - /// The output directory for the wasm_release build. /// /// We build CanvasKit in release mode to reduce code size. final io.Directory wasmReleaseOutDir; + /// The output directory for the host_debug_unopt build. + final io.Directory hostDebugUnoptDir; + /// The root of the Dart SDK. final io.Directory dartSdkDir; diff --git a/tools/gn b/tools/gn index b7db850015ae9..8e1f782b6376d 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'] @@ -251,10 +253,15 @@ def to_gn_args(args): # 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': + 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.enable_unittests: gn_args['enable_unittests'] = args.enable_unittests @@ -359,7 +366,6 @@ def to_gn_args(args): 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 @@ -627,6 +633,13 @@ def to_gn_wasm_args(args, gn_args): 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): @@ -702,6 +715,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' ) @@ -825,6 +839,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='', @@ -968,16 +1002,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 args.target_os != 'wasm': + 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') diff --git a/wasm/BUILD.gn b/wasm/BUILD.gn index 7d799fe9186c9..f4d6a54ee5e76 100644 --- a/wasm/BUILD.gn +++ b/wasm/BUILD.gn @@ -6,7 +6,11 @@ # //flutter/BUILD.gn pulls in Flutter SDK dependencies which will crash # when the target CPU is WASM. +import("//flutter/common/config.gni") + # This is the default target when building when the target CPU is WASM. group("wasm") { - deps = [ "//third_party/skia/modules/canvaskit" ] + if (flutter_build_web_sdk) { + deps = [ "//flutter/web_sdk" ] + } } diff --git a/web_sdk/BUILD.gn b/web_sdk/BUILD.gn index 1c653d5b91db1..bbebc9c0b3efb 100644 --- a/web_sdk/BUILD.gn +++ b/web_sdk/BUILD.gn @@ -6,9 +6,14 @@ import("//flutter/build/zip_bundle.gni") import("//flutter/common/config.gni") import("//third_party/dart/build/dart/dart_action.gni") -sdk_dill = "$root_out_dir/flutter_web_sdk/kernel/flutter_ddc_sdk.dill" -sdk_dill_sound = - "$root_out_dir/flutter_web_sdk/kernel/flutter_ddc_sdk_sound.dill" +declare_args() { + build_canvaskit = false + archive_flutter_web_sdk = true +} + +kernel_out_dir = "$root_out_dir/flutter_web_sdk/kernel" +sdk_dill = "$kernel_out_dir/flutter_ddc_sdk.dill" +sdk_dill_sound = "$kernel_out_dir/flutter_ddc_sdk_sound.dill" dart_sdk_package_config = "//third_party/dart/.dart_tool/package_config.json" @@ -30,6 +35,10 @@ group("web_sdk") { ":flutter_dartdevc_kernel_sdk_outline_sound", ":flutter_dartdevc_kernel_sdk_sound", ] + + if (archive_flutter_web_sdk && !is_fuchsia) { + deps += [ ":flutter_web_sdk_archive" ] + } } template("sdk_rewriter") { @@ -144,56 +153,35 @@ copy("web_ui_library") { # # args (required): The arguments to pass to dartdevc template("_dartdevc") { - if (flutter_prebuilt_dart_sdk) { - action(target_name) { - not_needed(invoker, [ "packages" ]) - deps = [ - ":skwasm_impl_library", - ":skwasm_stub_library", - ":web_engine_library", - ":web_ui_library", - ":web_ui_library_sources", - "//flutter:dart_sdk", - ] - script = "//build/gn_run_binary.py" - - inputs = invoker.inputs - outputs = invoker.outputs - - pool = "//flutter/build/dart:dart_pool" - - ext = "" - if (is_win) { - ext = ".exe" - } - dart = rebase_path("$host_prebuilt_dart_sdk/bin/dart$ext", root_out_dir) - dartdevc = rebase_path( - "$host_prebuilt_dart_sdk/bin/snapshots/dartdevc.dart.snapshot") - args = [ - dart, - dartdevc, - ] + invoker.args - } - } else { - prebuilt_dart_action(target_name) { - forward_variables_from(invoker, "*") - - deps = [ - ":skwasm_impl_library", - ":skwasm_stub_library", - ":web_engine_library", - ":web_ui_library", - ":web_ui_library_sources", - "//flutter:dart_sdk", - "//third_party/dart/pkg:pkg_files_stamp", - "//third_party/dart/utils/dartdevc:dartdevc_files_stamp", - "//third_party/dart/utils/dartdevc:dartdevc_sdk_patch_stamp", - ] + assert(flutter_prebuilt_dart_sdk, + "Cannot build web sdk without prebuilt dart sdk") + action(target_name) { + not_needed(invoker, [ "packages" ]) + deps = [ + ":skwasm_impl_library", + ":skwasm_stub_library", + ":web_engine_library", + ":web_ui_library", + ":web_ui_library_sources", + ] + script = "//build/gn_run_binary.py" + + inputs = invoker.inputs + outputs = invoker.outputs - script = "//third_party/dart/pkg/dev_compiler/bin/dartdevc.dart" + pool = "//flutter/build/dart:dart_pool" - pool = "//flutter/build/dart:dart_pool" + ext = "" + if (is_win) { + ext = ".exe" } + dart = rebase_path("$host_prebuilt_dart_sdk/bin/dart$ext", root_out_dir) + dartdevc = rebase_path( + "$host_prebuilt_dart_sdk/bin/snapshots/dartdevc.dart.snapshot") + args = [ + dart, + dartdevc, + ] + invoker.args } } @@ -207,412 +195,227 @@ template("_dartdevc") { # # args (required): The arguments to pass to the kernel_worker template("_kernel_worker") { - if (flutter_prebuilt_dart_sdk) { - action(target_name) { - deps = [ - ":skwasm_impl_library", - ":skwasm_stub_library", - ":web_engine_library", - ":web_ui_library", - ":web_ui_library_sources", - "//flutter:dart_sdk", - ] - script = "//build/gn_run_binary.py" - - inputs = invoker.inputs - outputs = invoker.outputs + assert(flutter_prebuilt_dart_sdk, + "Cannot build web sdk without prebuilt dart sdk") + action(target_name) { + deps = [ + ":skwasm_impl_library", + ":skwasm_stub_library", + ":web_engine_library", + ":web_ui_library", + ":web_ui_library_sources", + ] + script = "//build/gn_run_binary.py" - pool = "//flutter/build/dart:dart_pool" + inputs = invoker.inputs + outputs = invoker.outputs - ext = "" - if (is_win) { - ext = ".exe" - } - dart = rebase_path("$host_prebuilt_dart_sdk/bin/dart$ext", root_out_dir) - kernel_worker = rebase_path( - "$host_prebuilt_dart_sdk/bin/snapshots/kernel_worker.dart.snapshot") + pool = "//flutter/build/dart:dart_pool" - args = [ - dart, - kernel_worker, - ] + invoker.args + ext = "" + if (is_win) { + ext = ".exe" } - } else { - prebuilt_dart_action(target_name) { - forward_variables_from(invoker, "*") - - deps = [ - ":skwasm_impl_library", - ":skwasm_stub_library", - ":web_engine_library", - ":web_ui_library", - ":web_ui_library_sources", - "//flutter:dart_sdk", - "//third_party/dart/pkg:pkg_files_stamp", - "//third_party/dart/utils/dartdevc:dartdevc_files_stamp", - "//third_party/dart/utils/dartdevc:dartdevc_sdk_patch_stamp", - ] + dart = rebase_path("$host_prebuilt_dart_sdk/bin/dart$ext", root_out_dir) + kernel_worker = rebase_path( + "$host_prebuilt_dart_sdk/bin/snapshots/kernel_worker.dart.snapshot") + + args = [ + dart, + kernel_worker, + ] + invoker.args + } +} + +template("_compile_outline") { + assert(defined(invoker.sound_null_safety), + "sound_null_safety must be defined for $target_name") + assert(defined(invoker.output_dill), + "output_dill must be defined for $target_name") - script = "//third_party/dart/utils/bazel/kernel_worker.dart" + _kernel_worker(target_name) { + inputs = [ "sdk_rewriter.dart" ] + web_ui_sources - pool = "//flutter/build/dart:dart_pool" + outputs = [ invoker.output_dill ] + + if (invoker.sound_null_safety) { + args = [ "--sound-null-safety" ] + } else { + args = [ "--no-sound-null-safety" ] } + args += [ + "--summary-only", + "--target", + "ddc", + "--packages-file", + "file:///" + rebase_path(dart_sdk_package_config), + "--multi-root-scheme", + "org-dartlang-sdk", + "--multi-root", + "file:///" + rebase_path("$root_out_dir/flutter_web_sdk"), + "--multi-root", + "file:///" + rebase_path("$host_prebuilt_dart_sdk/.."), + "--libraries-file", + "org-dartlang-sdk:///libraries.json", + "--output", + rebase_path(invoker.output_dill), + "--source", + "dart:core", + + # Additional Flutter web dart libraries + "--source", + "dart:ui", + "--source", + "dart:_engine", + "--source", + "dart:_skwasm_stub", + ] } } # Compile the unsound DDC SDK's summary. -_kernel_worker("flutter_dartdevc_kernel_sdk_outline") { - inputs = [ "sdk_rewriter.dart" ] + web_ui_sources - - outputs = [ sdk_dill ] - - args = [ - "--no-sound-null-safety", - "--summary-only", - "--target", - "ddc", - "--packages-file", - "file:///" + rebase_path(dart_sdk_package_config), - "--multi-root-scheme", - "org-dartlang-sdk", - "--multi-root", - "file:///" + rebase_path("$root_out_dir"), - "--libraries-file", - "org-dartlang-sdk:///flutter_web_sdk/libraries.json", - "--output", - rebase_path(sdk_dill), - "--source", - "dart:core", - - # Additional Flutter web dart libraries - "--source", - "dart:ui", - "--source", - "dart:_engine", - ] +_compile_outline("flutter_dartdevc_kernel_sdk_outline") { + sound_null_safety = false + output_dill = sdk_dill } -# Compiles the unsound html only renderer. -_dartdevc("flutter_dartdevc_kernel_sdk") { - inputs = [ "sdk_rewriter.dart" ] + web_ui_sources - - packages = dart_sdk_package_config - - outputs = [ - "$root_out_dir/flutter_web_sdk/kernel/amd/dart_sdk.js", - "$root_out_dir/flutter_web_sdk/kernel/amd/dart_sdk.js.map", - "$root_out_dir/flutter_web_sdk/kernel/legacy/dart_sdk.js", - "$root_out_dir/flutter_web_sdk/kernel/legacy/dart_sdk.js.map", - ] - - args = [ - "--no-sound-null-safety", - "--compile-sdk", - "dart:core", - - # Additional Flutter web dart libraries - "dart:ui", - "dart:_engine", - "--no-summarize", - "--packages", - "file:///" + rebase_path(dart_sdk_package_config), - "--multi-root-scheme", - "org-dartlang-sdk", - "--multi-root", - "file:///" + rebase_path("$root_out_dir"), - "--multi-root-output-path", - rebase_path("$root_out_dir/"), - "--libraries-file", - "org-dartlang-sdk:///flutter_web_sdk/libraries.json", - "--inline-source-map", - "-DFLUTTER_WEB_USE_SKIA=false", - "-DFLUTTER_WEB_AUTO_DETECT=false", - "--modules", - "amd", - "-o", - rebase_path("$root_out_dir/flutter_web_sdk/kernel/amd/dart_sdk.js"), - "--modules", - "legacy", - "-o", - rebase_path("$root_out_dir/flutter_web_sdk/kernel/legacy/dart_sdk.js"), - ] +# Compile the sound DDC SDK's summary. +_compile_outline("flutter_dartdevc_kernel_sdk_outline_sound") { + sound_null_safety = true + output_dill = sdk_dill_sound } -# Compiles the unsound canvaskit only renderer. -_dartdevc("flutter_dartdevc_canvaskit_kernel_sdk") { - inputs = [ "sdk_rewriter.dart" ] + web_ui_sources +template("_compile_ddc_modules") { + assert(defined(invoker.sound_null_safety), + "sound_null_safety must be defined for $target_name") + assert(defined(invoker.use_skia), + "use_skia must be defined for $target_name") + assert(defined(invoker.auto_detect), + "auto_detect must be defined for $target_name") - packages = dart_sdk_package_config + _dartdevc(target_name) { + inputs = [ "sdk_rewriter.dart" ] + web_ui_sources - outputs = [ - "$root_out_dir/flutter_web_sdk/kernel/amd-canvaskit/dart_sdk.js", - "$root_out_dir/flutter_web_sdk/kernel/amd-canvaskit/dart_sdk.js.map", - "$root_out_dir/flutter_web_sdk/kernel/legacy-canvaskit/dart_sdk.js", - "$root_out_dir/flutter_web_sdk/kernel/legacy-canvaskit/dart_sdk.js.map", - ] + packages = dart_sdk_package_config - args = [ - "--no-sound-null-safety", - "--compile-sdk", - "dart:core", - - # Additional Flutter web dart libraries - "dart:ui", - "dart:_engine", - "--no-summarize", - "--packages", - "file:///" + rebase_path(dart_sdk_package_config), - "--multi-root-scheme", - "org-dartlang-sdk", - "--multi-root", - "file:///" + rebase_path("$root_out_dir"), - "--multi-root-output-path", - rebase_path("$root_out_dir/"), - "--libraries-file", - "org-dartlang-sdk:///flutter_web_sdk/libraries.json", - "--inline-source-map", - "-DFLUTTER_WEB_USE_SKIA=true", - "-DFLUTTER_WEB_AUTO_DETECT=false", - "--modules", - "amd", - "-o", - rebase_path( - "$root_out_dir/flutter_web_sdk/kernel/amd-canvaskit/dart_sdk.js"), - "--modules", - "legacy", - "-o", - rebase_path( - "$root_out_dir/flutter_web_sdk/kernel/legacy-canvaskit/dart_sdk.js"), - ] -} + name_suffix = "" + if (invoker.use_skia) { + name_suffix += "-canvaskit" + } + if (invoker.auto_detect) { + name_suffix += "-html" + } + if (invoker.sound_null_safety) { + name_suffix += "-sound" + } -# Compiles the unsound autodetect renderer. -_dartdevc("flutter_dartdevc_canvaskit_html_kernel_sdk") { - inputs = [ "sdk_rewriter.dart" ] + web_ui_sources + amd_js_path = + "$root_out_dir/flutter_web_sdk/kernel/amd${name_suffix}/dart_sdk.js" + legacy_js_path = + "$root_out_dir/flutter_web_sdk/kernel/legacy${name_suffix}/dart_sdk.js" - packages = dart_sdk_package_config + outputs = [ + amd_js_path, + amd_js_path + ".map", + legacy_js_path, + legacy_js_path + ".map", + ] - outputs = [ - "$root_out_dir/flutter_web_sdk/kernel/amd-canvaskit-html/dart_sdk.js", - "$root_out_dir/flutter_web_sdk/kernel/amd-canvaskit-html/dart_sdk.js.map", - "$root_out_dir/flutter_web_sdk/kernel/legacy-canvaskit-html/dart_sdk.js", - "$root_out_dir/flutter_web_sdk/kernel/legacy-canvaskit-html/dart_sdk.js.map", - ] + if (invoker.sound_null_safety) { + args = [ "--sound-null-safety" ] + } else { + args = [ "--no-sound-null-safety" ] + } - args = [ - "--no-sound-null-safety", - "--compile-sdk", - "dart:core", - - # Additional Flutter web dart libraries - "dart:ui", - "dart:_engine", - "--no-summarize", - "--packages", - "file:///" + rebase_path(dart_sdk_package_config), - "--multi-root-scheme", - "org-dartlang-sdk", - "--multi-root", - "file:///" + rebase_path("$root_out_dir"), - "--multi-root-output-path", - rebase_path("$root_out_dir/"), - "--libraries-file", - "org-dartlang-sdk:///flutter_web_sdk/libraries.json", - "--inline-source-map", - "-DFLUTTER_WEB_USE_SKIA=true", - "-DFLUTTER_WEB_AUTO_DETECT=true", - "--modules", - "amd", - "-o", - rebase_path( - "$root_out_dir/flutter_web_sdk/kernel/amd-canvaskit-html/dart_sdk.js"), - "--modules", - "legacy", - "-o", - rebase_path( - "$root_out_dir/flutter_web_sdk/kernel/legacy-canvaskit-html/dart_sdk.js"), - ] + args += [ + "--compile-sdk", + "dart:core", + + # Additional Flutter web dart libraries + "dart:ui", + "dart:_engine", + "dart:_skwasm_stub", + "--no-summarize", + "--packages", + "file:///" + rebase_path(dart_sdk_package_config), + "--multi-root-scheme", + "org-dartlang-sdk", + "--multi-root", + "file:///" + rebase_path("$root_out_dir/flutter_web_sdk"), + "--multi-root", + "file:///" + rebase_path("$host_prebuilt_dart_sdk/.."), + "--multi-root-output-path", + rebase_path("$root_out_dir/"), + "--libraries-file", + "org-dartlang-sdk:///libraries.json", + "--inline-source-map", + "-DFLUTTER_WEB_USE_SKIA=${invoker.use_skia}", + "-DFLUTTER_WEB_AUTO_DETECT=${invoker.auto_detect}", + "--modules", + "amd", + "-o", + rebase_path(amd_js_path), + "--modules", + "legacy", + "-o", + rebase_path(legacy_js_path), + ] + } } -# Compiles the sound html only renderer. -_dartdevc("flutter_dartdevc_kernel_sdk_sound") { - inputs = [ "sdk_rewriter.dart" ] + web_ui_sources +# Compiles the unsound html only renderer. +_compile_ddc_modules("flutter_dartdevc_kernel_sdk") { + sound_null_safety = false + use_skia = false + auto_detect = false +} - packages = dart_sdk_package_config +# Compiles the unsound canvaskit only renderer. +_compile_ddc_modules("flutter_dartdevc_canvaskit_kernel_sdk") { + sound_null_safety = false + use_skia = true + auto_detect = false +} - outputs = [ - "$root_out_dir/flutter_web_sdk/kernel/amd-sound/dart_sdk.js", - "$root_out_dir/flutter_web_sdk/kernel/amd-sound/dart_sdk.js.map", - "$root_out_dir/flutter_web_sdk/kernel/legacy-sound/dart_sdk.js", - "$root_out_dir/flutter_web_sdk/kernel/legacy-sound/dart_sdk.js.map", - ] +# Compiles the unsound autodetect renderer. +_compile_ddc_modules("flutter_dartdevc_canvaskit_html_kernel_sdk") { + sound_null_safety = false + use_skia = true + auto_detect = true +} - args = [ - "--sound-null-safety", - "--compile-sdk", - "dart:core", - - # Additional Flutter web dart libraries - "dart:ui", - "dart:_engine", - "--no-summarize", - "--packages", - "file:///" + rebase_path(dart_sdk_package_config), - "--multi-root-scheme", - "org-dartlang-sdk", - "--multi-root", - "file:///" + rebase_path("$root_out_dir"), - "--multi-root-output-path", - rebase_path("$root_out_dir/"), - "--libraries-file", - "org-dartlang-sdk:///flutter_web_sdk/libraries.json", - "--inline-source-map", - "-DFLUTTER_WEB_USE_SKIA=false", - "-DFLUTTER_WEB_AUTO_DETECT=false", - "--modules", - "amd", - "-o", - rebase_path("$root_out_dir/flutter_web_sdk/kernel/amd-sound/dart_sdk.js"), - "--modules", - "legacy", - "-o", - rebase_path( - "$root_out_dir/flutter_web_sdk/kernel/legacy-sound/dart_sdk.js"), - ] +# Compiles the sound html only renderer. +_compile_ddc_modules("flutter_dartdevc_kernel_sdk_sound") { + sound_null_safety = true + use_skia = false + auto_detect = false } # Compiles the sound canvaskit only renderer. -_dartdevc("flutter_dartdevc_canvaskit_kernel_sdk_sound") { - inputs = [ "sdk_rewriter.dart" ] + web_ui_sources - - packages = dart_sdk_package_config - - outputs = [ - "$root_out_dir/flutter_web_sdk/kernel/amd-canvaskit-sound/dart_sdk.js", - "$root_out_dir/flutter_web_sdk/kernel/amd-canvaskit-sound/dart_sdk.js.map", - "$root_out_dir/flutter_web_sdk/kernel/legacy-canvaskit-sound/dart_sdk.js", - "$root_out_dir/flutter_web_sdk/kernel/legacy-canvaskit-sound/dart_sdk.js.map", - ] - - args = [ - "--sound-null-safety", - "--compile-sdk", - "dart:core", - - # Additional Flutter web dart libraries - "dart:ui", - "dart:_engine", - "--no-summarize", - "--packages", - "file:///" + rebase_path(dart_sdk_package_config), - "--multi-root-scheme", - "org-dartlang-sdk", - "--multi-root", - "file:///" + rebase_path("$root_out_dir"), - "--multi-root-output-path", - rebase_path("$root_out_dir/"), - "--libraries-file", - "org-dartlang-sdk:///flutter_web_sdk/libraries.json", - "--inline-source-map", - "-DFLUTTER_WEB_USE_SKIA=true", - "-DFLUTTER_WEB_AUTO_DETECT=false", - "--modules", - "amd", - "-o", - rebase_path( - "$root_out_dir/flutter_web_sdk/kernel/amd-canvaskit-sound/dart_sdk.js"), - "--modules", - "legacy", - "-o", - rebase_path( - "$root_out_dir/flutter_web_sdk/kernel/legacy-canvaskit-sound/dart_sdk.js"), - ] +_compile_ddc_modules("flutter_dartdevc_canvaskit_kernel_sdk_sound") { + sound_null_safety = true + use_skia = true + auto_detect = false } # Compiles the sound autodetect renderer. -_dartdevc("flutter_dartdevc_canvaskit_html_kernel_sdk_sound") { - inputs = [ "sdk_rewriter.dart" ] + web_ui_sources - - packages = dart_sdk_package_config - - outputs = [ - "$root_out_dir/flutter_web_sdk/kernel/amd-canvaskit-html-sound/dart_sdk.js", - "$root_out_dir/flutter_web_sdk/kernel/amd-canvaskit-html-sound/dart_sdk.js.map", - "$root_out_dir/flutter_web_sdk/kernel/legacy-canvaskit-html-sound/dart_sdk.js", - "$root_out_dir/flutter_web_sdk/kernel/legacy-canvaskit-html-sound/dart_sdk.js.map", - ] - - args = [ - "--sound-null-safety", - "--compile-sdk", - "dart:core", - - # Additional Flutter web dart libraries - "dart:ui", - "dart:_engine", - "--no-summarize", - "--packages", - "file:///" + rebase_path(dart_sdk_package_config), - "--multi-root-scheme", - "org-dartlang-sdk", - "--multi-root", - "file:///" + rebase_path("$root_out_dir"), - "--multi-root-output-path", - rebase_path("$root_out_dir/"), - "--libraries-file", - "org-dartlang-sdk:///flutter_web_sdk/libraries.json", - "--inline-source-map", - "-DFLUTTER_WEB_USE_SKIA=false", - "-DFLUTTER_WEB_AUTO_DETECT=true", - "--modules", - "amd", - "-o", - rebase_path( - "$root_out_dir/flutter_web_sdk/kernel/amd-canvaskit-html-sound/dart_sdk.js"), - "--modules", - "legacy", - "-o", - rebase_path( - "$root_out_dir/flutter_web_sdk/kernel/legacy-canvaskit-html-sound/dart_sdk.js"), - ] -} - -# Compile the sound DDC SDK's summary. -_kernel_worker("flutter_dartdevc_kernel_sdk_outline_sound") { - inputs = [ "sdk_rewriter.dart" ] + web_ui_sources - - outputs = [ sdk_dill_sound ] - - args = [ - "--sound-null-safety", - "--summary-only", - "--target", - "ddc", - "--packages-file", - "file:///" + rebase_path(dart_sdk_package_config), - "--multi-root-scheme", - "org-dartlang-sdk", - "--multi-root", - "file:///" + rebase_path("$root_out_dir"), - "--libraries-file", - "org-dartlang-sdk:///flutter_web_sdk/libraries.json", - "--output", - rebase_path(sdk_dill_sound), - "--source", - "dart:core", - - # Additional Flutter web dart libraries - "--source", - "dart:ui", - "--source", - "dart:_engine", - ] +_compile_ddc_modules("flutter_dartdevc_canvaskit_html_kernel_sdk_sound") { + sound_null_safety = true + use_skia = true + auto_detect = true } # Archives Flutter Web SDK if (!is_fuchsia) { zip_bundle_from_file("flutter_web_sdk_archive") { - output = "flutter-web-sdk-${full_platform_name}.zip" + if (target_os == "wasm") { + output = "flutter-web-sdk.zip" + } else { + # TODO(jacksongardner): remove this once we stop making platform-specific + # flutter_web_sdk archives. + # https://github.com/flutter/flutter/issues/113303 + output = "flutter-web-sdk-${full_platform_name}.zip" + } deps = [ ":flutter_dartdevc_canvaskit_html_kernel_sdk", ":flutter_dartdevc_canvaskit_html_kernel_sdk_sound", @@ -628,6 +431,10 @@ if (!is_fuchsia) { ":web_ui_library", ":web_ui_library_sources", ] + + if (build_canvaskit) { + deps += [ "//third_party/skia/modules/canvaskit" ] + } sources = get_target_outputs(":flutter_dartdevc_canvaskit_html_kernel_sdk") sources += get_target_outputs(":flutter_dartdevc_canvaskit_html_kernel_sdk_sound") @@ -652,6 +459,18 @@ if (!is_fuchsia) { }, ] } + if (build_canvaskit) { + tmp_files += [ + { + source = rebase_path("$root_out_dir/canvaskit.js") + destination = "canvaskit/canvaskit.js" + }, + { + source = rebase_path("$root_out_dir/canvaskit.wasm") + destination = "canvaskit/canvaskit.wasm" + }, + ] + } files = tmp_files } } diff --git a/web_sdk/web_test_utils/lib/environment.dart b/web_sdk/web_test_utils/lib/environment.dart index fb3df30ea7ba5..96702b210acba 100644 --- a/web_sdk/web_test_utils/lib/environment.dart +++ b/web_sdk/web_test_utils/lib/environment.dart @@ -41,21 +41,17 @@ class Environment { required this.webUiRootDir, required this.engineSrcDir, required this.engineToolsDir, - required this.outDir, }); static Environment _prepareEnvironmentFromEngineDir( io.File self, io.Directory engineSrcDir) { final io.Directory engineToolsDir = io.Directory(pathlib.join(engineSrcDir.path, 'flutter', 'tools')); - final io.Directory outDir = - io.Directory(pathlib.join(engineSrcDir.path, 'out')); final io.Directory webUiRootDir = io.Directory( pathlib.join(engineSrcDir.path, 'flutter', 'lib', 'web_ui')); for (final io.Directory expectedDirectory in [ engineSrcDir, - outDir, webUiRootDir ]) { if (!expectedDirectory.existsSync()) { @@ -68,7 +64,6 @@ class Environment { webUiRootDir: webUiRootDir, engineSrcDir: engineSrcDir, engineToolsDir: engineToolsDir, - outDir: outDir, ); } @@ -84,11 +79,6 @@ class Environment { /// Path to the engine's "tools" directory. final io.Directory engineToolsDir; - /// Path to the engine's "out" directory. - /// - /// This is where you'll find the ninja output, such as the Dart SDK. - final io.Directory outDir; - /// Path to where github.com/flutter/engine is checked out inside the engine workspace. io.Directory get flutterDirectory => io.Directory(pathlib.join(engineSrcDir.path, 'flutter'));