# Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file # for details. All rights reserved. Use of this source code is governed by a # BSD-style license that can be found in the LICENSE file. import("../build/dart/dart_action.gni") import("../runtime/runtime_args.gni") import("../sdk_args.gni") _dart_root = get_path_info("..", "abspath") _is_dart = _dart_root == get_path_info("//", "abspath") declare_args() { # Default to building app-jit snapshots. The simulator and cross builds # override this to script snapshots to cut down on build time. if (dart_target_arch == target_cpu && target_cpu == host_cpu) { dart_snapshot_kind = "app-jit" } else { dart_snapshot_kind = "kernel" } } # Creates an app-jit snapshot for a Dart program based on a training run. # # Parameters: # main_dart (required): # The entrypoint to the Dart application. # # training_args (required): # Arguments to pass to the Dart application for the training run. # # training_deps (optional): # Deps needed for the training run. # # training_inputs (optional): # Inputs needed for the training run. # # vm_args (optional): # Additional arguments to the Dart VM. # # name (optional): # The name of the snapshot if different from the target name. The output # will be in $root_gen_dir/$name.dart.snapshot. # # extra_deps (optional): # Any additional build dependencies. # # extra_inputs (optional): # Any extra build inputs. # # package_config (optional): # The package_config.json file for the app. # Defaults to the $_dart_root/.dart_tool/package_config.json file. # # output (optional): # Overrides the full output path. template("application_snapshot") { assert(defined(invoker.main_dart), "Must specify 'main_dart'") assert(defined(invoker.training_args), "Must specify 'training_args'") if (defined(invoker.dart_snapshot_kind)) { dart_snapshot_kind = invoker.dart_snapshot_kind } snapshot_vm_args = [] if (defined(invoker.vm_args)) { snapshot_vm_args = invoker.vm_args } # If --coverage=true/false hasn't been explicitly specified, # add --coverage=false. has_coverage_setting = false foreach(vm_arg, snapshot_vm_args) { vm_arg_split = string_split(vm_arg, "=") if (vm_arg_split[0] == "--coverage") { has_coverage_setting = true } } if (!has_coverage_setting) { # Also add --ignore-unrecognized-flags because --coverage is unrecognized # in product mode. snapshot_vm_args += [ "--coverage=false", "--ignore-unrecognized-flags", ] } main_dart = invoker.main_dart training_args = invoker.training_args training_deps = [] if (defined(invoker.training_deps)) { training_deps += invoker.training_deps } training_inputs = [] if (defined(invoker.training_inputs)) { training_inputs += invoker.training_inputs } name = target_name if (defined(invoker.name)) { name = invoker.name } extra_deps = [] if (defined(invoker.deps)) { extra_deps += invoker.deps } extra_inputs = [ main_dart ] if (defined(invoker.inputs)) { extra_inputs += invoker.inputs } if (defined(invoker.package_config)) { package_config = invoker.package_config } else { package_config = rebase_path("$_dart_root/.dart_tool/package_config.json") } output = "$root_gen_dir/$name.dart.snapshot" if (defined(invoker.output)) { output = invoker.output } gen_kernel_args = [] if (defined(invoker.gen_kernel_args)) { gen_kernel_args += invoker.gen_kernel_args } if (precompile_tools) { action(target_name + "_dill") { mnemonic = "GEN_KERNEL" if (defined(invoker.pool)) { pool = invoker.pool } else if (_is_dart) { pool = "//build/toolchain:local_action_pool($host_toolchain)" } else { pool = "$_dart_root/build/dart:dart_action_pool($default_toolchain)" } gen_kernel_tool = "$_dart_root/utils:bootstrap_gen_kernel.exe" gen_kernel_exe = get_label_info(gen_kernel_tool, "root_out_dir") + "/bootstrap_gen_kernel.exe" deps = extra_deps + [ "$_dart_root/runtime/vm:kernel_platform_files($host_toolchain)", "$_dart_root/runtime/vm:vm_platform", gen_kernel_tool, ] platform_dill = "$root_out_dir/vm_platform.dill" inputs = extra_inputs + [ gen_kernel_exe, platform_dill, main_dart, package_config, ] output = "$target_out_dir/$name.jit.dill" outputs = [ output ] depfile = "$output.d" script = "$_dart_root/build/gn_run_binary.py" is_product_flag = dart_runtime_mode == "release" args = [ rebase_path(gen_kernel_exe, root_build_dir), "--packages=" + rebase_path(package_config, root_build_dir), "--platform=" + rebase_path(platform_dill, root_build_dir), "--no-aot", "--no-embed-sources", "--no-link-platform", "--output=" + rebase_path(output, root_build_dir), "--depfile=" + rebase_path(depfile, root_build_dir), # Ensure the compiled application (e.g. kernel-service, frontend-server, # ...) will use this SDK hash when consuming/producing kernel. # # (Instead of ensuring every user of the "application_snapshot" / # "kernel_snapshot" passes this if needed, we always pass it) "-Dsdk_hash=$sdk_hash", "-Ddart.vm.product=$is_product_flag", "-Ddart.vm.asan=$is_asan", "-Ddart.vm.msan=$is_msan", "-Ddart.vm.tsan=$is_tsan", ] args += gen_kernel_args args += [ rebase_path(main_dart, root_build_dir) ] } } else { prebuilt_dart_action(target_name + "_dill") { mnemonic = "GEN_KERNEL" if (defined(invoker.pool)) { pool = invoker.pool } deps = extra_deps + [ "$_dart_root/runtime/vm:kernel_platform_files($host_toolchain)", "$_dart_root/runtime/vm:vm_platform", "$_dart_root/utils:bootstrap_gen_kernel.dill", ] gen_kernel_kernel = get_label_info("$_dart_root/utils:bootstrap_gen_kernel.dill", "target_out_dir") + "/bootstrap_gen_kernel.dill" platform_dill = "$root_out_dir/vm_platform.dill" inputs = extra_inputs + [ gen_kernel_kernel, platform_dill, main_dart, package_config, ] output = "$target_out_dir/$name.jit.dill" outputs = [ output ] depfile = "$output.d" vm_args = [ # Ensure gen_kernel.dart will use this SDK hash when consuming/producing # kernel. "-Dsdk_hash=$sdk_hash", ] script = gen_kernel_kernel is_product_flag = dart_runtime_mode == "release" args = [ "--packages=" + rebase_path(package_config, root_build_dir), "--platform=" + rebase_path(platform_dill, root_build_dir), "--no-aot", "--no-embed-sources", "--no-link-platform", "--output=" + rebase_path(output, root_build_dir), "--depfile=" + rebase_path(depfile, root_build_dir), # Ensure the compiled application (e.g. kernel-service, frontend-server, # ...) will use this SDK hash when consuming/producing kernel. # # (Instead of ensuring every user of the "application_snapshot" / # "kernel_snapshot" passes this if needed, we always pass it) "-Dsdk_hash=$sdk_hash", "-Ddart.vm.product=$is_product_flag", "-Ddart.vm.asan=$is_asan", "-Ddart.vm.msan=$is_msan", "-Ddart.vm.tsan=$is_tsan", ] args += gen_kernel_args args += [ rebase_path(main_dart, root_build_dir) ] } } # Create a snapshot from kernel built above. if (dart_snapshot_kind == "kernel") { copy(target_name) { deps = extra_deps + [ ":${target_name}_dill" ] sources = [ "$target_out_dir/$name.jit.dill" ] outputs = [ output ] not_needed([ "snapshot_vm_args", "training_args", "training_inputs", "training_deps", ]) } } else if (dart_snapshot_kind == "app-jit") { dart_action(target_name) { mnemonic = "APP_JIT" if (defined(invoker.pool)) { pool = invoker.pool } deps = extra_deps + [ ":${target_name}_dill" ] + training_deps # No depfile needed when running from a kernel file. The set of inputs is # known at GN time. script = "$target_out_dir/$name.jit.dill" inputs = extra_inputs + training_inputs outputs = [ output ] # Explicitly set DFE so Dart doesn't implicitly depend on the kernel # service snapshot (creating a circular dep. for kernel-service_snapshot). dfe = "NEVER_LOADED" vm_args = [ "--deterministic", "--packages=" + rebase_path(package_config, root_build_dir), "--snapshot-kind=app-jit", "--snapshot=" + rebase_path(output, root_build_dir), ] + snapshot_vm_args args = training_args } } else { assert(false, "Unknown snapshot_kind: $dart_snapshot_kind") } }