BUILD.gn 9.2 KB
Newer Older
1 2 3 4
# Copyright 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

5
import("$flutter_root/lib/ui/dart_ui.gni")
6
import("//third_party/dart/utils/compile_platform.gni")
7
import("//third_party/dart/utils/generate_entry_points_json.gni")
8

9
if (is_fuchsia) {
10
  import("//build/dart/dart_library.gni")
11
  import("//build/dart/toolchain.gni")
12 13
  import("//topaz/public/dart-pkg/fuchsia/sdk_ext.gni")
  import("//topaz/public/dart-pkg/zircon/sdk_ext.gni")
14
  import("//topaz/public/lib/ui/flutter/sdk_ext/sdk_ext.gni")
15
}
16 17 18 19 20 21 22 23 24 25 26

bindings_output_dir = "$root_gen_dir/sky/bindings"

copy("generate_dart_ui") {
  sources = dart_ui_files

  outputs = [
    "$bindings_output_dir/dart_ui/{{source_file_part}}",
  ]
}

27
if (is_fuchsia) {
28 29 30 31
  dart_library("generate_package_map") {
    # The sole purpose of this target is to generate a .packages file.
    sources = []

32 33 34 35 36 37 38 39
    dot_packages_file = "$target_gen_dir/snapshot.packages"
    outputs = [
      dot_packages_file,
    ]
    deps = []
    foreach(dep, dart_deps) {
      deps += [ "$dep($dart_toolchain)" ]
    }
40 41 42

    disable_analysis = true

43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
    script = "//build/dart/gen_dot_packages.py"
    args = [
             "--out",
             rebase_path(dot_packages_file, root_build_dir),
             "--source-dir",
             rebase_path("."),
             "--root-build-dir",
             rebase_path(root_build_dir),
             "--root-gen-dir",
             rebase_path(dart_root_gen_dir),
             "--package-name",
             "snapshot_root",
             "--depfile",
             rebase_path(depfile),
             "--deps",
           ] + dart_deps
R
Ryan Macnak 已提交
59 60 61
  }
}

