BUILD.gn 9.8 KB
Newer Older
1 2 3 4 5
# 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.

import("//flutter/lib/ui/dart_ui.gni")
6

7 8 9
import("//dart/runtime/vm/gypi_contents.gni")
import("//dart/utils/generate_patch_sdk.gni")

10
if (is_fuchsia) {
11
  import("//apps/mozart/lib/flutter/sdk_ext/sdk_ext.gni")
12 13
  import("//lib/fidl/dart/sdk_ext/sdk_ext.gni")
}
14 15 16 17 18 19 20 21 22 23 24

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}}",
  ]
}

25
if (is_fuchsia) {
R
Ryan Macnak 已提交
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
  action("generate_package_map") {
    dart_deps = [
      "//lib/fidl/dart:dart",
      "//lib/flutter/packages/flutter:flutter",
      "//lib/widgets/packages/widgets:lib.widgets",
      "//application/lib/app/dart:dart",
    ]

    dot_packages_file = "$target_gen_dir/snapshot.packages"
    outputs = [
      dot_packages_file
    ]
    deps = dart_deps
    depfile = "$dot_packages_file.d"

    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(root_gen_dir),
      "--package-name",
      "snapshot_root",
      "--depfile",
      rebase_path(depfile),
      "--deps",
    ] + dart_deps
  }
}

60
action("generate_snapshot_bin") {
61
  if (is_fuchsia) {
62
    snapshot_dart = "snapshot_fuchsia.dart"
R
Ryan Macnak 已提交
63 64 65 66 67 68 69 70
    # 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"
    }
71 72
  } else {
    snapshot_dart = "snapshot.dart"
R
Ryan Macnak 已提交
73
    snapshot_kind = "core"
74 75
  }

76
  deps = [
77 78
    ":generate_dart_ui",
    "//dart/runtime/bin:gen_snapshot($dart_host_toolchain)",
79
  ]
80 81
  depfile = "$target_gen_dir/core_snapshot.d"

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

91 92 93 94 95
  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"
96
  outputs = [
97 98 99 100
    vm_snapshot_data,
    vm_snapshot_instructions,
    isolate_snapshot_data,
    isolate_snapshot_instructions,
101 102 103 104 105 106 107 108 109 110 111 112 113
  ]

  rebased_dart_ui_path = rebase_path(dart_ui_path)

  gen_snapshot_dir =
      get_label_info("//dart/runtime/bin:gen_snapshot($dart_host_toolchain)",
                     "root_out_dir")
  script = "//dart/runtime/tools/create_snapshot_bin.py"

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

R
Ryan Macnak 已提交
136 137 138 139 140 141 142 143 144 145 146 147 148
  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",
    ]
  }

149
  if (is_fuchsia) {
150
    inputs += fidl_dart_sdk_ext_files + mozart_dart_sdk_ext_files
151
    fidl_internal_path = rebase_path(fidl_dart_sdk_ext_lib)
152 153 154 155
    mozart_internal_path = rebase_path(mozart_dart_sdk_ext_lib)
    args += [
      "--url_mapping=dart:fidl.internal,$fidl_internal_path",
      "--url_mapping=dart:mozart.internal,$mozart_internal_path",
R
Ryan Macnak 已提交
156 157 158 159
      "--packages",
      rebase_path("$target_gen_dir/snapshot.packages"),
      "--load_compilation_trace",
      rebase_path("fuchsia_compilation_trace.txt"),
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
# 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
    script = "//dart/runtime/tools/bin_to_assembly.py"
    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") {
201 202 203
  deps = [
    ":generate_snapshot_bin",
  ]
204 205 206 207 208 209 210 211 212
  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",
213
  ]
214 215 216 217 218
  input = "$target_gen_dir/vm_snapshot_instructions.bin"
  output = "$target_gen_dir/vm_snapshot_instructions.S"
  symbol = "kDartVmSnapshotInstructions"
  executable = true
}
219

