Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
4c70893
Update ICU and license checks
harryterkelsen Apr 22, 2022
a7dd7f9
Build CanvasKit using cross-compilation as part of the Web SDK build
harryterkelsen Apr 22, 2022
5ec414b
Merge branch 'main' into crosscompile-wasm
harryterkelsen Apr 26, 2022
7de9a6b
Update GN for flutter_web_sdk
harryterkelsen Apr 27, 2022
4ae3584
gn format
harryterkelsen Apr 27, 2022
9225fe8
Merge branch 'main' into crosscompile-wasm
harryterkelsen Apr 27, 2022
ae79d17
Undo changes to licenses
harryterkelsen Apr 27, 2022
fbd145c
Merge branch 'main' into crosscompile-wasm
harryterkelsen Apr 28, 2022
da0a929
Merge branch 'main' into crosscompile-wasm
harryterkelsen May 5, 2022
7255b6d
Fix merge conflict
harryterkelsen May 5, 2022
8fdba5f
Merge branch 'main' into crosscompile-wasm
harryterkelsen May 9, 2022
92fe4ca
Merge branch 'main' into crosscompile-wasm
harryterkelsen May 17, 2022
5e150c5
WIP update ICU dep and add stamp file for recipes
harryterkelsen May 18, 2022
b2edf99
Update .ci.yaml with gclient custom vars
harryterkelsen May 18, 2022
e43a467
Put boolean in quotes to try to appease json decoder
harryterkelsen May 18, 2022
8623343
Revert "Revert "Update ICU to 71-1 (#32879)" (#33274)"
harryterkelsen May 18, 2022
0f50af0
Update licenses
harryterkelsen May 18, 2022
d29d199
Try to fix format of ci.yaml
harryterkelsen May 18, 2022
e0ccb57
Remove hostDebugUnoptDir since it's not used in the web build
harryterkelsen May 18, 2022
1ca5973
Update dart-sdk dir
harryterkelsen May 18, 2022
def1ed8
Update analysis script
harryterkelsen May 18, 2022
8794719
typo
harryterkelsen May 18, 2022
dc67639
Merge branch 'main' into crosscompile-wasm
harryterkelsen Jun 7, 2022
7ca592b
Update to latest main
harryterkelsen Jun 7, 2022
80b6e04
pyformat
harryterkelsen Jun 8, 2022
3f98442
fix formatting
harryterkelsen Jun 8, 2022
05a7f8f
Merge branch 'main' into crosscompile-wasm
harryterkelsen Aug 25, 2022
0709ea7
WIP
harryterkelsen Aug 29, 2022
f7fbcd0
Merge branch 'main' into crosscompile-wasm
harryterkelsen Aug 29, 2022
6309a4b
Cross-compile CanvasKit as part of the normal build
harryterkelsen Sep 6, 2022
2510896
Format gn
harryterkelsen Sep 6, 2022
6a8cdfa
Fix formatting
harryterkelsen Sep 6, 2022
b845f65
Merge branch 'main' into crosscompile-wasm
harryterkelsen Sep 6, 2022
3b15d6f
Rename toolchain
harryterkelsen Sep 7, 2022
8452fac
Revert bad merge
harryterkelsen Sep 7, 2022
4eee7a3
Format
harryterkelsen Sep 7, 2022
e003d5e
Merge branch 'main' into crosscompile-wasm
harryterkelsen Sep 7, 2022
7ade9fc
Fix merge
harryterkelsen Sep 7, 2022
662d022
Fix merge more
harryterkelsen Sep 7, 2022
719ae93
More cleanups
harryterkelsen Sep 7, 2022
215dad0
Clean up BUILD.gn
harryterkelsen Sep 7, 2022
f6a8e39
Format
harryterkelsen Sep 7, 2022
f3e6ec4
Fix up build
harryterkelsen Sep 7, 2022
1df1ca1
Fix bad name
harryterkelsen Sep 9, 2022
e1e7f58
Merge branch 'main' into crosscompile-wasm
harryterkelsen Sep 12, 2022
e002743
Undo bad merge
harryterkelsen Sep 12, 2022
d8e71d0
touchup bad merge
harryterkelsen Sep 12, 2022
5aac869
more merge
harryterkelsen Sep 12, 2022
7840983
Start to convert to building CanvasKit separately as part of a WASM
harryterkelsen Sep 12, 2022
ea79185
Refactor to build CanvasKit into out/wasm_debug
harryterkelsen Sep 13, 2022
a2105ca
Fix formatting
harryterkelsen Sep 13, 2022
155be8a
Merge branch 'main' into crosscompile-wasm
harryterkelsen Sep 13, 2022
b5bddae
Build CanvasKit in release mode for codesize
harryterkelsen Sep 13, 2022
90c183b
Roll buildroot
harryterkelsen Sep 13, 2022
3a0bb7d
format fix
harryterkelsen Sep 13, 2022
1d8cb76
Add documentation
harryterkelsen Sep 13, 2022
dd84da3
Keep `download_emsdk` to False for now
harryterkelsen Sep 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ allowed_hosts = [
]

deps = {
'src': 'https://github.com/flutter/buildroot.git' + '@' + '337fdd987f500ca48902aef9abbcde98be2803c7',
'src': 'https://github.com/flutter/buildroot.git' + '@' + 'af893d511e89f93194f86dae8a4ef39e3b3fe59b',

# Fuchsia compatibility
#
Expand Down
11 changes: 7 additions & 4 deletions lib/web_ui/dev/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class BuildCommand extends Command<bool> with ArgUtils<bool> {
if (buildCanvasKit) {
steps.addAll(<PipelineStep>[
GnPipelineStep(target: 'canvaskit'),
NinjaPipelineStep(target: environment.canvasKitOutDir),
NinjaPipelineStep(target: environment.wasmReleaseOutDir),
]);
}
final Pipeline buildPipeline = Pipeline(steps: steps);
Expand All @@ -74,7 +74,7 @@ class BuildCommand extends Command<bool> with ArgUtils<bool> {
/// 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 == 'sdk');
: assert(target == 'engine' || target == 'canvaskit');

@override
String get description => 'gn';
Expand All @@ -89,7 +89,7 @@ class GnPipelineStep extends ProcessStep {

@override
Future<ProcessManager> createProcess() {
print('Running gn...');
print('Running gn for $target...');
final List<String> gnArgs = <String>[];
if (target == 'engine') {
gnArgs.addAll(<String>[
Expand All @@ -98,7 +98,10 @@ class GnPipelineStep extends ProcessStep {
'--full-dart-sdk',
]);
} else if (target == 'canvaskit') {
gnArgs.add('--wasm');
gnArgs.addAll(<String>[
'--wasm',
'--runtime-mode=release',
]);
} else {
throw StateError('Target was not engine or canvaskit: $target');
}
Expand Down
17 changes: 10 additions & 7 deletions lib/web_ui/dev/environment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class Environment {
io.Directory(pathlib.join(engineSrcDir.path, 'out'));
final io.Directory hostDebugUnoptDir =
io.Directory(pathlib.join(outDir.path, 'host_debug_unopt'));
final io.Directory canvasKitOutDir =
io.Directory(pathlib.join(outDir.path, 'wasm_debug'));
final io.Directory wasmReleaseOutDir =
io.Directory(pathlib.join(outDir.path, 'wasm_release'));
final io.Directory dartSdkDir =
io.Directory(pathlib.join(hostDebugUnoptDir.path, 'dart-sdk'));
final io.Directory webUiRootDir = io.Directory(
Expand All @@ -44,14 +44,15 @@ class Environment {
}
}


return Environment._(
self: self,
webUiRootDir: webUiRootDir,
engineSrcDir: engineSrcDir,
engineToolsDir: engineToolsDir,
outDir: outDir,
hostDebugUnoptDir: hostDebugUnoptDir,
canvasKitOutDir: canvasKitOutDir,
wasmReleaseOutDir: wasmReleaseOutDir,
dartSdkDir: dartSdkDir,
);
}
Expand All @@ -63,7 +64,7 @@ class Environment {
required this.engineToolsDir,
required this.outDir,
required this.hostDebugUnoptDir,
required this.canvasKitOutDir,
required this.wasmReleaseOutDir,
required this.dartSdkDir,
});

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

/// The "host_debug_unopt" build of the Dart SDK.
/// The output directory for the host_debug_unopt build.
final io.Directory hostDebugUnoptDir;

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

/// The root of the Dart SDK.
final io.Directory dartSdkDir;
Expand Down
21 changes: 14 additions & 7 deletions lib/web_ui/dev/steps/compile_tests_step.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ import '../utils.dart';
/// * test/ - compiled test code
/// * test_images/ - test images copied from Skis sources.
class CompileTestsStep implements PipelineStep {
CompileTestsStep({this.testFiles});
CompileTestsStep({this.testFiles, this.useLocalCanvasKit = false});

final List<FilePath>? testFiles;

final bool useLocalCanvasKit;

@override
String get description => 'compile_tests';

Expand All @@ -41,7 +43,7 @@ class CompileTestsStep implements PipelineStep {
@override
Future<void> run() async {
await environment.webUiBuildDir.create();
await copyCanvasKitFiles();
await copyCanvasKitFiles(useLocalCanvasKit: useLocalCanvasKit);
await buildHostPage();
await copyTestFonts();
await copySkiaTestImages();
Expand Down Expand Up @@ -122,11 +124,13 @@ Future<void> copySkiaTestImages() async {
}
}

Future<void> copyCanvasKitFiles() async {
Future<void> copyCanvasKitFiles({bool useLocalCanvasKit = false}) async {
// If CanvasKit has been built locally, use that instead of the CIPD version.
final io.File localCanvasKitWasm =
io.File(pathlib.join(environment.canvasKitOutDir.path, 'canvaskit.wasm'));
final bool builtLocalCanvasKit = localCanvasKitWasm.existsSync();
final io.File localCanvasKitWasm = io.File(pathlib.join(
environment.wasmReleaseOutDir.path,
'canvaskit.wasm',
));
final bool builtLocalCanvasKit = localCanvasKitWasm.existsSync() && useLocalCanvasKit;

final io.Directory targetDir = io.Directory(pathlib.join(
environment.webUiBuildDir.path,
Expand All @@ -136,7 +140,10 @@ Future<void> copyCanvasKitFiles() async {
if (builtLocalCanvasKit) {
final List<io.File> canvasKitFiles = <io.File>[
localCanvasKitWasm,
io.File(pathlib.join(environment.canvasKitOutDir.path, 'canvaskit.js')),
io.File(pathlib.join(
environment.wasmReleaseOutDir.path,
'canvaskit.js',
)),
];
for (final io.File file in canvasKitFiles) {
final io.File normalTargetFile = io.File(pathlib.join(
Expand Down
10 changes: 9 additions & 1 deletion lib/web_ui/dev/test_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ class TestCommand extends Command<bool> with ArgUtils<bool> {
help: 'Optional. The path to a local build of CanvasKit to use in '
'tests. If omitted, the test runner uses the default CanvasKit '
'build.',
)
..addFlag(
'use-local-canvaskit',
help: 'Optional. Whether or not to use the locally built version of '
'CanvasKit in the tests.',
);
}

Expand Down Expand Up @@ -115,6 +120,9 @@ class TestCommand extends Command<bool> with ArgUtils<bool> {
/// Path to a CanvasKit build. Overrides the default CanvasKit.
String? get overridePathToCanvasKit => argResults!['canvaskit-path'] as String?;

/// Whether or not to use the locally built version of CanvasKit.
bool get useLocalCanvasKit => boolArg('use-local-canvaskit');

@override
Future<bool> run() async {
final List<FilePath> testFiles = runAllTests
Expand All @@ -123,7 +131,7 @@ class TestCommand extends Command<bool> with ArgUtils<bool> {

final Pipeline testPipeline = Pipeline(steps: <PipelineStep>[
if (isWatchMode) ClearTerminalScreenStep(),
CompileTestsStep(testFiles: testFiles),
CompileTestsStep(testFiles: testFiles, useLocalCanvasKit: useLocalCanvasKit),
RunTestsStep(
browserName: browserName,
testFiles: testFiles,
Expand Down
137 changes: 98 additions & 39 deletions tools/gn
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,14 @@ def to_gn_args(args):

gn_args = {}

gn_args['is_debug'] = args.unoptimized

# If building for WASM, set the GN args using 'to_gn_wasm_args' as most
# of the Flutter SDK specific arguments are unused.
if args.target_os == 'wasm':
to_gn_wasm_args(args, gn_args)
return gn_args

if args.bitcode:
if args.target_os != 'ios':
raise Exception('Bitcode is only supported for iOS')
Expand All @@ -237,13 +245,8 @@ def to_gn_args(args):

if args.enable_skshaper:
gn_args['skia_use_icu'] = True
if args.target_os != 'wasm':
gn_args['flutter_always_use_skshaper'] = args.always_use_skshaper
else:
gn_args['skia_use_harfbuzz'] = True
gn_args['icu_use_data_file'] = False
gn_args['flutter_always_use_skshaper'] = args.always_use_skshaper
gn_args['is_official_build'] = True # Disable Skia test utilities.
gn_args['is_debug'] = args.unoptimized
gn_args['android_full_debug'
] = args.target_os == 'android' and args.unoptimized
if args.clang is None:
Expand All @@ -253,8 +256,6 @@ def to_gn_args(args):

if args.target_os == 'android' or args.target_os == 'ios':
gn_args['skia_gl_standard'] = 'gles'
elif args.target_os == 'wasm':
gn_args['skia_gl_standard'] = 'webgl'
else:
# We explicitly don't want to pick GL because we run GLES tests using SwiftShader.
gn_args['skia_gl_standard'] = ''
Expand Down Expand Up @@ -318,36 +319,34 @@ def to_gn_args(args):
gn_args['dart_debug'] = True
gn_args['dart_debug_optimization_level'] = '0'

# Flutter-specific arguments which don't apply for a CanvasKit build.
if args.target_os != 'wasm':
gn_args['flutter_use_fontconfig'] = args.enable_fontconfig
gn_args['flutter_enable_skshaper'] = args.enable_skshaper
gn_args['dart_component_kind'
] = 'static_library' # Always link Dart in statically.
gn_args['embedder_for_target'] = args.embedder_for_target
gn_args['dart_lib_export_symbols'] = False
gn_args['flutter_runtime_mode'] = runtime_mode
gn_args['full_dart_sdk'] = args.full_dart_sdk
gn_args['dart_version_git_info'] = not args.no_dart_version_git_info

gn_args['dart_lib_export_symbols'] = False
if runtime_mode == 'debug':
gn_args['dart_runtime_mode'] = 'develop'
elif runtime_mode == 'jit_release':
gn_args['dart_runtime_mode'] = 'release'
else:
gn_args['dart_runtime_mode'] = runtime_mode
gn_args['flutter_use_fontconfig'] = args.enable_fontconfig
gn_args['flutter_enable_skshaper'] = args.enable_skshaper
gn_args['dart_component_kind'
] = 'static_library' # Always link Dart in statically.
gn_args['embedder_for_target'] = args.embedder_for_target
gn_args['dart_lib_export_symbols'] = False
gn_args['flutter_runtime_mode'] = runtime_mode
gn_args['full_dart_sdk'] = args.full_dart_sdk
gn_args['dart_version_git_info'] = not args.no_dart_version_git_info

gn_args['dart_lib_export_symbols'] = False
if runtime_mode == 'debug':
gn_args['dart_runtime_mode'] = 'develop'
elif runtime_mode == 'jit_release':
gn_args['dart_runtime_mode'] = 'release'
else:
gn_args['dart_runtime_mode'] = runtime_mode

# Desktop embeddings can have more dependencies than the engine library,
# which can be problematic in some build environments (e.g., building on
# Linux will bring in pkg-config dependencies at generation time). These
# flags allow preventing those those targets from being part of the build
# tree.
gn_args['enable_desktop_embeddings'] = not args.disable_desktop_embeddings
# Desktop embeddings can have more dependencies than the engine library,
# which can be problematic in some build environments (e.g., building on
# Linux will bring in pkg-config dependencies at generation time). These
# flags allow preventing those those targets from being part of the build
# tree.
gn_args['enable_desktop_embeddings'] = not args.disable_desktop_embeddings

# Overrides whether Boring SSL is compiled with system as. Only meaningful
# on Android.
gn_args['bssl_use_clang_integrated_as'] = True
# Overrides whether Boring SSL is compiled with system as. Only meaningful
# on Android.
gn_args['bssl_use_clang_integrated_as'] = True

if args.allow_deprecated_api_calls:
gn_args['allow_deprecated_api_calls'] = args.allow_deprecated_api_calls
Expand Down Expand Up @@ -417,8 +416,7 @@ def to_gn_args(args):
else:
gn_args['skia_use_gl'] = args.target_os != 'fuchsia'

if sys.platform == 'darwin' and args.target_os not in ['android', 'fuchsia',
'wasm']:
if sys.platform == 'darwin' and args.target_os not in ['android', 'fuchsia']:
# OpenGL is deprecated on macOS > 10.11.
# This is not necessarily needed but enabling this until we have a way to
# build a macOS metal only shell and a gl only shell.
Expand All @@ -429,7 +427,7 @@ def to_gn_args(args):
# Enable Vulkan on all platforms except for Android and iOS. This is just
# to save on mobile binary size, as there's no reason the Vulkan embedder
# features can't work on these platforms.
if args.target_os not in ['android', 'ios', 'wasm']:
if args.target_os not in ['android', 'ios']:
gn_args['skia_use_vulkan'] = True
gn_args['skia_vulkan_memory_allocator_dir'
] = '//third_party/vulkan_memory_allocator'
Expand Down Expand Up @@ -569,6 +567,67 @@ def to_gn_args(args):
return gn_args


# When building for WASM, almost all GN args used in the Flutter SDK
# build are unused. This method is used instead.
def to_gn_wasm_args(args, gn_args):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A comment explaining this function could be useful in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

gn_args['is_official_build'] = True
gn_args['skia_enable_flutter_defines'] = True
gn_args['is_component_build'] = False
gn_args['use_clang_static_analyzer'] = False
gn_args['is_clang'] = True
gn_args['target_os'] = 'wasm'
gn_args['target_cpu'] = 'wasm'
gn_args['skia_use_angle'] = False
gn_args['skia_use_dng_sdk'] = False
gn_args['skia_use_expat'] = False
gn_args['skia_use_vulkan'] = False
gn_args['skia_use_webgpu'] = False
gn_args['skia_use_libheif'] = False
gn_args['skia_use_libjpeg_turbo_decode'] = True
gn_args['skia_use_libjpeg_turbo_encode'] = False
gn_args['skia_use_libpng_decode'] = True
gn_args['skia_use_libpng_encode'] = True
gn_args['skia_use_libwebp_decode'] = True
gn_args['skia_use_libwebp_encode'] = False
gn_args['skia_use_lua'] = False
gn_args['skia_use_wuffs'] = True
gn_args['skia_use_zlib'] = True
gn_args['skia_gl_standard'] = 'webgl'
gn_args['skia_enable_gpu'] = True
gn_args['skia_enable_sksl_tracing'] = False
gn_args['skia_use_icu'] = True
gn_args['icu_use_data_file'] = False
gn_args['skia_use_freetype'] = True
gn_args['skia_use_harfbuzz'] = True
gn_args['skia_use_fontconfig'] = False
gn_args['skia_use_libheif'] = False
gn_args['skia_enable_fontmgr_custom_directory'] = False
gn_args['skia_enable_fontmgr_custom_embedded'] = True
gn_args['skia_enable_fontmgr_custom_empty'] = False
gn_args['skia_enable_skshaper'] = True
gn_args['skia_enable_skparagraph'] = True
gn_args['skia_canvaskit_force_tracing'] = False
gn_args['skia_canvaskit_enable_skp_serialization'] = True
gn_args['skia_canvaskit_enable_effects_deserialization'] = False
gn_args['skia_canvaskit_enable_skottie'] = False
gn_args['skia_canvaskit_include_viewer'] = False
gn_args['skia_canvaskit_enable_particles'] = False
gn_args['skia_canvaskit_enable_pathops'] = True
gn_args['skia_canvaskit_enable_rt_shader'] = True
gn_args['skia_canvaskit_enable_matrix_helper'] = False
gn_args['skia_canvaskit_enable_canvas_bindings'] = False
gn_args['skia_canvaskit_enable_font'] = True
gn_args['skia_canvaskit_enable_embedded_font'] = True
gn_args['skia_canvaskit_enable_alias_font'] = True
gn_args['skia_canvaskit_legacy_draw_vertices_blend_mode'] = False
gn_args['skia_canvaskit_enable_debugger'] = False
gn_args['skia_canvaskit_enable_paragraph'] = True
gn_args['skia_canvaskit_enable_webgl'] = True
gn_args['skia_canvaskit_enable_webgpu'] = False
is_profile_build = args.runtime_mode == 'profile' or args.runtime_mode == 'debug'
gn_args['skia_canvaskit_profile_build'] = is_profile_build


def parse_args(args):
args = args[1:]
parser = argparse.ArgumentParser(description='A script to run `gn gen`.')
Expand Down
12 changes: 12 additions & 0 deletions wasm/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright 2022 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.

# This BUILD.gn is kept separate from //flutter/BUILD.gn because
# //flutter/BUILD.gn pulls in Flutter SDK dependencies which will crash
# when the target CPU is WASM.

# This is the default target when building when the target CPU is WASM.
group("wasm") {
deps = [ "//third_party/skia/modules/canvaskit" ]
}