BUILD.gn 12.3 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

7 8 9 10 11 12 13 14 15 16 17 18 19
import("//third_party/dart/runtime/bin/io_sources.gni")
import("//third_party/dart/runtime/lib/async_sources.gni")
import("//third_party/dart/runtime/lib/collection_sources.gni")
import("//third_party/dart/runtime/lib/convert_sources.gni")
import("//third_party/dart/runtime/lib/core_sources.gni")
import("//third_party/dart/runtime/lib/developer_sources.gni")
import("//third_party/dart/runtime/lib/internal_sources.gni")
import("//third_party/dart/runtime/lib/isolate_sources.gni")
import("//third_party/dart/runtime/lib/math_sources.gni")
import("//third_party/dart/runtime/lib/mirrors_sources.gni")
import("//third_party/dart/runtime/lib/typed_data_sources.gni")

import("//third_party/dart/utils/generate_patch_sdk.gni")
20

21
if (is_fuchsia) {
22
  import("//build/dart/toolchain.gni")
23 24
  import("//topaz/public/dart-pkg/fuchsia/sdk_ext.gni")
  import("//topaz/public/dart-pkg/zircon/sdk_ext.gni")
25
  import("//topaz/public/lib/ui/flutter/sdk_ext/sdk_ext.gni")
26
}
27 28 29 30 31 32 33 34 35 36 37

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

38
if (is_fuchsia) {
R
Ryan Macnak 已提交
39 40
  action("generate_package_map") {
    dart_deps = [
41
      "//third_party/dart-pkg/git/flutter/packages/flutter:flutter",
42 43
      "//topaz/public/lib/app/dart:dart",
      "//topaz/public/lib/fidl/dart",
R
Ryan Macnak 已提交
44 45 46 47 48 49
    ]

    dot_packages_file = "$target_gen_dir/snapshot.packages"
    outputs = [
      dot_packages_file
    ]
50 51 52 53 54
    deps = []
    foreach(dep, dart_deps) {
      deps += [ "$dep($dart_toolchain)" ]
    }

R
Ryan Macnak 已提交
55 56 57 58 59 60 61 62 63 64 65
    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",
66
      rebase_path(dart_root_gen_dir),
R
Ryan Macnak 已提交
67 68 69 70 71 72 73 74 75
      "--package-name",
      "snapshot_root",
      "--depfile",
      rebase_path(depfile),
      "--deps",
    ] + dart_deps
  }
}

76
action("generate_snapshot_bin") {
77
  if (is_fuchsia) {
78
    snapshot_dart = "snapshot_fuchsia.dart"
R
Ryan Macnak 已提交
79 80 81 82 83 84 85 86
    # 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"
    }
87 88
  } else {
    snapshot_dart = "snapshot.dart"
R
Ryan Macnak 已提交
89
    snapshot_kind = "core"
90 91
  }

92
  deps = [
93
    ":generate_dart_ui",
94
    "//third_party/dart/runtime/bin:gen_snapshot($host_toolchain)",
95
  ]
96 97
  depfile = "$target_gen_dir/core_snapshot.d"

98
  inputs = [
99
             "//third_party/dart/runtime/tools/create_snapshot_bin.py",
100
             snapshot_dart,
J
Jason Simmons 已提交
101
           ] + dart_ui_files
102
  if (is_fuchsia) {
R
Ryan Macnak 已提交
103 104 105
    deps += [ ":generate_package_map" ]
    inputs += [ "fuchsia_compilation_trace.txt" ]
  }
106

107 108 109 110 111
  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"
112
  outputs = [
113 114 115 116
    vm_snapshot_data,
    vm_snapshot_instructions,
    isolate_snapshot_data,
    isolate_snapshot_instructions,
117 118 119 120 121
  ]

  rebased_dart_ui_path = rebase_path(dart_ui_path)

  gen_snapshot_dir =
122
      get_label_info("//third_party/dart/runtime/bin:gen_snapshot($host_toolchain)",
123
                     "root_out_dir")
124
  script = "//third_party/dart/runtime/tools/create_snapshot_bin.py"
125 126 127 128 129

  args = [
    "--executable",
    rebase_path("$gen_snapshot_dir/gen_snapshot"),
    "--script",
130
    rebase_path(snapshot_dart),
131
    "--snapshot_kind",
R
Ryan Macnak 已提交
132 133 134 135 136
    snapshot_kind,
    "--vm_flag",
    "--await_is_keyword",
    "--vm_flag",
    "--enable_mirrors=false",
137
    "--vm_output_bin",
138 139 140
    rebase_path(vm_snapshot_data, root_build_dir),
    "--vm_instructions_output_bin",
    rebase_path(vm_snapshot_instructions, root_build_dir),
141
    "--isolate_output_bin",
142 143 144
    rebase_path(isolate_snapshot_data, root_build_dir),
    "--isolate_instructions_output_bin",
    rebase_path(isolate_snapshot_instructions, root_build_dir),
145
    "--url_mapping=dart:ui,$rebased_dart_ui_path",
146 147
    "--vm_flag",
    "--dependencies=" + rebase_path(depfile),
148
  ]
149

R
Ryan Macnak 已提交
150 151 152 153 154 155 156 157 158 159 160 161 162
  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",
    ]
  }

