-
Notifications
You must be signed in to change notification settings - Fork 5.9k
/
rules.gni
392 lines (353 loc) · 12.2 KB
/
rules.gni
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# This file has rules for making Dart packages and snapshots.
import("//build/compiled_action.gni")
import("//build/module_args/dart.gni")
import("//flutter/build/dart/dart.gni")
import("//flutter/common/config.gni")
import("$dart_src/build/dart/dart_action.gni")
import("$dart_src/sdk_args.gni")
# Generates a Dart kernel snapshot using flutter_frontend_server.
#
# Arguments
# main_dart (required):
# The Dart entrypoint file.
#
# kernel_output (required):
# The path to the output kernel snapshot in the out directory.
#
# package_config (optional):
# The path to the package_config.json file.
#
# deps (optional):
# Additional dependencies. Dependencies on the frontend server and
# Flutter's platform.dill are included by default. This rule creates and
# uses a depfile, so listing all Dart sources is not necessary.
#
# extra_args (optional):
# Additional frontend server command line arguments.
template("flutter_frontend_server") {
assert(defined(invoker.main_dart), "The Dart test file must be specified.")
assert(defined(invoker.kernel_output),
"The Dart Kernel file location must be specified.")
kernel_output = invoker.kernel_output
common_deps = [ "//flutter/lib/snapshot:strong_platform" ]
if (defined(invoker.deps)) {
common_deps += invoker.deps
}
extra_args = []
if (defined(invoker.extra_args)) {
extra_args += invoker.extra_args
}
packages_args = []
if (defined(invoker.package_config)) {
packages_args += [
"--packages",
rebase_path(invoker.package_config, root_build_dir),
]
}
snapshot_depfile = "$kernel_output.d"
common_vm_args = [ "--disable-dart-dev" ]
flutter_patched_sdk =
rebase_path("$root_out_dir/flutter_patched_sdk", root_build_dir)
common_args = extra_args + packages_args + [
"--sdk-root",
flutter_patched_sdk,
"--target=flutter",
"--depfile",
rebase_path(snapshot_depfile, root_build_dir),
"--output-dill",
rebase_path(invoker.kernel_output, root_build_dir),
rebase_path(invoker.main_dart, root_build_dir),
]
if (flutter_prebuilt_dart_sdk) {
common_deps += [ "//flutter/flutter_frontend_server:frontend_server" ]
action(target_name) {
forward_variables_from(invoker,
[
"visibility",
"testonly",
],
[ "pool" ])
deps = common_deps
pool = "//build/toolchain:toolchain_pool"
script = "//build/gn_run_binary.py"
inputs = [ invoker.main_dart ]
outputs = [ invoker.kernel_output ]
depfile = snapshot_depfile
ext = ""
if (is_win) {
ext = ".exe"
}
dart = rebase_path("$host_prebuilt_dart_sdk/bin/dartaotruntime$ext",
root_out_dir)
frontend_server =
rebase_path("$root_gen_dir/frontend_server_aot.dart.snapshot")
args = [ dart ] + common_vm_args + [ frontend_server ] + common_args
}
} else {
prebuilt_dart_action(target_name) {
forward_variables_from(invoker,
[
"visibility",
"testonly",
],
[ "pool" ])
deps = common_deps
pool = "//build/toolchain:toolchain_pool"
script = "$dart_src/pkg/frontend_server/bin/frontend_server_starter.dart"
inputs = [ invoker.main_dart ]
outputs = [ invoker.kernel_output ]
depfile = snapshot_depfile
vm_args = common_vm_args
args = common_args
}
}
}
# Creates a dart kernel (dill) file suitable for use with gen_snapshot, as well
# as the app-jit, aot-elf, or aot-assembly snapshot for targeting Flutter on
# Android or iOS.
#
# Invoker must supply dart_main and package_config. Invoker may optionally
# supply aot as a boolean and product as a boolean.
#
# On Android, the invoker may provide output_aot_lib as a string to override
# the default filename for the aot-elf snapshot.
template("flutter_snapshot") {
assert(!is_fuchsia)
assert(defined(invoker.main_dart), "main_dart is a required parameter.")
assert(defined(invoker.package_config),
"package_config is a required parameter.")
kernel_target = "_${target_name}_kernel"
snapshot_target = "_${target_name}_snapshot"
is_aot =
flutter_runtime_mode == "profile" || flutter_runtime_mode == "release"
kernel_output = "$target_gen_dir/kernel_blob.bin"
extra_frontend_server_args = []
if (is_aot) {
extra_frontend_server_args += [
"--aot",
"--tfa",
]
} else {
# --no-link-platform is only valid when --aot isn't specified
extra_frontend_server_args += [ "--no-link-platform" ]
}
if (defined(invoker.product) && invoker.product) {
# Setting this flag in a non-product release build for AOT (a "profile"
# build) causes the vm service isolate code to be tree-shaken from an app.
# See the pragma on the entrypoint here:
#
# https://github.com/dart-lang/sdk/blob/main/sdk/lib/_internal/vm/bin/vmservice_io.dart#L240
#
# Also, this define excludes debugging and profiling code from Flutter.
extra_frontend_server_args += [ "-Ddart.vm.product=true" ]
} else {
if (flutter_runtime_mode == "profile") {
# The following define excludes debugging code from Flutter.
extra_frontend_server_args += [ "-Ddart.vm.profile=true" ]
}
}
flutter_frontend_server(kernel_target) {
main_dart = invoker.main_dart
package_config = invoker.package_config
kernel_output = kernel_output
extra_args = extra_frontend_server_args
}
compiled_action(snapshot_target) {
if (target_cpu == "x86" && host_os == "linux") {
# By default Dart will create a 32-bit gen_snapshot host binary if the target
# platform is 32-bit. Override this to create a 64-bit gen_snapshot for x86
# targets because some host platforms may not support 32-bit binaries.
tool = "$dart_src/runtime/bin:gen_snapshot_host_targeting_host"
toolchain = "//build/toolchain/$host_os:clang_x64"
} else {
tool = "$dart_src/runtime/bin:gen_snapshot"
}
inputs = [ kernel_output ]
deps = [ ":$kernel_target" ]
outputs = []
args = []
if (is_debug && flutter_runtime_mode != "profile" &&
flutter_runtime_mode != "release" &&
flutter_runtime_mode != "jit_release") {
args += [ "--enable_asserts" ]
}
if (is_aot) {
args += [ "--deterministic" ]
if (is_ios) {
snapshot_assembly = "$target_gen_dir/ios/snapshot_assembly.S"
outputs += [ snapshot_assembly ]
args += [
"--snapshot_kind=app-aot-assembly",
"--assembly=" + rebase_path(snapshot_assembly),
]
} else if (is_android) {
if (defined(invoker.output_aot_lib)) {
output_aot_lib = invoker.output_aot_lib
} else {
output_aot_lib = "libapp.so"
}
libapp = "$target_gen_dir/android/libs/$android_app_abi/$output_aot_lib"
outputs += [ libapp ]
args += [
"--snapshot_kind=app-aot-elf",
"--elf=" + rebase_path(libapp),
]
} else {
assert(false)
}
} else {
deps += [ "//flutter/lib/snapshot:generate_snapshot_bin" ]
vm_snapshot_data =
"$root_gen_dir/flutter/lib/snapshot/vm_isolate_snapshot.bin"
snapshot_data = "$root_gen_dir/flutter/lib/snapshot/isolate_snapshot.bin"
isolate_snapshot_data = "$target_gen_dir/isolate_snapshot_data"
isolate_snapshot_instructions = "$target_gen_dir/isolate_snapshot_instr"
inputs += [
vm_snapshot_data,
snapshot_data,
]
outputs += [
isolate_snapshot_data,
isolate_snapshot_instructions,
]
args += [
"--snapshot_kind=app-jit",
"--load_vm_snapshot_data=" + rebase_path(vm_snapshot_data),
"--load_isolate_snapshot_data=" + rebase_path(snapshot_data),
"--isolate_snapshot_data=" + rebase_path(isolate_snapshot_data),
"--isolate_snapshot_instructions=" +
rebase_path(isolate_snapshot_instructions),
]
}
args += [ rebase_path(kernel_output) ]
}
group(target_name) {
public_deps = [
":$kernel_target",
":$snapshot_target",
]
}
}
# Creates an app-jit snapshot for a command-line 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.
#
# vm_args (optional):
# Additional arguments to the Dart VM.
#
# deps (optional):
# Any build dependencies.
#
# package_config (required):
# The .packages file for the app. Defaults to the $_dart_root/.packages.
#
# output (optional):
# Overrides the full output path.
#
# snapshot_kind (optional)
# Either an "app-jit" snapshot (default) or a "kernel" snapshot
template("application_snapshot") {
assert(defined(invoker.main_dart), "Must specify 'main_dart'")
assert(defined(invoker.training_args), "Must specify 'training_args'")
assert(defined(invoker.package_config), "Must specify 'package_config'")
main_dart = invoker.main_dart
training_args = invoker.training_args
package_config = rebase_path(invoker.package_config)
name = target_name
extra_deps = []
if (defined(invoker.deps)) {
extra_deps += invoker.deps
}
extra_inputs = [ main_dart ]
if (defined(invoker.inputs)) {
extra_inputs += invoker.inputs
}
output = "$root_gen_dir/$name.dart.snapshot"
if (defined(invoker.output)) {
output = invoker.output
}
depfile = output + ".d"
abs_depfile = rebase_path(depfile)
abs_output = rebase_path(output)
rel_output = rebase_path(output, root_build_dir)
snapshot_vm_args = [
"--disable-dart-dev",
"--deterministic",
"--packages=$package_config",
"--snapshot=$abs_output",
"--snapshot-depfile=$abs_depfile",
"--depfile-output-filename=$rel_output",
]
if (defined(invoker.vm_args)) {
snapshot_vm_args += invoker.vm_args
}
snapshot_kind = "app-jit"
if (target_cpu != host_cpu) {
snapshot_kind = "kernel"
}
if (defined(invoker.snapshot_kind)) {
snapshot_kind = invoker.snapshot_kind
}
if (snapshot_kind == "kernel") {
snapshot_vm_args += [ "--snapshot-kind=kernel" ]
} else if (snapshot_kind == "app-jit") {
snapshot_vm_args += [ "--snapshot-kind=app-jit" ]
} else {
assert(false, "Bad snapshot_kind: '$snapshot_kind'")
}
# Ensure the compiled appliation (e.g. frontend-server, ...) will use this
# Dart SDK hash when consuming/producing kernel.
#
# (Instead of ensuring every user of the "application_snapshot" passes its
# own)
snapshot_vm_args += [ "-Dsdk_hash=$sdk_hash" ]
if (flutter_prebuilt_dart_sdk) {
action(target_name) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
deps = extra_deps
script = "//build/gn_run_binary.py"
inputs = extra_inputs
outputs = [ output ]
depfile = depfile
pool = "//build/toolchain:toolchain_pool"
ext = ""
if (is_win) {
ext = ".exe"
}
dart = rebase_path("$host_prebuilt_dart_sdk/bin/dart$ext", root_build_dir)
args = [ dart ]
args += snapshot_vm_args
args += [ rebase_path(main_dart) ]
args += training_args
}
} else {
dart_action(target_name) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
script = main_dart
pool = "//build/toolchain:toolchain_pool"
deps = extra_deps
inputs = extra_inputs
outputs = [ output ]
depfile = depfile
vm_args = snapshot_vm_args
args = training_args
}
}
}