Skip to content

Commit e78c3f5

Browse files
authored
[dart_aot_runner] Add support for generating dart_aot snapshots (flutter#13071)
This is part of the effort to port over dart_aot_runner
1 parent 835838c commit e78c3f5

File tree

2 files changed

+92
-27
lines changed

2 files changed

+92
-27
lines changed

shell/platform/fuchsia/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ if (using_fuchsia_sdk) {
2020
deps = [
2121
"dart:kernel_compiler",
2222
"dart_runner:$dart_runner_target",
23+
"dart_runner/embedder:dart_aot_product_snapshot_cc",
2324
"flutter:flutter_aot_${product_suffix}runner",
2425
"flutter:flutter_jit_${product_suffix}runner",
2526
"flutter:flutter_runner_tests",

shell/platform/fuchsia/dart_runner/embedder/BUILD.gn

Lines changed: 91 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,100 @@
22
# Use of this source code is governed by a BSD-style license that can be
33
# found in the LICENSE file.
44

5-
import("//build/dart/toolchain.gni")
6-
import("//topaz/runtime/dart/dart_component.gni")
7-
import("//topaz/runtime/dart/dart_kernel.gni")
5+
import("//build/compiled_action.gni")
6+
import("//third_party/dart/build/dart/dart_action.gni")
7+
import("$flutter_root/common/fuchsia_config.gni")
8+
import("$flutter_root/tools/fuchsia/dart.gni")
89

9-
dart_kernel("shim") {
10-
platform_name = "dart_runner"
11-
platform_deps = [ "//topaz/runtime/dart_runner/kernel:kernel_platform_files" ]
12-
platform_path = "$root_out_dir/dart_runner_patched_sdk"
10+
template("dart_shim_kernel") {
11+
prebuilt_dart_action(target_name) {
12+
assert(defined(invoker.main_dart), "main_dart is a required parameter.")
1313

14-
disable_analysis = true
14+
main_dart = rebase_path(invoker.main_dart)
1515

16-
main_dart = "shim.dart"
16+
deps = [
17+
"../kernel:kernel_platform_files($host_toolchain)",
18+
]
1719

18-
aot = true
19-
product = false
20+
gen_kernel_script = "//third_party/dart/pkg/vm/bin/gen_kernel.dart"
21+
platform_dill = "$root_out_dir/dart_runner_patched_sdk/platform_strong.dill"
2022

21-
visibility = [ ":*" ]
22-
}
23+
dot_packages = rebase_path("//third_party/dart/.packages")
2324

24-
dart_kernel("shim_product") {
25-
platform_name = "dart_runner"
26-
platform_deps = [ "//topaz/runtime/dart_runner/kernel:kernel_platform_files" ]
27-
platform_path = "$root_out_dir/dart_runner_patched_sdk"
25+
inputs = [
26+
gen_kernel_script,
27+
main_dart,
28+
dot_packages,
29+
]
2830

29-
disable_analysis = true
31+
output = "$target_gen_dir/$target_name.dill"
32+
outputs = [
33+
output,
34+
]
3035

31-
main_dart = "shim.dart"
36+
depfile = "$output.d"
37+
abs_depfile = rebase_path(depfile)
38+
rebased_output = rebase_path(output, root_build_dir)
39+
vm_args = [
40+
"--depfile=$abs_depfile",
41+
"--depfile_output_filename=$rebased_output",
42+
]
43+
44+
script = gen_kernel_script
45+
46+
args = [
47+
"--packages=" + rebase_path(dot_packages),
48+
"--target=dart_runner",
49+
"--platform=" + rebase_path(platform_dill),
50+
"--no-link-platform",
51+
"--output=" + rebase_path(output),
52+
]
53+
54+
if (is_debug) {
55+
args += [ "--embed-sources" ]
56+
} else {
57+
args += [ "--no-embed-sources" ]
58+
}
3259

60+
if (defined(invoker.aot) && invoker.aot) {
61+
args += [
62+
"--aot",
63+
"--tfa",
64+
]
65+
}
66+
67+
if (defined(invoker.product) && invoker.product) {
68+
# Setting this flag in a non-product release build for AOT (a "profile"
69+
# build) causes the vm service isolate code to be tree-shaken from an app.
70+
# See the pragma on the entrypoint here:
71+
#
72+
# https://github.com/dart-lang/sdk/blob/master/runtime/bin/vmservice/vmservice_io.dart#L240
73+
#
74+
# Also, this define excludes debugging and profiling code from Flutter.
75+
args += [ "-Ddart.vm.product=true" ]
76+
} else {
77+
if (!is_debug) {
78+
# The following define excludes debugging code from Flutter.
79+
args += [ "-Ddart.vm.profile=true" ]
80+
}
81+
}
82+
83+
visibility = [ ":*" ]
84+
85+
args += [ rebase_path(main_dart) ]
86+
}
87+
}
88+
89+
dart_shim_kernel("shim_kernel") {
90+
main_dart = "shim.dart"
91+
product = false
3392
aot = true
34-
product = true
93+
}
3594

36-
visibility = [ ":*" ]
95+
dart_shim_kernel("shim_product_kernel") {
96+
main_dart = "shim.dart"
97+
product = true
98+
aot = true
3799
}
38100

39101
template("create_aot_snapshot") {
@@ -42,13 +104,13 @@ template("create_aot_snapshot") {
42104
if (invoker.product) {
43105
product_suffix = "_product"
44106
}
45-
action("${target_name}_assembly") {
107+
compiled_action("${target_name}_assembly") {
46108
snapshot_assembly = "$target_gen_dir/aot${product_suffix}_vm_snapshot.S"
47109

48110
# gen_snapshot only needs this to go through the motions of setting up an isolate.
49111
shim_target = ":shim${product_suffix}_kernel"
50112
shim_kernel = get_label_info(shim_target, "target_gen_dir") +
51-
"/shim${product_suffix}_kernel.dil"
113+
"/shim${product_suffix}_kernel.dill"
52114

53115
inputs = [
54116
shim_kernel,
@@ -57,11 +119,13 @@ template("create_aot_snapshot") {
57119
snapshot_assembly,
58120
]
59121

60-
deps = gen_snapshot_deps + [ shim_target ]
122+
deps = [
123+
shim_target,
124+
]
61125
if (invoker.product) {
62-
script = gen_snapshot_product
126+
tool = gen_snapshot_product
63127
} else {
64-
script = gen_snapshot
128+
tool = gen_snapshot
65129
}
66130

67131
args = [
@@ -74,7 +138,7 @@ template("create_aot_snapshot") {
74138
# No asserts in debug or release product.
75139
# No asserts in release with flutter_profile=true (non-product)
76140
# Yes asserts in non-product debug.
77-
if (!invoker.product && (!flutter_profile || is_debug)) {
141+
if (!invoker.product && (!(flutter_runtime_mode == "profile") || is_debug)) {
78142
args += [ "--enable_asserts" ]
79143
}
80144
args += [ rebase_path(shim_kernel) ]

0 commit comments

Comments
 (0)