163
  if (is_fuchsia) {
164 165 166
    inputs += zircon_sdk_ext_files + mozart_dart_sdk_ext_files
    zircon_path = rebase_path(zircon_sdk_ext_lib)
    fuchsia_path = rebase_path(fuchsia_sdk_ext_lib)
167 168
    mozart_internal_path = rebase_path(mozart_dart_sdk_ext_lib)
    args += [
169 170
      "--url_mapping=dart:zircon,$zircon_path",
      "--url_mapping=dart:fuchsia,$fuchsia_path",
171
      "--url_mapping=dart:mozart.internal,$mozart_internal_path",
R
Ryan Macnak 已提交
172 173 174 175
      "--packages",
      rebase_path("$target_gen_dir/snapshot.packages"),
      "--load_compilation_trace",
      rebase_path("fuchsia_compilation_trace.txt"),
176
    ]
177
  }
178 179
}

180 181 182 183 184 185 186 187 188 189 190 191
# 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
192
    script = "//third_party/dart/runtime/tools/bin_to_assembly.py"
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
    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") {
217 218 219
  deps = [
    ":generate_snapshot_bin",
  ]
220 221 222 223 224 225 226 227 228
  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",
229
  ]
230 231 232 233 234
  input = "$target_gen_dir/vm_snapshot_instructions.bin"
  output = "$target_gen_dir/vm_snapshot_instructions.S"
  symbol = "kDartVmSnapshotInstructions"
  executable = true
}
235

236 237 238
bin_to_assembly("isolate_snapshot_data_assembly") {
  deps = [
    ":generate_snapshot_bin",
239
  ]
240 241 242 243
  input = "$target_gen_dir/isolate_snapshot.bin"
  output = "$target_gen_dir/isolate_snapshot_data.S"
  symbol = "kDartIsolateCoreSnapshotData"
  executable = false
244 245
}

246 247 248
bin_to_assembly("isolate_snapshot_instructions_assembly") {
  deps = [
    ":generate_snapshot_bin",
249
  ]
250 251 252 253 254
  input = "$target_gen_dir/isolate_snapshot_instructions.bin"
  output = "$target_gen_dir/isolate_snapshot_instructions.S"
  symbol = "kDartIsolateCoreSnapshotInstructions"
  executable = true
}
255

256
source_set("snapshot") {
257
  deps = [
258 259 260 261 262 263 264 265 266 267
    ":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",
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

# 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
301
    script = "//third_party/dart/runtime/tools/concatenate_patches.py"
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
    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"
330
    deps = concatenation_target_names + ["//third_party/dart/runtime/vm:kernel_platform_files"]
331 332
    input_patches_dir = "$target_gen_dir/patches"
    patched_sdk_dir = "flutter_patched_sdk"
333 334 335
    outputs = [
        "$root_out_dir/${patched_sdk_dir}/lib/libraries.json",
    ]
336 337 338
  }
}

339
generate_vm_patched_sdk("flutter_patched_sdk") {
340 341 342
  libraries = [
    [
      "async",
343
      async_runtime_sources,
344
      "//third_party/dart/runtime/lib",
345 346 347
    ],
    [
      "collection",
348
      collection_runtime_sources,
349
      "//third_party/dart/runtime/lib",
350 351 352
    ],
    [
      "convert",
353
      convert_runtime_sources,
354
      "//third_party/dart/runtime/lib",
355 356 357
    ],
    [
      "core",
358
      core_runtime_sources,
359
      "//third_party/dart/runtime/lib",
360 361 362
    ],
    [
      "developer",
363
      developer_runtime_sources,
364
      "//third_party/dart/runtime/lib",
365 366 367
    ],
    [
      "internal",
368
      internal_runtime_sources,
369
      "//third_party/dart/runtime/lib",
370 371 372
    ],
    [
      "io",
373
      io_runtime_sources,
374
      "//third_party/dart/runtime/bin",
375 376 377
    ],
    [
      "isolate",
378
      isolate_runtime_sources,
379
      "//third_party/dart/runtime/lib",
380 381 382
    ],
    [
      "math",
383
      math_runtime_sources,
384
      "//third_party/dart/runtime/lib",
385
    ],
386 387
    [
      "mirrors",
388
      mirrors_runtime_sources,
389
      "//third_party/dart/runtime/lib",
390
    ],
391 392
    [
      "typed_data",
393
      typed_data_runtime_sources,
394
      "//third_party/dart/runtime/lib",
395 396 397
    ],
  ]
}
398

399
action("compile_non_strong_platform") {
400
  script = "//third_party/dart/tools/compile_platform.py"
401

402 403 404 405
  visibility = [
    ":kernel_platform_files"
  ]

406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424
  sources = [
    "$root_out_dir/flutter_patched_sdk/lib/libraries.json",
  ]

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

  inputs = []

  deps = [
    ":flutter_patched_sdk",
  ]

  depfile = "$root_out_dir/flutter_patched_sdk/platform.dill.d"

  args = [
            "--target=flutter",
425
            "dart:core"
426 427 428 429
         ] + rebase_path(sources, root_build_dir) +
         rebase_path(outputs, root_build_dir)
}

430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461
action("compile_platform") {
  script = "//third_party/dart/tools/compile_platform.py"

  visibility = [
    ":kernel_platform_files"
  ]
  
  sources = [
    "$root_out_dir/flutter_patched_sdk/lib/libraries.json",
  ]

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

  inputs = []

  deps = [
    ":flutter_patched_sdk",
  ]

  depfile = "$root_out_dir/flutter_patched_sdk/platform_strong.dill.d"

  args = [
            "--target=flutter",
            "--strong",
            "dart:core"
         ] + rebase_path(sources, root_build_dir) +
         rebase_path(outputs, root_build_dir)
}

462 463 464
group("kernel_platform_files") {
  public_deps = [
    ":compile_platform",
465
    ":compile_non_strong_platform",
466 467
  ]
}