|
2 | 2 | # Use of this source code is governed by a BSD-style license that can be |
3 | 3 | # found in the LICENSE file. |
4 | 4 |
|
5 | | -# This file has rules for making Dart packages and Dart-based Mojo applications. |
6 | | -# The entrypoint is the dart_pkg rule. |
| 5 | +# This file has rules for making Dart packages and snapshots. |
7 | 6 |
|
| 7 | +import("//build/compiled_action.gni") |
8 | 8 | import("//build/module_args/dart.gni") |
| 9 | +import("//flutter/common/config.gni") |
| 10 | +import("//third_party/dart/build/dart/dart_action.gni") |
| 11 | + |
| 12 | +# Creates a dart kernel (dill) file suitable for use with gen_snapshot, as well |
| 13 | +# as the app-jit, aot-elf, or aot-assembly snapshot for Android or iOS. |
| 14 | +# |
| 15 | +# Invoker must supply dart_main and package_config. Invoker may optionally |
| 16 | +# supply aot as a boolean and product as a boolean. |
| 17 | +template("dart_snapshot") { |
| 18 | + assert(!is_fuchsia) |
| 19 | + assert(defined(invoker.main_dart), "main_dart is a required parameter.") |
| 20 | + assert(defined(invoker.package_config), |
| 21 | + "package_config is a required parameter.") |
| 22 | + |
| 23 | + kernel_target = "_${target_name}_kernel" |
| 24 | + snapshot_target = "_${target_name}_snapshot" |
| 25 | + is_aot = |
| 26 | + flutter_runtime_mode == "profile" || flutter_runtime_mode == "release" |
| 27 | + |
| 28 | + kernel_output = "$target_gen_dir/kernel_blob.bin" |
| 29 | + |
| 30 | + prebuilt_dart_action(kernel_target) { |
| 31 | + script = "//flutter/flutter_frontend_server/bin/starter.dart" |
| 32 | + |
| 33 | + main_dart = rebase_path(invoker.main_dart) |
| 34 | + package_config = rebase_path(invoker.package_config) |
| 35 | + flutter_patched_sdk = rebase_path("$root_out_dir/flutter_patched_sdk") |
| 36 | + |
| 37 | + deps = [ "//flutter/lib/snapshot:strong_platform" ] |
| 38 | + |
| 39 | + inputs = [ |
| 40 | + main_dart, |
| 41 | + package_config, |
| 42 | + ] |
| 43 | + |
| 44 | + outputs = [ kernel_output ] |
| 45 | + |
| 46 | + depfile = "$kernel_output.d" |
| 47 | + abs_depfile = rebase_path(depfile) |
| 48 | + rebased_output = rebase_path(kernel_output, root_build_dir) |
| 49 | + vm_args = [ |
| 50 | + "--depfile=$abs_depfile", |
| 51 | + "--depfile_output_filename=$rebased_output", |
| 52 | + "--disable-dart-dev", |
| 53 | + ] |
| 54 | + |
| 55 | + args = [ |
| 56 | + "--packages=" + rebase_path(package_config), |
| 57 | + "--target=flutter", |
| 58 | + "--sdk-root=" + flutter_patched_sdk, |
| 59 | + "--output-dill=" + rebase_path(kernel_output), |
| 60 | + ] |
| 61 | + |
| 62 | + if (is_aot) { |
| 63 | + args += [ |
| 64 | + "--aot", |
| 65 | + "--tfa", |
| 66 | + ] |
| 67 | + } else { |
| 68 | + # --no-link-platform is only valid when --aot isn't specified |
| 69 | + args += [ "--no-link-platform" ] |
| 70 | + } |
| 71 | + |
| 72 | + if (defined(invoker.product) && invoker.product) { |
| 73 | + # Setting this flag in a non-product release build for AOT (a "profile" |
| 74 | + # build) causes the vm service isolate code to be tree-shaken from an app. |
| 75 | + # See the pragma on the entrypoint here: |
| 76 | + # |
| 77 | + # https://github.com/dart-lang/sdk/blob/master/sdk/lib/_internal/vm/bin/vmservice_io.dart#L240 |
| 78 | + # |
| 79 | + # Also, this define excludes debugging and profiling code from Flutter. |
| 80 | + args += [ "-Ddart.vm.product=true" ] |
| 81 | + } else { |
| 82 | + if (!is_debug) { |
| 83 | + # The following define excludes debugging code from Flutter. |
| 84 | + args += [ "-Ddart.vm.profile=true" ] |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + args += [ rebase_path(main_dart) ] |
| 89 | + } |
| 90 | + |
| 91 | + compiled_action(snapshot_target) { |
| 92 | + if (target_cpu == "x86" && host_os == "linux") { |
| 93 | + # By default Dart will create a 32-bit gen_snapshot host binary if the target |
| 94 | + # platform is 32-bit. Override this to create a 64-bit gen_snapshot for x86 |
| 95 | + # targets because some host platforms may not support 32-bit binaries. |
| 96 | + tool = "//third_party/dart/runtime/bin:gen_snapshot_host_targeting_host" |
| 97 | + toolchain = "//build/toolchain/$host_os:clang_x64" |
| 98 | + } else { |
| 99 | + tool = "//third_party/dart/runtime/bin:gen_snapshot" |
| 100 | + } |
| 101 | + |
| 102 | + inputs = [ kernel_output ] |
| 103 | + deps = [ ":$kernel_target" ] |
| 104 | + outputs = [] |
| 105 | + |
| 106 | + args = [ "--lazy_async_stacks" ] |
| 107 | + |
| 108 | + if (is_debug && flutter_runtime_mode != "profile" && |
| 109 | + flutter_runtime_mode != "release" && |
| 110 | + flutter_runtime_mode != "jit_release") { |
| 111 | + args += [ "--enable_asserts" ] |
| 112 | + } |
| 113 | + |
| 114 | + if (is_aot) { |
| 115 | + args += [ "--deterministic" ] |
| 116 | + if (is_ios) { |
| 117 | + snapshot_assembly = "$target_gen_dir/ios/snapshot_assembly.S" |
| 118 | + outputs += [ snapshot_assembly ] |
| 119 | + args += [ |
| 120 | + "--snapshot_kind=app-aot-assembly", |
| 121 | + "--assembly=" + rebase_path(snapshot_assembly), |
| 122 | + ] |
| 123 | + } else if (is_android) { |
| 124 | + libapp = "$target_gen_dir/android/libs/$android_app_abi/libapp.so" |
| 125 | + outputs += [ libapp ] |
| 126 | + args += [ |
| 127 | + "--snapshot_kind=app-aot-elf", |
| 128 | + "--elf=" + rebase_path(libapp), |
| 129 | + ] |
| 130 | + } else { |
| 131 | + assert(false) |
| 132 | + } |
| 133 | + } else { |
| 134 | + deps += [ "//flutter/lib/snapshot:generate_snapshot_bin" ] |
| 135 | + vm_snapshot_data = |
| 136 | + "$root_gen_dir/flutter/lib/snapshot/vm_isolate_snapshot.bin" |
| 137 | + snapshot_data = "$root_gen_dir/flutter/lib/snapshot/isolate_snapshot.bin" |
| 138 | + isolate_snapshot_data = "$target_gen_dir/isolate_snapshot_data" |
| 139 | + isolate_snapshot_instructions = "$target_gen_dir/isolate_snapshot_instr" |
| 140 | + |
| 141 | + inputs += [ |
| 142 | + vm_snapshot_data, |
| 143 | + snapshot_data, |
| 144 | + ] |
| 145 | + |
| 146 | + outputs += [ |
| 147 | + isolate_snapshot_data, |
| 148 | + isolate_snapshot_instructions, |
| 149 | + ] |
| 150 | + args += [ |
| 151 | + "--snapshot_kind=app-jit", |
| 152 | + "--load_vm_snapshot_data=" + rebase_path(vm_snapshot_data), |
| 153 | + "--load_isolate_snapshot_data=" + rebase_path(snapshot_data), |
| 154 | + "--isolate_snapshot_data=" + rebase_path(isolate_snapshot_data), |
| 155 | + "--isolate_snapshot_instructions=" + |
| 156 | + rebase_path(isolate_snapshot_instructions), |
| 157 | + ] |
| 158 | + } |
| 159 | + |
| 160 | + args += [ rebase_path(kernel_output) ] |
| 161 | + } |
| 162 | + |
| 163 | + group(target_name) { |
| 164 | + public_deps = [ |
| 165 | + ":$kernel_target", |
| 166 | + ":$snapshot_target", |
| 167 | + ] |
| 168 | + } |
| 169 | +} |
9 | 170 |
|
10 | 171 | template("dart_pkg_helper") { |
11 | 172 | assert(defined(invoker.package_name)) |
|
0 commit comments