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

Commit 5ca962c

Browse files
authored
[web] Expose wasm_toolchain to customize CanvasKit through toolchain_args (#663)
1 parent 048ed7b commit 5ca962c

File tree

3 files changed

+44
-30
lines changed

3 files changed

+44
-30
lines changed

build/toolchain/gcc_toolchain.gni

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,10 @@ template("gcc_toolchain") {
291291
if (defined(invoker.is_clang)) {
292292
is_clang = invoker.is_clang
293293
}
294+
295+
if (defined(invoker.extra_toolchain_args)) {
296+
forward_variables_from(invoker.extra_toolchain_args, "*")
297+
}
294298
}
295299

296300
if (defined(invoker.deps)) {

build/toolchain/wasm.gni

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,53 @@
22
# Use of this source code is governed by a BSD-style license that can be
33
# found in the LICENSE file.
44

5+
import("//build/toolchain/ccache.gni")
6+
import("//build/toolchain/gcc_toolchain.gni")
7+
import("//build/toolchain/goma.gni")
8+
59
# Defines the configuration of emscripten for building WASM targets.
610

711
declare_args() {
812
# The location of an activated embedded emsdk.
913
emsdk_dir = rebase_path("//buildtools/emsdk")
1014
}
1115

12-
wasm_toolchain = "//build/toolchain/wasm"
13-
1416
em_config_path = "$emsdk_dir/.emscripten"
1517

18+
if (use_goma) {
19+
assert(!use_ccache, "Goma and ccache can't be used together.")
20+
compiler_prefix = "$goma_dir/gomacc "
21+
} else if (use_ccache) {
22+
compiler_prefix = "ccache "
23+
} else {
24+
compiler_prefix = ""
25+
}
26+
27+
template("wasm_toolchain") {
28+
gcc_toolchain(target_name) {
29+
# emsdk_dir and em_config are defined in wasm.gni.
30+
ar = "$compiler_prefix$emsdk_dir/upstream/emscripten/emar --em-config $em_config_path"
31+
cc = "$compiler_prefix$emsdk_dir/upstream/emscripten/emcc --em-config $em_config_path"
32+
cxx = "$compiler_prefix$emsdk_dir/upstream/emscripten/em++ --em-config $em_config_path"
33+
ld = cxx
34+
readelf = "readelf"
35+
nm = "nm"
36+
37+
toolchain_cpu = "wasm"
38+
toolchain_os = "wasm"
39+
40+
is_clang = true
41+
42+
link_outputs = [ "{{root_out_dir}}/{{target_output_name}}.wasm" ]
43+
44+
extra_toolchain_args = {
45+
if (defined(invoker.extra_toolchain_args)) {
46+
forward_variables_from(invoker.extra_toolchain_args, "*")
47+
}
48+
}
49+
}
50+
}
51+
1652
# Defines a WASM library target.
1753
# Args:
1854
# export_name: The public name of the module to expose (EXPORT_NAME for

build/toolchain/wasm/BUILD.gn

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,8 @@
22
# Use of this source code is governed by a BSD-style license that can be
33
# found in the LICENSE file.
44

5-
import("//build/toolchain/ccache.gni")
6-
import("//build/toolchain/clang.gni")
7-
import("//build/toolchain/gcc_toolchain.gni")
8-
import("//build/toolchain/goma.gni")
95
import("//build/toolchain/wasm.gni")
106

11-
if (use_goma) {
12-
assert(!use_ccache, "Goma and ccache can't be used together.")
13-
compiler_prefix = "$goma_dir/gomacc "
14-
} else if (use_ccache) {
15-
compiler_prefix = "ccache "
16-
} else {
17-
compiler_prefix = ""
18-
}
19-
20-
gcc_toolchain("wasm") {
21-
# emsdk_dir and em_config are defined in wasm.gni.
22-
ar = "$compiler_prefix$emsdk_dir/upstream/emscripten/emar --em-config $em_config_path"
23-
cc = "$compiler_prefix$emsdk_dir/upstream/emscripten/emcc --em-config $em_config_path"
24-
cxx = "$compiler_prefix$emsdk_dir/upstream/emscripten/em++ --em-config $em_config_path"
25-
ld = cxx
26-
readelf = "readelf"
27-
nm = "nm"
28-
29-
toolchain_cpu = "wasm"
30-
toolchain_os = "wasm"
31-
32-
is_clang = true
33-
34-
link_outputs = [ "{{root_out_dir}}/{{target_output_name}}.wasm" ]
7+
wasm_toolchain("wasm") {
8+
extra_toolchain_args = {}
359
}

0 commit comments

Comments
 (0)