62
action("generate_snapshot_bin") {
63
  if (is_fuchsia) {
64
    snapshot_dart = "snapshot_fuchsia.dart"
65

R
Ryan Macnak 已提交
66 67 68 69 70 71 72 73
    # TODO(rmacnak): Fuchsia cross builds use the wrong Dart target
    # architecture, and have added steps that depend on this error for
    # reasonable build times (e.g., invoking the analyzer).
    if (target_cpu == host_cpu) {
      snapshot_kind = "core-jit"
    } else {
      snapshot_kind = "core"
    }
74 75
  } else {
    snapshot_dart = "snapshot.dart"
R
Ryan Macnak 已提交
76
    snapshot_kind = "core"
77 78
  }

79
  deps = [
80
    ":generate_dart_ui",
81
    "//third_party/dart/runtime/bin:gen_snapshot($host_toolchain)",
82
  ]
83 84
  depfile = "$target_gen_dir/core_snapshot.d"

85
  inputs = [
86
             "//third_party/dart/runtime/tools/create_snapshot_bin.py",
87
             snapshot_dart,
J
Jason Simmons 已提交
88
           ] + dart_ui_files
89
  if (is_fuchsia) {
R
Ryan Macnak 已提交
90 91 92
    deps += [ ":generate_package_map" ]
    inputs += [ "fuchsia_compilation_trace.txt" ]
  }
93

94 95 96 97 98
  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"
99
  outputs = [
100 101 102 103
    vm_snapshot_data,
    vm_snapshot_instructions,
    isolate_snapshot_data,
    isolate_snapshot_instructions,
104 105 106 107
  ]

  rebased_dart_ui_path = rebase_path(dart_ui_path)

108 109 110
  gen_snapshot_dir = get_label_info(
          "//third_party/dart/runtime/bin:gen_snapshot($host_toolchain)",
          "root_out_dir")
111
  script = "//third_party/dart/runtime/tools/create_snapshot_bin.py"
112 113 114 115 116

  args = [
    "--executable",
    rebase_path("$gen_snapshot_dir/gen_snapshot"),
    "--script",
117
    rebase_path(snapshot_dart),
118
    "--snapshot_kind",
R
Ryan Macnak 已提交
119 120 121 122 123
    snapshot_kind,
    "--vm_flag",
    "--await_is_keyword",
    "--vm_flag",
    "--enable_mirrors=false",
124
    "--vm_output_bin",
125 126 127
    rebase_path(vm_snapshot_data, root_build_dir),
    "--vm_instructions_output_bin",
    rebase_path(vm_snapshot_instructions, root_build_dir),
128
    "--isolate_output_bin",
129 130 131
    rebase_path(isolate_snapshot_data, root_build_dir),
    "--isolate_instructions_output_bin",
    rebase_path(isolate_snapshot_instructions, root_build_dir),
132
    "--url_mapping=dart:ui,$rebased_dart_ui_path",
133 134
    "--vm_flag",
    "--dependencies=" + rebase_path(depfile),
135
  ]
136

R
Ryan Macnak 已提交
137 138 139 140 141 142 143 144 145 146 147 148 149
  if (is_debug) {
    args += [
      "--vm_flag",
      "--enable_asserts",
      "--vm_flag",
      "--enable_type_checks",
      "--vm_flag",
      "--error_on_bad_type",
      "--vm_flag",
      "--error_on_bad_override",
    ]
  }

150
  if (is_fuchsia) {
151 152 153 154
    package_gen_dir = get_label_info(":bogus($dart_toolchain)",
          "target_gen_dir")
    package_file = "$package_gen_dir/generate_package_map.packages"
    inputs += zircon_sdk_ext_files + mozart_dart_sdk_ext_files + [package_file]
155 156
    zircon_path = rebase_path(zircon_sdk_ext_lib)
    fuchsia_path = rebase_path(fuchsia_sdk_ext_lib)
157 158
    mozart_internal_path = rebase_path(mozart_dart_sdk_ext_lib)
    args += [
159 160
      "--url_mapping=dart:zircon,$zircon_path",
      "--url_mapping=dart:fuchsia,$fuchsia_path",
161
      "--url_mapping=dart:mozart.internal,$mozart_internal_path",
R
Ryan Macnak 已提交
162
      "--packages",
163
      rebase_path(package_file),
R
Ryan Macnak 已提交
164 165
      "--load_compilation_trace",
      rebase_path("fuchsia_compilation_trace.txt"),
166
    ]
167
  }
168 169
}

170 171 172 173 174 175 176 177 178 179 180 181
# 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.output), "Must define output assembly file")
  assert(defined(invoker.symbol), "Must define symbol name")
  assert(defined(invoker.executable), "Must define boolean executable")

  action(target_name) {
    deps = invoker.deps
182
    script = "//third_party/dart/runtime/tools/bin_to_assembly.py"
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
    args = [
      "--input",
      rebase_path(invoker.input),
      "--output",
      rebase_path(invoker.output),
      "--symbol_name",
      invoker.symbol,
      "--target_os",
      current_os,
    ]
    if (invoker.executable) {
      args += [ "--executable" ]
    }
    inputs = [
      script,
      invoker.input,
    ]
    outputs = [
      invoker.output,
    ]
  }
}

bin_to_assembly("vm_snapshot_data_assembly") {
207 208 209
  deps = [
    ":generate_snapshot_bin",
  ]
210 211 212 213 214 215 216 217 218
  input = "$target_gen_dir/vm_isolate_snapshot.bin"
  output = "$target_gen_dir/vm_snapshot_data.S"
  symbol = "kDartVmSnapshotData"
  executable = false
}

bin_to_assembly("vm_snapshot_instructions_assembly") {
  deps = [
    ":generate_snapshot_bin",
219
  ]
220 221 222 223 224
  input = "$target_gen_dir/vm_snapshot_instructions.bin"
  output = "$target_gen_dir/vm_snapshot_instructions.S"
  symbol = "kDartVmSnapshotInstructions"
  executable = true
}
225

