blob: ee98f51d68708c54a3ab6e00b0eceb9ba7e4c72e [file] [log] [blame]
# 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/build/zip_bundle.gni")
import("//flutter/common/config.gni")
import("//flutter/lib/ui/dart_ui.gni")
import("//flutter/sky/tools/macos_snapshots.gni")
import("//third_party/dart/utils/compile_platform.gni")
group("generate_snapshot_bins") {
deps = [
":generate_snapshot_bin",
":kernel_platform_files",
]
if (host_os == "mac" && (target_cpu == "arm" || target_cpu == "arm64")) {
deps += [ ":create_arm_gen_snapshot" ]
}
if (host_os == "mac" && target_os == "mac") {
deps += [ ":create_macos_gen_snapshots" ]
}
if (target_cpu == "x64" || target_cpu == "arm64") {
deps +=
[ "//third_party/dart/runtime/bin:analyze_snapshot($host_toolchain)" ]
}
}
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 ]
}
}
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
}
if (host_os == "mac" && (target_cpu == "arm" || target_cpu == "arm64")) {
action("create_arm_gen_snapshot") {
host_output_dir = get_label_info(
"//third_party/dart/runtime/bin:gen_snapshot($host_toolchain)",
"root_out_dir")
clang_dir = rebase_path(host_output_dir, root_build_dir)
script = "//flutter/sky/tools/create_macos_gen_snapshots.py"
visibility = [ ":*" ]
deps = [ "//third_party/dart/runtime/bin:gen_snapshot($host_toolchain)" ]
args = [
"--dst",
rebase_path(host_output_dir),
"--clang-dir",
clang_dir,
]
if (target_cpu == "arm") {
args += [
"--armv7-out-dir",
rebase_path("$root_out_dir"),
]
outputs = [ "$host_output_dir/gen_snapshot_armv7" ]
} else {
args += [
"--arm64-out-dir",
rebase_path("$root_out_dir"),
]
outputs = [ "$host_output_dir/gen_snapshot_arm64" ]
}
}
}
if (host_os == "mac" && target_os == "mac") {
macos_gen_snapshots("create_macos_gen_snapshots") {
deps = [ ":generate_snapshot_bin" ]
arch = "$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")
}
compile_platform("strong_platform") {
single_root_scheme = "org-dartlang-sdk"
single_root_base = rebase_path("../../../")
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" ]
}
if (is_win) {
zip_bundle("archive_win_gen_snapshot") {
deps = [ "//third_party/dart/runtime/bin:gen_snapshot" ]
output = "$target_platform_name-$target_cpu-$flutter_runtime_mode/windows-x64.zip"
files = [
{
source = "$root_out_dir/gen_snapshot.exe"
destination = "gen_snapshot.exe"
},
]
}
}