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

Commit 7d3233d

Browse files
authored
[web] Build multiple CanvasKit variants (using toolchain_args) (#38448)
* [web] New gn for building CanvasKit * Use toolchain_args to override CanvasKit gn args * Use correct path for the generated canvaskit files * Put toolchain close to target * remove extra toolchains * remove extra import * add canvaskit_lite to archive * fix local canvaskit path in tests * add some guards using visibility and asserts * renames * formatting * rename mistake * Add github issue to the TODO * Update buildroot sha * clang-tidy error * skip canvaskit targets when not needed
1 parent 94fc072 commit 7d3233d

File tree

6 files changed

+71
-6
lines changed

6 files changed

+71
-6
lines changed

DEPS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ allowed_hosts = [
236236
]
237237

238238
deps = {
239-
'src': 'https://github.com/flutter/buildroot.git' + '@' + 'b2ab6e1908b3eb268d2a2cab1ec5b63f38e1bc11',
239+
'src': 'https://github.com/flutter/buildroot.git' + '@' + '5ca962cdf56fa8e7313a37237d9f1d7e7466b93b',
240240

241241
# Fuchsia compatibility
242242
#

lib/web_ui/dev/steps/compile_tests_step.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ Future<void> copyCanvasKitFiles({bool useLocalCanvasKit = false}) async {
144144
// If CanvasKit has been built locally, use that instead of the CIPD version.
145145
final io.File localCanvasKitWasm = io.File(pathlib.join(
146146
environment.wasmReleaseOutDir.path,
147+
'canvaskit',
147148
'canvaskit.wasm',
148149
));
149150
final bool builtLocalCanvasKit = localCanvasKitWasm.existsSync();
@@ -163,6 +164,7 @@ Future<void> copyCanvasKitFiles({bool useLocalCanvasKit = false}) async {
163164
localCanvasKitWasm,
164165
io.File(pathlib.join(
165166
environment.wasmReleaseOutDir.path,
167+
'canvaskit',
166168
'canvaskit.js',
167169
)),
168170
];

third_party/canvaskit/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("//build/toolchain/wasm.gni")
6+
import("canvaskit.gni")
7+
8+
if (build_canvaskit) {
9+
# This toolchain is only to be used by canvaskit_group below.
10+
wasm_toolchain("canvaskit") {
11+
extra_toolchain_args = {
12+
skia_use_icu = true
13+
skia_use_client_icu = false
14+
}
15+
}
16+
17+
group("canvaskit_group") {
18+
visibility = [ "//flutter/web_sdk:*" ]
19+
public_deps = [ "//third_party/skia/modules/canvaskit(:canvaskit)" ]
20+
}
21+
}
22+
23+
if (build_canvaskit_chromium) {
24+
# This toolchain is only to be used by canvaskit_chromium_group below.
25+
wasm_toolchain("canvaskit_chromium") {
26+
extra_toolchain_args = {
27+
skia_use_icu = false
28+
skia_use_client_icu = true
29+
}
30+
}
31+
32+
group("canvaskit_chromium_group") {
33+
visibility = [ "//flutter/web_sdk:*" ]
34+
public_deps =
35+
[ "//third_party/skia/modules/canvaskit(:canvaskit_chromium)" ]
36+
}
37+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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+
declare_args() {
6+
build_canvaskit = false
7+
build_canvaskit_chromium = false
8+
}

tools/gn

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,6 @@ def to_gn_wasm_args(args, gn_args):
620620
gn_args['skia_gl_standard'] = 'webgl'
621621
gn_args['skia_enable_gpu'] = True
622622
gn_args['skia_enable_sksl_tracing'] = False
623-
gn_args['skia_use_icu'] = True
624623
gn_args['icu_use_data_file'] = False
625624
gn_args['skia_use_freetype'] = True
626625
gn_args['skia_use_harfbuzz'] = True
@@ -659,6 +658,9 @@ def to_gn_wasm_args(args, gn_args):
659658
# than forced to true, once the recipes are updated.
660659
# https://github.com/flutter/flutter/issues/113303
661660
gn_args['build_canvaskit'] = True
661+
# TODO(mdebbar): Read this from an input argument.
662+
# https://github.com/flutter/flutter/issues/118744
663+
gn_args['build_canvaskit_chromium'] = False
662664
gn_args['flutter_build_web_sdk'] = True
663665

664666

web_sdk/BUILD.gn

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
import("//flutter/build/zip_bundle.gni")
66
import("//flutter/common/config.gni")
7+
import("//flutter/third_party/canvaskit/canvaskit.gni")
78
import("//third_party/dart/build/dart/dart_action.gni")
89

910
declare_args() {
10-
build_canvaskit = false
1111
archive_flutter_web_sdk = true
1212
}
1313

@@ -561,7 +561,10 @@ if (!is_fuchsia) {
561561
] + web_engine_libraries
562562

563563
if (build_canvaskit) {
564-
deps += [ "//third_party/skia/modules/canvaskit" ]
564+
deps += [ "//flutter/third_party/canvaskit:canvaskit_group" ]
565+
}
566+
if (build_canvaskit_chromium) {
567+
deps += [ "//flutter/third_party/canvaskit:canvaskit_chromium_group" ]
565568
}
566569

567570
# flutter_ddc_modules
@@ -604,15 +607,28 @@ if (!is_fuchsia) {
604607
if (build_canvaskit) {
605608
tmp_files += [
606609
{
607-
source = rebase_path("$root_out_dir/canvaskit.js")
610+
source = rebase_path("$root_out_dir/canvaskit/canvaskit.js")
608611
destination = "flutter_web_sdk/canvaskit/canvaskit.js"
609612
},
610613
{
611-
source = rebase_path("$root_out_dir/canvaskit.wasm")
614+
source = rebase_path("$root_out_dir/canvaskit/canvaskit.wasm")
612615
destination = "flutter_web_sdk/canvaskit/canvaskit.wasm"
613616
},
614617
]
615618
}
619+
if (build_canvaskit_chromium) {
620+
tmp_files += [
621+
{
622+
source = rebase_path("$root_out_dir/canvaskit_chromium/canvaskit.js")
623+
destination = "flutter_web_sdk/canvaskit_chromium/canvaskit.js"
624+
},
625+
{
626+
source =
627+
rebase_path("$root_out_dir/canvaskit_chromium/canvaskit.wasm")
628+
destination = "flutter_web_sdk/canvaskit_chromium/canvaskit.wasm"
629+
},
630+
]
631+
}
616632
files = tmp_files
617633
}
618634
}

0 commit comments

Comments
 (0)