Я пытаюсь понять Bazel и выполнить кросс-компиляцию для простого файла C ++
Вот мой пример:
├── aarch64_compiler
│ ├── BUILD
│ ├── cc_toolchain_config.bzl
│ └── CROSSTOOL
├── aarch64_compiler.BUILD
├── helloworld
│ ├── BUILD.bazel
│ └── src
│ └── helloworld.cpp
└── WORKSPACE
и вот каждый файл,
РАБОЧЕЕ МЕСТО
new_local_repository(
name = "aarch64_compiler",
path = "/",
build_file = "aarch64_compiler.BUILD",
)
aarch64_compiler.BUILD
package(default_visibility = ['//visibility:public'])
filegroup(
name = 'gcc',
srcs = [
'usr/bin/aarch64-linux-gnu-gcc',
],
)
filegroup(
name = 'ar',
srcs = [
'usr/bin/aarch64-linux-gnu-ar',
],
)
filegroup(
name = 'ld',
srcs = [
'usr/bin/aarch64-linux-gnu-ld',
],
)
filegroup(
name = 'nm',
srcs = [
'usr/bin/aarch64-linux-gnu-nm',
],
)
filegroup(
name = 'objcopy',
srcs = [
'usr/bin/aarch64-linux-gnu-objcopy',
],
)
filegroup(
name = 'objdump',
srcs = [
'usr/bin/aarch64-linux-gnu-objdump',
],
)
filegroup(
name = 'strip',
srcs = [
'usr/bin/aarch64-linux-gnu-strip',
],
)
filegroup(
name = 'as',
srcs = [
'usr/bin/aarch64-linux-gnu-as',
],
)
filegroup(
name = 'compiler_pieces',
srcs = glob([
'usr/lib/gcc-cross/aarch64-linux-gnu/7/**',
'usr/aarch64-linux-gnu/**',
]),
)
filegroup(
name = 'compiler_components',
srcs = [
':gcc',
':ar',
':ld',
':nm',
':objcopy',
':objdump',
':strip',
':as',
],
)
aarch64_compiler / BUILD
package(default_visibility = ["//visibility:public"])
load(":cc_toolchain_config.bzl", "cc_toolchain_config")
cc_toolchain_suite(
name = 'toolchain',
toolchains = {
'aarch64|compiler':':gcc-linux-aarch64',
"aarch64": ":gcc-linux-aarch64",
},
)
filegroup(
name = "empty",
srcs = [],
)
filegroup(
name = "arm_linux_all_files",
srcs = [
"@aarch64_compiler//:compiler_pieces",
],
)
cc_toolchain_config(name = "aarch64_toolchain_config")
cc_toolchain(
name = 'gcc-linux-aarch64',
toolchain_identifier = "aarch64-linux-gnu",
toolchain_config = ":aarch64_toolchain_config",
all_files = ':arm_linux_all_files',
compiler_files = ':arm_linux_all_files',
#cpu = 'aarch64',
dwp_files = ':empty',
#dynamic_runtime_libs = [':empty'],
linker_files = ':arm_linux_all_files',
objcopy_files = ':arm_linux_all_files',
#static_runtime_libs = [':empty'],
strip_files = ':arm_linux_all_files',
supports_param_files = 1,
)
aarch64_compiler / cc_toolchain_config.bzl
# toolchain/cc_toolchain_config.bzl:
load("@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", "tool_path")
def _impl(ctx):
tool_paths = [
tool_path(
name = "gcc",
path = "/usr/bin/aarch64-linux-gnu-gcc",
),
tool_path(
name = "ld",
path = "/usr/bin/aarch64-linux-gnu-ld",
),
tool_path(
name = "ar",
path = "/usr/bin/aarch64-linux-gnu-ar",
),
tool_path(
name = "cpp",
path = "/usr/bin/aarch64-linux-gnu-cpp",
),
tool_path(
name = "gcov",
path = "/usr/bin/aarch64-linux-gnu-gcov",
),
tool_path(
name = "nm",
path = "/usr/bin/aarch64-linux-gnu-nm",
),
tool_path(
name = "objdump",
path = "/usr/bin/aarch64-linux-gnu-objdump",
),
tool_path(
name = "strip",
path = "/usr/bin/aarch64-linux-gnu-strip",
),
]
return cc_common.create_cc_toolchain_config_info(
ctx = ctx,
toolchain_identifier = "aarch64-linux-gnu",
host_system_name = "x86_64-unknown-linux-gnu",
target_system_name = "aarch64-unknown-linux-gnu",
target_cpu = "aarch64",
target_libc = "unknown",
compiler = "aarch64",
abi_version = "unknown",
abi_libc_version = "unknown",
tool_paths = tool_paths,
)
cc_toolchain_config = rule(
implementation = _impl,
attrs = {},
provides = [CcToolchainConfigInfo],
)
aarch64_compiler / CROSSTOOL
major_version: "local"
minor_version: ""
default_target_cpu: "aarch64"
default_toolchain {
cpu: "aarch64"
toolchain_identifier: "aarch64-linux-gnu"
}
toolchain {
abi_version: "aarch64"
abi_libc_version: "aarch64"
builtin_sysroot: ""
compiler: "compiler"
host_system_name: "aarch64"
needsPic: true
supports_gold_linker: true
supports_incremental_linker: false
supports_fission: false
supports_interface_shared_objects: false
supports_normalizing_ar: false
supports_start_end_lib: true
target_libc: "aarch64"
target_cpu: "aarch64"
target_system_name: "aarch64"
toolchain_identifier: "aarch64-linux-gnu"
cxx_flag: "-std=c++11"
linker_flag: "-lstdc++"
linker_flag: "-lm"
linker_flag: "-fuse-ld=gold"
linker_flag: "-Wl,-no-as-needed"
linker_flag: "-Wl,-z,relro,-z,now"
linker_flag: "-pass-exit-codes"
cxx_builtin_include_directory: "/usr/aarch64-linux-gnu/include/c++/7/"
cxx_builtin_include_directory: "/usr/aarch64-linux-gnu/include/c++/7/backward"
cxx_builtin_include_directory: "/usr/aarch64-linux-gnu/include/"
cxx_builtin_include_directory: "/usr/lib/gcc-cross/aarch64-linux-gnu/7/include"
cxx_builtin_include_directory: "/usr/lib/gcc-cross/aarch64-linux-gnu/7/include-fixed"
objcopy_embed_flag: "-I"
objcopy_embed_flag: "binary"
unfiltered_cxx_flag: "-fno-canonical-system-headers"
unfiltered_cxx_flag: "-Wno-builtin-macro-redefined"
unfiltered_cxx_flag: "-D__DATE__=\"redacted\""
unfiltered_cxx_flag: "-D__TIMESTAMP__=\"redacted\""
unfiltered_cxx_flag: "-D__TIME__=\"redacted\""
compiler_flag: "-U_FORTIFY_SOURCE"
compiler_flag: "-fstack-protector"
compiler_flag: "-Wall"
compiler_flag: "-Wunused-but-set-parameter"
compiler_flag: "-Wno-free-nonheap-object"
compiler_flag: "-fno-omit-frame-pointer"
tool_path { name: "ld" path: "/usr/bin/aarch64-linux-gnu-ld" }
tool_path { name: "cpp" path: "/usr/bin/aarch64-linux-gnu-cpp" }
tool_path { name: "dwp" path: "/usr/bin/aarch64-linux-gnu-dwp" }
tool_path { name: "gcov" path: "/usr/bin/aarch64-linux-gnu-gcov" }
tool_path { name: "nm" path: "/usr/bin/aarch64-linux-gnu-nm" }
tool_path { name: "objcopy" path: "/usr/bin/aarch64-linux-gnu-objcopy" }
tool_path { name: "objdump" path: "/usr/bin/aarch64-linux-gnu-objdump" }
tool_path { name: "strip" path: "/usr/bin/aarch64-linux-gnu-strip" }
tool_path { name: "gcc" path: "/usr/bin/aarch64-linux-gnu-gcc" }
tool_path { name: "ar" path: "/usr/bin/aarch64-linux-gnu-ar" }
compilation_mode_flags {
mode: DBG
# Enable debug symbols.
compiler_flag: "-g"
}
compilation_mode_flags {
mode: OPT
# No debug symbols.
# Maybe we should enable https://gcc.gnu.org/wiki/DebugFission for opt or
# even generally? However, that can't happen here, as it requires special
# handling in Bazel.
compiler_flag: "-g0"
# Conservative choice for -O
# -O3 can increase binary size and even slow down the resulting binaries.
# Profile first and / or use FDO if you need better performance than this.
compiler_flag: "-O2"
compiler_flag: "-D_FORTIFY_SOURCE=1"
# Disable assertions
compiler_flag: "-DNDEBUG"
# Removal of unused code and data at link time (can this increase binary size in some cases?).
compiler_flag: "-ffunction-sections"
compiler_flag: "-fdata-sections"
linker_flag: "-Wl,--gc-sections"
}
linking_mode_flags { mode: DYNAMIC }
feature {
name: 'coverage'
provides: 'profile'
flag_set {
action: 'preprocess-assemble'
action: 'c-compile'
action: 'c++-compile'
action: 'c++-header-parsing'
action: 'c++-header-preprocessing'
action: 'c++-module-compile'
flag_group {
flag: '-fprofile-arcs'
flag: '-ftest-coverage'
}
}
flag_set {
action: 'c++-link-interface-dynamic-library'
action: 'c++-link-dynamic-library'
action: 'c++-link-executable'
flag_group {
flag: '-lgcov'
}
}
}
}
helloworld / BUILD.bazel
cc_binary(
name = "helloworld",
srcs = [ "src/helloworld.cpp" ],
)
helloworld / src / helloworld. cpp
#include <iostream>
int main() {
std::cout << "Hello World from BAZEL" << std::endl;
}
Используемая команда bazel: bazel build //helloworld:helloworld --cpu=aarch64 --crosstool_top=//aarch64_compiler:toolchain --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --verbose_failures
и я получил эту ошибку:
ERROR: /data/cross-compile/bazel_sample/helloworld/BUILD.bazel:1:1: undeclared inclusion(s) in rule '//helloworld:helloworld':
this rule is missing dependency declarations for the following files included by 'helloworld/src/helloworld.cpp':
'/usr/aarch64-linux-gnu/include/stdc-predef.h'
'/usr/aarch64-linux-gnu/include/c++/7/iostream'
'/usr/aarch64-linux-gnu/include/c++/7/aarch64-linux-gnu/bits/c++config.h'
'/usr/aarch64-linux-gnu/include/c++/7/aarch64-linux-gnu/bits/os_defines.h'
'/usr/aarch64-linux-gnu/include/features.h'
'/usr/aarch64-linux-gnu/include/sys/cdefs.h'
'/usr/aarch64-linux-gnu/include/bits/wordsize.h'
'/usr/aarch64-linux-gnu/include/bits/long-double.h'
'/usr/aarch64-linux-gnu/include/gnu/stubs.h'
.....
что отсутствует в моей конфигурации?