Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit b41c172

Browse files
authored
[fuchsia] Kernel compiler is now ready (#10309)
Also fixes the architecture of the bundled SO files.
1 parent c67a36c commit b41c172

File tree

6 files changed

+178
-9
lines changed

6 files changed

+178
-9
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,7 @@ FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/natives.cc
836836
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/natives.h
837837
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/system.cc
838838
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/system.h
839+
FILE: ../../../flutter/shell/platform/fuchsia/dart/compiler.dart
839840
FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/builtin_libraries.cc
840841
FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/builtin_libraries.h
841842
FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/dart_component_controller.cc

shell/platform/fuchsia/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ if (using_fuchsia_sdk) {
1717

1818
group("fuchsia") {
1919
deps = [
20+
"dart:kernel_compiler",
2021
"dart_runner:$dart_runner_target",
2122
"flutter:$flutter_runner_target",
2223
]

shell/platform/fuchsia/dart/BUILD.gn

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright 2013 The Flutter Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# found in the LICENSE file.
4+
5+
import("//third_party/dart/build/dart/dart_action.gni")
6+
import("//third_party/dart/utils/application_snapshot.gni")
7+
import("//third_party/dart/utils/compile_platform.gni")
8+
9+
application_snapshot("kernel_compiler") {
10+
main_dart = "compiler.dart"
11+
12+
deps = [
13+
"../flutter/kernel:kernel_platform_files",
14+
]
15+
16+
dot_packages = rebase_path("//third_party/dart/.packages")
17+
18+
training_args = [ "--train" ]
19+
20+
kernel_compiler_files =
21+
exec_script("//third_party/dart/tools/list_dart_files.py",
22+
[
23+
"absolute",
24+
rebase_path("."),
25+
],
26+
"list lines")
27+
28+
kernel_compiler_files +=
29+
exec_script("//third_party/dart/tools/list_dart_files.py",
30+
[
31+
"absolute",
32+
rebase_path("//third_party/dart/pkg"),
33+
],
34+
"list lines")
35+
36+
inputs = kernel_compiler_files
37+
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'dart:async';
6+
import 'dart:io';
7+
8+
import 'package:args/args.dart';
9+
import 'package:crypto/crypto.dart';
10+
11+
import 'package:vm/kernel_front_end.dart'
12+
show createCompilerArgParser, runCompiler, successExitCode;
13+
14+
final ArgParser _argParser = createCompilerArgParser()
15+
..addFlag('train',
16+
help: 'Run through sample command line to produce snapshot',
17+
negatable: false)
18+
..addOption('component-name', help: 'Name of the component')
19+
..addOption('data-dir',
20+
help: 'Name of the subdirectory of //data for output files')
21+
..addOption('manifest', help: 'Path to output Fuchsia package manifest');
22+
23+
String _usage = '''
24+
Usage: compiler [options] input.dart
25+
26+
Options:
27+
${_argParser.usage}
28+
''';
29+
30+
Future<void> main(List<String> args) async {
31+
ArgResults options;
32+
33+
try {
34+
options = _argParser.parse(args);
35+
36+
if (options['train']) {
37+
final Directory temp =
38+
Directory.systemTemp.createTempSync('train_kernel_compiler');
39+
try {
40+
options = _argParser.parse(<String>[
41+
'--manifest=flutter',
42+
'--data-dir=${temp.absolute}',
43+
]);
44+
45+
await runCompiler(options, _usage);
46+
return;
47+
} finally {
48+
temp.deleteSync(recursive: true);
49+
}
50+
}
51+
52+
if (!options.rest.isNotEmpty) {
53+
throw Exception('Must specify input.dart');
54+
}
55+
} on Exception catch (error) {
56+
print('ERROR: $error\n');
57+
print(_usage);
58+
exitCode = 1;
59+
return;
60+
}
61+
62+
final compilerExitCode = await runCompiler(options, _usage);
63+
if (compilerExitCode != successExitCode) {
64+
exitCode = compilerExitCode;
65+
return;
66+
}
67+
68+
final String output = options['output'];
69+
final String dataDir = options.options.contains('component-name')
70+
? options['component-name']
71+
: options['data-dir'];
72+
final String manifestFilename = options['manifest'];
73+
74+
if (manifestFilename != null) {
75+
await createManifest(manifestFilename, dataDir, output);
76+
}
77+
}
78+
79+
Future createManifest(
80+
String packageManifestFilename, String dataDir, String output) async {
81+
List<String> packages = await File('$output-packages').readAsLines();
82+
83+
// Make sure the 'main' package is the last (convention with package loader).
84+
packages.remove('main');
85+
packages.add('main');
86+
87+
final IOSink packageManifest = File(packageManifestFilename).openWrite();
88+
89+
final String kernelListFilename = '$packageManifestFilename.dilplist';
90+
final IOSink kernelList = File(kernelListFilename).openWrite();
91+
for (String package in packages) {
92+
final String filenameInPackage = '$package.dilp';
93+
final String filenameInBuild = '$output-$package.dilp';
94+
packageManifest
95+
.write('data/$dataDir/$filenameInPackage=$filenameInBuild\n');
96+
kernelList.write('$filenameInPackage\n');
97+
}
98+
await kernelList.close();
99+
100+
final String frameworkVersionFilename =
101+
'$packageManifestFilename.frameworkversion';
102+
final IOSink frameworkVersion = File(frameworkVersionFilename).openWrite();
103+
for (String package in [
104+
'collection',
105+
'flutter',
106+
'meta',
107+
'typed_data',
108+
'vector_math'
109+
]) {
110+
Digest digest;
111+
if (packages.contains(package)) {
112+
final filenameInBuild = '$output-$package.dilp';
113+
final bytes = await File(filenameInBuild).readAsBytes();
114+
digest = sha256.convert(bytes);
115+
}
116+
frameworkVersion.write('$package=$digest\n');
117+
}
118+
await frameworkVersion.close();
119+
120+
packageManifest.write('data/$dataDir/app.dilplist=$kernelListFilename\n');
121+
packageManifest
122+
.write('data/$dataDir/app.frameworkversion=$frameworkVersionFilename\n');
123+
await packageManifest.close();
124+
}

tools/fuchsia/build_fuchsia_artifacts.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,22 @@ def FindFile(name, path):
9191
return os.path.join(root, name)
9292

9393

94+
def FindFileAndCopyTo(file_name, source, dest_parent, dst_name=None):
95+
found = FindFile(file_name, source)
96+
if not dst_name:
97+
dst_name = file_name
98+
if found:
99+
dst_path = os.path.join(dest_parent, dst_name)
100+
CopyPath(found, dst_path)
101+
102+
94103
def CopyGenSnapshotIfExists(source, destination):
95104
source_root = os.path.join(_out_dir, source)
96105
destination_base = os.path.join(destination, 'dart_binaries')
97-
gen_snapshot = FindFile('gen_snapshot', source_root)
98-
gen_snapshot_product = FindFile('gen_snapshot_product', source_root)
99-
if gen_snapshot:
100-
dst_path = os.path.join(destination_base, 'gen_snapshot')
101-
CopyPath(gen_snapshot, dst_path)
102-
if gen_snapshot_product:
103-
dst_path = os.path.join(destination_base, 'gen_snapshot_product')
104-
CopyPath(gen_snapshot_product, dst_path)
106+
FindFileAndCopyTo('gen_snapshot', source_root, destination_base)
107+
FindFileAndCopyTo('gen_snapshot_product', source_root, destination_base)
108+
FindFileAndCopyTo('kernel_compiler.dart.snapshot', source_root,
109+
destination_base, 'kernel_compiler.snapshot')
105110

106111

107112
def CopyToBucketWithMode(source, destination, aot, product, runner_type):
@@ -157,6 +162,7 @@ def ProcessCIPDPakcage(upload, engine_version):
157162

158163
subprocess.check_call(command, cwd=_bucket_directory)
159164

165+
160166
def GetRunnerTarget(runner_type, product, aot):
161167
base = 'flutter/shell/platform/fuchsia/%s:' % runner_type
162168
if 'dart' in runner_type:

tools/fuchsia/common_libs.gni

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import("$flutter_root/tools/fuchsia/clang.gni")
66

7-
fuchsia_sdk_base = "//fuchsia/sdk/$host_os/arch/$host_cpu"
7+
fuchsia_sdk_base = "//fuchsia/sdk/$host_os/arch/$target_cpu"
88
fuchsia_sdk_lib = "$fuchsia_sdk_base/lib"
99
sysroot_lib = "$fuchsia_sdk_base/sysroot/lib"
1010
sysroot_dist_lib = "$fuchsia_sdk_base/sysroot/dist/lib"

0 commit comments

Comments
 (0)