15f9996aaSopenharmony_ci# Copyright 2013 The Chromium Authors. All rights reserved. 25f9996aaSopenharmony_ci# Use of this source code is governed by a BSD-style license that can be 35f9996aaSopenharmony_ci# found in the LICENSE file. 45f9996aaSopenharmony_ci 55f9996aaSopenharmony_ciimport("//build/config/clang/clang.gni") 65f9996aaSopenharmony_ciimport("//build/config/ohos/config.gni") 75f9996aaSopenharmony_ciimport("//build/rust/rustc_toolchain.gni") 85f9996aaSopenharmony_ciimport("//build/toolchain/gcc_toolchain.gni") 95f9996aaSopenharmony_ci 105f9996aaSopenharmony_cideclare_args() { 115f9996aaSopenharmony_ci # Whether unstripped binaries, i.e. compiled with debug symbols, should be 125f9996aaSopenharmony_ci # considered runtime_deps rather than stripped ones. 135f9996aaSopenharmony_ci ohos_unstripped_runtime_outputs = true 145f9996aaSopenharmony_ci ohos_extra_cflags = "" 155f9996aaSopenharmony_ci ohos_extra_cppflags = "" 165f9996aaSopenharmony_ci ohos_extra_cxxflags = "" 175f9996aaSopenharmony_ci ohos_extra_asmflags = "" 185f9996aaSopenharmony_ci ohos_extra_ldflags = "" 195f9996aaSopenharmony_ci} 205f9996aaSopenharmony_ci 215f9996aaSopenharmony_ci# The ohos clang toolchains share most of the same parameters, so we have this 225f9996aaSopenharmony_ci# wrapper around gcc_toolchain to avoid duplication of logic. 235f9996aaSopenharmony_ci# 245f9996aaSopenharmony_ci# Parameters: 255f9996aaSopenharmony_ci# - toolchain_root 265f9996aaSopenharmony_ci# Path to cpu-specific toolchain within the ndk. 275f9996aaSopenharmony_ci# - sysroot 285f9996aaSopenharmony_ci# Sysroot for this architecture. 295f9996aaSopenharmony_ci# - lib_dir 305f9996aaSopenharmony_ci# Subdirectory inside of sysroot where libs go. 315f9996aaSopenharmony_ci# - binary_prefix 325f9996aaSopenharmony_ci# Prefix of compiler executables. 335f9996aaSopenharmony_citemplate("ohos_clang_toolchain") { 345f9996aaSopenharmony_ci gcc_toolchain(target_name) { 355f9996aaSopenharmony_ci assert(defined(invoker.toolchain_args), 365f9996aaSopenharmony_ci "toolchain_args must be defined for ohos_clang_toolchain()") 375f9996aaSopenharmony_ci toolchain_args = invoker.toolchain_args 385f9996aaSopenharmony_ci toolchain_args.current_os = "ohos" 395f9996aaSopenharmony_ci 405f9996aaSopenharmony_ci # Output linker map files for binary size analysis. 415f9996aaSopenharmony_ci enable_linker_map = true 425f9996aaSopenharmony_ci 435f9996aaSopenharmony_ci ohos_libc_dir = 445f9996aaSopenharmony_ci rebase_path(invoker.sysroot + "/" + invoker.lib_dir, root_build_dir) 455f9996aaSopenharmony_ci libs_section_prefix = "${ohos_libc_dir}/Scrt1.o" 465f9996aaSopenharmony_ci libs_section_prefix += " ${ohos_libc_dir}/crti.o" 475f9996aaSopenharmony_ci libs_section_postfix = "${ohos_libc_dir}/crtn.o" 485f9996aaSopenharmony_ci 495f9996aaSopenharmony_ci if (invoker.target_name == "ohos_clang_arm") { 505f9996aaSopenharmony_ci abi_target = "arm-linux-ohos" 515f9996aaSopenharmony_ci } else if (invoker.target_name == "ohos_clang_arm64") { 525f9996aaSopenharmony_ci abi_target = "aarch64-linux-ohos" 535f9996aaSopenharmony_ci } else if (invoker.target_name == "ohos_clang_riscv64") { 545f9996aaSopenharmony_ci abi_target = "riscv64-linux-ohos" 555f9996aaSopenharmony_ci } else if (invoker.target_name == "ohos_clang_x86_64") { 565f9996aaSopenharmony_ci abi_target = "x86_64-linux-ohos" 575f9996aaSopenharmony_ci } else if (invoker.target_name == "ohos_clang_loongarch64") { 585f9996aaSopenharmony_ci abi_target = "loongarch64-linux-ohos" 595f9996aaSopenharmony_ci } 605f9996aaSopenharmony_ci 615f9996aaSopenharmony_ci if (musl_is_legacy) { 625f9996aaSopenharmony_ci clang_rt_dir = 635f9996aaSopenharmony_ci rebase_path("${clang_lib_base_path}/${abi_target}/nanlegacy", 645f9996aaSopenharmony_ci root_build_dir) 655f9996aaSopenharmony_ci } else { 665f9996aaSopenharmony_ci clang_rt_dir = 675f9996aaSopenharmony_ci rebase_path("${clang_lib_base_path}/${abi_target}", root_build_dir) 685f9996aaSopenharmony_ci } 695f9996aaSopenharmony_ci 705f9996aaSopenharmony_ci solink_libs_section_prefix = "${ohos_libc_dir}/crti.o" 715f9996aaSopenharmony_ci solink_libs_section_prefix += " ${clang_rt_dir}/clang_rt.crtbegin.o" 725f9996aaSopenharmony_ci solink_libs_section_postfix = "${ohos_libc_dir}/crtn.o" 735f9996aaSopenharmony_ci solink_libs_section_postfix += " ${clang_rt_dir}/clang_rt.crtend.o" 745f9996aaSopenharmony_ci 755f9996aaSopenharmony_ci _prefix = rebase_path("${clang_base_path}/bin", root_build_dir) 765f9996aaSopenharmony_ci cc = "${_prefix}/clang" 775f9996aaSopenharmony_ci cxx = "${_prefix}/clang++" 785f9996aaSopenharmony_ci ar = "${_prefix}/llvm-ar" 795f9996aaSopenharmony_ci ld = cxx 805f9996aaSopenharmony_ci readelf = "${_prefix}/llvm-readobj" 815f9996aaSopenharmony_ci nm = "${_prefix}/llvm-nm" 825f9996aaSopenharmony_ci if (!is_debug) { 835f9996aaSopenharmony_ci strip = rebase_path("${clang_base_path}/bin/llvm-strip", root_build_dir) 845f9996aaSopenharmony_ci use_unstripped_as_runtime_outputs = ohos_unstripped_runtime_outputs 855f9996aaSopenharmony_ci } 865f9996aaSopenharmony_ci extra_cflags = ohos_extra_cflags 875f9996aaSopenharmony_ci extra_cppflags = ohos_extra_cppflags 885f9996aaSopenharmony_ci extra_cxxflags = ohos_extra_cxxflags 895f9996aaSopenharmony_ci extra_asmflags = ohos_extra_asmflags 905f9996aaSopenharmony_ci extra_ldflags = ohos_extra_ldflags 915f9996aaSopenharmony_ci 925f9996aaSopenharmony_ci # Don't use .cr.so for loadable_modules since they are always loaded via 935f9996aaSopenharmony_ci # absolute path. 945f9996aaSopenharmony_ci loadable_module_extension = ".so" 955f9996aaSopenharmony_ci rust_abi_target = invoker.rust_abi_target 965f9996aaSopenharmony_ci if (rust_abi_target == "armv7-unknown-linux-ohos") { 975f9996aaSopenharmony_ci 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++" 985f9996aaSopenharmony_ci } else if (rust_abi_target == "aarch64-unknown-linux-ohos") { 995f9996aaSopenharmony_ci 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++" 1005f9996aaSopenharmony_ci } else if (rust_abi_target == "x86_64-unknown-linux-ohos") { 1015f9996aaSopenharmony_ci 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++" 1025f9996aaSopenharmony_ci } else if (rust_abi_target == "x86_64-unknown-linux-gnu") { 1035f9996aaSopenharmony_ci cc_command_args = "--target=${rust_abi_target} -Clinker=$cxx -Clink-arg=-fuse-ld=lld -Clink-arg=-v -Clink-arg=--target=${abi_target}" 1045f9996aaSopenharmony_ci } else if (rust_abi_target == "riscv64-unknown-linux-ohos") { 1055f9996aaSopenharmony_ci 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++" 1065f9996aaSopenharmony_ci } else if (rust_abi_target == "loongarch64-linux-ohos") { 1075f9996aaSopenharmony_ci 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++" 1085f9996aaSopenharmony_ci } 1095f9996aaSopenharmony_ci } 1105f9996aaSopenharmony_ci} 111