Skip to content

Commit

Permalink
Support dartdevc, dart2js with shared source files, dartdevc sdk (flu…
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahwilliams authored Mar 18, 2019
1 parent e0782de commit 048d70b
Show file tree
Hide file tree
Showing 7 changed files with 359 additions and 215 deletions.
13 changes: 12 additions & 1 deletion BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

import("$flutter_root/common/config.gni")

# Whether to build the dartdevc sdk, libraries, and source files
# required for the flutter web sdk.
declare_args() {
full_dart_sdk = false
}

group("flutter") {
testonly = true

Expand All @@ -23,8 +29,13 @@ group("flutter") {
public_deps += [
"$flutter_root/frontend_server",
"//third_party/dart:create_sdk",
"$flutter_root/web_sdk",
]

if (full_dart_sdk) {
public_deps += [
"$flutter_root/web_sdk",
]
}
}
}

Expand Down
1 change: 1 addition & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@ FILE: ../../../flutter/vulkan/vulkan_utilities.cc
FILE: ../../../flutter/vulkan/vulkan_utilities.h
FILE: ../../../flutter/vulkan/vulkan_window.cc
FILE: ../../../flutter/vulkan/vulkan_window.h
FILE: ../../../flutter/web_sdk/flutter_kernel_sdk.dart
FILE: ../../../flutter/web_sdk/libraries.json
----------------------------------------------------------------------------------------------------
Copyright 2013 The Flutter Authors. All rights reserved.
Expand Down
4 changes: 3 additions & 1 deletion tools/gn
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,10 @@ def to_gn_args(args):
if args.arm_float_abi:
gn_args['arm_float_abi'] = args.arm_float_abi

# Whether to build trained Dart SDK snapshots of dart2js and dartdevc.
# Whether to build trained Dart SDK snapshots of dart2js and dartdevc,
# including the web sdk kernel and source files.
gn_args['dart_platform_sdk'] = not args.full_dart_sdk
gn_args['full_dart_sdk'] = args.full_dart_sdk

return gn_args

Expand Down
95 changes: 57 additions & 38 deletions web_sdk/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,82 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//third_party/dart/build/dart/dart_action.gni")
import("//third_party/dart/utils/compile_platform.gni")

sdk_dill = "$root_out_dir/flutter_web_sdk/kernel/flutter_ddc_sdk.dill"
sdk_libraries_json = "$flutter_root/web_sdk/libraries.json"

web_ui_sources = [
"$flutter_root/lib/stub_ui/compositing.dart",
"$flutter_root/lib/stub_ui/geometry.dart",
"$flutter_root/lib/stub_ui/hash_codes.dart",
"$flutter_root/lib/stub_ui/hooks.dart",
"$flutter_root/lib/stub_ui/isolate_name_server.dart",
"$flutter_root/lib/stub_ui/lerp.dart",
"$flutter_root/lib/stub_ui/natives.dart",
"$flutter_root/lib/stub_ui/painting.dart",
"$flutter_root/lib/stub_ui/plugins.dart",
"$flutter_root/lib/stub_ui/pointer.dart",
"$flutter_root/lib/stub_ui/semantics.dart",
"$flutter_root/lib/stub_ui/text.dart",
"$flutter_root/lib/stub_ui/ui.dart",
"$flutter_root/lib/stub_ui/versions.dart",
"$flutter_root/lib/stub_ui/window.dart",
]

group("web_sdk") {
deps = [
":web_ui_sources",
":web_libraries_json",
#":dart_sdk_internal",
":web_ui_library",
":flutter_dartdevc_kernel_sdk",
]
}

copy("web_ui_sources") {
sources = [
"$flutter_root/lib/stub_ui/compositing.dart",
"$flutter_root/lib/stub_ui/geometry.dart",
"$flutter_root/lib/stub_ui/hash_codes.dart",
"$flutter_root/lib/stub_ui/hooks.dart",
"$flutter_root/lib/stub_ui/isolate_name_server.dart",
"$flutter_root/lib/stub_ui/lerp.dart",
"$flutter_root/lib/stub_ui/natives.dart",
"$flutter_root/lib/stub_ui/painting.dart",
"$flutter_root/lib/stub_ui/plugins.dart",
"$flutter_root/lib/stub_ui/pointer.dart",
"$flutter_root/lib/stub_ui/semantics.dart",
"$flutter_root/lib/stub_ui/text.dart",
"$flutter_root/lib/stub_ui/ui.dart",
"$flutter_root/lib/stub_ui/versions.dart",
"$flutter_root/lib/stub_ui/window.dart",
]
sources = web_ui_sources

outputs = [
"$root_out_dir/flutter_web_sdk/lib/ui/{{source_file_part}}"
]
}

copy("web_libraries_json") {
copy("web_ui_library") {
sources = [
"libraries.json"
"$flutter_root/web_sdk/libraries.json",
]

outputs = [
"$root_out_dir/flutter_web_sdk/lib/libraries.json"
"$root_out_dir/flutter_web_sdk/{{source_file_part}}"
]
}

# copy("dart_sdk_internal") {
# deps = [
# "//third_party/dart:create_sdk"
# ]
prebuilt_dart_action("flutter_dartdevc_kernel_sdk") {
deps = [
"//third_party/dart/pkg:pkg_files_stamp",
"//third_party/dart/utils/dartdevc:dartdevc_files_stamp",
"//third_party/dart/utils/dartdevc:dartdevc_sdk_patch_stamp",
]

# sources = [
# "$root_out_dir/dart-sdk/lib/_internal/ddc_sdk.dill",
# "$root_out_dir/dart-sdk/lib/_internal/dart2js_platform.dill",
# "$root_out_dir/dart-sdk/lib/_internal/dart2js_server_platform.dill",
# "$root_out_dir/dart-sdk/lib/_internal/ddc_sdk.sum",
# "$root_out_dir/dart-sdk/lib/_internal/strong.sum",
# "$root_out_dir/dart-sdk/lib/_internal/vm_platform_strong.dill",
# ]
inputs = [
"//third_party/dart/pkg/dev_compiler/tool/kernel_sdk.dart",
]

# outputs = [
# "$root_out_dir/flutter_web_sdk/lib/_internal/{{source_file_part}}"
# ]
# }
outputs = [
sdk_dill,
"$root_out_dir/flutter_web_sdk/lib/_internal/libraries.json",
"$root_out_dir/flutter_web_sdk/kernel/amd/dart_sdk.js",
"$root_out_dir/flutter_web_sdk/kernel/amd/dart_sdk.js.map",
]

script = "flutter_kernel_sdk.dart"
packages = "//third_party/dart/.packages"

output_path = rebase_path(sdk_dill)
libraries_path = rebase_path(sdk_libraries_json)

args = [
"--output=$output_path",
"--libraries=$libraries_path",
]
}
109 changes: 109 additions & 0 deletions web_sdk/flutter_kernel_sdk.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// Copyright 2013 The Flutter 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:convert' show json;
import 'dart:io';
import 'package:args/args.dart' show ArgParser;
import 'package:dev_compiler/src/compiler/module_builder.dart';
import 'package:dev_compiler/src/compiler/shared_command.dart' show SharedCompilerOptions;
import 'package:dev_compiler/src/kernel/target.dart';
import 'package:dev_compiler/src/kernel/command.dart';
import 'package:dev_compiler/src/kernel/compiler.dart';
import 'package:front_end/src/api_unstable/ddc.dart' show CompilerOptions, kernelForComponent;
import 'package:kernel/kernel.dart';
import 'package:path/path.dart' as path;

// This script is forked from https://github.com/dart-lang/sdk/blob/master/pkg/dev_compiler/tool/kernel_sdk.dart
// and produces the precompiled sdk for dartdevc. This has been modified to include a dart:ui target.
Future main(List<String> args) async {
var ddcPath = path.dirname(path.dirname(path.fromUri(Platform.script)));

// Parse flags.
var parser = ArgParser()
..addOption('output')
..addOption('libraries',
defaultsTo: path.join(ddcPath, '../../sdk/lib/libraries.json'));
var parserOptions = parser.parse(args);

var outputPath = parserOptions['output'] as String;
if (outputPath == null) {
var sdkRoot = path.absolute(path.dirname(path.dirname(ddcPath)));
var buildDir = path.join(sdkRoot, Platform.isMacOS ? 'xcodebuild' : 'out');
var genDir = path.join(buildDir, 'ReleaseX64', 'gen', 'utils', 'dartdevc');
outputPath = path.join(genDir, 'kernel', 'ddc_sdk.dill');
}

var librarySpecPath = parserOptions['libraries'] as String;

var target = FlutterDevCompilerTarget();
var options = CompilerOptions()
..compileSdk = true
// TODO(sigmund): remove this unnecessary option when possible.
..sdkRoot = Uri.base
..librariesSpecificationUri = Uri.base.resolveUri(Uri.file(librarySpecPath))
..target = target;

var inputs = target.extraRequiredLibraries.map(Uri.parse).toList();
var component = await kernelForComponent(inputs, options);

var outputDir = path.dirname(outputPath);
await Directory(outputDir).create(recursive: true);
await writeComponentToBinary(component, outputPath);

var jsModule = ProgramCompiler(
component,
target.hierarchy,
SharedCompilerOptions(moduleName: 'dart_sdk'),
{}).emitModule(component, [], [], {});
var moduleFormats = {
'amd': ModuleFormat.amd,
};

for (var name in moduleFormats.keys) {
var format = moduleFormats[name];
var jsDir = path.join(outputDir, name);
var jsPath = path.join(jsDir, 'dart_sdk.js');
await Directory(jsDir).create();
var jsCode = jsProgramToCode(jsModule, format);
await File(jsPath).writeAsString(jsCode.code);
await File('$jsPath.map').writeAsString(json.encode(jsCode.sourceMap));
}
}

class FlutterDevCompilerTarget extends DevCompilerTarget {
@override
List<String> get extraRequiredLibraries => const [
'dart:_runtime',
'dart:_debugger',
'dart:_foreign_helper',
'dart:_interceptors',
'dart:_internal',
'dart:_isolate_helper',
'dart:_js_helper',
'dart:_js_mirrors',
'dart:_js_primitives',
'dart:_metadata',
'dart:_native_typed_data',
'dart:async',
'dart:collection',
'dart:convert',
'dart:developer',
'dart:io',
'dart:isolate',
'dart:js',
'dart:js_util',
'dart:math',
'dart:mirrors',
'dart:typed_data',
'dart:indexed_db',
'dart:html',
'dart:html_common',
'dart:svg',
'dart:web_audio',
'dart:web_gl',
'dart:web_sql',
'dart:ui',
];
}
Loading

0 comments on commit 048d70b

Please sign in to comment.