Skip to content

Commit

Permalink
Web sdk build reland (flutter#36851)
Browse files Browse the repository at this point in the history
  • Loading branch information
eyebrowsoffire authored Oct 20, 2022
1 parent 6803f42 commit 2b21a31
Show file tree
Hide file tree
Showing 13 changed files with 365 additions and 524 deletions.
28 changes: 3 additions & 25 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import("//third_party/dart/build/dart/copy_tree.gni")

# Whether to build the dartdevc sdk, libraries, and source files
# required for the flutter web sdk.
# TODO(jacksongardner): remove this poorly named argument once the recipes stop
# using it. https://github.com/flutter/flutter/issues/113303
declare_args() {
full_dart_sdk = false
}
Expand Down Expand Up @@ -44,30 +46,6 @@ config("export_dynamic_symbols") {
}
}

if (flutter_prebuilt_dart_sdk) {
copy_trees("_copy_trees") {
sources = [
{
target = "copy_dart_sdk"
visibility = [ ":dart_sdk" ]
source = prebuilt_dart_sdk
dest = "$root_out_dir/dart-sdk"
ignore_patterns = "{}"
},
]
}
}

group("dart_sdk") {
if (build_engine_artifacts) {
if (flutter_prebuilt_dart_sdk) {
public_deps = [ ":copy_dart_sdk" ]
} else {
public_deps = [ "//third_party/dart:create_sdk" ]
}
}
}