220 221 222
bin_to_assembly("isolate_snapshot_data_assembly") {
  deps = [
    ":generate_snapshot_bin",
223
  ]
224 225 226 227
  input = "$target_gen_dir/isolate_snapshot.bin"
  output = "$target_gen_dir/isolate_snapshot_data.S"
  symbol = "kDartIsolateCoreSnapshotData"
  executable = false
228 229
}

230 231 232
bin_to_assembly("isolate_snapshot_instructions_assembly") {
  deps = [
    ":generate_snapshot_bin",
233
  ]
234 235 236 237 238
  input = "$target_gen_dir/isolate_snapshot_instructions.bin"
  output = "$target_gen_dir/isolate_snapshot_instructions.S"
  symbol = "kDartIsolateCoreSnapshotInstructions"
  executable = true
}
239

240
source_set("snapshot") {
241
  deps = [
242 243 244 245 246 247 248 249 250 251
    ":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",
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

# Generate flutter_patched_sdk

template("process_library_source") {
  assert(defined(invoker.libsources), "Need libsources in $target_name")
  assert(defined(invoker.output), "Need output in $target_name")
  action(target_name) {
    deps = [
      ":generate_dart_ui",
    ]

    visibility = [ ":*" ]  # Only targets in this file can see this.
    libsources = invoker.libsources

    script = invoker.script
    inputs = invoker.inputs + libsources
    outputs = [
      invoker.output,
    ]
    args = invoker.args + rebase_path(libsources, root_build_dir)
  }
}

template("concatenate_patch") {
  assert(defined(invoker.libsources), "Need a sources in $target_name")
  assert(defined(invoker.output), "Need an output in $target_name")

  process_library_source(target_name) {
    libsources = invoker.libsources
    inputs = []
    output = invoker.output
    script = "//dart/runtime/tools/concatenate_patches.py"
    args = [
      "--output",
      rebase_path(output, root_build_dir),
    ]
  }
}

template("generate_vm_patched_sdk") {
  assert(defined(invoker.libraries), "Need libraries in $target_name")

  concatenation_target_names = []

  # Concatenate vm library patches.
  foreach(library, invoker.libraries) {
    name = library[0]

    target_output = "$target_gen_dir/patches/${name}_patch.dart"
    concatenate_patch("concatenate_${name}_patch") {
      libsources = rebase_path(library[1], ".", library[2])
      output = target_output
    }
    concatenation_target_names += [ ":concatenate_${name}_patch" ]
  }

  # Build the patched sdk out of the concatenated patches and the special
  # libraries.
  generate_patched_sdk(target_name) {
    mode = "flutter"
    deps = concatenation_target_names + ["//dart/runtime/vm:patched_sdk"]
    input_patches_dir = "$target_gen_dir/patches"
    patched_sdk_dir = "flutter_patched_sdk"
  }
}

320
generate_vm_patched_sdk("flutter_patched_sdk") {
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
  libraries = [
    [
      "async",
      processed_gypis.async_runtime_sources,
      "//dart/runtime/lib",
    ],
    [
      "collection",
      processed_gypis.collection_runtime_sources,
      "//dart/runtime/lib",
    ],
    [
      "convert",
      processed_gypis.convert_runtime_sources,
      "//dart/runtime/lib",
    ],
    [
      "core",
      processed_gypis.core_runtime_sources,
      "//dart/runtime/lib",
    ],
    [
      "developer",
      processed_gypis.developer_runtime_sources,
      "//dart/runtime/lib",
    ],
    [
      "internal",
      processed_gypis.internal_runtime_sources,
      "//dart/runtime/lib",
    ],
    [
      "io",
      processed_gypis.bin_io_sources,
      "//dart/runtime/bin",
    ],
    [
      "isolate",
      processed_gypis.isolate_runtime_sources,
      "//dart/runtime/lib",
    ],
    [
      "math",
      processed_gypis.math_runtime_sources,
      "//dart/runtime/lib",
    ],
    [
      "typed_data",
      processed_gypis.typed_data_runtime_sources,
      "//dart/runtime/lib",
    ],
  ]
}