3

I'm trying to cross-compile envoy (uses Bazel) on lubuntu 16.04 LTS for an aarch64 variant by using the Linaro toolchain at https://releases.linaro.org/components/toolchain/binaries/latest-7/aarch64-linux-gnu/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu.tar.xz

I have written a custom toolchain for bazel but gperftools is failing to build with the following error:

checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking for git... /usr/bin/git
checking for style of include used by make... GNU
checking for gcc... /home/user/Desktop/workspace/envoy/toolchain/aarch64-linux-gnu-gcc-7.4.1/bin/aarch64-linux-gnu-gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... configure error: in '/tmp/tmp.JdoXpg4e35'
configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details

Seems to me the host system type should be aarch64.

I'm wondering how I specify the --host argument in bazel for the configure script that's compiling gperftools. It's also entirely possible that my toolchain files are wrong since this is the first time i've attempted to write one.

I've been trying to adapt the tutorial at https://docs.bazel.build/versions/master/tutorial/cc-toolchain-config.html#setting-up-the-build-environment

My top level build contains

build:cross --crosstool_top=//toolchain:aarch64
build:cross --cpu=aarch64
build:cross --host_crosstool_top=//toolchain:aarch64
build:cross --linkopt -fPIE

My toolchain directory contains a BUILD file with

package(default_visibility = ['//visibility:public'])
filegroup(name = "crossbuild")

cc_toolchain_suite(
    name = "aarch64",
    toolchains = {
        "aarch64": ":aarch64_toolchain",
        "k8": ":aarch64_toolchain",
    },
)

filegroup(name = "empty")

load(":cc_toolchain_config.bzl", "cc_toolchain_config")
cc_toolchain_config(name = "aarch64_toolchain_config")

cc_toolchain(
    name = "aarch64_toolchain",
    toolchain_identifier = "aarch64-toolchain",
    toolchain_config = ":aarch64_toolchain_config",
    all_files = ":empty",
    compiler_files = ":empty",
    dwp_files = ":empty",
    linker_files = ":empty",
    objcopy_files = ":empty",
    strip_files = ":empty",
    supports_param_files = 0,
)

and a file named cc_toolchain_config.bzl with

load("@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", "tool_path")

def _impl(ctx):
    tool_paths = [
        tool_path(
            name = "gcc",
            path = "/home/user/Desktop/workspace/envoy/toolchain/aarch64-linux-gnu-gcc-7.4.1/bin/aarch64-linux-gnu-gcc",
        ),
        tool_path(
            name = "ld",
            path = "/home/user/Desktop/workspace/envoy/toolchain/aarch64-linux-gnu-gcc-7.4.1/bin/aarch64-linux-gnu-ld",
        ),
        tool_path(
            name = "ar",
            path = "/home/user/Desktop/workspace/envoy/toolchain/aarch64-linux-gnu-gcc-7.4.1/bin/aarch64-linux-gnu-ar",
        ),
        tool_path(
            name = "cpp",
            path = "/home/user/Desktop/workspace/envoy/toolchain/aarch64-linux-gnu-gcc-7.4.1/bin/aarch64-linux-gnu-cpp",
        ),
        tool_path(
            name = "gcov",
            path = "/home/user/Desktop/workspace/envoy/toolchain/aarch64-linux-gnu-gcc-7.4.1/bin/aarch64-linux-gnu-gcov",
        ),
        tool_path(
            name = "nm",
            path = "/home/user/Desktop/workspace/envoy/toolchain/aarch64-linux-gnu-gcc-7.4.1/bin/aarch64-linux-gnu-nm",
        ),
        tool_path(
            name = "objdump",
            path = "/home/user/Desktop/workspace/envoy/toolchain/aarch64-linux-gnu-gcc-7.4.1/bin/aarch64-linux-gnu-objdump",
        ),
        tool_path(
            name = "strip",
            path = "/home/user/Desktop/workspace/envoy/toolchain/aarch64-linux-gnu-gcc-7.4.1/bin/aarch64-linux-gnu-strip",
        ),
    ]                   
    return cc_common.create_cc_toolchain_config_info(
        ctx = ctx,
        toolchain_identifier = "aarch64-toolchain",
        host_system_name = "x86_64-linux-gnu",
        target_system_name = "aarch64",
        target_cpu = "aarch64",
        target_libc = "unknown",
        compiler = "gcc-7.4.1",
        abi_version = "unknown",
        abi_libc_version = "unknown",
        tool_paths=tool_paths,
        cxx_builtin_include_directories=["/home/user/Desktop/workspace/envoy/toolchain/aarch64-linux-gnu-gcc-7.4.1/aarch64-linux-gnu/libc/usr/include/",
                                         "/home/user/Desktop/workspace/envoy/toolchain/aarch64-linux-gnu-gcc-7.4.1/aarch64-linux-gnu/include/c++/7.4.1/",
                                         "/home/user/Desktop/workspace/envoy/toolchain/aarch64-linux-gnu-gcc-7.4.1/aarch64-linux-gnu/include/c++/7.4.1/aarch64-linux-gnu/bits/",
                                         "/home/user/Desktop/workspace/envoy/toolchain/aarch64-linux-gnu-gcc-7.4.1/aarch64-linux-gnu/libc/usr/include/",
                                         "/home/user/Desktop/workspace/envoy/toolchain/aarch64-linux-gnu-gcc-7.4.1/lib/gcc/aarch64-linux-gnu/7.4.1/include/",
                                         "/home/user/Desktop/workspace/envoy/toolchain/aarch64-linux-gnu-gcc-7.4.1/lib/gcc/aarch64-linux-gnu/7.4.1/include-fixed/"],
    )

cc_toolchain_config = rule(
    implementation = _impl,
    attrs = {},
    provides = [CcToolchainConfigInfo],
)

I've been using this build command

bazel build --config=cross -c opt //source/exe:envoy-static.stripped --verbose_failures

0 Answers0