Skip to content

Commit

Permalink
add a custom toolchain for customized use (#8077)
Browse files Browse the repository at this point in the history
* 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=<embedded_linux_sdk_sysroot> \
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=<embedded_linux_sdk_sysroot>" ]
      target_ldflags=[ "--sysroot=<embedded_linux_sdk_sysroot>" ]
      linux_arm_cross_compile="<path_to_cross_compile_tools>"'

Change-Id: Id4b7b4932e16fcc42d77af7020ebb6a7133e237b
Signed-off-by: faqiang.zhu <faqiang.zhu@nxp.com>

* 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=<sdk_root_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=<sdk_root_dir>" ]
    target_ldflags=[ "--sysroot=<sdk_root_dir>" ]
    custom_toolchain="${build_root}/toolchain/custom"
    target_cc="<gcc_in_sdk>"
    target_cxx="<g++_in_sdk>"
    target_ar="<ar_in_sdk>"'

Signed-off-by: faqiang.zhu <faqiang.zhu@nxp.com>

Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
FaqiangZhu-nxp and restyled-commits authored Jul 9, 2021
1 parent ac9c775 commit 8109c00
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions build/toolchain/custom/BUILD.gn
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 8109c00

Please sign in to comment.