1# Copyright (c) 2021 Huawei Device Co., Ltd.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6#     http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14import("//build/toolchain/gcc_toolchain.gni")
15declare_args() {
16  # Whether unstripped binaries, i.e. compiled with debug symbols, should be
17  # considered runtime_deps rather than stripped ones.
18  mingw_unstripped_runtime_outputs = true
19}
20
21template("mingw_toolchain") {
22  gcc_toolchain(target_name) {
23    assert(defined(invoker.toolchain_root),
24           "toolchain_root must be defined for mingw_toolchain.")
25    assert(defined(invoker.toolchain_args),
26           "toolchain_args must be defined for mingw_toolchain.")
27    toolchain_args = invoker.toolchain_args
28
29    # Output linker map files for binary size analysis.
30    enable_linker_map = true
31
32    _mingw_tool_prefix =
33        rebase_path("${invoker.toolchain_root}/bin", root_build_dir)
34
35    cc = "${_mingw_tool_prefix}/clang"
36    cxx = "${_mingw_tool_prefix}/clang++"
37    ar = "${_mingw_tool_prefix}/llvm-ar"
38    ld = cxx
39    readelf = "${_mingw_tool_prefix}/llvm-readelf"
40    nm = "${_mingw_tool_prefix}/llvm-nm"
41    strip = "${_mingw_tool_prefix}/llvm-strip"
42    use_unstripped_as_runtime_outputs = mingw_unstripped_runtime_outputs
43
44    executable_extension = ".exe"
45    shlib_extension = ".dll"
46    dylib_extension = ".dll"
47    rlib_extension = ".rlib"
48    rust_abi_target = invoker.rust_abi_target
49    if (rust_abi_target == "x86_64-pc-windows-gnullvm") {
50      cc_command_args = "--target=${rust_abi_target} -Clinker=${_mingw_tool_prefix}/x86_64-w64-mingw32-clang -Clink-arg=-Wl,-Bstatic -Clink-arg=-lunwind -Clink-arg=-fuse-ld=lld -Clink-arg=-Wl,-Bstatic -Clink-arg=-lc++ -Clink-arg=-v -Clink-arg=--target=${rust_abi_target}"
51    }
52  }
53}
54
55mingw_toolchain("mingw_x86_64") {
56  toolchain_root = "//prebuilts/mingw-w64/ohos/linux-x86_64/clang-mingw"
57  rust_abi_target = "x86_64-pc-windows-gnullvm"
58  toolchain_args = {
59    current_cpu = "x86_64"
60    current_os = "mingw"
61    use_custom_libcxx = false
62    is_clang = true
63  }
64}
65