• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2022 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_root/config/ohos/config.gni")
15import("$build_root/toolchain/gcc_toolchain.gni")
16
17declare_args() {
18  unstripped_runtime_outputs = true
19}
20
21template("ark_clang_toolchain") {
22  gcc_toolchain(target_name) {
23    ohos_libc_dir =
24        rebase_path(invoker.sysroot + "/" + invoker.lib_dir, root_build_dir)
25    libs_section_prefix = "${ohos_libc_dir}/Scrt1.o"
26    libs_section_prefix += " ${ohos_libc_dir}/crti.o"
27    libs_section_postfix = "${ohos_libc_dir}/crtn.o"
28
29    if (invoker.target_name == "ark_clang_arm") {
30      abi_target = "arm-linux-ohos"
31    } else if (invoker.target_name == "ark_clang_arm64") {
32      abi_target = "aarch64-linux-ohos"
33    } else if (invoker.target_name == "ark_clang_x86_64") {
34      abi_target = "x86_64-linux-ohos"
35    }
36
37    clang_rt_dir =
38        rebase_path("${clang_lib_base_path}/${abi_target}", root_build_dir)
39    solink_libs_section_prefix = "${ohos_libc_dir}/crti.o"
40    solink_libs_section_prefix += " ${clang_rt_dir}/clang_rt.crtbegin.o"
41    solink_libs_section_postfix = "${ohos_libc_dir}/crtn.o"
42    solink_libs_section_postfix += " ${clang_rt_dir}/clang_rt.crtend.o"
43
44    prefix = rebase_path("${clang_base_path}/bin", root_build_dir)
45    cc = "${prefix}/clang"
46    cxx = "${prefix}/clang++"
47    ar = "${prefix}/llvm-ar"
48    ld = cxx
49    if (!is_debug) {
50      strip = "${prefix}/llvm-strip"
51      use_unstripped_as_runtime_outputs = unstripped_runtime_outputs
52    }
53
54    toolchain_args = {
55      if (defined(invoker.toolchain_args)) {
56        forward_variables_from(invoker.toolchain_args, "*")
57      }
58      is_clang = true
59    }
60
61    if (defined(invoker.shlib_extension) && invoker.shlib_extension != "") {
62      shlib_extension = invoker.shlib_extension
63    }
64  }
65}
66