@@ -6,10 +6,13 @@ import 'dart:async';
6
6
7
7
import 'package:meta/meta.dart' ;
8
8
9
+ import '../artifacts.dart' ;
9
10
import '../asset.dart' ;
10
11
import '../base/common.dart' ;
11
12
import '../base/file_system.dart' ;
12
13
import '../base/io.dart' ;
14
+ import '../base/logger.dart' ;
15
+ import '../base/process.dart' ;
13
16
import '../base/utils.dart' ;
14
17
import '../build_info.dart' ;
15
18
import '../bundle.dart' ;
@@ -37,6 +40,7 @@ Future<void> _timedBuildStep(String name, Future<void> Function() action) async
37
40
// Fuchsia package.
38
41
Future <void > buildFuchsia ({
39
42
@required FuchsiaProject fuchsiaProject,
43
+ @required TargetPlatform targetPlatform,
40
44
@required String target, // E.g., lib/main.dart
41
45
BuildInfo buildInfo = BuildInfo .debug,
42
46
String runnerPackageSource = FuchsiaPackageServer .toolHost,
@@ -49,12 +53,66 @@ Future<void> buildFuchsia({
49
53
await _timedBuildStep ('fuchsia-kernel-compile' ,
50
54
() => fuchsiaSdk.fuchsiaKernelCompiler.build (
51
55
fuchsiaProject: fuchsiaProject, target: target, buildInfo: buildInfo));
56
+
57
+ if (buildInfo.usesAot) {
58
+ await _timedBuildStep ('fuchsia-gen-snapshot' ,
59
+ () => _genSnapshot (fuchsiaProject, target, buildInfo, targetPlatform));
60
+ }
61
+
52
62
await _timedBuildStep ('fuchsia-build-assets' ,
53
63
() => _buildAssets (fuchsiaProject, target, buildInfo));
54
64
await _timedBuildStep ('fuchsia-build-package' ,
55
65
() => _buildPackage (fuchsiaProject, target, buildInfo, runnerPackageSource));
56
66
}
57
67
68
+ Future <void > _genSnapshot (
69
+ FuchsiaProject fuchsiaProject,
70
+ String target, // lib/main.dart
71
+ BuildInfo buildInfo,
72
+ TargetPlatform targetPlatform,
73
+ ) async {
74
+ final String outDir = getFuchsiaBuildDirectory ();
75
+ final String appName = fuchsiaProject.project.manifest.appName;
76
+ final String dilPath = fs.path.join (outDir, '$appName .dil' );
77
+
78
+ final String vmSnapshotData = fs.path.join (outDir, 'vm_data.aotsnapshot' );
79
+ final String vmSnapshotInstructions = fs.path.join (outDir, 'vm_instructions.aotsnapshot' );
80
+ final String snapshotData = fs.path.join (outDir, 'data.aotsnapshot' );
81
+ final String snapshotInstructions = fs.path.join (outDir, 'instructions.aotsnapshot' );
82
+
83
+ final String genSnapshot = artifacts.getArtifactPath (
84
+ Artifact .genSnapshot,
85
+ platform: targetPlatform,
86
+ mode: buildInfo.mode,
87
+ );
88
+
89
+ final List <String > command = < String > [
90
+ genSnapshot,
91
+ '--no_causal_async_stacks' ,
92
+ '--deterministic' ,
93
+ '--snapshot_kind=app-aot-blobs' ,
94
+ '--vm_snapshot_data=$vmSnapshotData ' ,
95
+ '--vm_snapshot_instructions=$vmSnapshotInstructions ' ,
96
+ '--isolate_snapshot_data=$snapshotData ' ,
97
+ '--isolate_snapshot_instructions=$snapshotInstructions ' ,
98
+ if (buildInfo.isDebug) '--enable-asserts' ,
99
+ dilPath,
100
+ ];
101
+ int result;
102
+ final Status status = logger.startProgress (
103
+ 'Compiling Fuchsia application to native code...' ,
104
+ timeout: null ,
105
+ );
106
+ try {
107
+ result = await processUtils.stream (command, trace: true );
108
+ } finally {
109
+ status.cancel ();
110
+ }
111
+ if (result != 0 ) {
112
+ throwToolExit ('Build process failed' );
113
+ }
114
+ }
115
+
58
116
Future <void > _buildAssets (
59
117
FuchsiaProject fuchsiaProject,
60
118
String target, // lib/main.dart
@@ -98,12 +156,17 @@ void _rewriteCmx(BuildMode mode, String runnerPackageSource, File src, File dst)
98
156
String runner;
99
157
switch (mode) {
100
158
case BuildMode .debug:
101
- case BuildMode .profile:
102
159
runner = 'flutter_jit_runner' ;
103
160
break ;
104
- case BuildMode .release:
161
+ case BuildMode .profile:
162
+ runner = 'flutter_aot_runner' ;
163
+ break ;
164
+ case BuildMode .jitRelease:
105
165
runner = 'flutter_jit_product_runner' ;
106
166
break ;
167
+ case BuildMode .release:
168
+ runner = 'flutter_aot_product_runner' ;
169
+ break ;
107
170
default :
108
171
throwToolExit ('Fuchsia does not support build mode "$mode "' );
109
172
break ;
@@ -122,7 +185,6 @@ Future<void> _buildPackage(
122
185
final String outDir = getFuchsiaBuildDirectory ();
123
186
final String pkgDir = fs.path.join (outDir, 'pkg' );
124
187
final String appName = fuchsiaProject.project.manifest.appName;
125
- final String dilpmanifest = fs.path.join (outDir, '$appName .dilpmanifest' );
126
188
final String pkgassets = fs.path.join (outDir, '${appName }_pkgassets' );
127
189
final String packageManifest = fs.path.join (pkgDir, 'package_manifest' );
128
190
final String devKeyPath = fs.path.join (pkgDir, 'development.key' );
@@ -137,9 +199,29 @@ Future<void> _buildPackage(
137
199
final File dstCmx = fs.file (fs.path.join (outDir, '$appName .cmx' ));
138
200
_rewriteCmx (buildInfo.mode, runnerPackageSource, srcCmx, dstCmx);
139
201
140
- // Concatenate dilpmanifest and pkgassets into package_manifest.
141
202
final File manifestFile = fs.file (packageManifest);
142
- manifestFile.writeAsStringSync (fs.file (dilpmanifest).readAsStringSync ());
203
+
204
+ if (buildInfo.usesAot) {
205
+ final String vmSnapshotData = fs.path.join (outDir, 'vm_data.aotsnapshot' );
206
+ final String vmSnapshotInstructions = fs.path.join (outDir, 'vm_instructions.aotsnapshot' );
207
+ final String snapshotData = fs.path.join (outDir, 'data.aotsnapshot' );
208
+ final String snapshotInstructions = fs.path.join (outDir, 'instructions.aotsnapshot' );
209
+ manifestFile.writeAsStringSync (
210
+ 'data/$appName /vm_snapshot_data.bin=$vmSnapshotData \n ' );
211
+ manifestFile.writeAsStringSync (
212
+ 'data/$appName /vm_snapshot_instructions.bin=$vmSnapshotInstructions \n ' ,
213
+ mode: FileMode .append);
214
+ manifestFile.writeAsStringSync (
215
+ 'data/$appName /isolate_snapshot_data.bin=$snapshotData \n ' ,
216
+ mode: FileMode .append);
217
+ manifestFile.writeAsStringSync (
218
+ 'data/$appName /isolate_snapshot_instructions.bin=$snapshotInstructions \n ' ,
219
+ mode: FileMode .append);
220
+ } else {
221
+ final String dilpmanifest = fs.path.join (outDir, '$appName .dilpmanifest' );
222
+ manifestFile.writeAsStringSync (fs.file (dilpmanifest).readAsStringSync ());
223
+ }
224
+
143
225
manifestFile.writeAsStringSync (fs.file (pkgassets).readAsStringSync (),
144
226
mode: FileMode .append);
145
227
manifestFile.writeAsStringSync ('meta/$appName .cmx=${dstCmx .path }\n ' ,
0 commit comments