forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBUILD.gn
More file actions
349 lines (311 loc) · 11.2 KB
/
BUILD.gn
File metadata and controls
349 lines (311 loc) · 11.2 KB
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
# 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.
import("//build/compiled_action.gni")
import("//build/fuchsia/sdk.gni")
import("//flutter/common/config.gni")
import("//flutter/impeller/tools/impeller.gni")
import("//flutter/lib/ui/dart_ui.gni")
import("//third_party/dart/utils/compile_platform.gni")
# Generates the Dart/Flutter core platform files and tools.
#
# This target generates the platform-specific snapshots and snapshot-related
# tooling for a given target CPU.
#
# Outputs:
# * Core platform compiled to kernel bytecode
# * Core platform compiled to target_cpu-specific binary snapshot
# * target_cpu-specific gen_snapshot
# * target_cpu-specific analyze_snapshot
group("generate_snapshot_bins") {
deps = [
":generate_snapshot_bin",
":kernel_platform_files",
]
# Build gen_snapshot for the currently specified target_cpu.
#
# For macOS target builds: needed for both target CPUs (arm64, x64).
# For iOS, Android target builds: all AOT target CPUs are arm/arm64.
if (host_os == "mac" && target_os == "mac") {
deps += [ ":create_macos_gen_snapshots" ]
} else if (host_os == "mac" &&
(target_cpu == "arm" || target_cpu == "arm64")) {
deps += [ ":create_arm_gen_snapshot" ]
}
# Build analyze_snapshot for 64-bit target CPUs.
if (host_os == "linux" && (target_cpu == "x64" || target_cpu == "arm64")) {
deps +=
[ "//third_party/dart/runtime/bin:analyze_snapshot($host_toolchain)" ]
}
}
# Compiles a binary snapshot of the core Dart/Flutter platform.
#
# Inputs:
# * platform_strong.dill
#
# Tools:
# * gen_snapshot
#
# Outputs:
# * vm_snapshot_data.bin
# * vm_snapshot_instructions.bin
# * isolate_snapshot_data.bin
# * isolate_snapshot_instructions.bin
#
# See: `bin_to_linkable` rules below that build these outputs into linkable form
# See: https://github.com/flutter/flutter/wiki/Flutter-engine-operation-in-AOT-Mode
compiled_action("generate_snapshot_bin") {
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 = "//third_party/dart/runtime/bin:gen_snapshot_host_targeting_host"
toolchain = "//build/toolchain/$host_os:clang_x64"
} else {
tool = "//third_party/dart/runtime/bin:gen_snapshot"
}
platform_kernel = "$root_out_dir/flutter_patched_sdk/platform_strong.dill"
inputs = [ platform_kernel ]
deps = [ ":kernel_platform_files" ]
vm_snapshot_data = "$target_gen_dir/vm_isolate_snapshot.bin"
vm_snapshot_instructions = "$target_gen_dir/vm_snapshot_instructions.bin"
isolate_snapshot_data = "$target_gen_dir/isolate_snapshot.bin"
isolate_snapshot_instructions =
"$target_gen_dir/isolate_snapshot_instructions.bin"
outputs = [
vm_snapshot_data,
vm_snapshot_instructions,
isolate_snapshot_data,
isolate_snapshot_instructions,
]
args = [
"--snapshot_kind=core",
"--enable_mirrors=false",
"--vm_snapshot_data=" + rebase_path(vm_snapshot_data),
"--vm_snapshot_instructions=" + rebase_path(vm_snapshot_instructions),
"--isolate_snapshot_data=" + rebase_path(isolate_snapshot_data),
"--isolate_snapshot_instructions=" +
rebase_path(isolate_snapshot_instructions),
]
if (is_debug && flutter_runtime_mode != "profile" &&
flutter_runtime_mode != "release" &&
flutter_runtime_mode != "jit_release") {
args += [ "--enable_asserts" ]
}
args += [ rebase_path(platform_kernel) ]
metadata = {
entitlement_file_path = [ "gen_snapshot" ]
}
}
# Generates an assembly file defining a given symbol with the bytes from a
# binary file. Places the symbol in a text section if 'executable' is true,
# otherwise places the symbol in a read-only data section.
template("bin_to_assembly") {
assert(defined(invoker.deps), "Must define deps")
assert(defined(invoker.input), "Must define input binary file")
assert(defined(invoker.symbol), "Must define symbol name")
assert(defined(invoker.executable), "Must define boolean executable")
action(target_name) {
deps = invoker.deps
script = "//third_party/dart/runtime/tools/bin_to_assembly.py"
output = invoker.input + ".S"
args = [
"--input",
rebase_path(invoker.input),
"--output",
rebase_path(output),
"--symbol_name",
invoker.symbol,
"--target_os",
current_os,
]
if (defined(invoker.size_symbol)) {
args += [
"--size_symbol_name",
invoker.size_symbol,
"--target_arch",
current_cpu,
]
}
if (invoker.executable) {
args += [ "--executable" ]
}
inputs = [
script,
invoker.input,
]
outputs = [ output ]
}
}
# Generates an object file defining a given symbol with the bytes from a
# binary file. Places the symbol in the read-only data section.
template("bin_to_coff") {
assert(defined(invoker.deps), "Must define deps")
assert(defined(invoker.input), "Must define input binary file")
assert(defined(invoker.symbol), "Must define symbol name")
assert(defined(invoker.executable), "Must define executable")
action(target_name) {
deps = invoker.deps
script = "//third_party/dart/runtime/tools/bin_to_coff.py"
output = invoker.input + ".o"
args = [
"--input",
rebase_path(invoker.input),
"--output",
rebase_path(output),
"--symbol_name",
invoker.symbol,
]
if (defined(invoker.size_symbol)) {
args += [
"--size_symbol_name",
invoker.size_symbol,
]
}
if (invoker.executable) {
args += [ "--executable" ]
}
args += [ "--arch=$current_cpu" ]
inputs = [ invoker.input ]
outputs = [ output ]
}
}
# Generates a linkable output file defining the specified symbol with the bytes
# from the binary file. Emits a COFF object file when targeting Windows,
# otherwise assembly.
template("bin_to_linkable") {
assert(defined(invoker.deps), "Must define deps")
assert(defined(invoker.input), "Must define input binary file")
assert(defined(invoker.symbol), "Must define symbol name")
target_type = "bin_to_assembly"
if (is_win) {
target_type = "bin_to_coff"
}
target(target_type, target_name) {
forward_variables_from(invoker, "*")
}
}
bin_to_linkable("vm_snapshot_data_linkable") {
deps = [ ":generate_snapshot_bin" ]
input = "$target_gen_dir/vm_isolate_snapshot.bin"
symbol = "kDartVmSnapshotData"
executable = false
}
bin_to_linkable("vm_snapshot_instructions_linkable") {
deps = [ ":generate_snapshot_bin" ]
input = "$target_gen_dir/vm_snapshot_instructions.bin"
symbol = "kDartVmSnapshotInstructions"
executable = true
}
bin_to_linkable("isolate_snapshot_data_linkable") {
deps = [ ":generate_snapshot_bin" ]
input = "$target_gen_dir/isolate_snapshot.bin"
symbol = "kDartIsolateSnapshotData"
executable = false
}
bin_to_linkable("isolate_snapshot_instructions_linkable") {
deps = [ ":generate_snapshot_bin" ]
input = "$target_gen_dir/isolate_snapshot_instructions.bin"
symbol = "kDartIsolateSnapshotInstructions"
executable = true
}
bin_to_linkable("platform_strong_dill_linkable") {
deps = [ ":kernel_platform_files" ]
input = "$root_out_dir/flutter_patched_sdk/platform_strong.dill"
symbol = "kPlatformStrongDill"
size_symbol = "kPlatformStrongDillSize"
executable = false
}
# Creates a `gen_snapshot` binary suffixed with the target CPU architecture.
#
# Builds gen_snapshot using the host toolchain then copies the resulting binary
# to `gen_snapshot_armv7` or `gen_snapshot_arm64` depending on the target
# platform.
#
# This target is used for builds targeting iOS/Android OS.
if (host_os == "mac" && target_os != "mac" &&
(target_cpu == "arm" || target_cpu == "arm64")) {
copy("create_arm_gen_snapshot") {
# The toolchain-specific output directory. For cross-compiles, this is a
# clang-x64 or clang-arm64 subdirectory of the top-level build directory.
host_output_dir = get_label_info(
"//third_party/dart/runtime/bin:gen_snapshot($host_toolchain)",
"root_out_dir")
# Determine suffixed output gen_snapshot name.
target_cpu_suffix = target_cpu
if (target_cpu == "arm") {
target_cpu_suffix = "armv7"
}
sources = [ "${host_output_dir}/gen_snapshot" ]
outputs = [ "${host_output_dir}/gen_snapshot_${target_cpu_suffix}" ]
deps = [ "//third_party/dart/runtime/bin:gen_snapshot($host_toolchain)" ]
visibility = [ ":*" ]
}
}
# Creates a `gen_snapshot` binary suffixed with the target CPU architecture.
#
# Builds gen_snapshot using the host toolchain then copies the resulting binary
# to `gen_snapshot_arm64` or `gen_snapshot_x64` depending on the target
# platform.
#
# This target is used for builds targeting macOS.
if (host_os == "mac" && target_os == "mac") {
copy("create_macos_gen_snapshots") {
# The toolchain-specific output directory. For cross-compiles, this is a
# clang-x64 or clang-arm64 subdirectory of the top-level build directory.
host_output_dir = get_label_info(
"//third_party/dart/runtime/bin:gen_snapshot($host_toolchain)",
"root_out_dir")
sources = [ "${host_output_dir}/gen_snapshot" ]
outputs = [ "${root_out_dir}/gen_snapshot_${target_cpu}" ]
deps = [ "//third_party/dart/runtime/bin:gen_snapshot($host_toolchain)" ]
metadata = {
snapshot_entitlement_file_path = [ "gen_snapshot_{$target_cpu}" ]
}
}
}
source_set("snapshot") {
deps = [
":isolate_snapshot_data_linkable",
":isolate_snapshot_instructions_linkable",
":platform_strong_dill_linkable",
":vm_snapshot_data_linkable",
":vm_snapshot_instructions_linkable",
]
sources = get_target_outputs(":isolate_snapshot_data_linkable") +
get_target_outputs(":isolate_snapshot_instructions_linkable") +
get_target_outputs(":vm_snapshot_data_linkable") +
get_target_outputs(":vm_snapshot_instructions_linkable") +
get_target_outputs(":platform_strong_dill_linkable")
}
# Compiles the Dart/Flutter core libraries to kernel bytecode.
compile_platform("strong_platform") {
single_root_scheme = "org-dartlang-sdk"
single_root_base = rebase_path("../../../")
if (impeller_enable_3d) {
libraries_specification_uri =
"org-dartlang-sdk:///flutter/lib/snapshot/libraries_experimental.json"
} else {
libraries_specification_uri =
"org-dartlang-sdk:///flutter/lib/snapshot/libraries.json"
}
outputs = [
"$root_out_dir/flutter_patched_sdk/platform_strong.dill",
"$root_out_dir/flutter_patched_sdk/vm_outline_strong.dill",
]
pool = "//flutter/build/dart:dart_pool"
is_runtime_mode_release =
flutter_runtime_mode == "release" || flutter_runtime_mode == "jit_release"
args = [
"--enable-experiment=generic-metadata",
"--nnbd-agnostic",
"--target=flutter",
"-Ddart.vm.product=$is_runtime_mode_release",
"-Ddart.isVM=true",
"dart:core",
]
}
# Fuchsia's snapshot requires a different platform with extra dart: libraries.
group("kernel_platform_files") {
public_deps = [ ":strong_platform" ]
}