Missing include files while building for arm-poky-linux-gnueabi-gcc / ARM32v7 neon

Hi, I’m trying to compile tensorflow (libtensorflow.so : the C api, not tensorflow lite) for arm-poky-linux-gnueabi-gcc, targeting an ARM32v7 neon platform.

I need it since it’s used by the library cppflow (you can see it at https://serizba.github.io/cppflow/ and github . com / serizba / cppflow ). Normally with that library I would download and link the tensorflow C api with its binaries from https : // www . tensorflow . org / install / lang_c), but at that page there’s not the build artifact form my target platform (i.e., arm-poky-linux-gnueabi-gcc).

I’m applying the approach suggested in the tutorial available at Bazel 教程:配置 C++ 工具链 : add some information to describe my specific toolchain, and then run the build command with a switch that forces the use of that toolchain :

– WORKSPACE folder / toolchain / BUILD

package(default_visibility = ["//visibility:public"])

cc_toolchain_suite(
    name = "arm-poky-linux-gnueabi-gpp_suite",
    toolchains = {
        "arm": ":arm_toolchain",
    },
)

filegroup(name = "empty")

cc_toolchain(
    name = "arm_toolchain",
    toolchain_identifier = "arm-toolchain",
    toolchain_config = ":arm_toolchain_config",
    all_files = ":empty",
    compiler_files = ":empty",
    dwp_files = ":empty",
    linker_files = ":empty",
    objcopy_files = ":empty",
    strip_files = ":empty",
    supports_param_files = 0,
)

load(":cc_toolchain_config.bzl", "cc_toolchain_config")

cc_toolchain_config(name = "arm_toolchain_config")

– WORKSPACE folder / toolchain / cc_toolchain_config.bzl :

load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")

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

all_link_actions = [
    ACTION_NAMES.cpp_link_executable,
    ACTION_NAMES.cpp_link_dynamic_library,
    ACTION_NAMES.cpp_link_nodeps_dynamic_library,
]

def _impl(ctx):
    tool_paths = [
        tool_path(
            name = "gcc",
            path = "/home/developer/.cache/jolt/linux_sdk/d9737004eabf7fbdb5070aa1fceeb5b0cec9e96c/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc",
        ),
        tool_path(
            name = "g++",
            path = "/home/developer/.cache/jolt/linux_sdk/d9737004eabf7fbdb5070aa1fceeb5b0cec9e96c/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++",
        ),
        tool_path(
            name = "ld",
            path = "/home/developer/.cache/jolt/linux_sdk/d9737004eabf7fbdb5070aa1fceeb5b0cec9e96c/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/ld",
        ),
        tool_path(
            name = "ar",
            path = "/home/developer/.cache/jolt/linux_sdk/d9737004eabf7fbdb5070aa1fceeb5b0cec9e96c/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/ar",
        ),
        tool_path(
            name = "cpp",
            path = "/bin/false",
        ),
        tool_path(
            name = "gcov",
            path = "/bin/false",
        ),
        tool_path(
            name = "nm",
            path = "/bin/false",
        ),
        tool_path(
            name = "objdump",
            path = "/bin/false",
        ),
        tool_path(
            name = "strip",
            path = "/bin/false",
        ),
    ]
    
    features = [
        feature(
            name = "default_linker_flags",
            enabled = True,
            flag_sets = [
                flag_set(
                    actions = all_link_actions,
                    flag_groups = ([
                        flag_group(
                            flags = [
                                "-lstdc++",
                                "-march=armv7-a",
                                "-mfpu=neon", 
                                "-mfloat-abi=hard",
                            ],
                        ),
                    ]),
                ),
            ],
        ),
        feature(
            name = "default_compiler_flags",
            enabled = True,
            flag_sets = [
                flag_set(
                    actions = [ACTION_NAMES.cpp_compile],
                    flag_groups = ([
                        flag_group(
                            flags = [
                                "-march=armv7-a",
                                "-mfpu=neon", 
                                "-mfloat-abi=hard",
                            ],
                        ),
                    ]),
                ),
            ],
        ),
    ]
    
    return cc_common.create_cc_toolchain_config_info(
        ctx = ctx,
        features = features,
        cxx_builtin_include_directories = [
#            "/home/developer/.cache/jolt/linux_sdk/d9737004eabf7fbdb5070aa1fceeb5b0cec9e96c/sysroots/armv7ahf-neon-poky-linux-gnueabi/usr/include/c++/v1/",
            "/home/developer/.cache/jolt/linux_sdk/d9737004eabf7fbdb5070aa1fceeb5b0cec9e96c/sysroots/ECLR/usr/include/",
            "/home/developer/.cache/jolt/linux_sdk/d9737004eabf7fbdb5070aa1fceeb5b0cec9e96c/sysroots/ECLR/usr/include/c++/7.3.0/",
            "/home/developer/.cache/jolt/linux_sdk/d9737004eabf7fbdb5070aa1fceeb5b0cec9e96c/sysroots/armv7ahf-neon-poky-linux-gnueabi/",
            "/home/developer/.cache/jolt/linux_sdk/d9737004eabf7fbdb5070aa1fceeb5b0cec9e96c/sysroots/x86_64-pokysdk-linux/usr/lib/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/7.3.0/include/",
        ],
        builtin_sysroot = "/home/developer/.cache/jolt/linux_sdk/d9737004eabf7fbdb5070aa1fceeb5b0cec9e96c/sysroots/armv7ahf-neon-poky-linux-gnueabi/",
#        builtin_sysroot = "/home/developer/.cache/jolt/linux_sdk/d9737004eabf7fbdb5070aa1fceeb5b0cec9e96c/sysroots/ECLR/usr/include/",
#        builtin_sysroot = "/home/developer/.cache/jolt/linux_sdk/d9737004eabf7fbdb5070aa1fceeb5b0cec9e96c/sysroots/ECLR/usr/include/c++/7.3.0/",
        toolchain_identifier = "arm-toolchain",
        host_system_name = "local",
        target_system_name = "local",
        target_cpu = "arm",
        target_libc = "unknown",
        compiler = "arm-poky-linux-gnueabi-g++",
        abi_version = "unknown",
        abi_libc_version = "unknown",
        tool_paths = tool_paths
    )

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

– appended to existing tensorflow’s WORKSPACE folder /.bazelrc :

(...)

# Use our custom-configured c++ toolchain.

build:arm-poky-linux-gnueabi-gpp_config --crosstool_top=//toolchain:arm-poky-linux-gnueabi-gpp_suite

# Use --cpu as a differentiator.

build:arm-poky-linux-gnueabi-gpp_config --cpu=arm

# Use the default Bazel C++ toolchain to build the tools used during the
# build.

build:arm-poky-linux-gnueabi-gpp_config --host_crosstool_top=@bazel_tools//tools/cpp:toolchain

– attempt to launch tensorflow’s build with bazelisk:

bazelisk-linux-amd64 build --config=arm-poky-linux-gnueabi-gpp_config //tensorflow:libtensorflow.so


For the simple hello world program presented in the tutorial (a single, small source file) the approach works : I had just to tune some settings in the toolchain to let the arm-poky-linux-gnueabi-gcc compiler to locate some include files such as cstddef.

However, the same approach, applied to the tensorflow workspace directory (I’ve recreated the toolchain folder with its internal files and appended the example’s .bazelrc file contents to the end of the one in tensorflow lib), doesn’t seem to work, and although the proper compiler (arm-poky-linux-gnueabi-gcc) seems to be called, it doesn’t find the include files.

What am I supposed to do to let bazel see the include files like cstddef for libtensorflow compilation targeting arm-poky-linux-gnueabi-gcc ?