1# Copyright 2013 The Chromium 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 5import("//build/config/clang/clang.gni") 6import("//build/config/ohos/config.gni") 7import("//build/rust/rustc_toolchain.gni") 8import("//build/toolchain/gcc_toolchain.gni") 9 10declare_args() { 11 # Whether unstripped binaries, i.e. compiled with debug symbols, should be 12 # considered runtime_deps rather than stripped ones. 13 ohos_unstripped_runtime_outputs = true 14 ohos_extra_cflags = "" 15 ohos_extra_cppflags = "" 16 ohos_extra_cxxflags = "" 17 ohos_extra_asmflags = "" 18 ohos_extra_ldflags = "" 19} 20 21# The ohos clang toolchains share most of the same parameters, so we have this 22# wrapper around gcc_toolchain to avoid duplication of logic. 23# 24# Parameters: 25# - toolchain_root 26# Path to cpu-specific toolchain within the ndk. 27# - sysroot 28# Sysroot for this architecture. 29# - lib_dir 30# Subdirectory inside of sysroot where libs go. 31# - binary_prefix 32# Prefix of compiler executables. 33template("ohos_clang_toolchain") { 34 gcc_toolchain(target_name) { 35 assert(defined(invoker.toolchain_args), 36 "toolchain_args must be defined for ohos_clang_toolchain()") 37 toolchain_args = invoker.toolchain_args 38 toolchain_args.current_os = "ohos" 39 40 # Output linker map files for binary size analysis. 41 enable_linker_map = true 42 43 ohos_libc_dir = 44 rebase_path(invoker.sysroot + "/" + invoker.lib_dir, root_build_dir) 45 libs_section_prefix = "${ohos_libc_dir}/Scrt1.o" 46 libs_section_prefix += " ${ohos_libc_dir}/crti.o" 47 libs_section_postfix = "${ohos_libc_dir}/crtn.o" 48 49 if (invoker.target_name == "ohos_clang_arm") { 50 abi_target = "arm-linux-ohos" 51 } else if (invoker.target_name == "ohos_clang_arm64") { 52 abi_target = "aarch64-linux-ohos" 53 } else if (invoker.target_name == "ohos_clang_x86_64") { 54 abi_target = "x86_64-linux-ohos" 55 } 56 57 clang_rt_dir = 58 rebase_path("${clang_lib_base_path}/${abi_target}", root_build_dir) 59 solink_libs_section_prefix = "${ohos_libc_dir}/crti.o" 60 solink_libs_section_prefix += " ${clang_rt_dir}/clang_rt.crtbegin.o" 61 solink_libs_section_postfix = "${ohos_libc_dir}/crtn.o" 62 solink_libs_section_postfix += " ${clang_rt_dir}/clang_rt.crtend.o" 63 64 _prefix = rebase_path("${clang_base_path}/bin", root_build_dir) 65 cc = "${_prefix}/clang" 66 cxx = "${_prefix}/clang++" 67 ar = "${_prefix}/llvm-ar" 68 ld = cxx 69 readelf = "${_prefix}/llvm-readobj" 70 nm = "${_prefix}/llvm-nm" 71 if (!is_debug) { 72 strip = rebase_path("${clang_base_path}/bin/llvm-strip", root_build_dir) 73 use_unstripped_as_runtime_outputs = ohos_unstripped_runtime_outputs 74 } 75 extra_cflags = ohos_extra_cflags 76 extra_cppflags = ohos_extra_cppflags 77 extra_cxxflags = ohos_extra_cxxflags 78 extra_asmflags = ohos_extra_asmflags 79 extra_ldflags = ohos_extra_ldflags 80 81 # Don't use .cr.so for loadable_modules since they are always loaded via 82 # absolute path. 83 loadable_module_extension = ".so" 84 rust_abi_target = invoker.rust_abi_target 85 if (rust_abi_target == "armv7-linux-ohos") { 86 cc_command_args = "--target=${rust_abi_target} -Clinker=$cxx -Clink-arg=-lunwind -Clink-arg=-fuse-ld=lld -Clink-arg=-v -Clink-arg=--target=${abi_target} -Clink-arg=--sysroot=$musl_path -C target-feature=-crt-static -L $musllib -L${clang_base_path}/lib/${abi_target}/c++" 87 } else if (rust_abi_target == "aarch64-linux-ohos") { 88 cc_command_args = "--target=${rust_abi_target} -Clinker=$cxx -Clink-arg=-lunwind -Clink-arg=-fuse-ld=lld -Clink-arg=-v -Clink-arg=--target=${abi_target} -Clink-arg=--sysroot=$musl_path -C target-feature=-crt-static -L $musllib -L${clang_base_path}/lib/${abi_target}/c++" 89 } else if (rust_abi_target == "x86_64-unknown-linux-gnu") { 90 cc_command_args = "--target=${rust_abi_target} -Clinker=$cxx -Clink-arg=-fuse-ld=lld -Clink-arg=-v -Clink-arg=--target=${abi_target}" 91 } 92 } 93} 94