From 8c2321a128d311acc2b74eb963debd920637b2cb Mon Sep 17 00:00:00 2001 From: Faqiang Zhu <71302147+FaqiangZhu-nxp@users.noreply.github.com> Date: Sat, 10 Jul 2021 04:45:01 +0800 Subject: [PATCH] add a custom toolchain for customized use (#8077) * add a linux_arm toolchain for customized use This tool chain is targeted to Linux running on ARM SoC, because there is a demand of running some of the example tools like "chip-tool" on embeded linux device instead of on Linux laptop. If the target_os is linux and the target_cpu is "arm" or "arm64", this toolchain will be used. It is similar to the "CROSS_COMPILE" when build kernel, a build arg named "linux_arm_cross_compile" need to be specified also, it should be a path to the cross compile tools. Take the embedded linux SDK into consideration, other build args to specify in the command line includes: * target_os * target_cpu * arm_arch * target_cflags * target_ldflags * etc. And the pkg-config tool need below two enviroment to be well set to correctly find the include path: * PKG_CONFIG_SYSROOT_DIR * PKG_CONFIG_LIBDIR A demo command to generate ninja files are listed below, the content in angle brackets need to be updated with developer's local env. PKG_CONFIG_SYSROOT_DIR= \ PKG_CONFIG_LIBDIR=${PKG_CONFIG_SYSROOT_DIR}/usr/lib/pkgconfig:${PKG_CONFIG_SYSROOT_DIR}/usr/share/pkgconfig \ gn gen out out/aarch64 --args='target_os="linux" target_cpu="arm64" arm_arch="armv8-a" target_cflags=[ "--sysroot=" ] target_ldflags=[ "--sysroot=" ] linux_arm_cross_compile=""' Change-Id: Id4b7b4932e16fcc42d77af7020ebb6a7133e237b Signed-off-by: faqiang.zhu * Restyled by gn * rename the linux_arm toolchain as custom toolchain The original linux_arm toolchain is not arm specific, it's just a customizable toolchain. rename it as custom. Do not use this toolchain based on the target_cpu and target_os, use build argument "custom_toolchain" to specify this toolchain. For example, to build with tools in NXP i.MX 8M yocto release SDK, the command to generate ninja files can be: PKG_CONFIG_SYSROOT_DIR= \ PKG_CONFIG_LIBDIR=${PKG_CONFIG_SYSROOT_DIR}/usr/lib/pkgconfig:${PKG_CONFIG_SYSROOT_DIR}/usr/share/pkgconfig \ gn gen out/aarch64 --args='target_os="linux" target_cpu="arm64" arm_arch="armv8-a" import("//build_overrides/build.gni") target_cflags=[ "--sysroot=" ] target_ldflags=[ "--sysroot=" ] custom_toolchain="${build_root}/toolchain/custom" target_cc="" target_cxx="" target_ar=""' Signed-off-by: faqiang.zhu Co-authored-by: Restyled.io --- build/toolchain/custom/BUILD.gn | 45 +++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 build/toolchain/custom/BUILD.gn diff --git a/build/toolchain/custom/BUILD.gn b/build/toolchain/custom/BUILD.gn new file mode 100644 index 00000000000000..f0ee798e9db194 --- /dev/null +++ b/build/toolchain/custom/BUILD.gn @@ -0,0 +1,45 @@ +# Copyright (c) 2020 Project CHIP Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build_overrides/build.gni") +import("${build_root}/config/compiler/compiler.gni") +import("${build_root}/toolchain/gcc_toolchain.gni") + +declare_args() { + # C compiler to use for target build. + target_cc = "" + + # C++ compiler to use for target build. + target_cxx = "" + + # Archive tool to use for target build. + target_ar = "" +} + +gcc_toolchain("custom") { + if (target_cc == "" || target_cxx == "" || target_ar == "") { + assert(false, + "build arguments target_cc, target_cxx and target_ar need to be set") + } + + ar = target_ar + cc = target_cc + cxx = target_cxx + + toolchain_args = { + current_os = target_os + current_cpu = target_cpu + is_clang = is_clang + } +}