Creating bazel toolchain to crosscompile with
diff --git a/toolchain/BUILD b/toolchain/BUILD
new file mode 100644
index 0000000..46336fd
--- /dev/null
+++ b/toolchain/BUILD
@@ -0,0 +1,90 @@
+load(":cc_toolchain_config.bzl", "cc_toolchain_config")
+package(default_visibility = ["//visibility:public"])
+
+filegroup(name = "empty")
+
+
+cc_toolchain_suite(
+ name = "clang_suite",
+ toolchains = {
+ "aarch64": ":cc-compiler-aarch64",
+ "ppcle": "cc-compiler-ppcle",
+ "s390x": ":cc-compiler-s390x",
+ "x86_32": ":cc-compiler-x86_32",
+ "x86_64": ":cc-compiler-x86_64",
+ },
+)
+
+CC_TOOLCHAIN_CPUS = [
+ "aarch64",
+ "ppcle",
+ "s390x",
+ "x86_32",
+ "x86_64",
+]
+
+[
+ cc_toolchain(
+ name = "cc-compiler-" + cpu,
+ all_files = ":empty",
+ compiler_files = ":empty",
+ dwp_files = ":empty",
+ dynamic_runtime_lib = ":empty",
+ linker_files = ":empty",
+ objcopy_files = ":empty",
+ output_licenses = ["restricted"],
+ static_runtime_lib = ":empty",
+ strip_files = ":empty",
+ toolchain_config = ":" + cpu + "-config",
+ toolchain_identifier = "linux_" + cpu,
+ )
+ for cpu in CC_TOOLCHAIN_CPUS
+]
+
+cc_toolchain_config(
+ name = "aarch64-config",
+ bit_flag = "-m64",
+ include_flag = "-I/usr/aarch64-linux-gnu/include/c++/10/aarch64-linux-gnu/",
+ target_cpu = "aarch64",
+ target_full_name = "aarch64-linux-gnu",
+ toolchain_dir = "/usr/aarch64-linux-gnu/include",
+ toolchain_name = "linux_aarch64",
+)
+
+cc_toolchain_config(
+ name = "ppcle-config",
+ bit_flag = "-m64",
+ include_flag = "-I/usr/powerpc64le-linux-gnu/include/c++/10/powerpc64le-linux-gnu/",
+ target_cpu = "ppc64",
+ target_full_name = "powerpc64le-linux-gnu",
+ toolchain_dir = "/usr/powerpc64le-linux-gnu/include",
+ toolchain_name = "linux_ppcle",
+)
+
+cc_toolchain_config(
+ name = "s390x-config",
+ bit_flag = "-m64",
+ include_flag = "-I/usr/s390x-linux-gnu/include/c++/10/s390x-linux-gnu/",
+ target_cpu = "systemz",
+ target_full_name = "s390x-linux-gnu",
+ toolchain_dir = "/usr/s390x-linux-gnu/include",
+ toolchain_name = "linux_s390x",
+)
+
+cc_toolchain_config(
+ name = "x86_32-config",
+ bit_flag = "-m32",
+ target_cpu = "x86_32",
+ target_full_name = "i386-linux-gnu",
+ toolchain_dir = "/usr/include/x86_32-linux-gnu",
+ toolchain_name = "linux_x86_32",
+)
+
+cc_toolchain_config(
+ name = "x86_64-config",
+ bit_flag = "-m64",
+ target_cpu = "x86_64",
+ target_full_name = "x86_64-linux-gnu",
+ toolchain_dir = "/usr/include/x86_64-linux-gnu",
+ toolchain_name = "linux_x86_64",
+)
diff --git a/toolchain/cc_toolchain_config.bzl b/toolchain/cc_toolchain_config.bzl
new file mode 100644
index 0000000..8e8ac30
--- /dev/null
+++ b/toolchain/cc_toolchain_config.bzl
@@ -0,0 +1,151 @@
+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",
+ "tool_path",
+)
+
+all_link_actions = [
+ ACTION_NAMES.cpp_link_executable,
+ ACTION_NAMES.cpp_link_dynamic_library,
+ ACTION_NAMES.cpp_link_nodeps_dynamic_library,
+]
+
+all_compile_actions = [
+ ACTION_NAMES.assemble,
+ ACTION_NAMES.preprocess_assemble,
+ ACTION_NAMES.linkstamp_compile,
+ ACTION_NAMES.c_compile,
+ ACTION_NAMES.cpp_compile,
+ ACTION_NAMES.cpp_header_parsing,
+ ACTION_NAMES.cpp_module_codegen,
+ ACTION_NAMES.cpp_module_compile,
+ ACTION_NAMES.clif_match,
+ ACTION_NAMES.lto_backend,
+]
+
+def _impl(ctx):
+ tool_paths = [
+ tool_path(
+ name = "gcc",
+ path = "/usr/bin/clang",
+ ),
+ tool_path(
+ name = "ld",
+ path = "/usr/bin/ld",
+ ),
+ tool_path(
+ name = "ar",
+ path = "/usr/bin/llvm-ar-11",
+ ),
+ tool_path(
+ name = "compat-ld",
+ path = "/usr/bin/ld",
+ ),
+ tool_path(
+ name = "cpp",
+ path = "/usr/bin/clang-cpp",
+ ),
+ tool_path(
+ name = "dwp",
+ path = "/usr/bin/llvm-dwp",
+ ),
+ tool_path(
+ name = "gcov",
+ path = "/usr/bin/llvm-profdata",
+ ),
+ tool_path(
+ name = "nm",
+ path = "/usr/bin/llvm-nm",
+ ),
+ tool_path(
+ name = "objcopy",
+ path = "/usr/bin/llvm-objcopy",
+ ),
+ tool_path(
+ name = "objdump",
+ path = "/usr/bin/llvm-objdump",
+ ),
+ tool_path(
+ name = "strip",
+ path = "/usr/bin/llvm-strip",
+ ),
+ ]
+
+ features = [
+ feature(
+ name = "default_linker_flags",
+ enabled = True,
+ flag_sets = [
+ flag_set(
+ actions = all_link_actions,
+ flag_groups = ([
+ flag_group(
+ flags = [
+ "-lstdc++",
+ "--target=" + ctx.attr.target_full_name,
+ ],
+ ),
+ ]),
+ ),
+ ],
+ ),
+ ]
+
+ features.append(feature(
+ name = "default_compile_flags",
+ enabled = True,
+ flag_sets = [
+ flag_set(
+ actions = all_compile_actions,
+ flag_groups = [
+ flag_group(
+ flags = [
+ ctx.attr.bit_flag,
+ "-Wall",
+ "-no-canonical-prefixes",
+ "--target=" + ctx.attr.target_full_name,
+ "-isystem",
+ ctx.attr.toolchain_dir,
+ ctx.attr.include_flag,
+ ],
+ ),
+ ],
+ ),
+ ],
+ ))
+
+ return cc_common.create_cc_toolchain_config_info(
+ abi_libc_version = ctx.attr.target_cpu,
+ abi_version = ctx.attr.target_cpu,
+ ctx = ctx,
+ compiler = "clang",
+ cxx_builtin_include_directories = [
+ ctx.attr.toolchain_dir,
+ "/usr/include",
+ "/usr/lib/clang/11.0.1/include",
+ ],
+ features = features,
+ host_system_name = "local",
+ target_cpu = ctx.attr.target_cpu,
+ target_libc = ctx.attr.target_cpu,
+ target_system_name = ctx.attr.target_full_name,
+ toolchain_identifier = ctx.attr.toolchain_name,
+ tool_paths = tool_paths,
+ )
+
+cc_toolchain_config = rule(
+ implementation = _impl,
+ attrs = {
+ "bit_flag": attr.string(mandatory = True, values = ["-m32", "-m64"]),
+ "include_flag": attr.string(mandatory = False),
+ "target_cpu": attr.string(mandatory = True, values = ["aarch64", "ppc64", "systemz", "x86_32", "x86_64"]),
+ "target_full_name": attr.string(mandatory = True),
+ "toolchain_dir": attr.string(mandatory = True),
+ "toolchain_name": attr.string(mandatory = True),
+ },
+ provides = [CcToolchainConfigInfo],
+)
diff --git a/toolchain/toolchains.bazelrc b/toolchain/toolchains.bazelrc
new file mode 100644
index 0000000..2939e33
--- /dev/null
+++ b/toolchain/toolchains.bazelrc
@@ -0,0 +1,8 @@
+build:cross_config --crosstool_top=//toolchain:clang_suite
+build:cross_config --host_crosstool_top=@bazel_tools//tools/cpp:toolchain
+
+build:aarch64_config --config=cross_config --cpu=aarch64
+build:ppcle_config --config=cross_config --cpu=ppcle
+build:s390x_config --config=cross_config --cpu=s390x
+build:x86_32_config --config=cross_config --cpu=x86_32
+build:x86_64_config --config=cross_config --cpu=x86_64