group("flutter") {
testonly = true

Expand Down Expand Up @@ -96,7 +74,7 @@ group("flutter") {

if (build_engine_artifacts) {
public_deps += [
":dart_sdk",
"//flutter/build/dart:dart_sdk",
"//flutter/flutter_frontend_server:frontend_server",

# This must be listed explicitly for desktop cross-builds since
Expand Down
7 changes: 0 additions & 7 deletions build/archives/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,6 @@ if (build_engine_artifacts && !flutter_prebuilt_dart_sdk) {
}
}

# Archives Flutter Web SDK
if (!is_fuchsia) {
group("flutter_web_sdk") {
deps = [ "//flutter/web_sdk:flutter_web_sdk_archive" ]
}
}

# Archives Flutter Windows Artifacts
if (host_os == "win") {
zip_bundle("windows_flutter") {
Expand Down
24 changes: 24 additions & 0 deletions build/dart/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# found in the LICENSE file.

import("//flutter/build/concurrent_jobs.gni")
import("//flutter/common/config.gni")
import("//third_party/dart/build/dart/copy_tree.gni")

declare_args() {
# Maximum number of Dart processes to run in parallel.
Expand All @@ -14,3 +16,25 @@ declare_args() {
pool("dart_pool") {
depth = concurrent_dart_jobs
}

if (flutter_prebuilt_dart_sdk) {
copy_trees("_copy_trees") {
sources = [
{
target = "copy_dart_sdk"
visibility = [ ":dart_sdk" ]
source = prebuilt_dart_sdk
dest = "$root_out_dir/dart-sdk"
ignore_patterns = "{}"
},
]
}
}

group("dart_sdk") {
if (flutter_prebuilt_dart_sdk) {
public_deps = [ ":copy_dart_sdk" ]
} else {
public_deps = [ "//third_party/dart:create_sdk" ]
}
}
5 changes: 2 additions & 3 deletions ci/builders/linux_host_engine.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"flutter/build/archives:embedder",
"flutter/build/archives:flutter_patched_sdk",
"flutter/build/archives:dart_sdk_archive",
"flutter/build/archives:flutter_web_sdk",
"flutter/web_sdk",
"flutter/tools/font-subset",
"flutter/shell/platform/linux:flutter_gtk"
]
Expand Down Expand Up @@ -151,8 +151,7 @@
"targets": [
"flutter:unittests",
"flutter/build/archives:flutter_patched_sdk",
"flutter/shell/platform/linux:flutter_gtk",
"flutter/build/archives:flutter_web_sdk"
"flutter/shell/platform/linux:flutter_gtk"
]
},
"tests": [
Expand Down
2 changes: 1 addition & 1 deletion ci/builders/mac_host_engine.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"flutter/shell/platform/darwin/macos:zip_macos_flutter_framework",
"flutter/build/archives:artifacts",
"flutter/build/archives:dart_sdk_archive",
"flutter/build/archives:flutter_web_sdk",
"flutter/web_sdk",
"flutter/build/archives:archive_gen_snapshot",
"flutter/build/archives:flutter_embedder_framework"
]
Expand Down
2 changes: 1 addition & 1 deletion ci/builders/windows_host_engine.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"flutter/build/archives:dart_sdk_archive",
"flutter/shell/platform/windows/client_wrapper:client_wrapper_archive",
"flutter/build/archives:windows_flutter",
"flutter/build/archives:flutter_web_sdk"
"flutter/web_sdk"
]
},
"tests": [
Expand Down
5 changes: 4 additions & 1 deletion common/config.gni
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ declare_args() {

# Whether to use a prebuilt Dart SDK instead of building one.
flutter_prebuilt_dart_sdk = false

# Whether to build the flutter web sdk outline/DDC artifacts.
flutter_build_web_sdk = false
}

# feature_defines_list ---------------------------------------------------------
Expand Down Expand Up @@ -114,7 +117,7 @@ if (flutter_prebuilt_dart_sdk) {
# There is no prebuilt Dart SDK targeting Fuchsia, but we also don't need
# one, so even when the build is targeting Fuchsia, use the prebuilt
# Dart SDK for the host.
if (current_toolchain == host_toolchain || is_fuchsia) {
if (current_toolchain == host_toolchain || is_fuchsia || is_wasm) {
prebuilt_dart_sdk = host_prebuilt_dart_sdk
prebuilt_dart_sdk_config = _host_prebuilt_dart_sdk_config
} else {
Expand Down
64 changes: 31 additions & 33 deletions lib/web_ui/dev/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// found in the LICENSE file.

import 'dart:async';
import 'dart:io' show Directory, Platform;
import 'dart:io' show Directory;

import 'package:args/command_runner.dart';
import 'package:path/path.dart' as path;
Expand All @@ -25,6 +25,12 @@ class BuildCommand extends Command<bool> with ArgUtils<bool> {
'build-canvaskit',
help: 'Build CanvasKit locally instead of getting it from CIPD. Disabled '
'by default.',
defaultsTo: true
);
argParser.addFlag(
'host',
help: 'Build the host build instead of the wasm build, which is currently'
'needed for `flutter run --local-engine` to work'
);
}

Expand All @@ -38,19 +44,15 @@ class BuildCommand extends Command<bool> with ArgUtils<bool> {

bool get buildCanvasKit => boolArg('build-canvaskit');

bool get host => boolArg('host');

@override
FutureOr<bool> run() async {
final FilePath libPath = FilePath.fromWebUi('lib');
final List<PipelineStep> steps = <PipelineStep>[
GnPipelineStep(),
NinjaPipelineStep(target: environment.engineBuildDir),
GnPipelineStep(buildCanvasKit: buildCanvasKit, host: host),
NinjaPipelineStep(target: host ? environment.hostDebugUnoptDir : environment.wasmReleaseOutDir),
];
if (buildCanvasKit) {
steps.addAll(<PipelineStep>[
GnPipelineStep(target: 'canvaskit'),
NinjaPipelineStep(target: environment.wasmReleaseOutDir),
]);
}
final Pipeline buildPipeline = Pipeline(steps: steps);
await buildPipeline.run();

Expand All @@ -73,42 +75,38 @@ class BuildCommand extends Command<bool> with ArgUtils<bool> {
/// Not safe to interrupt as it may leave the `out/` directory in a corrupted
/// state. GN is pretty quick though, so it's OK to not support interruption.
class GnPipelineStep extends ProcessStep {
GnPipelineStep({this.target = 'engine'})
: assert(target == 'engine' || target == 'canvaskit');
GnPipelineStep({required this.buildCanvasKit, required this.host});

final bool buildCanvasKit;
final bool host;

@override
String get description => 'gn';

@override
bool get isSafeToInterrupt => false;

/// The target to build with gn.
///
/// Acceptable values: engine, canvaskit
final String target;

@override
Future<ProcessManager> createProcess() {
print('Running gn for $target...');
final List<String> gnArgs = <String>[];
if (target == 'engine') {
gnArgs.addAll(<String>[
'--unopt',
if (Platform.isMacOS) '--xcode-symlinks',
List<String> get _gnArgs {
if (host) {
return <String>[
'--unoptimized',
'--full-dart-sdk',
if (environment.isMacosArm) '--mac-cpu=arm64',
]);
} else if (target == 'canvaskit') {
gnArgs.addAll(<String>[
'--wasm',
'--runtime-mode=release',
]);
];
} else {
throw StateError('Target was not engine or canvaskit: $target');
return <String>[
'--web',
'--runtime-mode=release',
if (buildCanvasKit) '--build-canvaskit',
];
}
}

@override
Future<ProcessManager> createProcess() {
print('Running gn...');
return startProcess(
path.join(environment.flutterDirectory.path, 'tools', 'gn'),
gnArgs,
_gnArgs,
);
}
}
Expand Down
22 changes: 10 additions & 12 deletions lib/web_ui/dev/environment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,19 @@ Environment? _environment;
class Environment {
factory Environment() {
final bool isMacosArm = ffi.Abi.current() == ffi.Abi.macosArm64;
final io.File dartExecutable = io.File(io.Platform.resolvedExecutable);
final io.File self = io.File.fromUri(io.Platform.script);

final io.Directory engineSrcDir = self.parent.parent.parent.parent.parent;
final io.Directory engineToolsDir =
io.Directory(pathlib.join(engineSrcDir.path, 'flutter', 'tools'));
final io.Directory outDir =
io.Directory(pathlib.join(engineSrcDir.path, 'out'));
final io.Directory engineBuildDir =
io.Directory(pathlib.join(
outDir.path,
isMacosArm ? 'host_debug_unopt_arm64' : 'host_debug_unopt'
));
final io.Directory wasmReleaseOutDir =
io.Directory(pathlib.join(outDir.path, 'wasm_release'));
final io.Directory dartSdkDir =
io.Directory(pathlib.join(engineBuildDir.path, 'dart-sdk'));
final io.Directory hostDebugUnoptDir =
io.Directory(pathlib.join(outDir.path, 'host_debug_unopt'));
final io.Directory dartSdkDir = dartExecutable.parent.parent;
final io.Directory webUiRootDir = io.Directory(
pathlib.join(engineSrcDir.path, 'flutter', 'lib', 'web_ui'));

Expand All @@ -55,8 +53,8 @@ class Environment {
engineSrcDir: engineSrcDir,
engineToolsDir: engineToolsDir,
outDir: outDir,
engineBuildDir: engineBuildDir,
wasmReleaseOutDir: wasmReleaseOutDir,
hostDebugUnoptDir: hostDebugUnoptDir,
dartSdkDir: dartSdkDir,
);
}
Expand All @@ -68,8 +66,8 @@ class Environment {
required this.engineSrcDir,
required this.engineToolsDir,
required this.outDir,
required this.engineBuildDir,
required this.wasmReleaseOutDir,
required this.hostDebugUnoptDir,
required this.dartSdkDir,
});

Expand All @@ -93,14 +91,14 @@ class Environment {
/// This is where you'll find the ninja output, such as the Dart SDK.
final io.Directory outDir;

/// The output directory for the host_debug_unopt build.
final io.Directory engineBuildDir;

/// The output directory for the wasm_release build.
///
/// We build CanvasKit in release mode to reduce code size.
final io.Directory wasmReleaseOutDir;

/// The output directory for the host_debug_unopt build.
final io.Directory hostDebugUnoptDir;

/// The root of the Dart SDK.
final io.Directory dartSdkDir;

Expand Down
Loading

0 comments on commit 2b21a31

Please sign in to comment.