1d1527adf9
TEST=ci Change-Id: I56585a1fdb1bb6b92eab706fd0a66f78888bc55d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/464620 Reviewed-by: Alexander Aprelev <aam@google.com> Commit-Queue: Ryan Macnak <rmacnak@google.com>
208 lines
6.3 KiB
Plaintext
208 lines
6.3 KiB
Plaintext
# 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("../sdk_args.gni")
|
|
|
|
_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_gen_dir/$name.dart.dill"
|
|
|
|
# Build the kernel file using the prebuilt VM to speed up the debug and
|
|
# simulator builds.
|
|
prebuilt_dart_action(target_name + "_dill") {
|
|
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/gen_kernel:bootstrap_gen_kernel",
|
|
]
|
|
gen_kernel_kernel =
|
|
get_label_info("$_dart_root/utils/gen_kernel:bootstrap_gen_kernel",
|
|
"target_gen_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 = 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
|
|
|
|
args = [
|
|
"--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
|
|
}
|
|
}
|
|
|
|
# Whether to build an AOT snapshot, which can be opened by dlopen.
|
|
# Ignore this option on Linux, as the default app-aot-elf AOT
|
|
# snapshot already can be used with dlopen on Linux.
|
|
as_shared_library = defined(invoker.as_shared_library) &&
|
|
invoker.as_shared_library && !is_linux
|
|
|
|
assert(!(as_shared_library && is_win),
|
|
"AOT Snapshots as shared libraries are not supported on Windows")
|
|
|
|
if (!as_shared_library) {
|
|
# Create a snapshot from kernel built above.
|
|
gen_snapshot_action(target_name) {
|
|
if (defined(invoker.pool)) {
|
|
pool = invoker.pool
|
|
}
|
|
deps = extra_deps + [ ":${target_name}_dill" ]
|
|
|
|
inputs = extra_inputs
|
|
|
|
outputs = [ output ]
|
|
|
|
abs_output = rebase_path(output)
|
|
|
|
vm_args = [
|
|
"--deterministic",
|
|
"--snapshot-kind=app-aot-elf",
|
|
"--elf=$abs_output",
|
|
] + gen_snapshot_args
|
|
if (defined(invoker.vm_args)) {
|
|
vm_args += invoker.vm_args
|
|
}
|
|
|
|
args = [ rebase_path(dill) ]
|
|
|
|
force_product_mode = product_mode
|
|
}
|
|
} else {
|
|
assembly = "$target_gen_dir/$name.S"
|
|
dill_target_name = ":${target_name}_dill"
|
|
|
|
# Create an assembly snapshot from kernel built above.
|
|
assembly_target_name = target_name + "_assembly"
|
|
gen_snapshot_action(assembly_target_name) {
|
|
if (defined(invoker.pool)) {
|
|
pool = invoker.pool
|
|
}
|
|
deps = extra_deps + [ dill_target_name ]
|
|
|
|
inputs = extra_inputs
|
|
|
|
outputs = [ assembly ]
|
|
|
|
abs_output = rebase_path(assembly)
|
|
vm_args = [
|
|
"--deterministic",
|
|
"--snapshot-kind=app-aot-assembly",
|
|
"--assembly=$abs_output",
|
|
] + gen_snapshot_args
|
|
|
|
args = [ rebase_path(dill) ]
|
|
|
|
force_product_mode = product_mode
|
|
}
|
|
|
|
# build a shared library from assembly.
|
|
shared_library_target_name = target_name + "_shared_library"
|
|
shared_library(shared_library_target_name) {
|
|
sources = [ assembly ]
|
|
deps = [ ":${assembly_target_name}" ]
|
|
}
|
|
|
|
output_prefix = "lib"
|
|
output_extension = ""
|
|
|
|
if (current_os == "mac" || current_os == "ios" || current_os == "watchos") {
|
|
output_extension = "dylib"
|
|
} else if (current_os == "win") {
|
|
output_extension = "dll"
|
|
output_prefix = ""
|
|
} else if (current_os == "unknown" && current_cpu == "wasm32") {
|
|
output_extension = "wasm"
|
|
} else {
|
|
output_extension = "so"
|
|
}
|
|
|
|
shared_library_output_file_name =
|
|
"$output_prefix$shared_library_target_name"
|
|
if (output_extension != "") {
|
|
shared_library_output_file_name += ".$output_extension"
|
|
}
|
|
|
|
# copy shared library to the same output, as when
|
|
# `as_shared_library` is False.
|
|
copy(target_name) {
|
|
sources = [ "$root_out_dir/$shared_library_output_file_name" ]
|
|
outputs = [ output ]
|
|
|
|
deps = [ ":${shared_library_target_name}" ]
|
|
}
|
|
}
|
|
}
|