diff --git a/build/toolchain/gcc_toolchain.gni b/build/toolchain/gcc_toolchain.gni index 87aedbe739..d0922eac68 100644 --- a/build/toolchain/gcc_toolchain.gni +++ b/build/toolchain/gcc_toolchain.gni @@ -291,6 +291,10 @@ template("gcc_toolchain") { if (defined(invoker.is_clang)) { is_clang = invoker.is_clang } + + if (defined(invoker.extra_toolchain_args)) { + forward_variables_from(invoker.extra_toolchain_args, "*") + } } if (defined(invoker.deps)) { diff --git a/build/toolchain/wasm.gni b/build/toolchain/wasm.gni index 94bfdbf4b0..73111f0a2c 100644 --- a/build/toolchain/wasm.gni +++ b/build/toolchain/wasm.gni @@ -2,6 +2,10 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +import("//build/toolchain/ccache.gni") +import("//build/toolchain/gcc_toolchain.gni") +import("//build/toolchain/goma.gni") + # Defines the configuration of emscripten for building WASM targets. declare_args() { @@ -9,10 +13,42 @@ declare_args() { emsdk_dir = rebase_path("//buildtools/emsdk") } -wasm_toolchain = "//build/toolchain/wasm" - em_config_path = "$emsdk_dir/.emscripten" +if (use_goma) { + assert(!use_ccache, "Goma and ccache can't be used together.") + compiler_prefix = "$goma_dir/gomacc " +} else if (use_ccache) { + compiler_prefix = "ccache " +} else { + compiler_prefix = "" +} + +template("wasm_toolchain") { + gcc_toolchain(target_name) { + # emsdk_dir and em_config are defined in wasm.gni. + ar = "$compiler_prefix$emsdk_dir/upstream/emscripten/emar --em-config $em_config_path" + cc = "$compiler_prefix$emsdk_dir/upstream/emscripten/emcc --em-config $em_config_path" + cxx = "$compiler_prefix$emsdk_dir/upstream/emscripten/em++ --em-config $em_config_path" + ld = cxx + readelf = "readelf" + nm = "nm" + + toolchain_cpu = "wasm" + toolchain_os = "wasm" + + is_clang = true + + link_outputs = [ "{{root_out_dir}}/{{target_output_name}}.wasm" ] + + extra_toolchain_args = { + if (defined(invoker.extra_toolchain_args)) { + forward_variables_from(invoker.extra_toolchain_args, "*") + } + } + } +} + # Defines a WASM library target. # Args: # export_name: The public name of the module to expose (EXPORT_NAME for diff --git a/build/toolchain/wasm/BUILD.gn b/build/toolchain/wasm/BUILD.gn index e11b5687da..cfaf51bd40 100644 --- a/build/toolchain/wasm/BUILD.gn +++ b/build/toolchain/wasm/BUILD.gn @@ -2,34 +2,8 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -import("//build/toolchain/ccache.gni") -import("//build/toolchain/clang.gni") -import("//build/toolchain/gcc_toolchain.gni") -import("//build/toolchain/goma.gni") import("//build/toolchain/wasm.gni") -if (use_goma) { - assert(!use_ccache, "Goma and ccache can't be used together.") - compiler_prefix = "$goma_dir/gomacc " -} else if (use_ccache) { - compiler_prefix = "ccache " -} else { - compiler_prefix = "" -} - -gcc_toolchain("wasm") { - # emsdk_dir and em_config are defined in wasm.gni. - ar = "$compiler_prefix$emsdk_dir/upstream/emscripten/emar --em-config $em_config_path" - cc = "$compiler_prefix$emsdk_dir/upstream/emscripten/emcc --em-config $em_config_path" - cxx = "$compiler_prefix$emsdk_dir/upstream/emscripten/em++ --em-config $em_config_path" - ld = cxx - readelf = "readelf" - nm = "nm" - - toolchain_cpu = "wasm" - toolchain_os = "wasm" - - is_clang = true - - link_outputs = [ "{{root_out_dir}}/{{target_output_name}}.wasm" ] +wasm_toolchain("wasm") { + extra_toolchain_args = {} }