Skip to content

Commit

Permalink
AOT for Fuchsia. (flutter#3570)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmacnak-google authored Apr 11, 2017
1 parent 1fed16f commit 1084a83
Show file tree
Hide file tree
Showing 22 changed files with 626 additions and 328 deletions.
8 changes: 3 additions & 5 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,23 @@ group("flutter") {
testonly = true

deps = [
"//flutter/sky",
"//flutter/lib/snapshot:generate_snapshot_bin",
"//flutter/sky",
]

if (is_fuchsia) {
deps += [
"//flutter/content_handler",
"//flutter/content_handler:aot_content_handler",
"//flutter/examples",
"//flutter/flow",
"//flutter/runtime",
]
}

# If on the host, compile all unittests targets.
if (current_toolchain == host_toolchain) {
if (is_mac) {
deps += [
"//flutter/shell/platform/darwin:flutter_channels_unittests",
]
deps += [ "//flutter/shell/platform/darwin:flutter_channels_unittests" ]
}
deps += [
"//flutter/fml:fml_unittests",
Expand Down
59 changes: 59 additions & 0 deletions build/aot_snapshot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env python
# 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 argparse
import subprocess
import os
import sys


def main():
parser = argparse.ArgumentParser(description='Snapshot a Flutter application')

parser.add_argument('--snapshotter-path', type=str, required=True,
help='The Flutter snapshotter')

parser.add_argument('--main-dart', type=str, required=True,
help='The main.dart file to use')

parser.add_argument('--url-mapping', type=str, action='append',
help='The main.dart file to use')
parser.add_argument('--entry-points-manifest', type=str, action='append',
help='The main.dart file to use')

parser.add_argument('--packages', type=str, required=True,
help='The package map to use')
parser.add_argument('--assembly', type=str, required=True,
help='Where to output application assembly')
parser.add_argument('--depfile', type=str, required=True,
help='Where to output dependency information')
parser.add_argument('--root-build-dir', type=str, required=True,
help='The root build dir for --depfile and --snapshot')

args = parser.parse_args()

cmd = [
args.snapshotter_path,
"--enable_mirrors=false",
"--await_is_keyword",
"--assert_initializer",
'--snapshot_kind=app-aot-assembly',
'--packages=%s' % args.packages,
'--assembly=%s' % args.assembly,
'--dependencies=%s' % args.depfile,
]
for url_mapping in args.url_mapping:
cmd.append("--url_mapping=" + url_mapping)
for entry_points_manifest in args.entry_points_manifest:
cmd.append("--embedder_entry_points_manifest=" + entry_points_manifest)
cmd.append(args.main_dart)

result = subprocess.call(cmd, cwd=args.root_build_dir)

return result


if __name__ == '__main__':
sys.exit(main())
204 changes: 192 additions & 12 deletions build/flutter_app.gni
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
assert(is_fuchsia)

import("//build/dart/dart_package.gni")
import("//flutter/lib/ui/dart_ui.gni")
import("//apps/mozart/lib/flutter/sdk_ext/sdk_ext.gni")
import("//lib/fidl/dart/sdk_ext/sdk_ext.gni")

# Defines a Flutter application
#
Expand Down Expand Up @@ -58,14 +61,17 @@ template("flutter_app") {
bundle_name = "${target_name}.flx"
}

flutter_snapshot_label = "//dart/runtime/bin:gen_snapshot($host_toolchain)"
flutter_snapshot_dir = get_label_info(flutter_snapshot_label, "root_out_dir")
flutter_snapshot = "$flutter_snapshot_dir/gen_snapshot"
gen_snapshot_label = "//dart/runtime/bin:gen_snapshot($host_toolchain)"
gen_snapshot_dir = get_label_info(gen_snapshot_label, "root_out_dir")
gen_snapshot = "$gen_snapshot_dir/gen_snapshot"

flutter_core_snapshot_label = "//flutter/lib/snapshot:generate_snapshot_bin"
flutter_core_snapshot_gen_dir = get_label_info(flutter_core_snapshot_label, "target_gen_dir")
flutter_core_snapshot_vm_data = "$flutter_core_snapshot_gen_dir/vm_isolate_snapshot.bin"
flutter_core_snapshot_isolate_data = "$flutter_core_snapshot_gen_dir/isolate_snapshot.bin"
flutter_core_snapshot_gen_dir =
get_label_info(flutter_core_snapshot_label, "target_gen_dir")
flutter_core_snapshot_vm_data =
"$flutter_core_snapshot_gen_dir/vm_isolate_snapshot.bin"
flutter_core_snapshot_isolate_data =
"$flutter_core_snapshot_gen_dir/isolate_snapshot.bin"

flutter_root = "//lib/flutter"
flutter_tools_label = "$flutter_root/packages/flutter_tools($host_toolchain)"
Expand All @@ -80,9 +86,9 @@ template("flutter_app") {

main_dart = invoker.main_dart

flutter_snapshot_name = target_name + "_snapshot"
script_snapshot_label = target_name + "_snapshot"

action(flutter_snapshot_name) {
action(script_snapshot_label) {
depfile = snapshot_depfile

inputs = [
Expand All @@ -97,11 +103,11 @@ template("flutter_app") {
sources = invoker.sources
}

script = "//flutter/build/snapshot.py"
script = "//flutter/build/script_snapshot.py"

args = [
"--snapshotter-path",
rebase_path(flutter_snapshot),
rebase_path(gen_snapshot),
"--vm-snapshot-data",
rebase_path(flutter_core_snapshot_vm_data),
"--isolate-snapshot-data",
Expand All @@ -120,8 +126,8 @@ template("flutter_app") {

deps = [
":$dart_package_name",
flutter_snapshot_label,
flutter_core_snapshot_label,
gen_snapshot_label,
]

if (defined(invoker.deps)) {
Expand Down Expand Up @@ -164,6 +170,8 @@ template("flutter_app") {
rebase_path(root_build_dir),
"--depfile",
rebase_path(bundle_depfile),
"--interpreter",
"file:///system/apps/flutter_runner",
]
if (defined(invoker.manifest)) {
args += [
Expand All @@ -173,7 +181,179 @@ template("flutter_app") {
}

deps = [
":$flutter_snapshot_name",
":$script_snapshot_label",
flutter_tools_label,
]
}
}

template("flutter_aot_app") {
assert(defined(invoker.main_dart), "Must define main_dart")

dart_package_name = target_name + "_dart_package"

dart_package(dart_package_name) {
forward_variables_from(invoker,
[
"analysis_options",
"deps",
"disable_analysis",
"source_dir",
])
if (defined(invoker.package_name)) {
package_name = invoker.package_name
} else {
infer_package_name = true
}
}

if (defined(invoker.output_name)) {
bundle_name = invoker.output_name
} else {
bundle_name = "${target_name}.flx"
}

gen_snapshot_label = "//dart/runtime/bin:gen_snapshot($host_toolchain)"
gen_snapshot_dir = get_label_info(gen_snapshot_label, "root_out_dir")
gen_snapshot = "$gen_snapshot_dir/gen_snapshot"

flutter_root = "//lib/flutter"
flutter_tools_label = "$flutter_root/packages/flutter_tools($host_toolchain)"
flutter_tools_out_dir = get_label_info(flutter_tools_label, "root_out_dir")
flutter_tools_bin = "$flutter_tools_out_dir/dart-tools/flutter_tools"

dot_packages = "$target_gen_dir/$dart_package_name.packages"
bundle_path = "$root_out_dir/$bundle_name"
bundle_depfile = "$target_gen_dir/$bundle_name.d"
assembly_path = "$target_gen_dir/$target_name.S"
assembly_depfile = "${assembly_path}.d"

main_dart = invoker.main_dart

assembly_label = target_name + "_assembly"

action(assembly_label) {
depfile = assembly_depfile

inputs = [ main_dart ] + fidl_dart_sdk_ext_files + mozart_dart_sdk_ext_files

outputs = [
assembly_path,
]

if (defined(invoker.sources)) {
sources = invoker.sources
}

script = "//flutter/build/aot_snapshot.py"
args = [
"--snapshotter-path",
rebase_path(gen_snapshot),
"--assembly",
rebase_path(assembly_path, root_build_dir),
"--packages",
rebase_path(dot_packages),
"--depfile",
rebase_path(assembly_depfile),

"--url-mapping",
"dart:ui," + rebase_path(dart_ui_path),
"--url-mapping",
"dart:fidl.internal," + rebase_path(fidl_dart_sdk_ext_lib),
"--url-mapping",
"dart:mozart.internal," + rebase_path(mozart_dart_sdk_ext_lib),
"--url-mapping",
"dart:vmservice_sky," + rebase_path(
"$root_gen_dir/dart-pkg/sky_engine/sdk_ext/vmservice_io.dart"),

"--entry-points-manifest",
rebase_path("//flutter/runtime/dart_vm_entry_points.txt"),
"--entry-points-manifest",
rebase_path("//flutter/runtime/dart_vm_entry_points_fuchsia.txt"),

"--main-dart",
rebase_path(main_dart),
"--root-build-dir",
rebase_path(root_build_dir),
]

deps = [
":$dart_package_name",
"//flutter/lib/snapshot:generate_dart_ui",
gen_snapshot_label,
]

if (defined(invoker.deps)) {
deps += invoker.deps
}
}

dylib_label = target_name + "_dylib"

outer_target_name = target_name
shared_library(dylib_label) {
deps = [
":$assembly_label",
]
sources = [
assembly_path,
]
cflags = [
"-nostdlib",
"-nostartfiles",
]
output_name = outer_target_name
}

dylib_path = "$root_out_dir/lib.unstripped/lib$target_name.so"

action(target_name) {
depfile = bundle_depfile

inputs = [
dylib_path,
]
if (defined(invoker.manifest)) {
inputs += [ rebase_path(invoker.manifest) ]
}

outputs = [
bundle_path,
]

script = "//flutter/build/package.py"

args = [
"--flutter-root",
rebase_path(flutter_root),
"--flutter-tools",
rebase_path(flutter_tools_bin),
"--working-dir",
rebase_path("$target_gen_dir/build"),
"--app-dir",
rebase_path("."),
"--packages",
rebase_path(dot_packages),
"--output-file",
rebase_path(bundle_path),
"--dylib",
rebase_path(dylib_path),
"--build-root",
rebase_path(root_build_dir),
"--depfile",
rebase_path(bundle_depfile),
"--interpreter",
"file:///system/apps/flutter_aot_runner",
]
if (defined(invoker.manifest)) {
args += [
"--manifest",
rebase_path(invoker.manifest),
]
}

deps = [
":$dylib_label",
flutter_tools_label,
]
}
Expand Down
13 changes: 10 additions & 3 deletions build/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@ def main():
help='The root of the app')
parser.add_argument('--packages', type=str, required=True,
help='The package map to use')
parser.add_argument('--snapshot', type=str, required=True,
parser.add_argument('--snapshot', type=str, required=False,
help='Path to application snapshot')
parser.add_argument('--dylib', type=str, required=False,
help='Path to AOT dylib')
parser.add_argument('--output-file', type=str, required=True,
help='Where to output application bundle')
parser.add_argument('--build-root', type=str, required=True,
help='The build\'s root directory')
parser.add_argument('--depfile', type=str, required=True,
help='Where to output application bundle dependencies')
parser.add_argument('--interpreter', type=str, required=True,
help='')
parser.add_argument('--manifest', type=str, help='The application manifest')

args = parser.parse_args()
Expand All @@ -41,12 +45,15 @@ def main():
args.flutter_tools,
'--working-dir=%s' % args.working_dir,
'--packages=%s' % args.packages,
'--snapshot=%s' % args.snapshot,
'--output-file=%s' % args.output_file,
'--header=#!fuchsia file:///system/apps/flutter_runner',
'--header=#!fuchsia %s' % args.interpreter,
'--build-root=%s' % args.build_root,
'--depfile=%s' % args.depfile,
]
if args.snapshot != None:
call_args.append('--snapshot=%s' % args.snapshot)
if args.dylib != None:
call_args.append('--dylib=%s' % args.dylib)
if 'manifest' in args:
call_args.append('--manifest=%s' % args.manifest)

Expand Down
File renamed without changes.
Loading

0 comments on commit 1084a83

Please sign in to comment.