dart-sdk/utils/compile_platform.gni
Vyacheslav Egorov a4dd314c9e [tools] Allow precompiling gen_kernel and compile_platform
When iterating on core library changes or changes in the AOT compiler
many seconds are wasted waiting on gen_kernel/compile_platform to
parse Dart code. This happens because we are running these tools
from sources on prebuilt Dart SDK.

This CL allows SDK developer to opt-in into AOT compiling these
tools by adding `precompile_tools=true` to their DART_GN_ARGS.

AOT compilation is performed using prebuilt SDK - so these
executables do not need to be recompiled if core libraries or
VM changes reducing iteration cycles.

pkg/vm/tool/precompiler2 is tweaked to detect when DART_GN_ARGS
contains `precompile_tools=true` and use precompiled
gen_kernel.exe instead of running it from source.

Using precompiled compile_platform takes vm_platform_strong.dill
build from 20 seconds to 3 seconds.

Using precompiled gen_kernel takes small benchmark build from
~10 seconds to 2 seconds.

This relands 5cda2a871c with fixes
for Flutter build.

TEST=manually tested

Change-Id: I552861c80c152890655e41baaf6ea3fb3b03a57e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/367961
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2024-05-24 09:40:39 +00:00

141 lines
4.6 KiB
Plaintext

# Copyright (c) 2017, 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("compile_platform") {
assert(defined(invoker.libraries_specification_uri),
"Need 'libraries_specification_uri' in $target_name")
assert(defined(invoker.outputs), "Need 'outputs' in $target_name")
assert(defined(invoker.args), "Need 'args' in $target_name")
if (defined(invoker.single_root_scheme)) {
assert(defined(invoker.single_root_base),
"Need 'single_root_base' in $target_name")
}
if (defined(invoker.single_root_base)) {
assert(defined(invoker.single_root_scheme),
"Need 'single_root_scheme' in $target_name")
}
assert(!defined(invoker.script), "Remove 'script' from $target_name")
assert(!defined(invoker.depfile), "Remove 'depfile' from $target_name")
# In order to automatically compute dependencies, we need to add a dependency
# on vm_outline.dill. This is used to include the source code of Fasta itself
# in the dependency file. Without this, a change to Fasta wouldn't cause the
# platform dill files to be rebuilt. However, when building
# vm_outline_strong.dill, we shouldn't list it as a dependency as this would
# lead to cyclic dependencies.
add_implicit_vm_platform_dependency = true
if (defined(invoker.add_implicit_vm_platform_dependency)) {
add_implicit_vm_platform_dependency =
invoker.add_implicit_vm_platform_dependency
}
outline = "vm_outline_strong.dill"
if (defined(invoker.outline)) {
outline = invoker.outline
}
if (precompile_tools) {
action(target_name) {
if (defined(invoker.pool)) {
pool = invoker.pool
}
outputs = invoker.outputs
compile_platform_tool = "//utils:compile_platform.exe($host_toolchain)"
deps = [ compile_platform_tool ]
if (defined(invoker.deps)) {
deps += invoker.deps
}
inputs = []
if (defined(invoker.inputs)) {
inputs += invoker.inputs
}
if (add_implicit_vm_platform_dependency) {
inputs += [ "$root_out_dir/$outline" ]
deps += [ "$_dart_root/runtime/vm:vm_platform" ]
}
depfile = outputs[0] + ".d"
script = "$_dart_root/build/gn_run_binary.py"
args = [
"compiled_action",
rebase_path(get_label_info(compile_platform_tool, "root_out_dir") +
"/compile_platform.exe",
root_build_dir),
]
args += invoker.args
if (defined(invoker.single_root_scheme)) {
args += [ "--single-root-scheme=" + invoker.single_root_scheme ]
}
if (defined(invoker.single_root_base)) {
args += [ "--single-root-base=" + invoker.single_root_base ]
}
if (defined(invoker.single_root_scheme)) {
args += [ invoker.libraries_specification_uri ]
} else {
args +=
[ rebase_path(invoker.libraries_specification_uri, root_build_dir) ]
}
args += [ rebase_path("$root_out_dir/$outline", root_build_dir) ]
args += rebase_path(outputs, root_build_dir)
}
} else {
prebuilt_dart_action(target_name) {
if (defined(invoker.pool)) {
pool = invoker.pool
}
script = "$_dart_root/pkg/front_end/tool/_fasta/compile_platform.dart"
packages = "$_dart_root/.dart_tool/package_config.json"
outputs = invoker.outputs
vm_args = [ "-Dsdk_hash=$sdk_hash" ]
inputs = []
deps = []
args = []
if (defined(invoker.deps)) {
deps += invoker.deps
}
if (defined(invoker.inputs)) {
inputs += invoker.inputs
}
if (add_implicit_vm_platform_dependency) {
inputs += [ "$root_out_dir/$outline" ]
deps += [ "$_dart_root/runtime/vm:vm_platform" ]
}
depfile = outputs[0] + ".d"
args += invoker.args
if (defined(invoker.single_root_scheme)) {
args += [ "--single-root-scheme=" + invoker.single_root_scheme ]
}
if (defined(invoker.single_root_base)) {
args += [ "--single-root-base=" + invoker.single_root_base ]
}
if (defined(invoker.single_root_scheme)) {
args += [ invoker.libraries_specification_uri ]
} else {
args +=
[ rebase_path(invoker.libraries_specification_uri, root_build_dir) ]
}
args += [ rebase_path("$root_out_dir/$outline", root_build_dir) ]
args += rebase_path(outputs, root_build_dir)
}
}
}