[flutter] Fixes for Flutter/Dart roll

TEST=Manual,CQ,integration
Change-Id: I7983d0df19b9c916fc17b2ab4d31878cee18b3e4
diff --git a/examples/fidl/fidl_bindings_performance/lib/main.dart b/examples/fidl/fidl_bindings_performance/lib/main.dart
index 1c5cc44..7b7ba71 100644
--- a/examples/fidl/fidl_bindings_performance/lib/main.dart
+++ b/examples/fidl/fidl_bindings_performance/lib/main.dart
@@ -42,7 +42,7 @@
     print(message);
     completer.completeError(message);
   };
-  controller.ctrl.onConnectionError = () {
+  controller.ctrl.onConnectionError = () {  // ignore: cascade_invocations
     final message = '$server controller connection unexpectedly closed';
     print(message);
     completer.completeError(message);
@@ -62,9 +62,9 @@
       // Stop the echo server.
       echo.ctrl.onConnectionError = null;
       echo.ctrl.close();
-      controller.ctrl.onConnectionError = complete;
-      controller.ctrl.onClose = complete;
       controller
+        ..ctrl.onConnectionError = complete
+        ..ctrl.onClose = complete
         ..kill()
         ..onTerminated = (unusedReturnCode, unusedTerminationReason) {
           // Now we're done...
diff --git a/public/dart/fuchsia_modular/lib/src/agent/agent_task_handler.dart b/public/dart/fuchsia_modular/lib/src/agent/agent_task_handler.dart
index 43e1931..9ca0f9c 100644
--- a/public/dart/fuchsia_modular/lib/src/agent/agent_task_handler.dart
+++ b/public/dart/fuchsia_modular/lib/src/agent/agent_task_handler.dart
@@ -4,6 +4,8 @@
 
 // ignore_for_file: one_member_abstracts
 
+import 'dart:async';
+
 /// The [AgentTaskHandler] class is an abstract class which is intended to be
 /// extended by agent authors to handle incoming tasks. The class is intended to
 /// be registered with the [Agent] class inside of the agent's main method.
@@ -15,4 +17,4 @@
   /// Note that the framework may call [Lifecycle.Terminate()] before this
   /// method returns.
   Future<void> runTask(String taskId);
-}
\ No newline at end of file
+}
diff --git a/public/dart/fuchsia_modular/lib/src/lifecycle/lifecycle.dart b/public/dart/fuchsia_modular/lib/src/lifecycle/lifecycle.dart
index c304c9c..eb6a7ec 100644
--- a/public/dart/fuchsia_modular/lib/src/lifecycle/lifecycle.dart
+++ b/public/dart/fuchsia_modular/lib/src/lifecycle/lifecycle.dart
@@ -2,6 +2,8 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
+import 'dart:async';
+
 import 'internal/_lifecycle_impl.dart';
 
 /// Allows running components to be notified when lifecycle events happen in the
diff --git a/public/dart/fuchsia_modular/lib/src/proposal/internal/_proposal_listener_impl.dart b/public/dart/fuchsia_modular/lib/src/proposal/internal/_proposal_listener_impl.dart
index 8cfab8d..5d90bf7 100644
--- a/public/dart/fuchsia_modular/lib/src/proposal/internal/_proposal_listener_impl.dart
+++ b/public/dart/fuchsia_modular/lib/src/proposal/internal/_proposal_listener_impl.dart
@@ -2,6 +2,8 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
+import 'dart:async';
+
 import 'package:fidl_fuchsia_modular/fidl_async.dart' as fuchsia_modular;
 
 /// A class which implements the [fuchsia_modular.ProposalListener] interface
diff --git a/public/dart/fuchsia_modular/test/agent/internal/agent_impl_test.dart b/public/dart/fuchsia_modular/test/agent/internal/agent_impl_test.dart
index 52f917c..f7c91b4 100644
--- a/public/dart/fuchsia_modular/test/agent/internal/agent_impl_test.dart
+++ b/public/dart/fuchsia_modular/test/agent/internal/agent_impl_test.dart
@@ -4,6 +4,7 @@
 
 // ignore_for_file: implementation_imports
 
+import 'dart:async';
 import 'dart:collection';
 
 import 'package:fidl/fidl.dart' show AsyncBinding, AsyncProxyController;
diff --git a/public/dart/fuchsia_modular/test/entity/internal/entity_impl_test.dart b/public/dart/fuchsia_modular/test/entity/internal/entity_impl_test.dart
index 99bec26..c3d6f26 100644
--- a/public/dart/fuchsia_modular/test/entity/internal/entity_impl_test.dart
+++ b/public/dart/fuchsia_modular/test/entity/internal/entity_impl_test.dart
@@ -4,6 +4,7 @@
 
 // ignore_for_file: implementation_imports
 
+import 'dart:async';
 import 'dart:typed_data';
 
 import 'package:fidl/fidl.dart';
diff --git a/public/dart/fuchsia_modular/test/lifecycle/internal/lifecycle_impl_test.dart b/public/dart/fuchsia_modular/test/lifecycle/internal/lifecycle_impl_test.dart
index 5059789..52a1400 100644
--- a/public/dart/fuchsia_modular/test/lifecycle/internal/lifecycle_impl_test.dart
+++ b/public/dart/fuchsia_modular/test/lifecycle/internal/lifecycle_impl_test.dart
@@ -2,6 +2,8 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
+import 'dart:async';
+
 import 'package:test/test.dart';
 
 import 'package:fuchsia_modular/src/lifecycle/internal/_lifecycle_impl.dart'; // ignore: implementation_imports
diff --git a/public/dart/fuchsia_modular/test/module/internal/module_impl_integ_test.dart b/public/dart/fuchsia_modular/test/module/internal/module_impl_integ_test.dart
index 9e0f9d5..24dd4f8 100644
--- a/public/dart/fuchsia_modular/test/module/internal/module_impl_integ_test.dart
+++ b/public/dart/fuchsia_modular/test/module/internal/module_impl_integ_test.dart
@@ -2,6 +2,8 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
+import 'dart:async';
+
 import 'package:fidl_fuchsia_modular/fidl_async.dart' as fidl;
 import 'package:fuchsia_services/services.dart';
 import 'package:mockito/mockito.dart';
diff --git a/public/dart/fuchsia_scenic_flutter/lib/src/internal/_view_container_listener_impl.dart b/public/dart/fuchsia_scenic_flutter/lib/src/internal/_view_container_listener_impl.dart
index 3f4d5c1..4150aab 100644
--- a/public/dart/fuchsia_scenic_flutter/lib/src/internal/_view_container_listener_impl.dart
+++ b/public/dart/fuchsia_scenic_flutter/lib/src/internal/_view_container_listener_impl.dart
@@ -2,6 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
+import 'dart:async';
 import 'dart:collection';
 
 import 'package:fidl/fidl.dart';
diff --git a/public/dart/fuchsia_services/lib/src/service_connection.dart b/public/dart/fuchsia_services/lib/src/service_connection.dart
index fc673ef..ecd5d0b 100644
--- a/public/dart/fuchsia_services/lib/src/service_connection.dart
+++ b/public/dart/fuchsia_services/lib/src/service_connection.dart
@@ -2,6 +2,8 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
+import 'dart:async';
+
 import 'package:fidl/fidl.dart';
 import 'package:fidl_fuchsia_sys/fidl_async.dart' as fidl_sys;
 
diff --git a/public/dart/fuchsia_vfs/lib/src/internal/_error_node.dart b/public/dart/fuchsia_vfs/lib/src/internal/_error_node.dart
index 3fab8b0..b607545 100644
--- a/public/dart/fuchsia_vfs/lib/src/internal/_error_node.dart
+++ b/public/dart/fuchsia_vfs/lib/src/internal/_error_node.dart
@@ -2,6 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
+import 'dart:async';
 import 'dart:typed_data';
 
 import 'package:fidl/fidl.dart';
diff --git a/public/dart/fuchsia_vfs/lib/src/pseudo_file.dart b/public/dart/fuchsia_vfs/lib/src/pseudo_file.dart
index 0510fee..a4df604 100644
--- a/public/dart/fuchsia_vfs/lib/src/pseudo_file.dart
+++ b/public/dart/fuchsia_vfs/lib/src/pseudo_file.dart
@@ -2,6 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
+import 'dart:async';
 import 'dart:math';
 import 'dart:typed_data';
 
diff --git a/public/dart/fuchsia_vfs/test/pseudo_dir_test.dart b/public/dart/fuchsia_vfs/test/pseudo_dir_test.dart
index 9bef982..e14097c 100644
--- a/public/dart/fuchsia_vfs/test/pseudo_dir_test.dart
+++ b/public/dart/fuchsia_vfs/test/pseudo_dir_test.dart
@@ -2,6 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
+import 'dart:async';
 import 'dart:convert';
 import 'dart:typed_data';
 
diff --git a/public/dart/fuchsia_vfs/test/pseudo_file_test.dart b/public/dart/fuchsia_vfs/test/pseudo_file_test.dart
index 1d24dea..9fef86b 100644
--- a/public/dart/fuchsia_vfs/test/pseudo_file_test.dart
+++ b/public/dart/fuchsia_vfs/test/pseudo_file_test.dart
@@ -1,6 +1,8 @@
 // Copyright 2018 The Fuchsia 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 'dart:async';
 import 'dart:typed_data';
 
 import 'package:fidl/fidl.dart';
diff --git a/public/dart/fuchsia_vfs/test/service_test.dart b/public/dart/fuchsia_vfs/test/service_test.dart
index dd356e1..387dcaf 100644
--- a/public/dart/fuchsia_vfs/test/service_test.dart
+++ b/public/dart/fuchsia_vfs/test/service_test.dart
@@ -2,6 +2,8 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
+import 'dart:async';
+
 import 'package:fidl/fidl.dart';
 import 'package:fidl_fidl_examples_echo/fidl_async.dart';
 import 'package:fidl_fuchsia_io/fidl_async.dart' as io_fidl;
diff --git a/public/dart/widgets/lib/src/model/provider.dart b/public/dart/widgets/lib/src/model/provider.dart
index 91c07dc..113d837 100644
--- a/public/dart/widgets/lib/src/model/provider.dart
+++ b/public/dart/widgets/lib/src/model/provider.dart
@@ -1,3 +1,5 @@
+import 'dart:async';
+
 import 'package:flutter/widgets.dart';
 
 /// [ProviderNode] makes a set of [providers] available to any widgets below
diff --git a/runtime/dart/compiler.dart b/runtime/dart/compiler.dart
index 615d115..4abc043 100644
--- a/runtime/dart/compiler.dart
+++ b/runtime/dart/compiler.dart
@@ -3,51 +3,18 @@
 // found in the LICENSE file.
 
 import 'dart:async';
-import 'dart:io' hide FileSystemException;
+import 'dart:io';
 
 import 'package:args/args.dart';
 
-import 'package:front_end/src/api_unstable/vm.dart';
-import 'package:front_end/src/scheme_based_file_system.dart'
-    show SchemeBasedFileSystem;
-
-import 'package:build_integration/file_system/multi_root.dart'
-    show MultiRootFileSystem, MultiRootFileSystemEntity;
-
-import 'package:kernel/ast.dart';
-import 'package:kernel/binary/ast_to_binary.dart';
-import 'package:kernel/binary/limited_ast_to_binary.dart';
-import 'package:kernel/target/targets.dart';
-
 import 'package:vm/kernel_front_end.dart'
-    show compileToKernel, ErrorDetector, ErrorPrinter;
-import 'package:vm/target/dart_runner.dart' show DartRunnerTarget;
-import 'package:vm/target/flutter_runner.dart' show FlutterRunnerTarget;
+    show createCompilerArgParser, runCompiler, successExitCode;
 
-ArgParser _argParser = new ArgParser(allowTrailingOptions: true)
-  ..addOption('sdk-root', help: 'Path to runner_patched_sdk')
-  ..addOption('multi-root-scheme', help: 'The URI scheme for the multi root')
-  ..addMultiOption('multi-root',
-      help: 'A base for the multi root. Can be given multiple times to build an overlay')
-  ..addFlag('aot',
-      help: 'Run compiler in AOT mode (enables whole-program transformations)',
-      defaultsTo: false)
-  ..addFlag('tfa',
-      help: 'Run global type flow analysis', defaultsTo: false)
-  ..addFlag('drop-ast',
-      help: 'Drop AST for members with bytecode', defaultsTo: false)
+final ArgParser _argParser = createCompilerArgParser()
   ..addOption('component-name', help: 'Name of the component')
   ..addOption('data-dir',
       help: 'Name of the subdirectory of //data for output files')
-  ..addFlag('embed-sources',
-      help: 'Embed sources in the output dill file', defaultsTo: false)
-  ..addFlag('gen-bytecode', help: 'Generate bytecode', defaultsTo: false)
-  ..addOption('depfile', help: 'Path to output Ninja depfile')
-  ..addOption('manifest', help: 'Path to output Fuchsia package manifest')
-  ..addOption('output', help: 'Path to output dill file')
-  ..addOption('packages', help: 'Path to .packages file')
-  ..addOption('target', help: 'Kernel target name')
-  ..addFlag('verbose', help: 'Run in verbose mode');
+  ..addOption('manifest', help: 'Path to output Fuchsia package manifest');
 
 String _usage = '''
 Usage: compiler [options] input.dart
@@ -56,23 +23,6 @@
 ${_argParser.usage}
 ''';
 
-Uri _ensureFolderPath(String path) {
-  String uriPath = new Uri.file(path).toString();
-  if (!uriPath.endsWith('/')) {
-    uriPath = '$uriPath/';
-  }
-  return Uri.base.resolve(uriPath);
-}
-
-Future<Uri> _asFileUri(FileSystem fileSystem, Uri uri) async {
-  FileSystemEntity fse = fileSystem.entityForUri(uri);
-  if (fse is MultiRootFileSystemEntity) {
-    MultiRootFileSystemEntity mrfse = fse;
-    fse = await mrfse.delegate;
-  }
-  return fse.uri;
-}
-
 Future<void> main(List<String> args) async {
   ArgResults options;
   try {
@@ -87,233 +37,44 @@
     return;
   }
 
-  final Uri sdkRoot = _ensureFolderPath(options['sdk-root']);
-  final Uri packagesUri = Uri.base.resolve(options['packages']);
-  final bool aot = options['aot'];
-  final bool tfa = options['tfa'];
-  final bool embedSources = options['embed-sources'];
-  final String targetName = options['target'];
-  final bool genBytecode = options['gen-bytecode'];
-  final bool dropAST = options['drop-ast'];
-  final String dataDir = options.options.contains('component-name') ? options['component-name'] : options['data-dir'];
-  final bool verbose = options['verbose'];
-
-  Uri mainUri = Uri.parse(options.rest[0]);
-
-  Uri platformKernelDill = sdkRoot.resolve('platform_strong.dill');
-
-  TargetFlags targetFlags = new TargetFlags(syncAsync: true);
-  Target target;
-  switch (targetName) {
-    case 'dart_runner':
-      target = new DartRunnerTarget(targetFlags);
-      break;
-    case 'flutter_runner':
-      target = new FlutterRunnerTarget(targetFlags);
-      break;
-    default:
-      print('Unknown target: $targetName');
-      exitCode = 1;
-      return;
-  }
-
-  FileSystem fileSystem = StandardFileSystem.instance;
-  String multiRootScheme = options['multi-root-scheme'];
-  if (multiRootScheme != null) {
-    final rootUris = <Uri>[];
-    for (String root in options['multi-root']) {
-      rootUris.add(Uri.base.resolveUri(new Uri.file(root)));
-    }
-    final multiRootFS = new MultiRootFileSystem(multiRootScheme, rootUris, fileSystem);
-    fileSystem = new SchemeBasedFileSystem({
-      'file': fileSystem,
-      'data': fileSystem,
-      '': fileSystem,
-      multiRootScheme: multiRootFS,
-    });
-  }
-
-  // fuchsia-source:///x/y/main.dart -> file:///a/b/x/y/main.dart
-  String mainUriString = (await _asFileUri(fileSystem, mainUri)).toString();
-  // file:///a/b/x/y/main.dart -> package:x.y/main.dart
-  for (var line in await new File(
-          (await _asFileUri(fileSystem, packagesUri)).toFilePath())
-      .readAsLines()) {
-    var colon = line.indexOf(':');
-    if (colon == -1)
-      continue;
-    var packageName = line.substring(0, colon);
-    String packagePath;
-    try {
-      packagePath = (await _asFileUri(
-          fileSystem, packagesUri.resolve(line.substring(colon + 1))))
-          .toString();
-    } on FileSystemException {
-      // Can't resolve package path.
-      continue;
-    }
-    if (mainUriString.startsWith(packagePath)) {
-      mainUri = Uri.parse('package:$packageName/${mainUriString.substring(packagePath.length)}');
-      break;
-    }
-  }
-
-  final errorPrinter = new ErrorPrinter();
-  final errorDetector = new ErrorDetector(previousErrorHandler: errorPrinter);
-  final CompilerOptions compilerOptions = new CompilerOptions()
-    ..sdkSummary = platformKernelDill
-    ..fileSystem = fileSystem
-    ..packagesFileUri = packagesUri
-    ..target = target
-    ..embedSourceText = embedSources
-    ..onDiagnostic = (DiagnosticMessage m) {
-      printDiagnosticMessage(m, stderr.writeln);
-      errorDetector(m);
-    }
-    ..verbose = verbose;
-
-  if (aot) {
-    // Link in the platform to produce an output with no external references.
-    compilerOptions.linkedDependencies = <Uri>[platformKernelDill];
-  }
-
-  Component component = await compileToKernel(
-    mainUri,
-    compilerOptions,
-    aot: aot,
-    useGlobalTypeFlowAnalysis: tfa,
-    genBytecode: genBytecode,
-    dropAST: dropAST,
-  );
-
-  errorPrinter.printCompilationMessages(mainUri);
-  if (errorDetector.hasCompilationErrors || (component == null)) {
-    exitCode = 1;
+  final compilerExitCode = await runCompiler(options, _usage);
+  if (compilerExitCode != successExitCode) {
+    exitCode = compilerExitCode;
     return;
   }
 
-  // Single-file output.
-  final String kernelBinaryFilename = options['output'];
-  if (kernelBinaryFilename != null) {
-    final IOSink sink = new File(kernelBinaryFilename).openWrite();
-    final BinaryPrinter printer = new LimitedBinaryPrinter(sink,
-        (Library lib) => true, false /* excludeUriToSource */);
-    printer.writeComponentFile(component);
-    await sink.close();
-
-    final String depfile = options['depfile'];
-    if (depfile != null) {
-      await writeDepfile(fileSystem, component, kernelBinaryFilename, depfile);
-    }
-  }
-
-  // Multiple-file output.
+  final String output = options['output'];
+  final String dataDir = options.options.contains('component-name')
+      ? options['component-name']
+      : options['data-dir'];
   final String manifestFilename = options['manifest'];
+
   if (manifestFilename != null) {
-    await writePackages(component, kernelBinaryFilename, manifestFilename, dataDir);
+    await createManifest(manifestFilename, dataDir, output);
   }
 }
 
-String escapePath(String path) {
-  return path.replaceAll('\\', '\\\\').replaceAll(' ', '\\ ');
-}
+Future createManifest(
+    String packageManifestFilename, String dataDir, String output) async {
+  List<String> packages = await new File('$output-packages').readAsLines();
 
-List<Uri> getDependencies(Component component) {
-  var deps = <Uri>[];
-  for (Library lib in component.libraries) {
-    if (lib.importUri.scheme == 'dart') {
-      continue;
-    }
-    deps.add(lib.fileUri);
-    for (LibraryPart part in lib.parts) {
-      final Uri fileUri = lib.fileUri.resolve(part.partUri);
-      deps.add(fileUri);
-    }
-  }
-  return deps;
-}
-
-// https://ninja-build.org/manual.html#_depfile
-Future<void> writeDepfile(FileSystem fileSystem,
-    Component component, String output, String depfile) async {
-  var file = new File(depfile).openWrite();
-  file.write(escapePath(output));
-  file.write(':');
-  for (Uri dep in getDependencies(component)) {
-    Uri uri = await _asFileUri(fileSystem, dep);
-    file.write(' ');
-    file.write(escapePath(uri.toFilePath()));
-  }
-  file.write('\n');
-  await file.close();
-}
-
-Future writePackages(Component component, String output, String packageManifestFilename, String dataDir) async {
-  // Package sharing: make the encoding not depend on the order in which parts
-  // of a package are loaded.
-  component.libraries.sort((Library a, Library b) {
-    return a.importUri.toString().compareTo(b.importUri.toString());
-  });
-  for (Library lib in component.libraries) {
-    lib.additionalExports.sort((Reference a, Reference b) {
-      return a.canonicalName.toString().compareTo(b.canonicalName.toString());
-    });
-  }
+  // Make sure the 'main' package is the last (convention with package loader).
+  packages.remove('main');
+  packages.add('main');
 
   final IOSink packageManifest = new File(packageManifestFilename).openWrite();
   final String kernelListFilename = '$packageManifestFilename.dilplist';
   final IOSink kernelList = new File(kernelListFilename).openWrite();
 
-  final packages = new Set<String>();
-  for (Library lib in component.libraries) {
-    packages.add(packageFor(lib));
-  }
-  packages.remove('main');
-  packages.remove(null);
-
   for (String package in packages) {
-    await writePackage(component, output, package, packageManifest, kernelList, dataDir);
+    final String filenameInPackage = '$package.dilp';
+    final String filenameInBuild = '$output-$package.dilp';
+    packageManifest
+        .write('data/$dataDir/$filenameInPackage=$filenameInBuild\n');
+    kernelList.write('$filenameInPackage\n');
   }
-  await writePackage(component, output, 'main', packageManifest, kernelList, dataDir);
 
   packageManifest.write('data/$dataDir/app.dilplist=$kernelListFilename\n');
   await packageManifest.close();
   await kernelList.close();
 }
-
-Future writePackage(Component component, String output, String package,
-    IOSink packageManifest, IOSink kernelList, String dataDir) async {
-  final String filenameInPackage = '$package.dilp';
-  final String filenameInBuild = '$output-$package.dilp';
-  final IOSink sink = new File(filenameInBuild).openWrite();
-
-  var main = component.mainMethod;
-  if (package != 'main') {
-    // Package sharing: remove the information about the importer from package
-    // dilps.
-    component.mainMethod = null;
-  }
-  final BinaryPrinter printer = new LimitedBinaryPrinter(sink,
-      (lib) => packageFor(lib) == package, false /* excludeUriToSource */);
-  printer.writeComponentFile(component);
-  component.mainMethod = main;
-
-  await sink.close();
-
-  packageManifest.write('data/$dataDir/$filenameInPackage=$filenameInBuild\n');
-  kernelList.write('$filenameInPackage\n');
-}
-
-String packageFor(Library lib) {
-  // Core libraries are not written into any dilp.
-  if (lib.isExternal)
-    return null;
-
-  // Packages are written into their own dilp.
-  Uri uri = lib.importUri;
-  if (uri.scheme == 'package')
-    return uri.pathSegments.first;
-
-  // Everything else (e.g., file: or data: imports) is lumped into the main dilp.
-  return 'main';
-}
diff --git a/runtime/dart/dart_kernel.gni b/runtime/dart/dart_kernel.gni
index 1e2b49d..f0ba379 100644
--- a/runtime/dart/dart_kernel.gni
+++ b/runtime/dart/dart_kernel.gni
@@ -95,7 +95,7 @@
       outputs += [
         # Explicit output when using --manifest.
         invoker.manifest,
-        # Implicit output when using --manifest; see writePackages in compiler.dart.
+        # Implicit output when using --manifest; see createManifest in compiler.dart.
         invoker.manifest + ".dilplist",
       ]
     }
@@ -111,11 +111,11 @@
     args = invoker.args + [
              "--target",
              invoker.platform_name,
-             "--sdk-root",
-             rebase_path(invoker.platform_path),
-             "--multi-root-scheme",
+             "--platform",
+             rebase_path("${invoker.platform_path}/platform_strong.dill"),
+             "--filesystem-scheme",
              multi_root_scheme,
-             "--multi-root",
+             "--filesystem-root",
              rebase_path("//"),
              "--packages",
              "$multi_root_scheme:///$rebased_packages_path",
@@ -123,15 +123,19 @@
              rebase_path(depfile, root_build_dir),
              "--output",
              rebase_path(kernel_path, root_build_dir),
+             "--no-link-platform",
            ]
     if (defined(invoker.manifest)) {
       args += [
+        "--split-output-by-packages",
         "--manifest",
         rebase_path(invoker.manifest),
       ]
     }
     if (is_debug) {
       args += [ "--embed-sources" ]
+    } else {
+      args += [ "--no-embed-sources" ]
     }
 
     if (defined(invoker.gen_bytecode) && invoker.gen_bytecode) {
diff --git a/runtime/dart_runner/dart_runner.cc b/runtime/dart_runner/dart_runner.cc
index feb2655..0bfaee7 100644
--- a/runtime/dart_runner/dart_runner.cc
+++ b/runtime/dart_runner/dart_runner.cc
@@ -64,11 +64,6 @@
 #endif
   }
 
-  if (std::string(uri) == DART_KERNEL_ISOLATE_NAME) {
-    *error = strdup("The kernel isolate is not implemented in dart_runner");
-    return NULL;
-  }
-
   *error = strdup("Isolate spawning is not implemented in dart_runner");
   return NULL;
 }
diff --git a/runtime/dart_runner/kernel/BUILD.gn b/runtime/dart_runner/kernel/BUILD.gn
index 79d82be..347f34b 100644
--- a/runtime/dart_runner/kernel/BUILD.gn
+++ b/runtime/dart_runner/kernel/BUILD.gn
@@ -6,7 +6,10 @@
 import("//third_party/dart/utils/compile_platform.gni")
 
 compile_platform("kernel_platform_files") {
-  libraries_specification_uri = "libraries.json"
+  single_root_scheme = "org-dartlang-sdk"
+  single_root_base = rebase_path("../../../../")
+
+  libraries_specification_uri = "org-dartlang-sdk:///topaz/runtime/dart_runner/kernel/libraries.json"
 
   outputs = [
     "$root_out_dir/dart_runner_patched_sdk/platform_strong.dill",