226 227 228
bin_to_assembly("isolate_snapshot_data_assembly") {
  deps = [
    ":generate_snapshot_bin",
229
  ]
230 231
  input = "$target_gen_dir/isolate_snapshot.bin"
  output = "$target_gen_dir/isolate_snapshot_data.S"
232
  symbol = "kDartIsolateSnapshotData"
233
  executable = false
234 235
}

236 237 238
bin_to_assembly("isolate_snapshot_instructions_assembly") {
  deps = [
    ":generate_snapshot_bin",
239
  ]
240 241
  input = "$target_gen_dir/isolate_snapshot_instructions.bin"
  output = "$target_gen_dir/isolate_snapshot_instructions.S"
242
  symbol = "kDartIsolateSnapshotInstructions"
243 244
  executable = true
}
245

246
source_set("snapshot") {
247
  deps = [
248 249 250 251 252 253 254 255 256 257
    ":isolate_snapshot_data_assembly",
    ":isolate_snapshot_instructions_assembly",
    ":vm_snapshot_data_assembly",
    ":vm_snapshot_instructions_assembly",
  ]
  sources = [
    "$target_gen_dir/isolate_snapshot_data.S",
    "$target_gen_dir/isolate_snapshot_instructions.S",
    "$target_gen_dir/vm_snapshot_data.S",
    "$target_gen_dir/vm_snapshot_instructions.S",
258 259
  ]
}
260

261
compile_platform("non_strong_platform") {
262
  sources = [
263
    "libraries.json",
264 265 266 267 268 269 270 271
  ]

  outputs = [
    "$root_out_dir/flutter_patched_sdk/platform.dill",
    "$root_out_dir/flutter_patched_sdk/vm_outline.dill",
  ]

  args = [
272 273 274
    "--target=flutter",
    "dart:core",
  ]
275 276
}

277
compile_platform("strong_platform") {
278
  sources = [
279
    "libraries.json",
280 281 282 283 284 285 286 287
  ]

  outputs = [
    "$root_out_dir/flutter_patched_sdk/platform_strong.dill",
    "$root_out_dir/flutter_patched_sdk/vm_outline_strong.dill",
  ]

  args = [
288 289 290 291
    "--target=flutter",
    "--strong",
    "dart:core",
  ]
292 293
}

294 295
group("kernel_platform_files") {
  public_deps = [
296 297
    ":non_strong_platform",
    ":strong_platform",
298 299
  ]
}
300 301 302

generate_entry_points_json_with_gen_snapshot("entry_points_json") {
  input = "$flutter_root/lib/snapshot/snapshot.dart"
303
  output = "$root_out_dir/dart_entry_points/entry_points.json"
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
  dart_ui = "$flutter_root/lib/ui/ui.dart"
  vmservice_io = "//third_party/dart/runtime/bin/vmservice/vmservice_io.dart"
  dart_vm_entry_points_txt = "$flutter_root/runtime/dart_vm_entry_points.txt"
  dart_io_entries_txt = "//third_party/dart/runtime/bin/dart_io_entries.txt"

  extra_inputs = [
    dart_ui,
    vmservice_io,
    dart_vm_entry_points_txt,
    dart_io_entries_txt,
  ]

  extra_args = [
    "--await_is_keyword",
    "--url_mapping=dart:ui," + rebase_path(dart_ui),
    "--url_mapping=dart:vmservice_io," + rebase_path(vmservice_io),
    "--causal_async_stacks",
    "--embedder_entry_points_manifest=" + rebase_path(dart_vm_entry_points_txt),
    "--embedder_entry_points_manifest=" + rebase_path(dart_io_entries_txt),
  ]
}

copy_entry_points_extra_json("entry_points_extra_json") {
327
  output = "$root_out_dir/dart_entry_points/entry_points_extra.json"
328 329 330 331 332 333 334 335
}

group("entry_points_json_files") {
  public_deps = [
    ":entry_points_json",
    ":entry_points_extra_json",
  ]
}