| # Copyright (c) 2022, 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("../build/toolchain/signing.gni") |
| import("../sdk_args.gni") |
| |
| _dart_root = get_path_info("..", "abspath") |
| _is_dart = _dart_root == get_path_info("//", "abspath") |
| |
| template("aot_snapshot") { |
| assert(defined(invoker.main_dart), "Must specify 'main_dart'") |
| product_mode = |
| (defined(dart_runtime_mode) && dart_runtime_mode == "release") || |
| (defined(invoker.force_product_mode) && invoker.force_product_mode) |
| gen_kernel_args = [] |
| if (defined(invoker.gen_kernel_args)) { |
| gen_kernel_args = invoker.gen_kernel_args |
| } |
| gen_snapshot_args = [] |
| if (defined(invoker.gen_snapshot_args)) { |
| gen_snapshot_args = invoker.gen_snapshot_args |
| } |
| main_dart = invoker.main_dart |
| 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_out_dir/$name.snapshot" |
| if (defined(invoker.output)) { |
| output = invoker.output |
| } |
| |
| dill = "$target_out_dir/$name.aot.dill" |
| unsigned_snapshot = "$target_out_dir/$name.dart.snapshot.unsigned" |
| signed_snapshot = output |
| |
| # Build the kernel file using the prebuilt VM to speed up the debug and |
| # simulator builds. |
| kernel_label = target_name + "_dill" |
| action(kernel_label) { |
| 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($host_toolchain)" |
| 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 = dill |
| outputs = [ output ] |
| |
| depfile = "$output.d" |
| |
| script = "$_dart_root/build/gn_run_binary.py" |
| |
| 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), |
| "--aot", |
| "--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=$product_mode", |
| "-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) ] |
| if (defined(invoker.args)) { |
| args += invoker.args |
| } |
| } |
| |
| # Create a snapshot from kernel built above. |
| gen_snapshot_label = "${target_name}_gen_snapshot" |
| gen_snapshot_action(gen_snapshot_label) { |
| if (defined(invoker.pool)) { |
| pool = invoker.pool |
| } |
| deps = extra_deps + [ ":$kernel_label" ] |
| |
| inputs = [ dill ] + extra_inputs |
| |
| outputs = [ unsigned_snapshot ] |
| |
| rebased_output = rebase_path(unsigned_snapshot, root_build_dir) |
| |
| # TODO(60813): Generate PE DLL on Windows. |
| if (is_mac) { |
| vm_args = [ |
| "--deterministic", |
| "--snapshot-kind=app-aot-macho-dylib", |
| "--macho=$rebased_output", |
| ] + gen_snapshot_args |
| } else { |
| vm_args = [ |
| "--deterministic", |
| "--snapshot-kind=app-aot-elf", |
| "--elf=$rebased_output", |
| ] + gen_snapshot_args |
| } |
| if (defined(invoker.vm_args)) { |
| vm_args += invoker.vm_args |
| } |
| |
| args = [ rebase_path(dill, root_build_dir) ] |
| |
| force_product_mode = product_mode |
| } |
| |
| if (is_mac && codesigning_identity != "") { |
| action(target_name) { |
| mnemonic = "CODESIGN" |
| |
| deps = [ ":$gen_snapshot_label" ] |
| inputs = [ unsigned_snapshot ] |
| outputs = [ signed_snapshot ] |
| |
| script = "$_dart_root/runtime/tools/dart_copy_and_codesign.py" |
| args = [ |
| "--identity", |
| codesigning_identity, |
| "--input", |
| rebase_path(unsigned_snapshot, root_build_dir), |
| "--output", |
| rebase_path(signed_snapshot, root_build_dir), |
| ] |
| } |
| } else { |
| copy(target_name) { |
| deps = [ ":$gen_snapshot_label" ] |
| sources = [ unsigned_snapshot ] |
| outputs = [ signed_snapshot ] |
| } |
| } |
| } |