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_riscv64") { 54 abi_target = "riscv64-linux-ohos" 55 } else if (invoker.target_name == "ohos_clang_x86_64") { 56 abi_target = "x86_64-linux-ohos" 57 } 58 59 if (is_legacy) { 60 clang_rt_dir = 61 rebase_path("${clang_lib_base_path}/${abi_target}/nanlegacy", 62 root_build_dir) 63 } else { 64 clang_rt_dir = 65 rebase_path("${clang_lib_base_path}/${abi_target}", root_build_dir) 66 } 67 68 solink_libs_section_prefix = "${ohos_libc_dir}/crti.o" 69 solink_libs_section_prefix += " ${clang_rt_dir}/clang_rt.crtbegin.o" 70 solink_libs_section_postfix = "${ohos_libc_dir}/crtn.o" 71 solink_libs_section_postfix += " ${clang_rt_dir}/clang_rt.crtend.o" 72 73 _prefix = rebase_path("${clang_base_path}/bin", root_build_dir) 74 cc = "${_prefix}/clang" 75 cxx = "${_prefix}/clang++" 76 ar = "${_prefix}/llvm-ar" 77 ld = cxx 78 readelf = "${_prefix}/llvm-readobj" 79 nm = "${_prefix}/llvm-nm" 80 if (!is_debug) { 81 strip = rebase_path("${clang_base_path}/bin/llvm-strip", root_build_dir) 82 use_unstripped_as_runtime_outputs = ohos_unstripped_runtime_outputs 83 } 84 extra_cflags = ohos_extra_cflags 85 extra_cppflags = ohos_extra_cppflags 86 extra_cxxflags = ohos_extra_cxxflags 87 extra_asmflags = ohos_extra_asmflags 88 extra_ldflags = ohos_extra_ldflags 89 90 # Don't use .cr.so for loadable_modules since they are always loaded via 91 # absolute path. 92 loadable_module_extension = ".so" 93 rust_abi_target = invoker.rust_abi_target 94 if (rust_abi_target == "armv7-linux-ohos") { 95 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++" 96 } else if (rust_abi_target == "aarch64-linux-ohos") { 97 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++" 98 } else if (rust_abi_target == "x86_64-unknown-linux-ohos") { 99 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++" 100 } else if (rust_abi_target == "x86_64-unknown-linux-gnu") { 101 cc_command_args = "--target=${rust_abi_target} -Clinker=$cxx -Clink-arg=-fuse-ld=lld -Clink-arg=-v -Clink-arg=--target=${abi_target}" 102 } else if (rust_abi_target == "riscv64-unknown-linux-ohos") { 103 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++" 104 } 105 } 106} 107