diff --git a/.bazelrc b/.bazelrc index eabf3f9e6..b4075b996 100644 --- a/.bazelrc +++ b/.bazelrc @@ -29,3 +29,148 @@ run --incompatible_strict_action_env build --define kafka_enabled=false test --define kafka_enabled=false run --define kafka_enabled=false + + +# multi-arch cross-compiling toolchain configs: +----------------------------------------------- +build:cross --crosstool_top=@prysm_toolchains//:multiarch_toolchain +build:cross --host_platform=@io_bazel_rules_go//go/toolchain:linux_amd64 +build:cross --host_crosstool_top=@prysm_toolchains//:hostonly_toolchain + +# linux_amd64 config for cross compiler toolchain, not strictly necessary since host/exec env is amd64 +build:linux_amd64 --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64_cgo + +# osx_amd64 config for cross compiler toolchain +build:osx_amd64 --config=cross +build:osx_amd64 --platforms=@io_bazel_rules_go//go/toolchain:darwin_amd64_cgo +build:osx_amd64 --compiler=osxcross + +# windows +build:windows_amd64 --config=cross +build:windows_amd64 --platforms=@io_bazel_rules_go//go/toolchain:windows_amd64_cgo +build:windows_amd64 --compiler=mingw-w64 + +# linux_arm64 conifg for cross compiler toolchain +build:linux_arm64 --config=cross +build:linux_arm64 --platforms=@io_bazel_rules_go//go/toolchain:linux_arm64_cgo +build:linux_arm64 --copt=-funsafe-math-optimizations +build:linux_arm64 --copt=-ftree-vectorize +build:linux_arm64 --copt=-fomit-frame-pointer +build:linux_arm64 --cpu=aarch64 +build:linux_arm64 --compiler=clang +build:linux_arm64 --copt=-march=armv8-a + + +# toolchain build debug configs +#------------------------------ +build:debug --sandbox_debug +build:debug --toolchain_resolution_debug +build:debug --verbose_failures +build:debug -s + +# windows debug +build:windows_amd64_debug --config=windows_amd64 +build:windows_amd64_debug --config=debug + +# osx_amd64 debug config +build:osx_amd64_debug --config=debug +build:osx_amd64_debug --config=osx_amd64 + +# linux_arm64_debug +build:linux_arm64_debug --config=linux_arm64 +build:linux_arm64_debug --config=debug + +# linux_amd64_debug +build:linux_amd64_debug --config=linux_amd64 +build:linux_amd64_debug --config=debug + + +# Docker Sandbox Configs +#----------------------- +# Note all docker sandbox configs must run from a linux x86_64 host +# build:docker-sandbox --experimental_docker_image=gcr.io/prysmaticlabs/rbe-worker:latest +build:docker-sandbox --spawn_strategy=docker --strategy=Javac=docker --genrule_strategy=docker +build:docker-sandbox --define=EXECUTOR=remote +build:docker-sandbox --experimental_docker_verbose +build:docker-sandbox --experimental_enable_docker_sandbox +build:docker-sandbox --crosstool_top=@rbe_ubuntu_clang//cc:toolchain +build:docker-sandbox --host_javabase=@rbe_ubuntu_clang//java:jdk +build:docker-sandbox --javabase=@rbe_ubuntu_clang//java:jdk +build:docker-sandbox --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8 +build:docker-sandbox --java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8 +build:docker-sandbox --extra_execution_platforms=@rbe_ubuntu_clang//config:platform +build:docker-sandbox --host_platform=@rbe_ubuntu_clang//config:platform +build:docker-sandbox --platforms=@rbe_ubuntu_clang//config:platform +build:docker-sandbox --extra_toolchains=@prysm_toolchains//:cc-toolchain-multiarch + +# windows_amd64 docker sandbox build config +build:windows_amd64_docker --config=docker-sandbox --config=windows_amd64 +build:windows_amd64_docker_debug --config=windows_amd64_docker --config=debug + +# osx_amd64 docker sandbox build config +build:osx_amd64_docker --config=docker-sandbox --config=osx_amd64 +build:osx_amd64_docker_debug --config=osx_amd64_docker --config=debug + +# linux_arm64 docker sandbox build config +build:linux_arm64_docker --config=docker-sandbox --config=linux_arm64 +build:linux_arm64_docker_debug --config=linux_arm64_docker --config=debug + +# linux_amd64 docker sandbox build config +build:linux_amd64_docker --config=docker-sandbox --config=linux_amd64 +build:linux_amd64_docker_debug --config=linux_amd64_docker --config=debug + + +# Remote Build Execution +#----------------------- +# Originally from https://github.com/bazelbuild/bazel-toolchains/blob/master/bazelrc/bazel-2.0.0.bazelrc +# +# Depending on how many machines are in the remote execution instance, setting +# this higher can make builds faster by allowing more jobs to run in parallel. +# Setting it too high can result in jobs that timeout, however, while waiting +# for a remote machine to execute them. +build:remote --jobs=50 + +# Set several flags related to specifying the platform, toolchain and java +# properties. +# These flags should only be used as is for the rbe-ubuntu16-04 container +# and need to be adapted to work with other toolchain containers. +build:remote --host_javabase=@rbe_ubuntu_clang//java:jdk +build:remote --javabase=@rbe_ubuntu_clang//java:jdk +build:remote --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8 +build:remote --java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8 +build:remote --crosstool_top=@rbe_ubuntu_clang//cc:toolchain +build:remote --action_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 +# Platform flags: +# The toolchain container used for execution is defined in the target indicated +# by "extra_execution_platforms", "host_platform" and "platforms". +# More about platforms: https://docs.bazel.build/versions/master/platforms.html +build:remote --extra_toolchains=@rbe_ubuntu_clang//config:cc-toolchain +build:remote --extra_execution_platforms=@rbe_ubuntu_clang//config:platform +build:remote --host_platform=@rbe_ubuntu_clang//config:platform +build:remote --platforms=@rbe_ubuntu_clang//config:platform + +# Starting with Bazel 0.27.0 strategies do not need to be explicitly +# defined. See https://github.com/bazelbuild/bazel/issues/7480 +build:remote --define=EXECUTOR=remote + +# Enable remote execution so actions are performed on the remote systems. +# build:remote --remote_executor=grpcs://remotebuildexecution.googleapis.com + +# Enforce stricter environment rules, which eliminates some non-hermetic +# behavior and therefore improves both the remote cache hit rate and the +# correctness and repeatability of the build. +build:remote --incompatible_strict_action_env=true + +# Set a higher timeout value, just in case. +build:remote --remote_timeout=3600 + +# Enable authentication. This will pick up application default credentials by +# default. You can use --google_credentials=some_file.json to use a service +# account credential instead. +# build:remote --google_default_credentials=true + +# Enable build without the bytes +# See: https://github.com/bazelbuild/bazel/issues/6862 +build:remote --experimental_remote_download_outputs=toplevel --experimental_inmemory_jdeps_files --experimental_inmemory_dotd_files + +build:remote --remote_local_fallback diff --git a/WORKSPACE b/WORKSPACE index ab3bf592a..fc29b0038 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -3,6 +3,24 @@ workspace(name = "prysm") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") +http_archive( + name = "bazel_toolchains", + sha256 = "b5a8039df7119d618402472f3adff8a1bd0ae9d5e253f53fcc4c47122e91a3d2", + strip_prefix = "bazel-toolchains-2.1.1", + urls = [ + "https://github.com/bazelbuild/bazel-toolchains/releases/download/2.1.1/bazel-toolchains-2.1.1.tar.gz", + "https://mirror.bazel.build/github.com/bazelbuild/bazel-toolchains/archive/2.1.1.tar.gz", + ], +) + +load("@prysm//tools/cross-toolchain:prysm_toolchains.bzl", "configure_prysm_toolchains") + +configure_prysm_toolchains() + +load("@prysm//tools/cross-toolchain:rbe_toolchains_config.bzl", "rbe_toolchains_config") + +rbe_toolchains_config() + http_archive( name = "bazel_skylib", sha256 = "2ea8a5ed2b448baf4a6855d3ce049c4c452a6470b1efd1504fdb7c1c134d220a", @@ -28,9 +46,9 @@ http_archive( http_archive( name = "io_bazel_rules_docker", - # sha256 = "9ff889216e28c918811b77999257d4ac001c26c1f7c7fb17a79bc28abf74182e", - strip_prefix = "rules_docker-0.12.1", - url = "https://github.com/bazelbuild/rules_docker/archive/v0.12.1.tar.gz", + sha256 = "dc97fccceacd4c6be14e800b2a00693d5e8d07f69ee187babfd04a80a9f8e250", + strip_prefix = "rules_docker-0.14.1", + url = "https://github.com/bazelbuild/rules_docker/archive/v0.14.1.tar.gz", ) http_archive( diff --git a/third_party/kafka/BUILD.bazel b/third_party/kafka/BUILD.bazel index f55aa70e4..5305e46e8 100644 --- a/third_party/kafka/BUILD.bazel +++ b/third_party/kafka/BUILD.bazel @@ -17,4 +17,5 @@ cmake_external( "librdkafka.a", ], visibility = ["//visibility:public"], + tags = ["no-remote-exec"], ) diff --git a/tools/cross-toolchain/BUILD.bazel b/tools/cross-toolchain/BUILD.bazel new file mode 100644 index 000000000..e69de29bb diff --git a/tools/cross-toolchain/Dockerfile b/tools/cross-toolchain/Dockerfile new file mode 100644 index 000000000..950b438ef --- /dev/null +++ b/tools/cross-toolchain/Dockerfile @@ -0,0 +1,40 @@ +# Prysmatic Labs Remote Build Execution Image with Cross Compile Support. +# +# Update instructions. +# - Build the docker image. +# - Push to gcr.io. +# - Update _PRYSM_BUILD_IMAGE_DIGEST in //tools/cross-toolchain/rbe_toolchains_config.bzl +# - Run ./tools/cross-toolchain/regenerate.sh +# - Add and commit the newly generated configs. +# - Done! +# +# docker build -t gcr.io/prysmaticlabs/rbe-worker:latest . +# gcloud docker -- push gcr.io/prysmaticlabs/rbe-worker:latest + +FROM debian:buster as build + +# install gnu/gcc cross-build toolchain (gcc 8.3) +ENV DOCKER_CLI_EXPERIMENTAL=enabled +RUN apt-get update && \ + apt-get install -y \ + curl xz-utils \ + gcc g++ mingw-w64 \ + gcc-aarch64-linux-gnu g++-aarch64-linux-gnu \ + cmake libssl-dev libxml2-dev vim apt-transport-https \ + zip unzip libtinfo5 patch zlib1g-dev autoconf libtool \ + pkg-config make docker.io gnupg2 + +# install llvm/clang cross-build toolchains +ENV INSTALL_LLVM_VERSION=10.0.0-rc2 +ADD install_clang_cross10.sh /tmp/install_clang_cross.sh +RUN /tmp/install_clang_cross.sh + +# install osxcross +ADD install_osxcross.sh /tmp/install_osxcross.sh +RUN /tmp/install_osxcross.sh + +# containerized development environment +FROM build as devel +RUN mkdir /workdir +WORKDIR /workdir +RUN echo 'PS1="\[$(tput setaf 3)$(tput bold)[\]devel@\\h:\\W]#\[$(tput sgr0) \]"' >> /root/.bashrc diff --git a/tools/cross-toolchain/README.md b/tools/cross-toolchain/README.md new file mode 100644 index 000000000..17ffaff71 --- /dev/null +++ b/tools/cross-toolchain/README.md @@ -0,0 +1,40 @@ +# Multiarch Cross Compiling Toolchain + +## Toolchain suite + +This package declares a c++ toolchain suite with cross compilers for targeting four platforms: +* linux_amd64 +* linux_arm64 +* osx_amd64 +* windows_amd64 + +This toolchain suite describes cross compile configuration with a Dockerfile with the appropriate host dependencies. These toolchains can be used locally (see [caveats](#caveats)), [Remote Build Execution (RBE)](https://docs.bazel.build/versions/master/remote-execution.html), and in a docker sandbox (like RBE, but local). + + +### Cross compile target support + +| target | linux_amd64 | linux_arm64 | osx_amd64 | windows_amd64 | +|----------|-------------------|------------------|-----------------|-----------------------| +| `//beacon-chain` | :heavy_check_mark: docker-sandbox and RBE, libkafka supported locally only | :heavy_check_mark: docker-sandbox and RBE, no libkafka support | :heavy_check_mark: docker-sandbox, no libkafka support | :heavy_check_mark: docker-sandbox, no libkafka support | +| `//validator`| :heavy_check_mark: docker-sandbox and RBE | :heavy_check_mark: docker-sandbox and RBE | :heavy_check_mark: docker-sandbox | :x: Doesn't work. [#5008](https://github.com/prysmaticlabs/prysm/issues/5008) | + +The configurations above are enforced via pull request presubmit checks. + +### Bazel config flag values + +Use these values with `--config=`, multiple times if more than one value is defined in the table. Example: `bazel build //beacon-chain --config=windows_amd64_docker` to build windows binary in a docker sandbox. + +| Config | linux_amd64 | linux_arm64 | osx_amd64 | windows_amd64 | +|----------|-------------------|------------------|-----------------|-----------------------| +| Local run | `linux_amd64` | `linux_arm64` | `osx_amd64` | `windows_amd64` | +| Docker sandbox | `linux_amd64_docker` | `linux_arm64_docker` | `osx_amd64_docker` | `windows_amd64_docker `| +| RBE (See [Caveats](#caveats)) | `linux_amd64` and `remote` | `linux_arm64` and `remote` | `osx_amd64` and `remote` | `windows_amd64` and `remote` | + +### Caveats + +There are a few caveats to each of these strategies. + +- Local runs require clang compiler and the appropriate cross compilers installed. These runs should only be considered for a power user or user with specific build requirements. See the Dockerfile setup scripts to understand what dependencies must be installed and where. +- Docker sandbox is *slow*. Like really slow! The purpose of the docker sandbox is to test RBE builds without deploying a full RBE system. Each build action is executed in its own container. Given the large number of small targets in this project, the overhead of creating docker containers makes this strategy the slowest of all, but requires zero additional setup. +- Remote Build Execution is by far the fastest, if you have a RBE backend available. This is another advanced use case which will require two config flags above as well as additional flags to specify the `--remote_executor`. Some of these flags are present in the project `.bazelrc` with example values, but commented out. +- Building with libkafka (`--define kafka_enabled=true`) is not supported with docker-sandbox or RBE at this time. Likely due to missing cmake dependencies in the builder image or lack of configuration via toolchains. \ No newline at end of file diff --git a/tools/cross-toolchain/cc_toolchain.BUILD.bazel.tpl b/tools/cross-toolchain/cc_toolchain.BUILD.bazel.tpl new file mode 100644 index 000000000..5496b2889 --- /dev/null +++ b/tools/cross-toolchain/cc_toolchain.BUILD.bazel.tpl @@ -0,0 +1,148 @@ +package(default_visibility = ["//visibility:public"]) + +load(":cc_toolchain_config_osx.bzl", "osx_cc_toolchain_config") +load(":cc_toolchain_config_linux_arm64.bzl", "arm64_cc_toolchain_config") +load(":cc_toolchain_config_windows.bzl", "windows_cc_toolchain_config") + + +cc_toolchain_suite( + name = "multiarch_toolchain", + toolchains = { + "k8|osxcross": ":cc-clang-osx", + "k8|clang": "cc-clang-amd64", + "aarch64|clang": ":cc-clang-arm64", + "k8": "cc-clang-amd64", + "aarch64": ":cc-clang-arm64", + "k8|mingw-w64": ":cc-mingw-amd64", + }, +) + +cc_toolchain_suite( + name = "hostonly_toolchain", + toolchains = { + "k8": "cc-clang-amd64", + }, +) + +filegroup( + name = "empty", + srcs = [], +) + +config_setting( + name = "osx_amd64", + constraint_values = [ + "@platforms//os:osx", + "@platforms//cpu:x86_64", + ], +) + +config_setting( + name = "linux_arm64", + constraint_values = [ + "@platforms//os:linux", + "@platforms//cpu:aarch64", + ], +) + +config_setting( + name = "linux_amd64", + constraint_values = [ + "@platforms//os:linux", + "@platforms//cpu:x86_64", + ], +) + +config_setting( + name = "windows_amd64", + constraint_values = [ + "@platforms//os:windows", + "@platforms//cpu:x86_64", + ], +) + +arm64_cc_toolchain_config( + name = "local-arm64", + target = "aarch64-linux-gnu", +) + +arm64_cc_toolchain_config( + name = "local-amd64", + target = "x86_64-unknown-linux-gnu", +) + +osx_cc_toolchain_config( + name = "local-osxcross", + target = "darwin_x86_64", +) + +windows_cc_toolchain_config( + name = "local-windows", + target = "x86_64-w64", +) + +cc_toolchain( + name = "cc-mingw-amd64", + all_files = ":empty", + ar_files = ":empty", + as_files = ":mingw_compiler_files", + compiler_files = ":mingw_compiler_files", + dwp_files = ":empty", + linker_files = ":empty", + objcopy_files = ":empty", + strip_files = ":empty", + supports_param_files = 0, + toolchain_config = ":local-windows", +) + +cc_toolchain( + name = "cc-clang-arm64", + all_files = ":empty", + compiler_files = ":empty", + dwp_files = ":empty", + linker_files = ":empty", + objcopy_files = ":empty", + strip_files = ":empty", + supports_param_files = 1, + toolchain_config = ":local-arm64", +) + +cc_toolchain( + name = "cc-clang-osx", + all_files = ":empty", + compiler_files = ":empty", + dwp_files = ":empty", + linker_files = ":empty", + objcopy_files = ":empty", + strip_files = ":empty", + supports_param_files = 1, + toolchain_config = ":local-osxcross", +) + +cc_toolchain( + name = "cc-clang-amd64", + all_files = ":empty", + compiler_files = ":empty", + dwp_files = ":empty", + linker_files = ":empty", + objcopy_files = ":empty", + strip_files = ":empty", + supports_param_files = 1, + toolchain_config = ":local-amd64", +) + +toolchain( + name = "cc-toolchain-multiarch", + exec_compatible_with = [ + "@platforms//os:linux", + "@platforms//cpu:x86_64", + ], + target_compatible_with = [], + toolchain = select({ + ":linux_arm64": ":cc-clang-arm64", + ":linux_amd64": ":cc-clang-amd64", + ":osx_amd64": ":cc-clang-osx", + ":windows_amd64": ":cc-mingw-amd64", + }), + toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", +) diff --git a/tools/cross-toolchain/cc_toolchain_config_linux_arm64.bzl.tpl b/tools/cross-toolchain/cc_toolchain_config_linux_arm64.bzl.tpl new file mode 100644 index 000000000..ee8918f82 --- /dev/null +++ b/tools/cross-toolchain/cc_toolchain_config_linux_arm64.bzl.tpl @@ -0,0 +1,305 @@ +load( + "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", + "action_config", + "feature", + "feature_set", + "flag_group", + "flag_set", + "make_variable", + "tool", + "tool_path", + "with_feature_set", +) + +load( + "@bazel_tools//tools/cpp:cc_toolchain_config.bzl", + ALL_COMPILE_ACTIONS = "all_compile_actions", + ALL_CPP_COMPILE_ACTIONS = "all_cpp_compile_actions", + ALL_LINK_ACTIONS = "all_link_actions", +) + +def _impl(ctx): + toolchain_identifier = "clang-linux-cross" + compiler = "clang" + abi_version = "clang" + abi_libc_version = "glibc_unknown" + target_libc = "glibc_unknown" + target_cpu = ctx.attr.target.split("-")[0] + + if (target_cpu == "aarch64"): + sysroot = "/usr/aarch64-linux-gnu" + include_path_prefix = sysroot + elif (target_cpu == "x86_64"): + sysroot = "/" + include_path_prefix = "/usr" + else: + fail("Unreachable") + + if (target_cpu == "aarch64"): + cross_system_include_dirs = [ + include_path_prefix + "/include/c++/v1", + include_path_prefix + "/lib/clang/10.0.0/include", + ] + else: + cross_system_include_dirs = [ + include_path_prefix + "/include/c++/v1", + include_path_prefix + "/lib/clang/10.0.0/include", + include_path_prefix + "/include/x86_64-linux-gnu", + ] + + cross_system_include_dirs += [ + include_path_prefix + "/include/", + include_path_prefix + "/include/linux", + include_path_prefix + "/include/asm", + include_path_prefix + "/include/asm-generic", + ] + + if (target_cpu == "aarch64"): + cross_system_lib_dirs = [ + "/usr/" + ctx.attr.target + "/lib", + ] + else: + cross_system_lib_dirs = [ + "/usr/lib/x86_64-linux-gnu/", + ] + + cross_system_lib_dirs += [ + "/usr/lib/gcc/x86_64-linux-gnu/8", + ] + + opt_feature = feature(name = "opt") + dbg_feature = feature(name = "dbg") + fastbuild_feature = feature(name = "fastbuild") + random_seed_feature = feature(name = "random_seed", enabled = True) + supports_pic_feature = feature(name = "supports_pic", enabled = True) + supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True) + + unfiltered_compile_flags_feature = feature( + name = "unfiltered_compile_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = ALL_COMPILE_ACTIONS, + flag_groups = [ + flag_group( + flags = [ + "-no-canonical-prefixes", + "-Wno-builtin-macro-redefined", + "-D__DATE__=\"redacted\"", + "-D__TIMESTAMP__=\"redacted\"", + "-D__TIME__=\"redacted\"", + ], + ), + ], + ), + ], + ) + + # explicit arch specific system includes + system_include_flags = [] + for d in cross_system_include_dirs: + system_include_flags += ["-idirafter", d] + + default_compile_flags_feature = feature( + name = "default_compile_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = ALL_COMPILE_ACTIONS, + flag_groups = [ + flag_group( + flags = [ + "--target=" + ctx.attr.target, + "-nostdinc", + "-U_FORTIFY_SOURCE", + "-fstack-protector", + "-fno-omit-frame-pointer", + "-fcolor-diagnostics", + "-Wall", + "-Wthread-safety", + "-Wself-assign", + ] + system_include_flags, + ), + ], + ), + flag_set( + actions = ALL_COMPILE_ACTIONS, + flag_groups = [flag_group(flags = ["-g", "-fstandalone-debug"])], + with_features = [with_feature_set(features = ["dbg"])], + ), + flag_set( + actions = ALL_COMPILE_ACTIONS, + flag_groups = [ + flag_group( + flags = [ + "-g0", + "-O2", + "-D_FORTIFY_SOURCE=1", + "-DNDEBUG", + "-ffunction-sections", + "-fdata-sections", + ], + ), + ], + with_features = [with_feature_set(features = ["opt"])], + ), + flag_set( + actions = ALL_CPP_COMPILE_ACTIONS, + flag_groups = [flag_group(flags = ["-std=c++17", "-nostdinc++"])], + ), + ], + ) + + additional_link_flags = [ + "-l:libc++.a", + "-l:libc++abi.a", + "-l:libunwind.a", + "-lpthread", + "-ldl", + "-rtlib=compiler-rt", + ] + + default_link_flags_feature = feature( + name = "default_link_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = ALL_LINK_ACTIONS, + flag_groups = [ + flag_group( + flags = additional_link_flags + [ + "--target=" + ctx.attr.target, + "-lm", + "-no-canonical-prefixes", + "-fuse-ld=lld", + "-Wl,--build-id=md5", + "-Wl,--hash-style=gnu", + "-Wl,-z,relro,-z,now", + ] + ["-L" + d for d in cross_system_lib_dirs], + ), + ], + ), + flag_set( + actions = ALL_LINK_ACTIONS, + flag_groups = [flag_group(flags = ["-Wl,--gc-sections"])], + with_features = [with_feature_set(features = ["opt"])], + ), + ], + ) + + objcopy_embed_flags_feature = feature( + name = "objcopy_embed_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = ["objcopy_embed_data"], + flag_groups = [flag_group(flags = ["-I", "binary"])], + ), + ], + ) + + user_compile_flags_feature = feature( + name = "user_compile_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = ALL_COMPILE_ACTIONS, + flag_groups = [ + flag_group( + expand_if_available = "user_compile_flags", + flags = ["%{user_compile_flags}"], + iterate_over = "user_compile_flags", + ), + ], + ), + ], + ) + + sysroot_feature = feature( + name = "sysroot", + enabled = True, + flag_sets = [ + flag_set( + actions = ALL_COMPILE_ACTIONS + ALL_LINK_ACTIONS, + flag_groups = [ + flag_group( + expand_if_available = "sysroot", + flags = ["--sysroot=%{sysroot}"], + ), + ], + ), + ], + ) + + coverage_feature = feature( + name = "coverage", + flag_sets = [ + flag_set( + actions = ALL_COMPILE_ACTIONS, + flag_groups = [ + flag_group( + flags = ["-fprofile-instr-generate", "-fcoverage-mapping"], + ), + ], + ), + flag_set( + actions = ALL_LINK_ACTIONS, + flag_groups = [flag_group(flags = ["-fprofile-instr-generate"])], + ), + ], + provides = ["profile"], + ) + + features = [ + opt_feature, + fastbuild_feature, + dbg_feature, + random_seed_feature, + supports_pic_feature, + supports_dynamic_linker_feature, + unfiltered_compile_flags_feature, + default_link_flags_feature, + default_compile_flags_feature, + objcopy_embed_flags_feature, + user_compile_flags_feature, + sysroot_feature, + coverage_feature, + ] + + tool_paths = [ + tool_path(name = "ld", path = "/usr/bin/ld.lld"), + 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/strip"), + tool_path(name = "gcc", path = "/usr/bin/clang"), + tool_path(name = "ar", path = "/usr/bin/llvm-ar"), + ] + + return cc_common.create_cc_toolchain_config_info( + ctx = ctx, + features = features, + abi_version = abi_version, + abi_libc_version = abi_libc_version, + builtin_sysroot = sysroot, + compiler = compiler, + cxx_builtin_include_directories = cross_system_include_dirs, + host_system_name = "x86_64-unknown-linux-gnu", + target_cpu = target_cpu, + target_libc = target_libc, + target_system_name = ctx.attr.target, + tool_paths = tool_paths, + toolchain_identifier = toolchain_identifier, + ) + +arm64_cc_toolchain_config = rule( + implementation = _impl, + attrs = { + "target": attr.string(mandatory = True), + "stdlib": attr.string(), + }, + provides = [CcToolchainConfigInfo], +) diff --git a/tools/cross-toolchain/cc_toolchain_config_osx.bzl.tpl b/tools/cross-toolchain/cc_toolchain_config_osx.bzl.tpl new file mode 100644 index 000000000..f3ad1e8c7 --- /dev/null +++ b/tools/cross-toolchain/cc_toolchain_config_osx.bzl.tpl @@ -0,0 +1,251 @@ +load( + "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", + "action_config", + "feature", + "feature_set", + "flag_group", + "flag_set", + "make_variable", + "tool", + "tool_path", + "with_feature_set", +) + +load( + "@bazel_tools//tools/cpp:cc_toolchain_config.bzl", + ALL_COMPILE_ACTIONS = "all_compile_actions", + ALL_CPP_COMPILE_ACTIONS = "all_cpp_compile_actions", + ALL_LINK_ACTIONS = "all_link_actions", +) + +def _impl(ctx): + toolchain_identifier = "osxcross" + compiler = "clang" + abi_version = "darwin_x86_64" + abi_libc_version = "darwin_x86_64" + install = "/usr/x86_64-apple-darwin/" + clang_version = "10.0.0" + target_libc = "macosx" + target_cpu = "x86_64" + osxcross = install + "osxcross/" + osxcross_binprefix = osxcross + "bin/x86_64-apple-darwin14-" + sdkroot = osxcross + "SDK/MacOSX10.10.sdk/" + cross_system_include_dirs = [ + "/usr/lib/clang/10.0.0/include", + osxcross + "include", + sdkroot + "usr/include", + ] + cross_system_lib_dirs = [ + "/usr/x86_64-apple-darwin/lib", + sdkroot + "usr/lib", + osxcross + "/lib", + ] + + opt_feature = feature(name = "opt") + dbg_feature = feature(name = "dbg") + fastbuild_feature = feature(name = "fastbuild") + random_seed_feature = feature(name = "random_seed", enabled = True) + supports_pic_feature = feature(name = "supports_pic", enabled = True) + supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True) + + unfiltered_compile_flags_feature = feature( + name = "unfiltered_compile_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = ALL_COMPILE_ACTIONS, + flag_groups = [ + flag_group( + flags = [ + "-stdlib=libc++", + "-no-canonical-prefixes", + "-Wno-builtin-macro-redefined", + "-D__DATE__=\"redacted\"", + "-D__TIMESTAMP__=\"redacted\"", + "-D__TIME__=\"redacted\"", + ], + ), + ], + ), + ], + ) + + # explicit arch specific system includes + system_include_flags = [] + for d in cross_system_include_dirs: + system_include_flags += ["-idirafter", d] + + default_compile_flags_feature = feature( + name = "default_compile_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = ALL_COMPILE_ACTIONS, + flag_groups = [ + flag_group( + flags = [ + "-mlinker-version=400", + "-B " + osxcross + "bin", + "-nostdinc", + "-U_FORTIFY_SOURCE", + "-fstack-protector", + "-fno-omit-frame-pointer", + "-fcolor-diagnostics", + "-Wall", + "-Wthread-safety", + "-Wself-assign", + ] + system_include_flags, + ), + ], + ), + flag_set( + actions = ALL_COMPILE_ACTIONS, + flag_groups = [flag_group(flags = ["-g", "-fstandalone-debug"])], + with_features = [with_feature_set(features = ["dbg"])], + ), + flag_set( + actions = ALL_COMPILE_ACTIONS, + flag_groups = [ + flag_group( + flags = [ + "-g0", + "-O2", + "-D_FORTIFY_SOURCE=1", + "-DNDEBUG", + "-ffunction-sections", + "-fdata-sections", + ], + ), + ], + with_features = [with_feature_set(features = ["opt"])], + ), + flag_set( + actions = ALL_CPP_COMPILE_ACTIONS, + flag_groups = [flag_group(flags = ["-std=c++17", "-nostdinc++"])], + ), + ], + ) + + default_link_flags_feature = feature( + name = "default_link_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = ALL_LINK_ACTIONS, + flag_groups = [ + flag_group( + flags = [ + "-v", + "-lm", + "-no-canonical-prefixes", + "-fuse-ld=lld", + "-lc++", + "-lc++abi", + "-F" + sdkroot + "System/Library/Frameworks/", + "-L"+ sdkroot + "usr/lib", + "-undefined", + "dynamic_lookup", + ], + ), + ], + ), + ], + ) + + objcopy_embed_flags_feature = feature( + name = "objcopy_embed_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = ["objcopy_embed_data"], + flag_groups = [flag_group(flags = ["-I", "binary"])], + ), + ], + ) + + user_compile_flags_feature = feature( + name = "user_compile_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = ALL_COMPILE_ACTIONS, + flag_groups = [ + flag_group( + expand_if_available = "user_compile_flags", + flags = ["%{user_compile_flags}"], + iterate_over = "user_compile_flags", + ), + ], + ), + ], + ) + + coverage_feature = feature( + name = "coverage", + flag_sets = [ + flag_set( + actions = ALL_COMPILE_ACTIONS, + flag_groups = [ + flag_group( + flags = ["-fprofile-instr-generate", "-fcoverage-mapping"], + ), + ], + ), + flag_set( + actions = ALL_LINK_ACTIONS, + flag_groups = [flag_group(flags = ["-fprofile-instr-generate"])], + ), + ], + provides = ["profile"], + ) + + features = [ + opt_feature, + fastbuild_feature, + dbg_feature, + random_seed_feature, + supports_pic_feature, + supports_dynamic_linker_feature, + unfiltered_compile_flags_feature, + default_link_flags_feature, + default_compile_flags_feature, + objcopy_embed_flags_feature, + user_compile_flags_feature, + coverage_feature, + ] + + tool_paths = [ + tool_path(name = "ld", path = osxcross_binprefix + "ld"), + tool_path(name = "cpp", path = osxcross + "bin/o64-clang++"), + tool_path(name = "dwp", path = "/usr/bin/dwp"), + tool_path(name = "gcov", path = "/usr/bin/gcov"), + tool_path(name = "nm", path = osxcross_binprefix + "nm"), + tool_path(name = "objdump", path = osxcross_binprefix + "ObjectDump"), + tool_path(name = "strip", path = osxcross_binprefix + "strip"), + tool_path(name = "gcc", path = osxcross + "bin/o64-clang"), + tool_path(name = "ar", path = osxcross_binprefix + "libtool"), + ] + + return cc_common.create_cc_toolchain_config_info( + ctx = ctx, + features = features, + abi_version = abi_version, + abi_libc_version = abi_libc_version, + compiler = compiler, + cxx_builtin_include_directories = cross_system_include_dirs, + host_system_name = "x86_64-unknown-linux-gnu", + target_cpu = target_cpu, + target_libc = target_libc, + target_system_name = ctx.attr.target, + tool_paths = tool_paths, + toolchain_identifier = toolchain_identifier, + ) + +osx_cc_toolchain_config = rule( + implementation = _impl, + attrs = { + "target": attr.string(mandatory = True), + "stdlib": attr.string(), + }, + provides = [CcToolchainConfigInfo], +) diff --git a/tools/cross-toolchain/cc_toolchain_config_windows.bzl.tpl b/tools/cross-toolchain/cc_toolchain_config_windows.bzl.tpl new file mode 100644 index 000000000..eb783208f --- /dev/null +++ b/tools/cross-toolchain/cc_toolchain_config_windows.bzl.tpl @@ -0,0 +1,213 @@ +load( + "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", + "action_config", + "feature", + "feature_set", + "flag_group", + "flag_set", + "make_variable", + "tool", + "tool_path", + "with_feature_set", + "artifact_name_pattern", + "env_set", + "env_entry", +) + +load( + "@bazel_tools//tools/cpp:cc_toolchain_config.bzl", + ALL_COMPILE_ACTIONS = "all_compile_actions", + ALL_CPP_COMPILE_ACTIONS = "all_cpp_compile_actions", + ALL_LINK_ACTIONS = "all_link_actions", +) + +load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES") + +def _impl(ctx): + toolchain_identifier = "msys_x64_mingw" + host_system_name = "local" + target_system_name = "local" + target_cpu = "x64_windows" + target_libc = "mingw" + compiler = "mingw-gcc" + abi_version = "local" + abi_libc_version = "local" + cc_target_os = None + builtin_sysroot = None + action_configs = [] + + install = "/usr/x86_64-w64-mingw32/" + bin_prefix = "/usr/bin/x86_64-w64-mingw32-" + + + targets_windows_feature = feature( + name = "targets_windows", + implies = ["copy_dynamic_libraries_to_binary"], + enabled = True, + ) + + copy_dynamic_libraries_to_binary_feature = feature(name = "copy_dynamic_libraries_to_binary") + + gcc_env_feature = feature( + name = "gcc_env", + enabled = True, + env_sets = [ + env_set( + actions = [ + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.cpp_module_compile, + ACTION_NAMES.cpp_module_codegen, + ACTION_NAMES.cpp_header_parsing, + ACTION_NAMES.assemble, + ACTION_NAMES.preprocess_assemble, + ACTION_NAMES.cpp_link_executable, + ACTION_NAMES.cpp_link_dynamic_library, + ACTION_NAMES.cpp_link_nodeps_dynamic_library, + ACTION_NAMES.cpp_link_static_library, + ], + env_entries = [ + env_entry(key = "PATH", value = "NOT_USED"), + ], + ), + ], + ) + + msys_mingw_flags = [ + "-B " + install + "bin", + "-nostdinc", + "-U_FORTIFY_SOURCE", + "-fstack-protector", + "-fno-omit-frame-pointer", + "-fcolor-diagnostics", + "-Wall", + "-Wthread-safety", + "-Wself-assign", + "-x c++", + "-lstdc++", + "-lpthread" + ] + + msys_mingw_link_flags = [ + "-l:libstdc++.a", + "-L" + install + "lib", + "-L/usr/lib/gcc/x86_64-w64-mingw32/8.3-w32", + "-v", + "-lm", + "-no-canonical-prefixes", + ] + + default_compile_flags_feature = feature( + name = "default_compile_flags", + enabled = True, + flag_sets = [ + flag_set( + 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_compile, + ACTION_NAMES.cpp_module_codegen, + ACTION_NAMES.lto_backend, + ACTION_NAMES.clif_match, + ], + ), + flag_set( + actions = [ + ACTION_NAMES.linkstamp_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.cpp_header_parsing, + ACTION_NAMES.cpp_module_compile, + ACTION_NAMES.cpp_module_codegen, + ACTION_NAMES.lto_backend, + ACTION_NAMES.clif_match, + ], + flag_groups = ([flag_group(flags = msys_mingw_flags)] if msys_mingw_flags else []), + ), + ], + ) + + compiler_param_file_feature = feature( + name = "compiler_param_file", + ) + + default_link_flags_feature = feature( + name = "default_link_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = ALL_LINK_ACTIONS, + flag_groups = ([flag_group(flags = msys_mingw_link_flags)] if msys_mingw_link_flags else []), + ), + ], + ) + + supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True) + + features = [ + targets_windows_feature, + copy_dynamic_libraries_to_binary_feature, + gcc_env_feature, + default_compile_flags_feature, + compiler_param_file_feature, + default_link_flags_feature, + supports_dynamic_linker_feature, + ] + + cxx_builtin_include_directories = [ + install +"include" + ] + + artifact_name_patterns = [ + artifact_name_pattern( + category_name = "executable", + prefix = "", + extension = ".exe", + ), + ] + + make_variables = [] + tool_paths = [ + tool_path(name = "ld", path = bin_prefix + "ld"), + tool_path(name = "cpp", path = bin_prefix + "cpp"), + tool_path(name = "gcov", path = "/usr/bin/gcov"), + tool_path(name = "nm", path = bin_prefix + "nm"), + tool_path(name = "objcopy", path = bin_prefix + "objcopy"), + tool_path(name = "objdump", path = bin_prefix + "objdump"), + tool_path(name = "strip", path = bin_prefix + "strip"), + tool_path(name = "gcc", path = bin_prefix + "gcc"), + tool_path(name = "ar", path = bin_prefix + "ar"), + ] + + return cc_common.create_cc_toolchain_config_info( + ctx = ctx, + features = features, + action_configs = action_configs, + artifact_name_patterns = artifact_name_patterns, + cxx_builtin_include_directories = cxx_builtin_include_directories, + toolchain_identifier = toolchain_identifier, + host_system_name = host_system_name, + target_system_name = target_system_name, + target_cpu = target_cpu, + target_libc = target_libc, + compiler = compiler, + abi_version = abi_version, + abi_libc_version = abi_libc_version, + tool_paths = tool_paths, + make_variables = make_variables, + builtin_sysroot = builtin_sysroot, + cc_target_os = cc_target_os, + ) + +windows_cc_toolchain_config = rule( + implementation = _impl, + attrs = { + "target": attr.string(mandatory = True), + "stdlib": attr.string(), + }, + provides = [CcToolchainConfigInfo], +) + diff --git a/tools/cross-toolchain/configs/.latest.bazelrc b/tools/cross-toolchain/configs/.latest.bazelrc new file mode 100644 index 000000000..267d84860 --- /dev/null +++ b/tools/cross-toolchain/configs/.latest.bazelrc @@ -0,0 +1,33 @@ +# Copyright 2016 The Bazel Authors. All rights reserved. +# +# 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. + +# This .bazelrc file is generated by rbe_autoconfig +# when the output_base attr is used. +# It contains some of the flags required for the provided +# toolchain with Remote Build Execution. +# Specifically, it includes all toolchain/platform flags +# This file is used for testing purposes. + +build:remote --host_javabase=//tools/cross-toolchain/configs/gcc/bazel_2.1.1/java:jdk +build:remote --javabase=//tools/cross-toolchain/configs/gcc/bazel_2.1.1/java:jdk +build:remote --crosstool_top=//tools/cross-toolchain/configs/gcc/bazel_2.1.1/cc:toolchain +build:remote --extra_toolchains=//tools/cross-toolchain/configs/gcc/bazel_2.1.1/config:cc-toolchain +build:remote --extra_execution_platforms=//tools/cross-toolchain/configs/gcc/bazel_2.1.1/config:platform +build:remote --host_platform=//tools/cross-toolchain/configs/gcc/bazel_2.1.1/config:platform +build:remote --platforms=//tools/cross-toolchain/configs/gcc/bazel_2.1.1/config:platform + +# Import the default bazelrc file in bazel-toolchains repo. +# This will only work for tests executed from bazel-toolchains +# repo. +try-import %workspace%/bazelrc/.bazelrc.notoolchain diff --git a/tools/cross-toolchain/configs/clang/bazel_2.1.1/cc/BUILD b/tools/cross-toolchain/configs/clang/bazel_2.1.1/cc/BUILD new file mode 100755 index 000000000..ea9e10562 --- /dev/null +++ b/tools/cross-toolchain/configs/clang/bazel_2.1.1/cc/BUILD @@ -0,0 +1,166 @@ +# Copyright 2016 The Bazel Authors. All rights reserved. +# +# 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. + +# This becomes the BUILD file for @local_config_cc// under non-FreeBSD unixes. + +package(default_visibility = ["//visibility:public"]) + +load(":cc_toolchain_config.bzl", "cc_toolchain_config") +load(":armeabi_cc_toolchain_config.bzl", "armeabi_cc_toolchain_config") +load("@rules_cc//cc:defs.bzl", "cc_toolchain", "cc_toolchain_suite") + +licenses(["notice"]) # Apache 2.0 + +cc_library( + name = "malloc", +) + +filegroup( + name = "empty", + srcs = [], +) + +filegroup( + name = "cc_wrapper", + srcs = ["cc_wrapper.sh"], +) + +filegroup( + name = "compiler_deps", + srcs = glob( + ["extra_tools/**"], + allow_empty = True, + ) + [":builtin_include_directory_paths"], +) + +# This is the entry point for --crosstool_top. Toolchains are found +# by lopping off the name of --crosstool_top and searching for +# the "${CPU}" entry in the toolchains attribute. +cc_toolchain_suite( + name = "toolchain", + toolchains = { + "k8|clang": ":cc-compiler-k8", + "k8": ":cc-compiler-k8", + "armeabi-v7a|compiler": ":cc-compiler-armeabi-v7a", + "armeabi-v7a": ":cc-compiler-armeabi-v7a", + }, +) + +cc_toolchain( + name = "cc-compiler-k8", + all_files = ":compiler_deps", + ar_files = ":compiler_deps", + as_files = ":compiler_deps", + compiler_files = ":compiler_deps", + dwp_files = ":empty", + linker_files = ":compiler_deps", + objcopy_files = ":empty", + strip_files = ":empty", + supports_param_files = 1, + toolchain_config = ":local", + toolchain_identifier = "local", +) + +cc_toolchain_config( + name = "local", + abi_libc_version = "local", + abi_version = "local", + compile_flags = [ + "-U_FORTIFY_SOURCE", + "-fstack-protector", + "-Wall", + "-Wthread-safety", + "-Wself-assign", + "-fcolor-diagnostics", + "-fno-omit-frame-pointer", + ], + compiler = "clang", + coverage_compile_flags = [ + "-fprofile-instr-generate", + "-fcoverage-mapping", + ], + coverage_link_flags = ["-fprofile-instr-generate"], + cpu = "k8", + cxx_builtin_include_directories = [ + "/usr/local/include", + "/usr/lib/clang/10.0.0/include", + "/usr/include/x86_64-linux-gnu", + "/usr/include", + "/usr/include/c++/8", + "/usr/include/x86_64-linux-gnu/c++/8", + "/usr/include/c++/8/backward", + ], + cxx_flags = ["-std=c++0x"], + dbg_compile_flags = ["-g"], + host_system_name = "local", + link_flags = [ + "-fuse-ld=/usr/bin/ld.gold", + "-Wl,-no-as-needed", + "-Wl,-z,relro,-z,now", + "-B/usr/bin", + "-lm", + "-static-libgcc", + ], + link_libs = ["-l:libstdc++.a"], + opt_compile_flags = [ + "-g0", + "-O2", + "-D_FORTIFY_SOURCE=1", + "-DNDEBUG", + "-ffunction-sections", + "-fdata-sections", + ], + opt_link_flags = ["-Wl,--gc-sections"], + supports_start_end_lib = True, + target_libc = "local", + target_system_name = "local", + tool_paths = { + "ar": "/usr/bin/ar", + "ld": "/usr/bin/ld", + "cpp": "/usr/bin/cpp", + "gcc": "/usr/bin/clang", + "dwp": "/usr/bin/dwp", + "gcov": "/usr/bin/llvm-profdata", + "nm": "/usr/bin/nm", + "objcopy": "/usr/bin/objcopy", + "objdump": "/usr/bin/objdump", + "strip": "/usr/bin/strip", + }, + toolchain_identifier = "local", + unfiltered_compile_flags = [ + "-no-canonical-prefixes", + "-Wno-builtin-macro-redefined", + "-D__DATE__=\"redacted\"", + "-D__TIMESTAMP__=\"redacted\"", + "-D__TIME__=\"redacted\"", + ], +) + +# Android tooling requires a default toolchain for the armeabi-v7a cpu. +cc_toolchain( + name = "cc-compiler-armeabi-v7a", + all_files = ":empty", + ar_files = ":empty", + as_files = ":empty", + compiler_files = ":empty", + dwp_files = ":empty", + linker_files = ":empty", + objcopy_files = ":empty", + strip_files = ":empty", + supports_param_files = 1, + toolchain_config = ":stub_armeabi-v7a", + toolchain_identifier = "stub_armeabi-v7a", +) + +armeabi_cc_toolchain_config(name = "stub_armeabi-v7a") diff --git a/tools/cross-toolchain/configs/clang/bazel_2.1.1/cc/armeabi_cc_toolchain_config.bzl b/tools/cross-toolchain/configs/clang/bazel_2.1.1/cc/armeabi_cc_toolchain_config.bzl new file mode 100755 index 000000000..94e0720bf --- /dev/null +++ b/tools/cross-toolchain/configs/clang/bazel_2.1.1/cc/armeabi_cc_toolchain_config.bzl @@ -0,0 +1,82 @@ +# Copyright 2019 The Bazel Authors. All rights reserved. +# +# 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. + +"""A Starlark cc_toolchain configuration rule""" + +load( + "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", + "feature", + "tool_path", +) + +def _impl(ctx): + toolchain_identifier = "stub_armeabi-v7a" + host_system_name = "armeabi-v7a" + target_system_name = "armeabi-v7a" + target_cpu = "armeabi-v7a" + target_libc = "armeabi-v7a" + compiler = "compiler" + abi_version = "armeabi-v7a" + abi_libc_version = "armeabi-v7a" + cc_target_os = None + builtin_sysroot = None + action_configs = [] + + supports_pic_feature = feature(name = "supports_pic", enabled = True) + supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True) + features = [supports_dynamic_linker_feature, supports_pic_feature] + + cxx_builtin_include_directories = [] + artifact_name_patterns = [] + make_variables = [] + + tool_paths = [ + tool_path(name = "ar", path = "/bin/false"), + tool_path(name = "compat-ld", path = "/bin/false"), + tool_path(name = "cpp", path = "/bin/false"), + tool_path(name = "dwp", path = "/bin/false"), + tool_path(name = "gcc", path = "/bin/false"), + tool_path(name = "gcov", path = "/bin/false"), + tool_path(name = "ld", path = "/bin/false"), + tool_path(name = "nm", path = "/bin/false"), + tool_path(name = "objcopy", path = "/bin/false"), + tool_path(name = "objdump", path = "/bin/false"), + tool_path(name = "strip", path = "/bin/false"), + ] + + return cc_common.create_cc_toolchain_config_info( + ctx = ctx, + features = features, + action_configs = action_configs, + artifact_name_patterns = artifact_name_patterns, + cxx_builtin_include_directories = cxx_builtin_include_directories, + toolchain_identifier = toolchain_identifier, + host_system_name = host_system_name, + target_system_name = target_system_name, + target_cpu = target_cpu, + target_libc = target_libc, + compiler = compiler, + abi_version = abi_version, + abi_libc_version = abi_libc_version, + tool_paths = tool_paths, + make_variables = make_variables, + builtin_sysroot = builtin_sysroot, + cc_target_os = cc_target_os, + ) + +armeabi_cc_toolchain_config = rule( + implementation = _impl, + attrs = {}, + provides = [CcToolchainConfigInfo], +) diff --git a/tools/cross-toolchain/configs/clang/bazel_2.1.1/cc/builtin_include_directory_paths b/tools/cross-toolchain/configs/clang/bazel_2.1.1/cc/builtin_include_directory_paths new file mode 100755 index 000000000..7c391cb29 --- /dev/null +++ b/tools/cross-toolchain/configs/clang/bazel_2.1.1/cc/builtin_include_directory_paths @@ -0,0 +1,13 @@ +This file is generated by cc_configure and contains builtin include directories +that /usr/bin/clang reported. This file is a dependency of every compilation action and +changes to it will be reflected in the action cache key. When some of these +paths change, Bazel will make sure to rerun the action, even though none of +declared action inputs or the action commandline changes. + +/usr/local/include +/usr/lib/clang/10.0.0/include +/usr/include/x86_64-linux-gnu +/usr/include +/usr/include/c++/8 +/usr/include/x86_64-linux-gnu/c++/8 +/usr/include/c++/8/backward diff --git a/tools/cross-toolchain/configs/clang/bazel_2.1.1/cc/cc_toolchain_config.bzl b/tools/cross-toolchain/configs/clang/bazel_2.1.1/cc/cc_toolchain_config.bzl new file mode 100755 index 000000000..c5fd79eae --- /dev/null +++ b/tools/cross-toolchain/configs/clang/bazel_2.1.1/cc/cc_toolchain_config.bzl @@ -0,0 +1,1197 @@ +# Copyright 2019 The Bazel Authors. All rights reserved. +# +# 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. + +"""A Starlark cc_toolchain configuration rule""" + +load( + "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", + "feature", + "feature_set", + "flag_group", + "flag_set", + "tool_path", + "variable_with_value", + "with_feature_set", +) +load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES") + +all_compile_actions = [ + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.linkstamp_compile, + ACTION_NAMES.assemble, + ACTION_NAMES.preprocess_assemble, + ACTION_NAMES.cpp_header_parsing, + ACTION_NAMES.cpp_module_compile, + ACTION_NAMES.cpp_module_codegen, + ACTION_NAMES.clif_match, + ACTION_NAMES.lto_backend, +] + +all_cpp_compile_actions = [ + ACTION_NAMES.cpp_compile, + ACTION_NAMES.linkstamp_compile, + ACTION_NAMES.cpp_header_parsing, + ACTION_NAMES.cpp_module_compile, + ACTION_NAMES.cpp_module_codegen, + ACTION_NAMES.clif_match, +] + +preprocessor_compile_actions = [ + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.linkstamp_compile, + ACTION_NAMES.preprocess_assemble, + ACTION_NAMES.cpp_header_parsing, + ACTION_NAMES.cpp_module_compile, + ACTION_NAMES.clif_match, +] + +codegen_compile_actions = [ + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.linkstamp_compile, + ACTION_NAMES.assemble, + ACTION_NAMES.preprocess_assemble, + ACTION_NAMES.cpp_module_codegen, + ACTION_NAMES.lto_backend, +] + +all_link_actions = [ + ACTION_NAMES.cpp_link_executable, + ACTION_NAMES.cpp_link_dynamic_library, + ACTION_NAMES.cpp_link_nodeps_dynamic_library, +] + +lto_index_actions = [ + ACTION_NAMES.lto_index_for_executable, + ACTION_NAMES.lto_index_for_dynamic_library, + ACTION_NAMES.lto_index_for_nodeps_dynamic_library, +] + +def _impl(ctx): + tool_paths = [ + tool_path(name = name, path = path) + for name, path in ctx.attr.tool_paths.items() + ] + action_configs = [] + + supports_pic_feature = feature( + name = "supports_pic", + enabled = True, + ) + supports_start_end_lib_feature = feature( + name = "supports_start_end_lib", + enabled = True, + ) + + default_compile_flags_feature = feature( + name = "default_compile_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = all_compile_actions, + flag_groups = ([ + flag_group( + flags = ctx.attr.compile_flags, + ), + ] if ctx.attr.compile_flags else []), + ), + flag_set( + actions = all_compile_actions, + flag_groups = ([ + flag_group( + flags = ctx.attr.dbg_compile_flags, + ), + ] if ctx.attr.dbg_compile_flags else []), + with_features = [with_feature_set(features = ["dbg"])], + ), + flag_set( + actions = all_compile_actions, + flag_groups = ([ + flag_group( + flags = ctx.attr.opt_compile_flags, + ), + ] if ctx.attr.opt_compile_flags else []), + with_features = [with_feature_set(features = ["opt"])], + ), + flag_set( + actions = all_cpp_compile_actions + [ACTION_NAMES.lto_backend], + flag_groups = ([ + flag_group( + flags = ctx.attr.cxx_flags, + ), + ] if ctx.attr.cxx_flags else []), + ), + ], + ) + + default_link_flags_feature = feature( + name = "default_link_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = all_link_actions + lto_index_actions, + flag_groups = ([ + flag_group( + flags = ctx.attr.link_flags, + ), + ] if ctx.attr.link_flags else []), + ), + flag_set( + actions = all_link_actions + lto_index_actions, + flag_groups = ([ + flag_group( + flags = ctx.attr.opt_link_flags, + ), + ] if ctx.attr.opt_link_flags else []), + with_features = [with_feature_set(features = ["opt"])], + ), + ], + ) + + dbg_feature = feature(name = "dbg") + + opt_feature = feature(name = "opt") + + sysroot_feature = feature( + name = "sysroot", + enabled = True, + flag_sets = [ + flag_set( + actions = [ + 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_compile, + ACTION_NAMES.cpp_module_codegen, + ACTION_NAMES.lto_backend, + ACTION_NAMES.clif_match, + ] + all_link_actions + lto_index_actions, + flag_groups = [ + flag_group( + flags = ["--sysroot=%{sysroot}"], + expand_if_available = "sysroot", + ), + ], + ), + ], + ) + + fdo_optimize_feature = feature( + name = "fdo_optimize", + flag_sets = [ + flag_set( + actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], + flag_groups = [ + flag_group( + flags = [ + "-fprofile-use=%{fdo_profile_path}", + "-fprofile-correction", + ], + expand_if_available = "fdo_profile_path", + ), + ], + ), + ], + provides = ["profile"], + ) + + supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True) + + user_compile_flags_feature = feature( + name = "user_compile_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = all_compile_actions, + flag_groups = [ + flag_group( + flags = ["%{user_compile_flags}"], + iterate_over = "user_compile_flags", + expand_if_available = "user_compile_flags", + ), + ], + ), + ], + ) + + unfiltered_compile_flags_feature = feature( + name = "unfiltered_compile_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = all_compile_actions, + flag_groups = ([ + flag_group( + flags = ctx.attr.unfiltered_compile_flags, + ), + ] if ctx.attr.unfiltered_compile_flags else []), + ), + ], + ) + + library_search_directories_feature = feature( + name = "library_search_directories", + flag_sets = [ + flag_set( + actions = all_link_actions + lto_index_actions, + flag_groups = [ + flag_group( + flags = ["-L%{library_search_directories}"], + iterate_over = "library_search_directories", + expand_if_available = "library_search_directories", + ), + ], + ), + ], + ) + + static_libgcc_feature = feature( + name = "static_libgcc", + enabled = True, + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.cpp_link_executable, + ACTION_NAMES.cpp_link_dynamic_library, + ACTION_NAMES.lto_index_for_executable, + ACTION_NAMES.lto_index_for_dynamic_library, + ], + flag_groups = [flag_group(flags = ["-static-libgcc"])], + with_features = [ + with_feature_set(features = ["static_link_cpp_runtimes"]), + ], + ), + ], + ) + + pic_feature = feature( + name = "pic", + enabled = True, + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.assemble, + ACTION_NAMES.preprocess_assemble, + ACTION_NAMES.linkstamp_compile, + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.cpp_module_codegen, + ACTION_NAMES.cpp_module_compile, + ], + flag_groups = [ + flag_group(flags = ["-fPIC"], expand_if_available = "pic"), + ], + ), + ], + ) + + per_object_debug_info_feature = feature( + name = "per_object_debug_info", + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.assemble, + ACTION_NAMES.preprocess_assemble, + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.cpp_module_codegen, + ], + flag_groups = [ + flag_group( + flags = ["-gsplit-dwarf"], + expand_if_available = "per_object_debug_info_file", + ), + ], + ), + ], + ) + + preprocessor_defines_feature = feature( + name = "preprocessor_defines", + enabled = True, + flag_sets = [ + flag_set( + actions = [ + 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_compile, + ACTION_NAMES.clif_match, + ], + flag_groups = [ + flag_group( + flags = ["-D%{preprocessor_defines}"], + iterate_over = "preprocessor_defines", + ), + ], + ), + ], + ) + + cs_fdo_optimize_feature = feature( + name = "cs_fdo_optimize", + flag_sets = [ + flag_set( + actions = [ACTION_NAMES.lto_backend], + flag_groups = [ + flag_group( + flags = [ + "-fprofile-use=%{fdo_profile_path}", + "-Xclang-only=-Wno-profile-instr-unprofiled", + "-Xclang-only=-Wno-profile-instr-out-of-date", + "-fprofile-correction", + ], + expand_if_available = "fdo_profile_path", + ), + ], + ), + ], + provides = ["csprofile"], + ) + + autofdo_feature = feature( + name = "autofdo", + flag_sets = [ + flag_set( + actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], + flag_groups = [ + flag_group( + flags = [ + "-fauto-profile=%{fdo_profile_path}", + "-fprofile-correction", + ], + expand_if_available = "fdo_profile_path", + ), + ], + ), + ], + provides = ["profile"], + ) + + runtime_library_search_directories_feature = feature( + name = "runtime_library_search_directories", + flag_sets = [ + flag_set( + actions = all_link_actions + lto_index_actions, + flag_groups = [ + flag_group( + iterate_over = "runtime_library_search_directories", + flag_groups = [ + flag_group( + flags = [ + "-Wl,-rpath,$EXEC_ORIGIN/%{runtime_library_search_directories}", + ], + expand_if_true = "is_cc_test", + ), + flag_group( + flags = [ + "-Wl,-rpath,$ORIGIN/%{runtime_library_search_directories}", + ], + expand_if_false = "is_cc_test", + ), + ], + expand_if_available = + "runtime_library_search_directories", + ), + ], + with_features = [ + with_feature_set(features = ["static_link_cpp_runtimes"]), + ], + ), + flag_set( + actions = all_link_actions + lto_index_actions, + flag_groups = [ + flag_group( + iterate_over = "runtime_library_search_directories", + flag_groups = [ + flag_group( + flags = [ + "-Wl,-rpath,$ORIGIN/%{runtime_library_search_directories}", + ], + ), + ], + expand_if_available = + "runtime_library_search_directories", + ), + ], + with_features = [ + with_feature_set( + not_features = ["static_link_cpp_runtimes"], + ), + ], + ), + ], + ) + + fission_support_feature = feature( + name = "fission_support", + flag_sets = [ + flag_set( + actions = all_link_actions + lto_index_actions, + flag_groups = [ + flag_group( + flags = ["-Wl,--gdb-index"], + expand_if_available = "is_using_fission", + ), + ], + ), + ], + ) + + shared_flag_feature = feature( + name = "shared_flag", + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.cpp_link_dynamic_library, + ACTION_NAMES.cpp_link_nodeps_dynamic_library, + ACTION_NAMES.lto_index_for_dynamic_library, + ACTION_NAMES.lto_index_for_nodeps_dynamic_library, + ], + flag_groups = [flag_group(flags = ["-shared"])], + ), + ], + ) + + random_seed_feature = feature( + name = "random_seed", + enabled = True, + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.cpp_module_codegen, + ACTION_NAMES.cpp_module_compile, + ], + flag_groups = [ + flag_group( + flags = ["-frandom-seed=%{output_file}"], + expand_if_available = "output_file", + ), + ], + ), + ], + ) + + includes_feature = feature( + name = "includes", + enabled = True, + flag_sets = [ + flag_set( + actions = [ + 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_compile, + ACTION_NAMES.clif_match, + ACTION_NAMES.objc_compile, + ACTION_NAMES.objcpp_compile, + ], + flag_groups = [ + flag_group( + flags = ["-include", "%{includes}"], + iterate_over = "includes", + expand_if_available = "includes", + ), + ], + ), + ], + ) + + fdo_instrument_feature = feature( + name = "fdo_instrument", + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ] + all_link_actions + lto_index_actions, + flag_groups = [ + flag_group( + flags = [ + "-fprofile-generate=%{fdo_instrument_path}", + "-fno-data-sections", + ], + expand_if_available = "fdo_instrument_path", + ), + ], + ), + ], + provides = ["profile"], + ) + + cs_fdo_instrument_feature = feature( + name = "cs_fdo_instrument", + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.lto_backend, + ] + all_link_actions + lto_index_actions, + flag_groups = [ + flag_group( + flags = [ + "-fcs-profile-generate=%{cs_fdo_instrument_path}", + ], + expand_if_available = "cs_fdo_instrument_path", + ), + ], + ), + ], + provides = ["csprofile"], + ) + + include_paths_feature = feature( + name = "include_paths", + enabled = True, + flag_sets = [ + flag_set( + actions = [ + 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_compile, + ACTION_NAMES.clif_match, + ACTION_NAMES.objc_compile, + ACTION_NAMES.objcpp_compile, + ], + flag_groups = [ + flag_group( + flags = ["-iquote", "%{quote_include_paths}"], + iterate_over = "quote_include_paths", + ), + flag_group( + flags = ["-I%{include_paths}"], + iterate_over = "include_paths", + ), + flag_group( + flags = ["-isystem", "%{system_include_paths}"], + iterate_over = "system_include_paths", + ), + ], + ), + ], + ) + + symbol_counts_feature = feature( + name = "symbol_counts", + flag_sets = [ + flag_set( + actions = all_link_actions + lto_index_actions, + flag_groups = [ + flag_group( + flags = [ + "-Wl,--print-symbol-counts=%{symbol_counts_output}", + ], + expand_if_available = "symbol_counts_output", + ), + ], + ), + ], + ) + + llvm_coverage_map_format_feature = feature( + name = "llvm_coverage_map_format", + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.preprocess_assemble, + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.cpp_module_compile, + ACTION_NAMES.objc_compile, + ACTION_NAMES.objcpp_compile, + ], + flag_groups = [ + flag_group( + flags = [ + "-fprofile-instr-generate", + "-fcoverage-mapping", + ], + ), + ], + ), + flag_set( + actions = all_link_actions + lto_index_actions + [ + "objc-executable", + "objc++-executable", + ], + flag_groups = [ + flag_group(flags = ["-fprofile-instr-generate"]), + ], + ), + ], + requires = [feature_set(features = ["coverage"])], + provides = ["profile"], + ) + + strip_debug_symbols_feature = feature( + name = "strip_debug_symbols", + flag_sets = [ + flag_set( + actions = all_link_actions + lto_index_actions, + flag_groups = [ + flag_group( + flags = ["-Wl,-S"], + expand_if_available = "strip_debug_symbols", + ), + ], + ), + ], + ) + + build_interface_libraries_feature = feature( + name = "build_interface_libraries", + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.cpp_link_dynamic_library, + ACTION_NAMES.cpp_link_nodeps_dynamic_library, + ACTION_NAMES.lto_index_for_dynamic_library, + ACTION_NAMES.lto_index_for_nodeps_dynamic_library, + ], + flag_groups = [ + flag_group( + flags = [ + "%{generate_interface_library}", + "%{interface_library_builder_path}", + "%{interface_library_input_path}", + "%{interface_library_output_path}", + ], + expand_if_available = "generate_interface_library", + ), + ], + with_features = [ + with_feature_set( + features = ["supports_interface_shared_libraries"], + ), + ], + ), + ], + ) + + libraries_to_link_feature = feature( + name = "libraries_to_link", + flag_sets = [ + flag_set( + actions = all_link_actions + lto_index_actions, + flag_groups = [ + flag_group( + iterate_over = "libraries_to_link", + flag_groups = [ + flag_group( + flags = ["-Wl,--start-lib"], + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "object_file_group", + ), + ), + flag_group( + flags = ["-Wl,-whole-archive"], + expand_if_true = + "libraries_to_link.is_whole_archive", + ), + flag_group( + flags = ["%{libraries_to_link.object_files}"], + iterate_over = "libraries_to_link.object_files", + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "object_file_group", + ), + ), + flag_group( + flags = ["%{libraries_to_link.name}"], + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "object_file", + ), + ), + flag_group( + flags = ["%{libraries_to_link.name}"], + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "interface_library", + ), + ), + flag_group( + flags = ["%{libraries_to_link.name}"], + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "static_library", + ), + ), + flag_group( + flags = ["-l%{libraries_to_link.name}"], + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "dynamic_library", + ), + ), + flag_group( + flags = ["-l:%{libraries_to_link.name}"], + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "versioned_dynamic_library", + ), + ), + flag_group( + flags = ["-Wl,-no-whole-archive"], + expand_if_true = "libraries_to_link.is_whole_archive", + ), + flag_group( + flags = ["-Wl,--end-lib"], + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "object_file_group", + ), + ), + ], + expand_if_available = "libraries_to_link", + ), + flag_group( + flags = ["-Wl,@%{thinlto_param_file}"], + expand_if_true = "thinlto_param_file", + ), + ], + ), + ], + ) + + user_link_flags_feature = feature( + name = "user_link_flags", + flag_sets = [ + flag_set( + actions = all_link_actions + lto_index_actions, + flag_groups = [ + flag_group( + flags = ["%{user_link_flags}"], + iterate_over = "user_link_flags", + expand_if_available = "user_link_flags", + ), + ] + ([flag_group(flags = ctx.attr.link_libs)] if ctx.attr.link_libs else []), + ), + ], + ) + + fdo_prefetch_hints_feature = feature( + name = "fdo_prefetch_hints", + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.lto_backend, + ], + flag_groups = [ + flag_group( + flags = [ + "-Xclang-only=-mllvm", + "-Xclang-only=-prefetch-hints-file=%{fdo_prefetch_hints_path}", + ], + expand_if_available = "fdo_prefetch_hints_path", + ), + ], + ), + ], + ) + + linkstamps_feature = feature( + name = "linkstamps", + flag_sets = [ + flag_set( + actions = all_link_actions + lto_index_actions, + flag_groups = [ + flag_group( + flags = ["%{linkstamp_paths}"], + iterate_over = "linkstamp_paths", + expand_if_available = "linkstamp_paths", + ), + ], + ), + ], + ) + + gcc_coverage_map_format_feature = feature( + name = "gcc_coverage_map_format", + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.preprocess_assemble, + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.cpp_module_compile, + ACTION_NAMES.objc_compile, + ACTION_NAMES.objcpp_compile, + "objc-executable", + "objc++-executable", + ], + flag_groups = [ + flag_group( + flags = ["-fprofile-arcs", "-ftest-coverage"], + expand_if_available = "gcov_gcno_file", + ), + ], + ), + flag_set( + actions = all_link_actions + lto_index_actions, + flag_groups = [flag_group(flags = ["--coverage"])], + ), + ], + requires = [feature_set(features = ["coverage"])], + provides = ["profile"], + ) + + archiver_flags_feature = feature( + name = "archiver_flags", + flag_sets = [ + flag_set( + actions = [ACTION_NAMES.cpp_link_static_library], + flag_groups = [ + flag_group(flags = ["rcsD"]), + flag_group( + flags = ["%{output_execpath}"], + expand_if_available = "output_execpath", + ), + ], + ), + flag_set( + actions = [ACTION_NAMES.cpp_link_static_library], + flag_groups = [ + flag_group( + iterate_over = "libraries_to_link", + flag_groups = [ + flag_group( + flags = ["%{libraries_to_link.name}"], + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "object_file", + ), + ), + flag_group( + flags = ["%{libraries_to_link.object_files}"], + iterate_over = "libraries_to_link.object_files", + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "object_file_group", + ), + ), + ], + expand_if_available = "libraries_to_link", + ), + ], + ), + ], + ) + + force_pic_flags_feature = feature( + name = "force_pic_flags", + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.cpp_link_executable, + ACTION_NAMES.lto_index_for_executable, + ], + flag_groups = [ + flag_group( + flags = ["-pie"], + expand_if_available = "force_pic", + ), + ], + ), + ], + ) + + dependency_file_feature = feature( + name = "dependency_file", + enabled = True, + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.assemble, + ACTION_NAMES.preprocess_assemble, + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.cpp_module_compile, + ACTION_NAMES.objc_compile, + ACTION_NAMES.objcpp_compile, + ACTION_NAMES.cpp_header_parsing, + ACTION_NAMES.clif_match, + ], + flag_groups = [ + flag_group( + flags = ["-MD", "-MF", "%{dependency_file}"], + expand_if_available = "dependency_file", + ), + ], + ), + ], + ) + + dynamic_library_linker_tool_path = tool_paths + dynamic_library_linker_tool_feature = feature( + name = "dynamic_library_linker_tool", + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.cpp_link_dynamic_library, + ACTION_NAMES.cpp_link_nodeps_dynamic_library, + ACTION_NAMES.lto_index_for_dynamic_library, + ACTION_NAMES.lto_index_for_nodeps_dynamic_library, + ], + flag_groups = [ + flag_group( + flags = [" + cppLinkDynamicLibraryToolPath + "], + expand_if_available = "generate_interface_library", + ), + ], + with_features = [ + with_feature_set( + features = ["supports_interface_shared_libraries"], + ), + ], + ), + ], + ) + + output_execpath_flags_feature = feature( + name = "output_execpath_flags", + flag_sets = [ + flag_set( + actions = all_link_actions + lto_index_actions, + flag_groups = [ + flag_group( + flags = ["-o", "%{output_execpath}"], + expand_if_available = "output_execpath", + ), + ], + ), + ], + ) + + # Note that we also set --coverage for c++-link-nodeps-dynamic-library. The + # generated code contains references to gcov symbols, and the dynamic linker + # can't resolve them unless the library is linked against gcov. + coverage_feature = feature( + name = "coverage", + provides = ["profile"], + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.preprocess_assemble, + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.cpp_header_parsing, + ACTION_NAMES.cpp_module_compile, + ], + flag_groups = ([ + flag_group(flags = ctx.attr.coverage_compile_flags), + ] if ctx.attr.coverage_compile_flags else []), + ), + flag_set( + actions = all_link_actions + lto_index_actions, + flag_groups = ([ + flag_group(flags = ctx.attr.coverage_link_flags), + ] if ctx.attr.coverage_link_flags else []), + ), + ], + ) + + thinlto_feature = feature( + name = "thin_lto", + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ] + all_link_actions + lto_index_actions, + flag_groups = [ + flag_group(flags = ["-flto=thin"]), + flag_group( + expand_if_available = "lto_indexing_bitcode_file", + flags = [ + "-Xclang", + "-fthin-link-bitcode=%{lto_indexing_bitcode_file}", + ], + ), + ], + ), + flag_set( + actions = [ACTION_NAMES.linkstamp_compile], + flag_groups = [flag_group(flags = ["-DBUILD_LTO_TYPE=thin"])], + ), + flag_set( + actions = lto_index_actions, + flag_groups = [ + flag_group(flags = [ + "-flto=thin", + "-Wl,-plugin-opt,thinlto-index-only%{thinlto_optional_params_file}", + "-Wl,-plugin-opt,thinlto-emit-imports-files", + "-Wl,-plugin-opt,thinlto-prefix-replace=%{thinlto_prefix_replace}", + ]), + flag_group( + expand_if_available = "thinlto_object_suffix_replace", + flags = [ + "-Wl,-plugin-opt,thinlto-object-suffix-replace=%{thinlto_object_suffix_replace}", + ], + ), + flag_group( + expand_if_available = "thinlto_merged_object_file", + flags = [ + "-Wl,-plugin-opt,obj-path=%{thinlto_merged_object_file}", + ], + ), + ], + ), + flag_set( + actions = [ACTION_NAMES.lto_backend], + flag_groups = [ + flag_group(flags = [ + "-c", + "-fthinlto-index=%{thinlto_index}", + "-o", + "%{thinlto_output_object_file}", + "-x", + "ir", + "%{thinlto_input_bitcode_file}", + ]), + ], + ), + ], + ) + + is_linux = ctx.attr.target_libc != "macosx" + + # TODO(#8303): Mac crosstool should also declare every feature. + if is_linux: + features = [ + dependency_file_feature, + random_seed_feature, + pic_feature, + per_object_debug_info_feature, + preprocessor_defines_feature, + includes_feature, + include_paths_feature, + fdo_instrument_feature, + cs_fdo_instrument_feature, + cs_fdo_optimize_feature, + thinlto_feature, + fdo_prefetch_hints_feature, + autofdo_feature, + build_interface_libraries_feature, + dynamic_library_linker_tool_feature, + symbol_counts_feature, + shared_flag_feature, + linkstamps_feature, + output_execpath_flags_feature, + runtime_library_search_directories_feature, + library_search_directories_feature, + archiver_flags_feature, + force_pic_flags_feature, + fission_support_feature, + strip_debug_symbols_feature, + coverage_feature, + supports_pic_feature, + ] + ( + [ + supports_start_end_lib_feature, + ] if ctx.attr.supports_start_end_lib else [] + ) + [ + default_compile_flags_feature, + default_link_flags_feature, + libraries_to_link_feature, + user_link_flags_feature, + static_libgcc_feature, + fdo_optimize_feature, + supports_dynamic_linker_feature, + dbg_feature, + opt_feature, + user_compile_flags_feature, + sysroot_feature, + unfiltered_compile_flags_feature, + ] + else: + features = [ + supports_pic_feature, + ] + ( + [ + supports_start_end_lib_feature, + ] if ctx.attr.supports_start_end_lib else [] + ) + [ + coverage_feature, + default_compile_flags_feature, + default_link_flags_feature, + fdo_optimize_feature, + supports_dynamic_linker_feature, + dbg_feature, + opt_feature, + user_compile_flags_feature, + sysroot_feature, + unfiltered_compile_flags_feature, + ] + + return cc_common.create_cc_toolchain_config_info( + ctx = ctx, + features = features, + action_configs = action_configs, + cxx_builtin_include_directories = ctx.attr.cxx_builtin_include_directories, + toolchain_identifier = ctx.attr.toolchain_identifier, + host_system_name = ctx.attr.host_system_name, + target_system_name = ctx.attr.target_system_name, + target_cpu = ctx.attr.cpu, + target_libc = ctx.attr.target_libc, + compiler = ctx.attr.compiler, + abi_version = ctx.attr.abi_version, + abi_libc_version = ctx.attr.abi_libc_version, + tool_paths = tool_paths, + ) + +cc_toolchain_config = rule( + implementation = _impl, + attrs = { + "cpu": attr.string(mandatory = True), + "compiler": attr.string(mandatory = True), + "toolchain_identifier": attr.string(mandatory = True), + "host_system_name": attr.string(mandatory = True), + "target_system_name": attr.string(mandatory = True), + "target_libc": attr.string(mandatory = True), + "abi_version": attr.string(mandatory = True), + "abi_libc_version": attr.string(mandatory = True), + "cxx_builtin_include_directories": attr.string_list(), + "tool_paths": attr.string_dict(), + "compile_flags": attr.string_list(), + "dbg_compile_flags": attr.string_list(), + "opt_compile_flags": attr.string_list(), + "cxx_flags": attr.string_list(), + "link_flags": attr.string_list(), + "link_libs": attr.string_list(), + "opt_link_flags": attr.string_list(), + "unfiltered_compile_flags": attr.string_list(), + "coverage_compile_flags": attr.string_list(), + "coverage_link_flags": attr.string_list(), + "supports_start_end_lib": attr.bool(), + }, + provides = [CcToolchainConfigInfo], +) diff --git a/tools/cross-toolchain/configs/clang/bazel_2.1.1/cc/cc_wrapper.sh b/tools/cross-toolchain/configs/clang/bazel_2.1.1/cc/cc_wrapper.sh new file mode 100755 index 000000000..bfc4ce503 --- /dev/null +++ b/tools/cross-toolchain/configs/clang/bazel_2.1.1/cc/cc_wrapper.sh @@ -0,0 +1,25 @@ +#!/bin/bash +# +# Copyright 2015 The Bazel Authors. All rights reserved. +# +# 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. +# +# Ship the environment to the C++ action +# +set -eu + +# Set-up the environment + + +# Call the C++ compiler +/usr/bin/clang "$@" diff --git a/tools/cross-toolchain/configs/clang/bazel_2.1.1/config/BUILD b/tools/cross-toolchain/configs/clang/bazel_2.1.1/config/BUILD new file mode 100644 index 000000000..41d5d33f2 --- /dev/null +++ b/tools/cross-toolchain/configs/clang/bazel_2.1.1/config/BUILD @@ -0,0 +1,53 @@ +# Copyright 2016 The Bazel Authors. All rights reserved. +# +# 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. + +# This file is auto-generated by an rbe_autoconfig repository rule +# and should not be modified directly. +# See @bazel_toolchains//rules:rbe_repo.bzl + +package(default_visibility = ["//visibility:public"]) + +toolchain( + name = "cc-toolchain", + exec_compatible_with = [ + "@bazel_tools//platforms:x86_64", + "@bazel_tools//platforms:linux", + "@bazel_tools//tools/cpp:clang", + ], + target_compatible_with = [ + "@bazel_tools//platforms:linux", + "@bazel_tools//platforms:x86_64", + ], + toolchain = "//tools/cross-toolchain/configs/clang/bazel_2.1.1/cc:cc-compiler-k8", + toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", +) + +platform( + name = "platform", + constraint_values = [ + "@bazel_tools//platforms:x86_64", + "@bazel_tools//platforms:linux", + "@bazel_tools//tools/cpp:clang", + ], + remote_execution_properties = """ + properties: { + name: "container-image" + value:"docker://gcr.io/prysmaticlabs/rbe-worker@sha256:dd72753a00743d0010ebc9fbcc73061623adc863532b49bb994c6e5c70739e97" + } + properties { + name: "OSFamily" + value: "Linux" + } + """, +) diff --git a/tools/cross-toolchain/configs/clang/bazel_2.1.1/java/BUILD b/tools/cross-toolchain/configs/clang/bazel_2.1.1/java/BUILD new file mode 100644 index 000000000..7c273a5b0 --- /dev/null +++ b/tools/cross-toolchain/configs/clang/bazel_2.1.1/java/BUILD @@ -0,0 +1,25 @@ +# Copyright 2016 The Bazel Authors. All rights reserved. +# +# 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. + +# This file is auto-generated by an rbe_autoconfig repository rule +# and should not be modified directly. +# See @bazel_toolchains//rules:rbe_repo.bzl + +package(default_visibility = ["//visibility:public"]) + +java_runtime( + name = "jdk", + srcs = [], + java_home = "/usr/lib/jvm/java-8-openjdk-amd64", +) diff --git a/tools/cross-toolchain/configs/clang/bazel_2.1.1/prysm_toolchains/BUILD.bazel b/tools/cross-toolchain/configs/clang/bazel_2.1.1/prysm_toolchains/BUILD.bazel new file mode 100755 index 000000000..ba33afec8 --- /dev/null +++ b/tools/cross-toolchain/configs/clang/bazel_2.1.1/prysm_toolchains/BUILD.bazel @@ -0,0 +1,147 @@ +package(default_visibility = ["//visibility:public"]) + +load(":cc_toolchain_config_osx.bzl", "osx_cc_toolchain_config") +load(":cc_toolchain_config_linux_arm64.bzl", "arm64_cc_toolchain_config") +load(":cc_toolchain_config_windows.bzl", "windows_cc_toolchain_config") + +cc_toolchain_suite( + name = "multiarch_toolchain", + toolchains = { + "k8|osxcross": ":cc-clang-osx", + "k8|clang": "cc-clang-amd64", + "aarch64|clang": ":cc-clang-arm64", + "k8": "cc-clang-amd64", + "aarch64": ":cc-clang-arm64", + "k8|mingw-w64": ":cc-mingw-amd64", + }, +) + +cc_toolchain_suite( + name = "hostonly_toolchain", + toolchains = { + "k8": "cc-clang-amd64", + }, +) + +filegroup( + name = "empty", + srcs = [], +) + +config_setting( + name = "osx_amd64", + constraint_values = [ + "@platforms//os:osx", + "@platforms//cpu:x86_64", + ], +) + +config_setting( + name = "linux_arm64", + constraint_values = [ + "@platforms//os:linux", + "@platforms//cpu:aarch64", + ], +) + +config_setting( + name = "linux_amd64", + constraint_values = [ + "@platforms//os:linux", + "@platforms//cpu:x86_64", + ], +) + +config_setting( + name = "windows_amd64", + constraint_values = [ + "@platforms//os:windows", + "@platforms//cpu:x86_64", + ], +) + +arm64_cc_toolchain_config( + name = "local-arm64", + target = "aarch64-linux-gnu", +) + +arm64_cc_toolchain_config( + name = "local-amd64", + target = "x86_64-unknown-linux-gnu", +) + +osx_cc_toolchain_config( + name = "local-osxcross", + target = "darwin_x86_64", +) + +windows_cc_toolchain_config( + name = "local-windows", + target = "x86_64-w64", +) + +cc_toolchain( + name = "cc-mingw-amd64", + all_files = ":empty", + ar_files = ":empty", + as_files = ":mingw_compiler_files", + compiler_files = ":mingw_compiler_files", + dwp_files = ":empty", + linker_files = ":empty", + objcopy_files = ":empty", + strip_files = ":empty", + supports_param_files = 0, + toolchain_config = ":local-windows", +) + +cc_toolchain( + name = "cc-clang-arm64", + all_files = ":empty", + compiler_files = ":empty", + dwp_files = ":empty", + linker_files = ":empty", + objcopy_files = ":empty", + strip_files = ":empty", + supports_param_files = 1, + toolchain_config = ":local-arm64", +) + +cc_toolchain( + name = "cc-clang-osx", + all_files = ":empty", + compiler_files = ":empty", + dwp_files = ":empty", + linker_files = ":empty", + objcopy_files = ":empty", + strip_files = ":empty", + supports_param_files = 1, + toolchain_config = ":local-osxcross", +) + +cc_toolchain( + name = "cc-clang-amd64", + all_files = ":empty", + compiler_files = ":empty", + dwp_files = ":empty", + linker_files = ":empty", + objcopy_files = ":empty", + strip_files = ":empty", + supports_param_files = 1, + toolchain_config = ":local-amd64", +) + +toolchain( + name = "cc-toolchain-multiarch", + exec_compatible_with = [ + "@platforms//os:linux", + "@platforms//cpu:x86_64", + ], + target_compatible_with = [], + toolchain = select({ + ":linux_arm64": ":cc-clang-arm64", + ":linux_amd64": ":cc-clang-amd64", + ":osx_amd64": ":cc-clang-osx", + ":windows_amd64": ":cc-mingw-amd64", + }), + toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", +) diff --git a/tools/cross-toolchain/configs/clang/bazel_2.1.1/prysm_toolchains/WORKSPACE b/tools/cross-toolchain/configs/clang/bazel_2.1.1/prysm_toolchains/WORKSPACE new file mode 100644 index 000000000..34eee8288 --- /dev/null +++ b/tools/cross-toolchain/configs/clang/bazel_2.1.1/prysm_toolchains/WORKSPACE @@ -0,0 +1,2 @@ +# DO NOT EDIT: automatically generated WORKSPACE file for prysm_toolchains rule +workspace(name = "prysm_toolchains") diff --git a/tools/cross-toolchain/configs/clang/bazel_2.1.1/prysm_toolchains/cc_toolchain_config_linux_arm64.bzl b/tools/cross-toolchain/configs/clang/bazel_2.1.1/prysm_toolchains/cc_toolchain_config_linux_arm64.bzl new file mode 100755 index 000000000..5405f0bd4 --- /dev/null +++ b/tools/cross-toolchain/configs/clang/bazel_2.1.1/prysm_toolchains/cc_toolchain_config_linux_arm64.bzl @@ -0,0 +1,304 @@ +load( + "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", + "action_config", + "feature", + "feature_set", + "flag_group", + "flag_set", + "make_variable", + "tool", + "tool_path", + "with_feature_set", +) +load( + "@bazel_tools//tools/cpp:cc_toolchain_config.bzl", + ALL_COMPILE_ACTIONS = "all_compile_actions", + ALL_CPP_COMPILE_ACTIONS = "all_cpp_compile_actions", + ALL_LINK_ACTIONS = "all_link_actions", +) + +def _impl(ctx): + toolchain_identifier = "clang-linux-cross" + compiler = "clang" + abi_version = "clang" + abi_libc_version = "glibc_unknown" + target_libc = "glibc_unknown" + target_cpu = ctx.attr.target.split("-")[0] + + if (target_cpu == "aarch64"): + sysroot = "/usr/aarch64-linux-gnu" + include_path_prefix = sysroot + elif (target_cpu == "x86_64"): + sysroot = "/" + include_path_prefix = "/usr" + else: + fail("Unreachable") + + if (target_cpu == "aarch64"): + cross_system_include_dirs = [ + include_path_prefix + "/include/c++/v1", + include_path_prefix + "/lib/clang/10.0.0/include", + ] + else: + cross_system_include_dirs = [ + include_path_prefix + "/include/c++/v1", + include_path_prefix + "/lib/clang/10.0.0/include", + include_path_prefix + "/include/x86_64-linux-gnu", + ] + + cross_system_include_dirs += [ + include_path_prefix + "/include/", + include_path_prefix + "/include/linux", + include_path_prefix + "/include/asm", + include_path_prefix + "/include/asm-generic", + ] + + if (target_cpu == "aarch64"): + cross_system_lib_dirs = [ + "/usr/" + ctx.attr.target + "/lib", + ] + else: + cross_system_lib_dirs = [ + "/usr/lib/x86_64-linux-gnu/", + ] + + cross_system_lib_dirs += [ + "/usr/lib/gcc/x86_64-linux-gnu/8", + ] + + opt_feature = feature(name = "opt") + dbg_feature = feature(name = "dbg") + fastbuild_feature = feature(name = "fastbuild") + random_seed_feature = feature(name = "random_seed", enabled = True) + supports_pic_feature = feature(name = "supports_pic", enabled = True) + supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True) + + unfiltered_compile_flags_feature = feature( + name = "unfiltered_compile_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = ALL_COMPILE_ACTIONS, + flag_groups = [ + flag_group( + flags = [ + "-no-canonical-prefixes", + "-Wno-builtin-macro-redefined", + "-D__DATE__=\"redacted\"", + "-D__TIMESTAMP__=\"redacted\"", + "-D__TIME__=\"redacted\"", + ], + ), + ], + ), + ], + ) + + # explicit arch specific system includes + system_include_flags = [] + for d in cross_system_include_dirs: + system_include_flags += ["-idirafter", d] + + default_compile_flags_feature = feature( + name = "default_compile_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = ALL_COMPILE_ACTIONS, + flag_groups = [ + flag_group( + flags = [ + "--target=" + ctx.attr.target, + "-nostdinc", + "-U_FORTIFY_SOURCE", + "-fstack-protector", + "-fno-omit-frame-pointer", + "-fcolor-diagnostics", + "-Wall", + "-Wthread-safety", + "-Wself-assign", + ] + system_include_flags, + ), + ], + ), + flag_set( + actions = ALL_COMPILE_ACTIONS, + flag_groups = [flag_group(flags = ["-g", "-fstandalone-debug"])], + with_features = [with_feature_set(features = ["dbg"])], + ), + flag_set( + actions = ALL_COMPILE_ACTIONS, + flag_groups = [ + flag_group( + flags = [ + "-g0", + "-O2", + "-D_FORTIFY_SOURCE=1", + "-DNDEBUG", + "-ffunction-sections", + "-fdata-sections", + ], + ), + ], + with_features = [with_feature_set(features = ["opt"])], + ), + flag_set( + actions = ALL_CPP_COMPILE_ACTIONS, + flag_groups = [flag_group(flags = ["-std=c++17", "-nostdinc++"])], + ), + ], + ) + + additional_link_flags = [ + "-l:libc++.a", + "-l:libc++abi.a", + "-l:libunwind.a", + "-lpthread", + "-ldl", + "-rtlib=compiler-rt", + ] + + default_link_flags_feature = feature( + name = "default_link_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = ALL_LINK_ACTIONS, + flag_groups = [ + flag_group( + flags = additional_link_flags + [ + "--target=" + ctx.attr.target, + "-lm", + "-no-canonical-prefixes", + "-fuse-ld=lld", + "-Wl,--build-id=md5", + "-Wl,--hash-style=gnu", + "-Wl,-z,relro,-z,now", + ] + ["-L" + d for d in cross_system_lib_dirs], + ), + ], + ), + flag_set( + actions = ALL_LINK_ACTIONS, + flag_groups = [flag_group(flags = ["-Wl,--gc-sections"])], + with_features = [with_feature_set(features = ["opt"])], + ), + ], + ) + + objcopy_embed_flags_feature = feature( + name = "objcopy_embed_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = ["objcopy_embed_data"], + flag_groups = [flag_group(flags = ["-I", "binary"])], + ), + ], + ) + + user_compile_flags_feature = feature( + name = "user_compile_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = ALL_COMPILE_ACTIONS, + flag_groups = [ + flag_group( + expand_if_available = "user_compile_flags", + flags = ["%{user_compile_flags}"], + iterate_over = "user_compile_flags", + ), + ], + ), + ], + ) + + sysroot_feature = feature( + name = "sysroot", + enabled = True, + flag_sets = [ + flag_set( + actions = ALL_COMPILE_ACTIONS + ALL_LINK_ACTIONS, + flag_groups = [ + flag_group( + expand_if_available = "sysroot", + flags = ["--sysroot=%{sysroot}"], + ), + ], + ), + ], + ) + + coverage_feature = feature( + name = "coverage", + flag_sets = [ + flag_set( + actions = ALL_COMPILE_ACTIONS, + flag_groups = [ + flag_group( + flags = ["-fprofile-instr-generate", "-fcoverage-mapping"], + ), + ], + ), + flag_set( + actions = ALL_LINK_ACTIONS, + flag_groups = [flag_group(flags = ["-fprofile-instr-generate"])], + ), + ], + provides = ["profile"], + ) + + features = [ + opt_feature, + fastbuild_feature, + dbg_feature, + random_seed_feature, + supports_pic_feature, + supports_dynamic_linker_feature, + unfiltered_compile_flags_feature, + default_link_flags_feature, + default_compile_flags_feature, + objcopy_embed_flags_feature, + user_compile_flags_feature, + sysroot_feature, + coverage_feature, + ] + + tool_paths = [ + tool_path(name = "ld", path = "/usr/bin/ld.lld"), + 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/strip"), + tool_path(name = "gcc", path = "/usr/bin/clang"), + tool_path(name = "ar", path = "/usr/bin/llvm-ar"), + ] + + return cc_common.create_cc_toolchain_config_info( + ctx = ctx, + features = features, + abi_version = abi_version, + abi_libc_version = abi_libc_version, + builtin_sysroot = sysroot, + compiler = compiler, + cxx_builtin_include_directories = cross_system_include_dirs, + host_system_name = "x86_64-unknown-linux-gnu", + target_cpu = target_cpu, + target_libc = target_libc, + target_system_name = ctx.attr.target, + tool_paths = tool_paths, + toolchain_identifier = toolchain_identifier, + ) + +arm64_cc_toolchain_config = rule( + implementation = _impl, + attrs = { + "target": attr.string(mandatory = True), + "stdlib": attr.string(), + }, + provides = [CcToolchainConfigInfo], +) diff --git a/tools/cross-toolchain/configs/clang/bazel_2.1.1/prysm_toolchains/cc_toolchain_config_osx.bzl b/tools/cross-toolchain/configs/clang/bazel_2.1.1/prysm_toolchains/cc_toolchain_config_osx.bzl new file mode 100755 index 000000000..d1a027d80 --- /dev/null +++ b/tools/cross-toolchain/configs/clang/bazel_2.1.1/prysm_toolchains/cc_toolchain_config_osx.bzl @@ -0,0 +1,250 @@ +load( + "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", + "action_config", + "feature", + "feature_set", + "flag_group", + "flag_set", + "make_variable", + "tool", + "tool_path", + "with_feature_set", +) +load( + "@bazel_tools//tools/cpp:cc_toolchain_config.bzl", + ALL_COMPILE_ACTIONS = "all_compile_actions", + ALL_CPP_COMPILE_ACTIONS = "all_cpp_compile_actions", + ALL_LINK_ACTIONS = "all_link_actions", +) + +def _impl(ctx): + toolchain_identifier = "osxcross" + compiler = "clang" + abi_version = "darwin_x86_64" + abi_libc_version = "darwin_x86_64" + install = "/usr/x86_64-apple-darwin/" + clang_version = "10.0.0" + target_libc = "macosx" + target_cpu = "x86_64" + osxcross = install + "osxcross/" + osxcross_binprefix = osxcross + "bin/x86_64-apple-darwin14-" + sdkroot = osxcross + "SDK/MacOSX10.10.sdk/" + cross_system_include_dirs = [ + "/usr/lib/clang/10.0.0/include", + osxcross + "include", + sdkroot + "usr/include", + ] + cross_system_lib_dirs = [ + "/usr/x86_64-apple-darwin/lib", + sdkroot + "usr/lib", + osxcross + "/lib", + ] + + opt_feature = feature(name = "opt") + dbg_feature = feature(name = "dbg") + fastbuild_feature = feature(name = "fastbuild") + random_seed_feature = feature(name = "random_seed", enabled = True) + supports_pic_feature = feature(name = "supports_pic", enabled = True) + supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True) + + unfiltered_compile_flags_feature = feature( + name = "unfiltered_compile_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = ALL_COMPILE_ACTIONS, + flag_groups = [ + flag_group( + flags = [ + "-stdlib=libc++", + "-no-canonical-prefixes", + "-Wno-builtin-macro-redefined", + "-D__DATE__=\"redacted\"", + "-D__TIMESTAMP__=\"redacted\"", + "-D__TIME__=\"redacted\"", + ], + ), + ], + ), + ], + ) + + # explicit arch specific system includes + system_include_flags = [] + for d in cross_system_include_dirs: + system_include_flags += ["-idirafter", d] + + default_compile_flags_feature = feature( + name = "default_compile_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = ALL_COMPILE_ACTIONS, + flag_groups = [ + flag_group( + flags = [ + "-mlinker-version=400", + "-B " + osxcross + "bin", + "-nostdinc", + "-U_FORTIFY_SOURCE", + "-fstack-protector", + "-fno-omit-frame-pointer", + "-fcolor-diagnostics", + "-Wall", + "-Wthread-safety", + "-Wself-assign", + ] + system_include_flags, + ), + ], + ), + flag_set( + actions = ALL_COMPILE_ACTIONS, + flag_groups = [flag_group(flags = ["-g", "-fstandalone-debug"])], + with_features = [with_feature_set(features = ["dbg"])], + ), + flag_set( + actions = ALL_COMPILE_ACTIONS, + flag_groups = [ + flag_group( + flags = [ + "-g0", + "-O2", + "-D_FORTIFY_SOURCE=1", + "-DNDEBUG", + "-ffunction-sections", + "-fdata-sections", + ], + ), + ], + with_features = [with_feature_set(features = ["opt"])], + ), + flag_set( + actions = ALL_CPP_COMPILE_ACTIONS, + flag_groups = [flag_group(flags = ["-std=c++17", "-nostdinc++"])], + ), + ], + ) + + default_link_flags_feature = feature( + name = "default_link_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = ALL_LINK_ACTIONS, + flag_groups = [ + flag_group( + flags = [ + "-v", + "-lm", + "-no-canonical-prefixes", + "-fuse-ld=lld", + "-lc++", + "-lc++abi", + "-F" + sdkroot + "System/Library/Frameworks/", + "-L" + sdkroot + "usr/lib", + "-undefined", + "dynamic_lookup", + ], + ), + ], + ), + ], + ) + + objcopy_embed_flags_feature = feature( + name = "objcopy_embed_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = ["objcopy_embed_data"], + flag_groups = [flag_group(flags = ["-I", "binary"])], + ), + ], + ) + + user_compile_flags_feature = feature( + name = "user_compile_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = ALL_COMPILE_ACTIONS, + flag_groups = [ + flag_group( + expand_if_available = "user_compile_flags", + flags = ["%{user_compile_flags}"], + iterate_over = "user_compile_flags", + ), + ], + ), + ], + ) + + coverage_feature = feature( + name = "coverage", + flag_sets = [ + flag_set( + actions = ALL_COMPILE_ACTIONS, + flag_groups = [ + flag_group( + flags = ["-fprofile-instr-generate", "-fcoverage-mapping"], + ), + ], + ), + flag_set( + actions = ALL_LINK_ACTIONS, + flag_groups = [flag_group(flags = ["-fprofile-instr-generate"])], + ), + ], + provides = ["profile"], + ) + + features = [ + opt_feature, + fastbuild_feature, + dbg_feature, + random_seed_feature, + supports_pic_feature, + supports_dynamic_linker_feature, + unfiltered_compile_flags_feature, + default_link_flags_feature, + default_compile_flags_feature, + objcopy_embed_flags_feature, + user_compile_flags_feature, + coverage_feature, + ] + + tool_paths = [ + tool_path(name = "ld", path = osxcross_binprefix + "ld"), + tool_path(name = "cpp", path = osxcross + "bin/o64-clang++"), + tool_path(name = "dwp", path = "/usr/bin/dwp"), + tool_path(name = "gcov", path = "/usr/bin/gcov"), + tool_path(name = "nm", path = osxcross_binprefix + "nm"), + tool_path(name = "objdump", path = osxcross_binprefix + "ObjectDump"), + tool_path(name = "strip", path = osxcross_binprefix + "strip"), + tool_path(name = "gcc", path = osxcross + "bin/o64-clang"), + tool_path(name = "ar", path = osxcross_binprefix + "libtool"), + ] + + return cc_common.create_cc_toolchain_config_info( + ctx = ctx, + features = features, + abi_version = abi_version, + abi_libc_version = abi_libc_version, + compiler = compiler, + cxx_builtin_include_directories = cross_system_include_dirs, + host_system_name = "x86_64-unknown-linux-gnu", + target_cpu = target_cpu, + target_libc = target_libc, + target_system_name = ctx.attr.target, + tool_paths = tool_paths, + toolchain_identifier = toolchain_identifier, + ) + +osx_cc_toolchain_config = rule( + implementation = _impl, + attrs = { + "target": attr.string(mandatory = True), + "stdlib": attr.string(), + }, + provides = [CcToolchainConfigInfo], +) diff --git a/tools/cross-toolchain/configs/clang/bazel_2.1.1/prysm_toolchains/cc_toolchain_config_windows.bzl b/tools/cross-toolchain/configs/clang/bazel_2.1.1/prysm_toolchains/cc_toolchain_config_windows.bzl new file mode 100755 index 000000000..dce5d55ff --- /dev/null +++ b/tools/cross-toolchain/configs/clang/bazel_2.1.1/prysm_toolchains/cc_toolchain_config_windows.bzl @@ -0,0 +1,209 @@ +load( + "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", + "action_config", + "artifact_name_pattern", + "env_entry", + "env_set", + "feature", + "feature_set", + "flag_group", + "flag_set", + "make_variable", + "tool", + "tool_path", + "with_feature_set", +) +load( + "@bazel_tools//tools/cpp:cc_toolchain_config.bzl", + ALL_COMPILE_ACTIONS = "all_compile_actions", + ALL_CPP_COMPILE_ACTIONS = "all_cpp_compile_actions", + ALL_LINK_ACTIONS = "all_link_actions", +) +load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES") + +def _impl(ctx): + toolchain_identifier = "msys_x64_mingw" + host_system_name = "local" + target_system_name = "local" + target_cpu = "x64_windows" + target_libc = "mingw" + compiler = "mingw-gcc" + abi_version = "local" + abi_libc_version = "local" + cc_target_os = None + builtin_sysroot = None + action_configs = [] + + install = "/usr/x86_64-w64-mingw32/" + bin_prefix = "/usr/bin/x86_64-w64-mingw32-" + + targets_windows_feature = feature( + name = "targets_windows", + implies = ["copy_dynamic_libraries_to_binary"], + enabled = True, + ) + + copy_dynamic_libraries_to_binary_feature = feature(name = "copy_dynamic_libraries_to_binary") + + gcc_env_feature = feature( + name = "gcc_env", + enabled = True, + env_sets = [ + env_set( + actions = [ + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.cpp_module_compile, + ACTION_NAMES.cpp_module_codegen, + ACTION_NAMES.cpp_header_parsing, + ACTION_NAMES.assemble, + ACTION_NAMES.preprocess_assemble, + ACTION_NAMES.cpp_link_executable, + ACTION_NAMES.cpp_link_dynamic_library, + ACTION_NAMES.cpp_link_nodeps_dynamic_library, + ACTION_NAMES.cpp_link_static_library, + ], + env_entries = [ + env_entry(key = "PATH", value = "NOT_USED"), + ], + ), + ], + ) + + msys_mingw_flags = [ + "-B " + install + "bin", + "-nostdinc", + "-U_FORTIFY_SOURCE", + "-fstack-protector", + "-fno-omit-frame-pointer", + "-fcolor-diagnostics", + "-Wall", + "-Wthread-safety", + "-Wself-assign", + "-x c++", + "-lstdc++", + "-lpthread", + ] + + msys_mingw_link_flags = [ + "-l:libstdc++.a", + "-L" + install + "lib", + "-L/usr/lib/gcc/x86_64-w64-mingw32/8.3-w32", + "-v", + "-lm", + "-no-canonical-prefixes", + ] + + default_compile_flags_feature = feature( + name = "default_compile_flags", + enabled = True, + flag_sets = [ + flag_set( + 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_compile, + ACTION_NAMES.cpp_module_codegen, + ACTION_NAMES.lto_backend, + ACTION_NAMES.clif_match, + ], + ), + flag_set( + actions = [ + ACTION_NAMES.linkstamp_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.cpp_header_parsing, + ACTION_NAMES.cpp_module_compile, + ACTION_NAMES.cpp_module_codegen, + ACTION_NAMES.lto_backend, + ACTION_NAMES.clif_match, + ], + flag_groups = ([flag_group(flags = msys_mingw_flags)] if msys_mingw_flags else []), + ), + ], + ) + + compiler_param_file_feature = feature( + name = "compiler_param_file", + ) + + default_link_flags_feature = feature( + name = "default_link_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = ALL_LINK_ACTIONS, + flag_groups = ([flag_group(flags = msys_mingw_link_flags)] if msys_mingw_link_flags else []), + ), + ], + ) + + supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True) + + features = [ + targets_windows_feature, + copy_dynamic_libraries_to_binary_feature, + gcc_env_feature, + default_compile_flags_feature, + compiler_param_file_feature, + default_link_flags_feature, + supports_dynamic_linker_feature, + ] + + cxx_builtin_include_directories = [ + install + "include", + ] + + artifact_name_patterns = [ + artifact_name_pattern( + category_name = "executable", + prefix = "", + extension = ".exe", + ), + ] + + make_variables = [] + tool_paths = [ + tool_path(name = "ld", path = bin_prefix + "ld"), + tool_path(name = "cpp", path = bin_prefix + "cpp"), + tool_path(name = "gcov", path = "/usr/bin/gcov"), + tool_path(name = "nm", path = bin_prefix + "nm"), + tool_path(name = "objcopy", path = bin_prefix + "objcopy"), + tool_path(name = "objdump", path = bin_prefix + "objdump"), + tool_path(name = "strip", path = bin_prefix + "strip"), + tool_path(name = "gcc", path = bin_prefix + "gcc"), + tool_path(name = "ar", path = bin_prefix + "ar"), + ] + + return cc_common.create_cc_toolchain_config_info( + ctx = ctx, + features = features, + action_configs = action_configs, + artifact_name_patterns = artifact_name_patterns, + cxx_builtin_include_directories = cxx_builtin_include_directories, + toolchain_identifier = toolchain_identifier, + host_system_name = host_system_name, + target_system_name = target_system_name, + target_cpu = target_cpu, + target_libc = target_libc, + compiler = compiler, + abi_version = abi_version, + abi_libc_version = abi_libc_version, + tool_paths = tool_paths, + make_variables = make_variables, + builtin_sysroot = builtin_sysroot, + cc_target_os = cc_target_os, + ) + +windows_cc_toolchain_config = rule( + implementation = _impl, + attrs = { + "target": attr.string(mandatory = True), + "stdlib": attr.string(), + }, + provides = [CcToolchainConfigInfo], +) diff --git a/tools/cross-toolchain/configs/gcc/bazel_2.1.1/cc/BUILD b/tools/cross-toolchain/configs/gcc/bazel_2.1.1/cc/BUILD new file mode 100755 index 000000000..269b27b69 --- /dev/null +++ b/tools/cross-toolchain/configs/gcc/bazel_2.1.1/cc/BUILD @@ -0,0 +1,164 @@ +# Copyright 2016 The Bazel Authors. All rights reserved. +# +# 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. + +# This becomes the BUILD file for @local_config_cc// under non-FreeBSD unixes. + +package(default_visibility = ["//visibility:public"]) + +load(":cc_toolchain_config.bzl", "cc_toolchain_config") +load(":armeabi_cc_toolchain_config.bzl", "armeabi_cc_toolchain_config") +load("@rules_cc//cc:defs.bzl", "cc_toolchain", "cc_toolchain_suite") + +licenses(["notice"]) # Apache 2.0 + +cc_library( + name = "malloc", +) + +filegroup( + name = "empty", + srcs = [], +) + +filegroup( + name = "cc_wrapper", + srcs = ["cc_wrapper.sh"], +) + +filegroup( + name = "compiler_deps", + srcs = glob( + ["extra_tools/**"], + allow_empty = True, + ) + [":builtin_include_directory_paths"], +) + +# This is the entry point for --crosstool_top. Toolchains are found +# by lopping off the name of --crosstool_top and searching for +# the "${CPU}" entry in the toolchains attribute. +cc_toolchain_suite( + name = "toolchain", + toolchains = { + "k8|gcc": ":cc-compiler-k8", + "k8": ":cc-compiler-k8", + "armeabi-v7a|compiler": ":cc-compiler-armeabi-v7a", + "armeabi-v7a": ":cc-compiler-armeabi-v7a", + }, +) + +cc_toolchain( + name = "cc-compiler-k8", + all_files = ":compiler_deps", + ar_files = ":compiler_deps", + as_files = ":compiler_deps", + compiler_files = ":compiler_deps", + dwp_files = ":empty", + linker_files = ":compiler_deps", + objcopy_files = ":empty", + strip_files = ":empty", + supports_param_files = 1, + toolchain_config = ":local", + toolchain_identifier = "local", +) + +cc_toolchain_config( + name = "local", + abi_libc_version = "local", + abi_version = "local", + compile_flags = [ + "-U_FORTIFY_SOURCE", + "-fstack-protector", + "-Wall", + "-Wunused-but-set-parameter", + "-Wno-free-nonheap-object", + "-fno-omit-frame-pointer", + ], + compiler = "gcc", + coverage_compile_flags = ["--coverage"], + coverage_link_flags = ["--coverage"], + cpu = "k8", + cxx_builtin_include_directories = [ + "/usr/lib/gcc/x86_64-linux-gnu/8/include", + "/usr/local/include", + "/usr/lib/gcc/x86_64-linux-gnu/8/include-fixed", + "/usr/include/x86_64-linux-gnu", + "/usr/include", + "/usr/include/c++/8", + "/usr/include/x86_64-linux-gnu/c++/8", + "/usr/include/c++/8/backward", + ], + cxx_flags = ["-std=c++0x"], + dbg_compile_flags = ["-g"], + host_system_name = "local", + link_flags = [ + "-fuse-ld=gold", + "-Wl,-no-as-needed", + "-Wl,-z,relro,-z,now", + "-B/usr/bin", + "-pass-exit-codes", + "-lm", + "-static-libgcc", + ], + link_libs = ["-l:libstdc++.a"], + opt_compile_flags = [ + "-g0", + "-O2", + "-D_FORTIFY_SOURCE=1", + "-DNDEBUG", + "-ffunction-sections", + "-fdata-sections", + ], + opt_link_flags = ["-Wl,--gc-sections"], + supports_start_end_lib = True, + target_libc = "local", + target_system_name = "local", + tool_paths = { + "ar": "/usr/bin/ar", + "ld": "/usr/bin/ld", + "cpp": "/usr/bin/cpp", + "gcc": "/usr/bin/gcc", + "dwp": "/usr/bin/dwp", + "gcov": "/usr/bin/gcov", + "nm": "/usr/bin/nm", + "objcopy": "/usr/bin/objcopy", + "objdump": "/usr/bin/objdump", + "strip": "/usr/bin/strip", + }, + toolchain_identifier = "local", + unfiltered_compile_flags = [ + "-fno-canonical-system-headers", + "-Wno-builtin-macro-redefined", + "-D__DATE__=\"redacted\"", + "-D__TIMESTAMP__=\"redacted\"", + "-D__TIME__=\"redacted\"", + ], +) + +# Android tooling requires a default toolchain for the armeabi-v7a cpu. +cc_toolchain( + name = "cc-compiler-armeabi-v7a", + all_files = ":empty", + ar_files = ":empty", + as_files = ":empty", + compiler_files = ":empty", + dwp_files = ":empty", + linker_files = ":empty", + objcopy_files = ":empty", + strip_files = ":empty", + supports_param_files = 1, + toolchain_config = ":stub_armeabi-v7a", + toolchain_identifier = "stub_armeabi-v7a", +) + +armeabi_cc_toolchain_config(name = "stub_armeabi-v7a") diff --git a/tools/cross-toolchain/configs/gcc/bazel_2.1.1/cc/armeabi_cc_toolchain_config.bzl b/tools/cross-toolchain/configs/gcc/bazel_2.1.1/cc/armeabi_cc_toolchain_config.bzl new file mode 100755 index 000000000..94e0720bf --- /dev/null +++ b/tools/cross-toolchain/configs/gcc/bazel_2.1.1/cc/armeabi_cc_toolchain_config.bzl @@ -0,0 +1,82 @@ +# Copyright 2019 The Bazel Authors. All rights reserved. +# +# 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. + +"""A Starlark cc_toolchain configuration rule""" + +load( + "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", + "feature", + "tool_path", +) + +def _impl(ctx): + toolchain_identifier = "stub_armeabi-v7a" + host_system_name = "armeabi-v7a" + target_system_name = "armeabi-v7a" + target_cpu = "armeabi-v7a" + target_libc = "armeabi-v7a" + compiler = "compiler" + abi_version = "armeabi-v7a" + abi_libc_version = "armeabi-v7a" + cc_target_os = None + builtin_sysroot = None + action_configs = [] + + supports_pic_feature = feature(name = "supports_pic", enabled = True) + supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True) + features = [supports_dynamic_linker_feature, supports_pic_feature] + + cxx_builtin_include_directories = [] + artifact_name_patterns = [] + make_variables = [] + + tool_paths = [ + tool_path(name = "ar", path = "/bin/false"), + tool_path(name = "compat-ld", path = "/bin/false"), + tool_path(name = "cpp", path = "/bin/false"), + tool_path(name = "dwp", path = "/bin/false"), + tool_path(name = "gcc", path = "/bin/false"), + tool_path(name = "gcov", path = "/bin/false"), + tool_path(name = "ld", path = "/bin/false"), + tool_path(name = "nm", path = "/bin/false"), + tool_path(name = "objcopy", path = "/bin/false"), + tool_path(name = "objdump", path = "/bin/false"), + tool_path(name = "strip", path = "/bin/false"), + ] + + return cc_common.create_cc_toolchain_config_info( + ctx = ctx, + features = features, + action_configs = action_configs, + artifact_name_patterns = artifact_name_patterns, + cxx_builtin_include_directories = cxx_builtin_include_directories, + toolchain_identifier = toolchain_identifier, + host_system_name = host_system_name, + target_system_name = target_system_name, + target_cpu = target_cpu, + target_libc = target_libc, + compiler = compiler, + abi_version = abi_version, + abi_libc_version = abi_libc_version, + tool_paths = tool_paths, + make_variables = make_variables, + builtin_sysroot = builtin_sysroot, + cc_target_os = cc_target_os, + ) + +armeabi_cc_toolchain_config = rule( + implementation = _impl, + attrs = {}, + provides = [CcToolchainConfigInfo], +) diff --git a/tools/cross-toolchain/configs/gcc/bazel_2.1.1/cc/builtin_include_directory_paths b/tools/cross-toolchain/configs/gcc/bazel_2.1.1/cc/builtin_include_directory_paths new file mode 100755 index 000000000..f15865c23 --- /dev/null +++ b/tools/cross-toolchain/configs/gcc/bazel_2.1.1/cc/builtin_include_directory_paths @@ -0,0 +1,14 @@ +This file is generated by cc_configure and contains builtin include directories +that /usr/bin/gcc reported. This file is a dependency of every compilation action and +changes to it will be reflected in the action cache key. When some of these +paths change, Bazel will make sure to rerun the action, even though none of +declared action inputs or the action commandline changes. + +/usr/lib/gcc/x86_64-linux-gnu/8/include +/usr/local/include +/usr/lib/gcc/x86_64-linux-gnu/8/include-fixed +/usr/include/x86_64-linux-gnu +/usr/include +/usr/include/c++/8 +/usr/include/x86_64-linux-gnu/c++/8 +/usr/include/c++/8/backward diff --git a/tools/cross-toolchain/configs/gcc/bazel_2.1.1/cc/cc_toolchain_config.bzl b/tools/cross-toolchain/configs/gcc/bazel_2.1.1/cc/cc_toolchain_config.bzl new file mode 100755 index 000000000..c5fd79eae --- /dev/null +++ b/tools/cross-toolchain/configs/gcc/bazel_2.1.1/cc/cc_toolchain_config.bzl @@ -0,0 +1,1197 @@ +# Copyright 2019 The Bazel Authors. All rights reserved. +# +# 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. + +"""A Starlark cc_toolchain configuration rule""" + +load( + "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", + "feature", + "feature_set", + "flag_group", + "flag_set", + "tool_path", + "variable_with_value", + "with_feature_set", +) +load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES") + +all_compile_actions = [ + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.linkstamp_compile, + ACTION_NAMES.assemble, + ACTION_NAMES.preprocess_assemble, + ACTION_NAMES.cpp_header_parsing, + ACTION_NAMES.cpp_module_compile, + ACTION_NAMES.cpp_module_codegen, + ACTION_NAMES.clif_match, + ACTION_NAMES.lto_backend, +] + +all_cpp_compile_actions = [ + ACTION_NAMES.cpp_compile, + ACTION_NAMES.linkstamp_compile, + ACTION_NAMES.cpp_header_parsing, + ACTION_NAMES.cpp_module_compile, + ACTION_NAMES.cpp_module_codegen, + ACTION_NAMES.clif_match, +] + +preprocessor_compile_actions = [ + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.linkstamp_compile, + ACTION_NAMES.preprocess_assemble, + ACTION_NAMES.cpp_header_parsing, + ACTION_NAMES.cpp_module_compile, + ACTION_NAMES.clif_match, +] + +codegen_compile_actions = [ + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.linkstamp_compile, + ACTION_NAMES.assemble, + ACTION_NAMES.preprocess_assemble, + ACTION_NAMES.cpp_module_codegen, + ACTION_NAMES.lto_backend, +] + +all_link_actions = [ + ACTION_NAMES.cpp_link_executable, + ACTION_NAMES.cpp_link_dynamic_library, + ACTION_NAMES.cpp_link_nodeps_dynamic_library, +] + +lto_index_actions = [ + ACTION_NAMES.lto_index_for_executable, + ACTION_NAMES.lto_index_for_dynamic_library, + ACTION_NAMES.lto_index_for_nodeps_dynamic_library, +] + +def _impl(ctx): + tool_paths = [ + tool_path(name = name, path = path) + for name, path in ctx.attr.tool_paths.items() + ] + action_configs = [] + + supports_pic_feature = feature( + name = "supports_pic", + enabled = True, + ) + supports_start_end_lib_feature = feature( + name = "supports_start_end_lib", + enabled = True, + ) + + default_compile_flags_feature = feature( + name = "default_compile_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = all_compile_actions, + flag_groups = ([ + flag_group( + flags = ctx.attr.compile_flags, + ), + ] if ctx.attr.compile_flags else []), + ), + flag_set( + actions = all_compile_actions, + flag_groups = ([ + flag_group( + flags = ctx.attr.dbg_compile_flags, + ), + ] if ctx.attr.dbg_compile_flags else []), + with_features = [with_feature_set(features = ["dbg"])], + ), + flag_set( + actions = all_compile_actions, + flag_groups = ([ + flag_group( + flags = ctx.attr.opt_compile_flags, + ), + ] if ctx.attr.opt_compile_flags else []), + with_features = [with_feature_set(features = ["opt"])], + ), + flag_set( + actions = all_cpp_compile_actions + [ACTION_NAMES.lto_backend], + flag_groups = ([ + flag_group( + flags = ctx.attr.cxx_flags, + ), + ] if ctx.attr.cxx_flags else []), + ), + ], + ) + + default_link_flags_feature = feature( + name = "default_link_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = all_link_actions + lto_index_actions, + flag_groups = ([ + flag_group( + flags = ctx.attr.link_flags, + ), + ] if ctx.attr.link_flags else []), + ), + flag_set( + actions = all_link_actions + lto_index_actions, + flag_groups = ([ + flag_group( + flags = ctx.attr.opt_link_flags, + ), + ] if ctx.attr.opt_link_flags else []), + with_features = [with_feature_set(features = ["opt"])], + ), + ], + ) + + dbg_feature = feature(name = "dbg") + + opt_feature = feature(name = "opt") + + sysroot_feature = feature( + name = "sysroot", + enabled = True, + flag_sets = [ + flag_set( + actions = [ + 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_compile, + ACTION_NAMES.cpp_module_codegen, + ACTION_NAMES.lto_backend, + ACTION_NAMES.clif_match, + ] + all_link_actions + lto_index_actions, + flag_groups = [ + flag_group( + flags = ["--sysroot=%{sysroot}"], + expand_if_available = "sysroot", + ), + ], + ), + ], + ) + + fdo_optimize_feature = feature( + name = "fdo_optimize", + flag_sets = [ + flag_set( + actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], + flag_groups = [ + flag_group( + flags = [ + "-fprofile-use=%{fdo_profile_path}", + "-fprofile-correction", + ], + expand_if_available = "fdo_profile_path", + ), + ], + ), + ], + provides = ["profile"], + ) + + supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True) + + user_compile_flags_feature = feature( + name = "user_compile_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = all_compile_actions, + flag_groups = [ + flag_group( + flags = ["%{user_compile_flags}"], + iterate_over = "user_compile_flags", + expand_if_available = "user_compile_flags", + ), + ], + ), + ], + ) + + unfiltered_compile_flags_feature = feature( + name = "unfiltered_compile_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = all_compile_actions, + flag_groups = ([ + flag_group( + flags = ctx.attr.unfiltered_compile_flags, + ), + ] if ctx.attr.unfiltered_compile_flags else []), + ), + ], + ) + + library_search_directories_feature = feature( + name = "library_search_directories", + flag_sets = [ + flag_set( + actions = all_link_actions + lto_index_actions, + flag_groups = [ + flag_group( + flags = ["-L%{library_search_directories}"], + iterate_over = "library_search_directories", + expand_if_available = "library_search_directories", + ), + ], + ), + ], + ) + + static_libgcc_feature = feature( + name = "static_libgcc", + enabled = True, + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.cpp_link_executable, + ACTION_NAMES.cpp_link_dynamic_library, + ACTION_NAMES.lto_index_for_executable, + ACTION_NAMES.lto_index_for_dynamic_library, + ], + flag_groups = [flag_group(flags = ["-static-libgcc"])], + with_features = [ + with_feature_set(features = ["static_link_cpp_runtimes"]), + ], + ), + ], + ) + + pic_feature = feature( + name = "pic", + enabled = True, + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.assemble, + ACTION_NAMES.preprocess_assemble, + ACTION_NAMES.linkstamp_compile, + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.cpp_module_codegen, + ACTION_NAMES.cpp_module_compile, + ], + flag_groups = [ + flag_group(flags = ["-fPIC"], expand_if_available = "pic"), + ], + ), + ], + ) + + per_object_debug_info_feature = feature( + name = "per_object_debug_info", + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.assemble, + ACTION_NAMES.preprocess_assemble, + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.cpp_module_codegen, + ], + flag_groups = [ + flag_group( + flags = ["-gsplit-dwarf"], + expand_if_available = "per_object_debug_info_file", + ), + ], + ), + ], + ) + + preprocessor_defines_feature = feature( + name = "preprocessor_defines", + enabled = True, + flag_sets = [ + flag_set( + actions = [ + 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_compile, + ACTION_NAMES.clif_match, + ], + flag_groups = [ + flag_group( + flags = ["-D%{preprocessor_defines}"], + iterate_over = "preprocessor_defines", + ), + ], + ), + ], + ) + + cs_fdo_optimize_feature = feature( + name = "cs_fdo_optimize", + flag_sets = [ + flag_set( + actions = [ACTION_NAMES.lto_backend], + flag_groups = [ + flag_group( + flags = [ + "-fprofile-use=%{fdo_profile_path}", + "-Xclang-only=-Wno-profile-instr-unprofiled", + "-Xclang-only=-Wno-profile-instr-out-of-date", + "-fprofile-correction", + ], + expand_if_available = "fdo_profile_path", + ), + ], + ), + ], + provides = ["csprofile"], + ) + + autofdo_feature = feature( + name = "autofdo", + flag_sets = [ + flag_set( + actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], + flag_groups = [ + flag_group( + flags = [ + "-fauto-profile=%{fdo_profile_path}", + "-fprofile-correction", + ], + expand_if_available = "fdo_profile_path", + ), + ], + ), + ], + provides = ["profile"], + ) + + runtime_library_search_directories_feature = feature( + name = "runtime_library_search_directories", + flag_sets = [ + flag_set( + actions = all_link_actions + lto_index_actions, + flag_groups = [ + flag_group( + iterate_over = "runtime_library_search_directories", + flag_groups = [ + flag_group( + flags = [ + "-Wl,-rpath,$EXEC_ORIGIN/%{runtime_library_search_directories}", + ], + expand_if_true = "is_cc_test", + ), + flag_group( + flags = [ + "-Wl,-rpath,$ORIGIN/%{runtime_library_search_directories}", + ], + expand_if_false = "is_cc_test", + ), + ], + expand_if_available = + "runtime_library_search_directories", + ), + ], + with_features = [ + with_feature_set(features = ["static_link_cpp_runtimes"]), + ], + ), + flag_set( + actions = all_link_actions + lto_index_actions, + flag_groups = [ + flag_group( + iterate_over = "runtime_library_search_directories", + flag_groups = [ + flag_group( + flags = [ + "-Wl,-rpath,$ORIGIN/%{runtime_library_search_directories}", + ], + ), + ], + expand_if_available = + "runtime_library_search_directories", + ), + ], + with_features = [ + with_feature_set( + not_features = ["static_link_cpp_runtimes"], + ), + ], + ), + ], + ) + + fission_support_feature = feature( + name = "fission_support", + flag_sets = [ + flag_set( + actions = all_link_actions + lto_index_actions, + flag_groups = [ + flag_group( + flags = ["-Wl,--gdb-index"], + expand_if_available = "is_using_fission", + ), + ], + ), + ], + ) + + shared_flag_feature = feature( + name = "shared_flag", + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.cpp_link_dynamic_library, + ACTION_NAMES.cpp_link_nodeps_dynamic_library, + ACTION_NAMES.lto_index_for_dynamic_library, + ACTION_NAMES.lto_index_for_nodeps_dynamic_library, + ], + flag_groups = [flag_group(flags = ["-shared"])], + ), + ], + ) + + random_seed_feature = feature( + name = "random_seed", + enabled = True, + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.cpp_module_codegen, + ACTION_NAMES.cpp_module_compile, + ], + flag_groups = [ + flag_group( + flags = ["-frandom-seed=%{output_file}"], + expand_if_available = "output_file", + ), + ], + ), + ], + ) + + includes_feature = feature( + name = "includes", + enabled = True, + flag_sets = [ + flag_set( + actions = [ + 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_compile, + ACTION_NAMES.clif_match, + ACTION_NAMES.objc_compile, + ACTION_NAMES.objcpp_compile, + ], + flag_groups = [ + flag_group( + flags = ["-include", "%{includes}"], + iterate_over = "includes", + expand_if_available = "includes", + ), + ], + ), + ], + ) + + fdo_instrument_feature = feature( + name = "fdo_instrument", + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ] + all_link_actions + lto_index_actions, + flag_groups = [ + flag_group( + flags = [ + "-fprofile-generate=%{fdo_instrument_path}", + "-fno-data-sections", + ], + expand_if_available = "fdo_instrument_path", + ), + ], + ), + ], + provides = ["profile"], + ) + + cs_fdo_instrument_feature = feature( + name = "cs_fdo_instrument", + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.lto_backend, + ] + all_link_actions + lto_index_actions, + flag_groups = [ + flag_group( + flags = [ + "-fcs-profile-generate=%{cs_fdo_instrument_path}", + ], + expand_if_available = "cs_fdo_instrument_path", + ), + ], + ), + ], + provides = ["csprofile"], + ) + + include_paths_feature = feature( + name = "include_paths", + enabled = True, + flag_sets = [ + flag_set( + actions = [ + 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_compile, + ACTION_NAMES.clif_match, + ACTION_NAMES.objc_compile, + ACTION_NAMES.objcpp_compile, + ], + flag_groups = [ + flag_group( + flags = ["-iquote", "%{quote_include_paths}"], + iterate_over = "quote_include_paths", + ), + flag_group( + flags = ["-I%{include_paths}"], + iterate_over = "include_paths", + ), + flag_group( + flags = ["-isystem", "%{system_include_paths}"], + iterate_over = "system_include_paths", + ), + ], + ), + ], + ) + + symbol_counts_feature = feature( + name = "symbol_counts", + flag_sets = [ + flag_set( + actions = all_link_actions + lto_index_actions, + flag_groups = [ + flag_group( + flags = [ + "-Wl,--print-symbol-counts=%{symbol_counts_output}", + ], + expand_if_available = "symbol_counts_output", + ), + ], + ), + ], + ) + + llvm_coverage_map_format_feature = feature( + name = "llvm_coverage_map_format", + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.preprocess_assemble, + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.cpp_module_compile, + ACTION_NAMES.objc_compile, + ACTION_NAMES.objcpp_compile, + ], + flag_groups = [ + flag_group( + flags = [ + "-fprofile-instr-generate", + "-fcoverage-mapping", + ], + ), + ], + ), + flag_set( + actions = all_link_actions + lto_index_actions + [ + "objc-executable", + "objc++-executable", + ], + flag_groups = [ + flag_group(flags = ["-fprofile-instr-generate"]), + ], + ), + ], + requires = [feature_set(features = ["coverage"])], + provides = ["profile"], + ) + + strip_debug_symbols_feature = feature( + name = "strip_debug_symbols", + flag_sets = [ + flag_set( + actions = all_link_actions + lto_index_actions, + flag_groups = [ + flag_group( + flags = ["-Wl,-S"], + expand_if_available = "strip_debug_symbols", + ), + ], + ), + ], + ) + + build_interface_libraries_feature = feature( + name = "build_interface_libraries", + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.cpp_link_dynamic_library, + ACTION_NAMES.cpp_link_nodeps_dynamic_library, + ACTION_NAMES.lto_index_for_dynamic_library, + ACTION_NAMES.lto_index_for_nodeps_dynamic_library, + ], + flag_groups = [ + flag_group( + flags = [ + "%{generate_interface_library}", + "%{interface_library_builder_path}", + "%{interface_library_input_path}", + "%{interface_library_output_path}", + ], + expand_if_available = "generate_interface_library", + ), + ], + with_features = [ + with_feature_set( + features = ["supports_interface_shared_libraries"], + ), + ], + ), + ], + ) + + libraries_to_link_feature = feature( + name = "libraries_to_link", + flag_sets = [ + flag_set( + actions = all_link_actions + lto_index_actions, + flag_groups = [ + flag_group( + iterate_over = "libraries_to_link", + flag_groups = [ + flag_group( + flags = ["-Wl,--start-lib"], + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "object_file_group", + ), + ), + flag_group( + flags = ["-Wl,-whole-archive"], + expand_if_true = + "libraries_to_link.is_whole_archive", + ), + flag_group( + flags = ["%{libraries_to_link.object_files}"], + iterate_over = "libraries_to_link.object_files", + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "object_file_group", + ), + ), + flag_group( + flags = ["%{libraries_to_link.name}"], + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "object_file", + ), + ), + flag_group( + flags = ["%{libraries_to_link.name}"], + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "interface_library", + ), + ), + flag_group( + flags = ["%{libraries_to_link.name}"], + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "static_library", + ), + ), + flag_group( + flags = ["-l%{libraries_to_link.name}"], + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "dynamic_library", + ), + ), + flag_group( + flags = ["-l:%{libraries_to_link.name}"], + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "versioned_dynamic_library", + ), + ), + flag_group( + flags = ["-Wl,-no-whole-archive"], + expand_if_true = "libraries_to_link.is_whole_archive", + ), + flag_group( + flags = ["-Wl,--end-lib"], + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "object_file_group", + ), + ), + ], + expand_if_available = "libraries_to_link", + ), + flag_group( + flags = ["-Wl,@%{thinlto_param_file}"], + expand_if_true = "thinlto_param_file", + ), + ], + ), + ], + ) + + user_link_flags_feature = feature( + name = "user_link_flags", + flag_sets = [ + flag_set( + actions = all_link_actions + lto_index_actions, + flag_groups = [ + flag_group( + flags = ["%{user_link_flags}"], + iterate_over = "user_link_flags", + expand_if_available = "user_link_flags", + ), + ] + ([flag_group(flags = ctx.attr.link_libs)] if ctx.attr.link_libs else []), + ), + ], + ) + + fdo_prefetch_hints_feature = feature( + name = "fdo_prefetch_hints", + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.lto_backend, + ], + flag_groups = [ + flag_group( + flags = [ + "-Xclang-only=-mllvm", + "-Xclang-only=-prefetch-hints-file=%{fdo_prefetch_hints_path}", + ], + expand_if_available = "fdo_prefetch_hints_path", + ), + ], + ), + ], + ) + + linkstamps_feature = feature( + name = "linkstamps", + flag_sets = [ + flag_set( + actions = all_link_actions + lto_index_actions, + flag_groups = [ + flag_group( + flags = ["%{linkstamp_paths}"], + iterate_over = "linkstamp_paths", + expand_if_available = "linkstamp_paths", + ), + ], + ), + ], + ) + + gcc_coverage_map_format_feature = feature( + name = "gcc_coverage_map_format", + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.preprocess_assemble, + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.cpp_module_compile, + ACTION_NAMES.objc_compile, + ACTION_NAMES.objcpp_compile, + "objc-executable", + "objc++-executable", + ], + flag_groups = [ + flag_group( + flags = ["-fprofile-arcs", "-ftest-coverage"], + expand_if_available = "gcov_gcno_file", + ), + ], + ), + flag_set( + actions = all_link_actions + lto_index_actions, + flag_groups = [flag_group(flags = ["--coverage"])], + ), + ], + requires = [feature_set(features = ["coverage"])], + provides = ["profile"], + ) + + archiver_flags_feature = feature( + name = "archiver_flags", + flag_sets = [ + flag_set( + actions = [ACTION_NAMES.cpp_link_static_library], + flag_groups = [ + flag_group(flags = ["rcsD"]), + flag_group( + flags = ["%{output_execpath}"], + expand_if_available = "output_execpath", + ), + ], + ), + flag_set( + actions = [ACTION_NAMES.cpp_link_static_library], + flag_groups = [ + flag_group( + iterate_over = "libraries_to_link", + flag_groups = [ + flag_group( + flags = ["%{libraries_to_link.name}"], + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "object_file", + ), + ), + flag_group( + flags = ["%{libraries_to_link.object_files}"], + iterate_over = "libraries_to_link.object_files", + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "object_file_group", + ), + ), + ], + expand_if_available = "libraries_to_link", + ), + ], + ), + ], + ) + + force_pic_flags_feature = feature( + name = "force_pic_flags", + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.cpp_link_executable, + ACTION_NAMES.lto_index_for_executable, + ], + flag_groups = [ + flag_group( + flags = ["-pie"], + expand_if_available = "force_pic", + ), + ], + ), + ], + ) + + dependency_file_feature = feature( + name = "dependency_file", + enabled = True, + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.assemble, + ACTION_NAMES.preprocess_assemble, + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.cpp_module_compile, + ACTION_NAMES.objc_compile, + ACTION_NAMES.objcpp_compile, + ACTION_NAMES.cpp_header_parsing, + ACTION_NAMES.clif_match, + ], + flag_groups = [ + flag_group( + flags = ["-MD", "-MF", "%{dependency_file}"], + expand_if_available = "dependency_file", + ), + ], + ), + ], + ) + + dynamic_library_linker_tool_path = tool_paths + dynamic_library_linker_tool_feature = feature( + name = "dynamic_library_linker_tool", + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.cpp_link_dynamic_library, + ACTION_NAMES.cpp_link_nodeps_dynamic_library, + ACTION_NAMES.lto_index_for_dynamic_library, + ACTION_NAMES.lto_index_for_nodeps_dynamic_library, + ], + flag_groups = [ + flag_group( + flags = [" + cppLinkDynamicLibraryToolPath + "], + expand_if_available = "generate_interface_library", + ), + ], + with_features = [ + with_feature_set( + features = ["supports_interface_shared_libraries"], + ), + ], + ), + ], + ) + + output_execpath_flags_feature = feature( + name = "output_execpath_flags", + flag_sets = [ + flag_set( + actions = all_link_actions + lto_index_actions, + flag_groups = [ + flag_group( + flags = ["-o", "%{output_execpath}"], + expand_if_available = "output_execpath", + ), + ], + ), + ], + ) + + # Note that we also set --coverage for c++-link-nodeps-dynamic-library. The + # generated code contains references to gcov symbols, and the dynamic linker + # can't resolve them unless the library is linked against gcov. + coverage_feature = feature( + name = "coverage", + provides = ["profile"], + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.preprocess_assemble, + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.cpp_header_parsing, + ACTION_NAMES.cpp_module_compile, + ], + flag_groups = ([ + flag_group(flags = ctx.attr.coverage_compile_flags), + ] if ctx.attr.coverage_compile_flags else []), + ), + flag_set( + actions = all_link_actions + lto_index_actions, + flag_groups = ([ + flag_group(flags = ctx.attr.coverage_link_flags), + ] if ctx.attr.coverage_link_flags else []), + ), + ], + ) + + thinlto_feature = feature( + name = "thin_lto", + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ] + all_link_actions + lto_index_actions, + flag_groups = [ + flag_group(flags = ["-flto=thin"]), + flag_group( + expand_if_available = "lto_indexing_bitcode_file", + flags = [ + "-Xclang", + "-fthin-link-bitcode=%{lto_indexing_bitcode_file}", + ], + ), + ], + ), + flag_set( + actions = [ACTION_NAMES.linkstamp_compile], + flag_groups = [flag_group(flags = ["-DBUILD_LTO_TYPE=thin"])], + ), + flag_set( + actions = lto_index_actions, + flag_groups = [ + flag_group(flags = [ + "-flto=thin", + "-Wl,-plugin-opt,thinlto-index-only%{thinlto_optional_params_file}", + "-Wl,-plugin-opt,thinlto-emit-imports-files", + "-Wl,-plugin-opt,thinlto-prefix-replace=%{thinlto_prefix_replace}", + ]), + flag_group( + expand_if_available = "thinlto_object_suffix_replace", + flags = [ + "-Wl,-plugin-opt,thinlto-object-suffix-replace=%{thinlto_object_suffix_replace}", + ], + ), + flag_group( + expand_if_available = "thinlto_merged_object_file", + flags = [ + "-Wl,-plugin-opt,obj-path=%{thinlto_merged_object_file}", + ], + ), + ], + ), + flag_set( + actions = [ACTION_NAMES.lto_backend], + flag_groups = [ + flag_group(flags = [ + "-c", + "-fthinlto-index=%{thinlto_index}", + "-o", + "%{thinlto_output_object_file}", + "-x", + "ir", + "%{thinlto_input_bitcode_file}", + ]), + ], + ), + ], + ) + + is_linux = ctx.attr.target_libc != "macosx" + + # TODO(#8303): Mac crosstool should also declare every feature. + if is_linux: + features = [ + dependency_file_feature, + random_seed_feature, + pic_feature, + per_object_debug_info_feature, + preprocessor_defines_feature, + includes_feature, + include_paths_feature, + fdo_instrument_feature, + cs_fdo_instrument_feature, + cs_fdo_optimize_feature, + thinlto_feature, + fdo_prefetch_hints_feature, + autofdo_feature, + build_interface_libraries_feature, + dynamic_library_linker_tool_feature, + symbol_counts_feature, + shared_flag_feature, + linkstamps_feature, + output_execpath_flags_feature, + runtime_library_search_directories_feature, + library_search_directories_feature, + archiver_flags_feature, + force_pic_flags_feature, + fission_support_feature, + strip_debug_symbols_feature, + coverage_feature, + supports_pic_feature, + ] + ( + [ + supports_start_end_lib_feature, + ] if ctx.attr.supports_start_end_lib else [] + ) + [ + default_compile_flags_feature, + default_link_flags_feature, + libraries_to_link_feature, + user_link_flags_feature, + static_libgcc_feature, + fdo_optimize_feature, + supports_dynamic_linker_feature, + dbg_feature, + opt_feature, + user_compile_flags_feature, + sysroot_feature, + unfiltered_compile_flags_feature, + ] + else: + features = [ + supports_pic_feature, + ] + ( + [ + supports_start_end_lib_feature, + ] if ctx.attr.supports_start_end_lib else [] + ) + [ + coverage_feature, + default_compile_flags_feature, + default_link_flags_feature, + fdo_optimize_feature, + supports_dynamic_linker_feature, + dbg_feature, + opt_feature, + user_compile_flags_feature, + sysroot_feature, + unfiltered_compile_flags_feature, + ] + + return cc_common.create_cc_toolchain_config_info( + ctx = ctx, + features = features, + action_configs = action_configs, + cxx_builtin_include_directories = ctx.attr.cxx_builtin_include_directories, + toolchain_identifier = ctx.attr.toolchain_identifier, + host_system_name = ctx.attr.host_system_name, + target_system_name = ctx.attr.target_system_name, + target_cpu = ctx.attr.cpu, + target_libc = ctx.attr.target_libc, + compiler = ctx.attr.compiler, + abi_version = ctx.attr.abi_version, + abi_libc_version = ctx.attr.abi_libc_version, + tool_paths = tool_paths, + ) + +cc_toolchain_config = rule( + implementation = _impl, + attrs = { + "cpu": attr.string(mandatory = True), + "compiler": attr.string(mandatory = True), + "toolchain_identifier": attr.string(mandatory = True), + "host_system_name": attr.string(mandatory = True), + "target_system_name": attr.string(mandatory = True), + "target_libc": attr.string(mandatory = True), + "abi_version": attr.string(mandatory = True), + "abi_libc_version": attr.string(mandatory = True), + "cxx_builtin_include_directories": attr.string_list(), + "tool_paths": attr.string_dict(), + "compile_flags": attr.string_list(), + "dbg_compile_flags": attr.string_list(), + "opt_compile_flags": attr.string_list(), + "cxx_flags": attr.string_list(), + "link_flags": attr.string_list(), + "link_libs": attr.string_list(), + "opt_link_flags": attr.string_list(), + "unfiltered_compile_flags": attr.string_list(), + "coverage_compile_flags": attr.string_list(), + "coverage_link_flags": attr.string_list(), + "supports_start_end_lib": attr.bool(), + }, + provides = [CcToolchainConfigInfo], +) diff --git a/tools/cross-toolchain/configs/gcc/bazel_2.1.1/cc/cc_wrapper.sh b/tools/cross-toolchain/configs/gcc/bazel_2.1.1/cc/cc_wrapper.sh new file mode 100755 index 000000000..f246528ab --- /dev/null +++ b/tools/cross-toolchain/configs/gcc/bazel_2.1.1/cc/cc_wrapper.sh @@ -0,0 +1,25 @@ +#!/bin/bash +# +# Copyright 2015 The Bazel Authors. All rights reserved. +# +# 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. +# +# Ship the environment to the C++ action +# +set -eu + +# Set-up the environment + + +# Call the C++ compiler +/usr/bin/gcc "$@" diff --git a/tools/cross-toolchain/configs/gcc/bazel_2.1.1/config/BUILD b/tools/cross-toolchain/configs/gcc/bazel_2.1.1/config/BUILD new file mode 100644 index 000000000..a4a0e1b42 --- /dev/null +++ b/tools/cross-toolchain/configs/gcc/bazel_2.1.1/config/BUILD @@ -0,0 +1,53 @@ +# Copyright 2016 The Bazel Authors. All rights reserved. +# +# 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. + +# This file is auto-generated by an rbe_autoconfig repository rule +# and should not be modified directly. +# See @bazel_toolchains//rules:rbe_repo.bzl + +package(default_visibility = ["//visibility:public"]) + +toolchain( + name = "cc-toolchain", + exec_compatible_with = [ + "@bazel_tools//platforms:x86_64", + "@bazel_tools//platforms:linux", + "@bazel_tools//tools/cpp:clang", + ], + target_compatible_with = [ + "@bazel_tools//platforms:linux", + "@bazel_tools//platforms:x86_64", + ], + toolchain = "//tools/cross-toolchain/configs/gcc/bazel_2.1.1/cc:cc-compiler-k8", + toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", +) + +platform( + name = "platform", + constraint_values = [ + "@bazel_tools//platforms:x86_64", + "@bazel_tools//platforms:linux", + "@bazel_tools//tools/cpp:clang", + ], + remote_execution_properties = """ + properties: { + name: "container-image" + value:"docker://gcr.io/prysmaticlabs/rbe-worker@sha256:dd72753a00743d0010ebc9fbcc73061623adc863532b49bb994c6e5c70739e97" + } + properties { + name: "OSFamily" + value: "Linux" + } + """, +) diff --git a/tools/cross-toolchain/configs/gcc/bazel_2.1.1/java/BUILD b/tools/cross-toolchain/configs/gcc/bazel_2.1.1/java/BUILD new file mode 100644 index 000000000..7c273a5b0 --- /dev/null +++ b/tools/cross-toolchain/configs/gcc/bazel_2.1.1/java/BUILD @@ -0,0 +1,25 @@ +# Copyright 2016 The Bazel Authors. All rights reserved. +# +# 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. + +# This file is auto-generated by an rbe_autoconfig repository rule +# and should not be modified directly. +# See @bazel_toolchains//rules:rbe_repo.bzl + +package(default_visibility = ["//visibility:public"]) + +java_runtime( + name = "jdk", + srcs = [], + java_home = "/usr/lib/jvm/java-8-openjdk-amd64", +) diff --git a/tools/cross-toolchain/configs/gcc/bazel_2.1.1/prysm_toolchains/BUILD.bazel b/tools/cross-toolchain/configs/gcc/bazel_2.1.1/prysm_toolchains/BUILD.bazel new file mode 100755 index 000000000..ba33afec8 --- /dev/null +++ b/tools/cross-toolchain/configs/gcc/bazel_2.1.1/prysm_toolchains/BUILD.bazel @@ -0,0 +1,147 @@ +package(default_visibility = ["//visibility:public"]) + +load(":cc_toolchain_config_osx.bzl", "osx_cc_toolchain_config") +load(":cc_toolchain_config_linux_arm64.bzl", "arm64_cc_toolchain_config") +load(":cc_toolchain_config_windows.bzl", "windows_cc_toolchain_config") + +cc_toolchain_suite( + name = "multiarch_toolchain", + toolchains = { + "k8|osxcross": ":cc-clang-osx", + "k8|clang": "cc-clang-amd64", + "aarch64|clang": ":cc-clang-arm64", + "k8": "cc-clang-amd64", + "aarch64": ":cc-clang-arm64", + "k8|mingw-w64": ":cc-mingw-amd64", + }, +) + +cc_toolchain_suite( + name = "hostonly_toolchain", + toolchains = { + "k8": "cc-clang-amd64", + }, +) + +filegroup( + name = "empty", + srcs = [], +) + +config_setting( + name = "osx_amd64", + constraint_values = [ + "@platforms//os:osx", + "@platforms//cpu:x86_64", + ], +) + +config_setting( + name = "linux_arm64", + constraint_values = [ + "@platforms//os:linux", + "@platforms//cpu:aarch64", + ], +) + +config_setting( + name = "linux_amd64", + constraint_values = [ + "@platforms//os:linux", + "@platforms//cpu:x86_64", + ], +) + +config_setting( + name = "windows_amd64", + constraint_values = [ + "@platforms//os:windows", + "@platforms//cpu:x86_64", + ], +) + +arm64_cc_toolchain_config( + name = "local-arm64", + target = "aarch64-linux-gnu", +) + +arm64_cc_toolchain_config( + name = "local-amd64", + target = "x86_64-unknown-linux-gnu", +) + +osx_cc_toolchain_config( + name = "local-osxcross", + target = "darwin_x86_64", +) + +windows_cc_toolchain_config( + name = "local-windows", + target = "x86_64-w64", +) + +cc_toolchain( + name = "cc-mingw-amd64", + all_files = ":empty", + ar_files = ":empty", + as_files = ":mingw_compiler_files", + compiler_files = ":mingw_compiler_files", + dwp_files = ":empty", + linker_files = ":empty", + objcopy_files = ":empty", + strip_files = ":empty", + supports_param_files = 0, + toolchain_config = ":local-windows", +) + +cc_toolchain( + name = "cc-clang-arm64", + all_files = ":empty", + compiler_files = ":empty", + dwp_files = ":empty", + linker_files = ":empty", + objcopy_files = ":empty", + strip_files = ":empty", + supports_param_files = 1, + toolchain_config = ":local-arm64", +) + +cc_toolchain( + name = "cc-clang-osx", + all_files = ":empty", + compiler_files = ":empty", + dwp_files = ":empty", + linker_files = ":empty", + objcopy_files = ":empty", + strip_files = ":empty", + supports_param_files = 1, + toolchain_config = ":local-osxcross", +) + +cc_toolchain( + name = "cc-clang-amd64", + all_files = ":empty", + compiler_files = ":empty", + dwp_files = ":empty", + linker_files = ":empty", + objcopy_files = ":empty", + strip_files = ":empty", + supports_param_files = 1, + toolchain_config = ":local-amd64", +) + +toolchain( + name = "cc-toolchain-multiarch", + exec_compatible_with = [ + "@platforms//os:linux", + "@platforms//cpu:x86_64", + ], + target_compatible_with = [], + toolchain = select({ + ":linux_arm64": ":cc-clang-arm64", + ":linux_amd64": ":cc-clang-amd64", + ":osx_amd64": ":cc-clang-osx", + ":windows_amd64": ":cc-mingw-amd64", + }), + toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", +) diff --git a/tools/cross-toolchain/configs/gcc/bazel_2.1.1/prysm_toolchains/WORKSPACE b/tools/cross-toolchain/configs/gcc/bazel_2.1.1/prysm_toolchains/WORKSPACE new file mode 100644 index 000000000..34eee8288 --- /dev/null +++ b/tools/cross-toolchain/configs/gcc/bazel_2.1.1/prysm_toolchains/WORKSPACE @@ -0,0 +1,2 @@ +# DO NOT EDIT: automatically generated WORKSPACE file for prysm_toolchains rule +workspace(name = "prysm_toolchains") diff --git a/tools/cross-toolchain/configs/gcc/bazel_2.1.1/prysm_toolchains/cc_toolchain_config_linux_arm64.bzl b/tools/cross-toolchain/configs/gcc/bazel_2.1.1/prysm_toolchains/cc_toolchain_config_linux_arm64.bzl new file mode 100755 index 000000000..5405f0bd4 --- /dev/null +++ b/tools/cross-toolchain/configs/gcc/bazel_2.1.1/prysm_toolchains/cc_toolchain_config_linux_arm64.bzl @@ -0,0 +1,304 @@ +load( + "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", + "action_config", + "feature", + "feature_set", + "flag_group", + "flag_set", + "make_variable", + "tool", + "tool_path", + "with_feature_set", +) +load( + "@bazel_tools//tools/cpp:cc_toolchain_config.bzl", + ALL_COMPILE_ACTIONS = "all_compile_actions", + ALL_CPP_COMPILE_ACTIONS = "all_cpp_compile_actions", + ALL_LINK_ACTIONS = "all_link_actions", +) + +def _impl(ctx): + toolchain_identifier = "clang-linux-cross" + compiler = "clang" + abi_version = "clang" + abi_libc_version = "glibc_unknown" + target_libc = "glibc_unknown" + target_cpu = ctx.attr.target.split("-")[0] + + if (target_cpu == "aarch64"): + sysroot = "/usr/aarch64-linux-gnu" + include_path_prefix = sysroot + elif (target_cpu == "x86_64"): + sysroot = "/" + include_path_prefix = "/usr" + else: + fail("Unreachable") + + if (target_cpu == "aarch64"): + cross_system_include_dirs = [ + include_path_prefix + "/include/c++/v1", + include_path_prefix + "/lib/clang/10.0.0/include", + ] + else: + cross_system_include_dirs = [ + include_path_prefix + "/include/c++/v1", + include_path_prefix + "/lib/clang/10.0.0/include", + include_path_prefix + "/include/x86_64-linux-gnu", + ] + + cross_system_include_dirs += [ + include_path_prefix + "/include/", + include_path_prefix + "/include/linux", + include_path_prefix + "/include/asm", + include_path_prefix + "/include/asm-generic", + ] + + if (target_cpu == "aarch64"): + cross_system_lib_dirs = [ + "/usr/" + ctx.attr.target + "/lib", + ] + else: + cross_system_lib_dirs = [ + "/usr/lib/x86_64-linux-gnu/", + ] + + cross_system_lib_dirs += [ + "/usr/lib/gcc/x86_64-linux-gnu/8", + ] + + opt_feature = feature(name = "opt") + dbg_feature = feature(name = "dbg") + fastbuild_feature = feature(name = "fastbuild") + random_seed_feature = feature(name = "random_seed", enabled = True) + supports_pic_feature = feature(name = "supports_pic", enabled = True) + supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True) + + unfiltered_compile_flags_feature = feature( + name = "unfiltered_compile_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = ALL_COMPILE_ACTIONS, + flag_groups = [ + flag_group( + flags = [ + "-no-canonical-prefixes", + "-Wno-builtin-macro-redefined", + "-D__DATE__=\"redacted\"", + "-D__TIMESTAMP__=\"redacted\"", + "-D__TIME__=\"redacted\"", + ], + ), + ], + ), + ], + ) + + # explicit arch specific system includes + system_include_flags = [] + for d in cross_system_include_dirs: + system_include_flags += ["-idirafter", d] + + default_compile_flags_feature = feature( + name = "default_compile_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = ALL_COMPILE_ACTIONS, + flag_groups = [ + flag_group( + flags = [ + "--target=" + ctx.attr.target, + "-nostdinc", + "-U_FORTIFY_SOURCE", + "-fstack-protector", + "-fno-omit-frame-pointer", + "-fcolor-diagnostics", + "-Wall", + "-Wthread-safety", + "-Wself-assign", + ] + system_include_flags, + ), + ], + ), + flag_set( + actions = ALL_COMPILE_ACTIONS, + flag_groups = [flag_group(flags = ["-g", "-fstandalone-debug"])], + with_features = [with_feature_set(features = ["dbg"])], + ), + flag_set( + actions = ALL_COMPILE_ACTIONS, + flag_groups = [ + flag_group( + flags = [ + "-g0", + "-O2", + "-D_FORTIFY_SOURCE=1", + "-DNDEBUG", + "-ffunction-sections", + "-fdata-sections", + ], + ), + ], + with_features = [with_feature_set(features = ["opt"])], + ), + flag_set( + actions = ALL_CPP_COMPILE_ACTIONS, + flag_groups = [flag_group(flags = ["-std=c++17", "-nostdinc++"])], + ), + ], + ) + + additional_link_flags = [ + "-l:libc++.a", + "-l:libc++abi.a", + "-l:libunwind.a", + "-lpthread", + "-ldl", + "-rtlib=compiler-rt", + ] + + default_link_flags_feature = feature( + name = "default_link_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = ALL_LINK_ACTIONS, + flag_groups = [ + flag_group( + flags = additional_link_flags + [ + "--target=" + ctx.attr.target, + "-lm", + "-no-canonical-prefixes", + "-fuse-ld=lld", + "-Wl,--build-id=md5", + "-Wl,--hash-style=gnu", + "-Wl,-z,relro,-z,now", + ] + ["-L" + d for d in cross_system_lib_dirs], + ), + ], + ), + flag_set( + actions = ALL_LINK_ACTIONS, + flag_groups = [flag_group(flags = ["-Wl,--gc-sections"])], + with_features = [with_feature_set(features = ["opt"])], + ), + ], + ) + + objcopy_embed_flags_feature = feature( + name = "objcopy_embed_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = ["objcopy_embed_data"], + flag_groups = [flag_group(flags = ["-I", "binary"])], + ), + ], + ) + + user_compile_flags_feature = feature( + name = "user_compile_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = ALL_COMPILE_ACTIONS, + flag_groups = [ + flag_group( + expand_if_available = "user_compile_flags", + flags = ["%{user_compile_flags}"], + iterate_over = "user_compile_flags", + ), + ], + ), + ], + ) + + sysroot_feature = feature( + name = "sysroot", + enabled = True, + flag_sets = [ + flag_set( + actions = ALL_COMPILE_ACTIONS + ALL_LINK_ACTIONS, + flag_groups = [ + flag_group( + expand_if_available = "sysroot", + flags = ["--sysroot=%{sysroot}"], + ), + ], + ), + ], + ) + + coverage_feature = feature( + name = "coverage", + flag_sets = [ + flag_set( + actions = ALL_COMPILE_ACTIONS, + flag_groups = [ + flag_group( + flags = ["-fprofile-instr-generate", "-fcoverage-mapping"], + ), + ], + ), + flag_set( + actions = ALL_LINK_ACTIONS, + flag_groups = [flag_group(flags = ["-fprofile-instr-generate"])], + ), + ], + provides = ["profile"], + ) + + features = [ + opt_feature, + fastbuild_feature, + dbg_feature, + random_seed_feature, + supports_pic_feature, + supports_dynamic_linker_feature, + unfiltered_compile_flags_feature, + default_link_flags_feature, + default_compile_flags_feature, + objcopy_embed_flags_feature, + user_compile_flags_feature, + sysroot_feature, + coverage_feature, + ] + + tool_paths = [ + tool_path(name = "ld", path = "/usr/bin/ld.lld"), + 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/strip"), + tool_path(name = "gcc", path = "/usr/bin/clang"), + tool_path(name = "ar", path = "/usr/bin/llvm-ar"), + ] + + return cc_common.create_cc_toolchain_config_info( + ctx = ctx, + features = features, + abi_version = abi_version, + abi_libc_version = abi_libc_version, + builtin_sysroot = sysroot, + compiler = compiler, + cxx_builtin_include_directories = cross_system_include_dirs, + host_system_name = "x86_64-unknown-linux-gnu", + target_cpu = target_cpu, + target_libc = target_libc, + target_system_name = ctx.attr.target, + tool_paths = tool_paths, + toolchain_identifier = toolchain_identifier, + ) + +arm64_cc_toolchain_config = rule( + implementation = _impl, + attrs = { + "target": attr.string(mandatory = True), + "stdlib": attr.string(), + }, + provides = [CcToolchainConfigInfo], +) diff --git a/tools/cross-toolchain/configs/gcc/bazel_2.1.1/prysm_toolchains/cc_toolchain_config_osx.bzl b/tools/cross-toolchain/configs/gcc/bazel_2.1.1/prysm_toolchains/cc_toolchain_config_osx.bzl new file mode 100755 index 000000000..d1a027d80 --- /dev/null +++ b/tools/cross-toolchain/configs/gcc/bazel_2.1.1/prysm_toolchains/cc_toolchain_config_osx.bzl @@ -0,0 +1,250 @@ +load( + "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", + "action_config", + "feature", + "feature_set", + "flag_group", + "flag_set", + "make_variable", + "tool", + "tool_path", + "with_feature_set", +) +load( + "@bazel_tools//tools/cpp:cc_toolchain_config.bzl", + ALL_COMPILE_ACTIONS = "all_compile_actions", + ALL_CPP_COMPILE_ACTIONS = "all_cpp_compile_actions", + ALL_LINK_ACTIONS = "all_link_actions", +) + +def _impl(ctx): + toolchain_identifier = "osxcross" + compiler = "clang" + abi_version = "darwin_x86_64" + abi_libc_version = "darwin_x86_64" + install = "/usr/x86_64-apple-darwin/" + clang_version = "10.0.0" + target_libc = "macosx" + target_cpu = "x86_64" + osxcross = install + "osxcross/" + osxcross_binprefix = osxcross + "bin/x86_64-apple-darwin14-" + sdkroot = osxcross + "SDK/MacOSX10.10.sdk/" + cross_system_include_dirs = [ + "/usr/lib/clang/10.0.0/include", + osxcross + "include", + sdkroot + "usr/include", + ] + cross_system_lib_dirs = [ + "/usr/x86_64-apple-darwin/lib", + sdkroot + "usr/lib", + osxcross + "/lib", + ] + + opt_feature = feature(name = "opt") + dbg_feature = feature(name = "dbg") + fastbuild_feature = feature(name = "fastbuild") + random_seed_feature = feature(name = "random_seed", enabled = True) + supports_pic_feature = feature(name = "supports_pic", enabled = True) + supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True) + + unfiltered_compile_flags_feature = feature( + name = "unfiltered_compile_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = ALL_COMPILE_ACTIONS, + flag_groups = [ + flag_group( + flags = [ + "-stdlib=libc++", + "-no-canonical-prefixes", + "-Wno-builtin-macro-redefined", + "-D__DATE__=\"redacted\"", + "-D__TIMESTAMP__=\"redacted\"", + "-D__TIME__=\"redacted\"", + ], + ), + ], + ), + ], + ) + + # explicit arch specific system includes + system_include_flags = [] + for d in cross_system_include_dirs: + system_include_flags += ["-idirafter", d] + + default_compile_flags_feature = feature( + name = "default_compile_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = ALL_COMPILE_ACTIONS, + flag_groups = [ + flag_group( + flags = [ + "-mlinker-version=400", + "-B " + osxcross + "bin", + "-nostdinc", + "-U_FORTIFY_SOURCE", + "-fstack-protector", + "-fno-omit-frame-pointer", + "-fcolor-diagnostics", + "-Wall", + "-Wthread-safety", + "-Wself-assign", + ] + system_include_flags, + ), + ], + ), + flag_set( + actions = ALL_COMPILE_ACTIONS, + flag_groups = [flag_group(flags = ["-g", "-fstandalone-debug"])], + with_features = [with_feature_set(features = ["dbg"])], + ), + flag_set( + actions = ALL_COMPILE_ACTIONS, + flag_groups = [ + flag_group( + flags = [ + "-g0", + "-O2", + "-D_FORTIFY_SOURCE=1", + "-DNDEBUG", + "-ffunction-sections", + "-fdata-sections", + ], + ), + ], + with_features = [with_feature_set(features = ["opt"])], + ), + flag_set( + actions = ALL_CPP_COMPILE_ACTIONS, + flag_groups = [flag_group(flags = ["-std=c++17", "-nostdinc++"])], + ), + ], + ) + + default_link_flags_feature = feature( + name = "default_link_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = ALL_LINK_ACTIONS, + flag_groups = [ + flag_group( + flags = [ + "-v", + "-lm", + "-no-canonical-prefixes", + "-fuse-ld=lld", + "-lc++", + "-lc++abi", + "-F" + sdkroot + "System/Library/Frameworks/", + "-L" + sdkroot + "usr/lib", + "-undefined", + "dynamic_lookup", + ], + ), + ], + ), + ], + ) + + objcopy_embed_flags_feature = feature( + name = "objcopy_embed_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = ["objcopy_embed_data"], + flag_groups = [flag_group(flags = ["-I", "binary"])], + ), + ], + ) + + user_compile_flags_feature = feature( + name = "user_compile_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = ALL_COMPILE_ACTIONS, + flag_groups = [ + flag_group( + expand_if_available = "user_compile_flags", + flags = ["%{user_compile_flags}"], + iterate_over = "user_compile_flags", + ), + ], + ), + ], + ) + + coverage_feature = feature( + name = "coverage", + flag_sets = [ + flag_set( + actions = ALL_COMPILE_ACTIONS, + flag_groups = [ + flag_group( + flags = ["-fprofile-instr-generate", "-fcoverage-mapping"], + ), + ], + ), + flag_set( + actions = ALL_LINK_ACTIONS, + flag_groups = [flag_group(flags = ["-fprofile-instr-generate"])], + ), + ], + provides = ["profile"], + ) + + features = [ + opt_feature, + fastbuild_feature, + dbg_feature, + random_seed_feature, + supports_pic_feature, + supports_dynamic_linker_feature, + unfiltered_compile_flags_feature, + default_link_flags_feature, + default_compile_flags_feature, + objcopy_embed_flags_feature, + user_compile_flags_feature, + coverage_feature, + ] + + tool_paths = [ + tool_path(name = "ld", path = osxcross_binprefix + "ld"), + tool_path(name = "cpp", path = osxcross + "bin/o64-clang++"), + tool_path(name = "dwp", path = "/usr/bin/dwp"), + tool_path(name = "gcov", path = "/usr/bin/gcov"), + tool_path(name = "nm", path = osxcross_binprefix + "nm"), + tool_path(name = "objdump", path = osxcross_binprefix + "ObjectDump"), + tool_path(name = "strip", path = osxcross_binprefix + "strip"), + tool_path(name = "gcc", path = osxcross + "bin/o64-clang"), + tool_path(name = "ar", path = osxcross_binprefix + "libtool"), + ] + + return cc_common.create_cc_toolchain_config_info( + ctx = ctx, + features = features, + abi_version = abi_version, + abi_libc_version = abi_libc_version, + compiler = compiler, + cxx_builtin_include_directories = cross_system_include_dirs, + host_system_name = "x86_64-unknown-linux-gnu", + target_cpu = target_cpu, + target_libc = target_libc, + target_system_name = ctx.attr.target, + tool_paths = tool_paths, + toolchain_identifier = toolchain_identifier, + ) + +osx_cc_toolchain_config = rule( + implementation = _impl, + attrs = { + "target": attr.string(mandatory = True), + "stdlib": attr.string(), + }, + provides = [CcToolchainConfigInfo], +) diff --git a/tools/cross-toolchain/configs/gcc/bazel_2.1.1/prysm_toolchains/cc_toolchain_config_windows.bzl b/tools/cross-toolchain/configs/gcc/bazel_2.1.1/prysm_toolchains/cc_toolchain_config_windows.bzl new file mode 100755 index 000000000..dce5d55ff --- /dev/null +++ b/tools/cross-toolchain/configs/gcc/bazel_2.1.1/prysm_toolchains/cc_toolchain_config_windows.bzl @@ -0,0 +1,209 @@ +load( + "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", + "action_config", + "artifact_name_pattern", + "env_entry", + "env_set", + "feature", + "feature_set", + "flag_group", + "flag_set", + "make_variable", + "tool", + "tool_path", + "with_feature_set", +) +load( + "@bazel_tools//tools/cpp:cc_toolchain_config.bzl", + ALL_COMPILE_ACTIONS = "all_compile_actions", + ALL_CPP_COMPILE_ACTIONS = "all_cpp_compile_actions", + ALL_LINK_ACTIONS = "all_link_actions", +) +load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES") + +def _impl(ctx): + toolchain_identifier = "msys_x64_mingw" + host_system_name = "local" + target_system_name = "local" + target_cpu = "x64_windows" + target_libc = "mingw" + compiler = "mingw-gcc" + abi_version = "local" + abi_libc_version = "local" + cc_target_os = None + builtin_sysroot = None + action_configs = [] + + install = "/usr/x86_64-w64-mingw32/" + bin_prefix = "/usr/bin/x86_64-w64-mingw32-" + + targets_windows_feature = feature( + name = "targets_windows", + implies = ["copy_dynamic_libraries_to_binary"], + enabled = True, + ) + + copy_dynamic_libraries_to_binary_feature = feature(name = "copy_dynamic_libraries_to_binary") + + gcc_env_feature = feature( + name = "gcc_env", + enabled = True, + env_sets = [ + env_set( + actions = [ + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.cpp_module_compile, + ACTION_NAMES.cpp_module_codegen, + ACTION_NAMES.cpp_header_parsing, + ACTION_NAMES.assemble, + ACTION_NAMES.preprocess_assemble, + ACTION_NAMES.cpp_link_executable, + ACTION_NAMES.cpp_link_dynamic_library, + ACTION_NAMES.cpp_link_nodeps_dynamic_library, + ACTION_NAMES.cpp_link_static_library, + ], + env_entries = [ + env_entry(key = "PATH", value = "NOT_USED"), + ], + ), + ], + ) + + msys_mingw_flags = [ + "-B " + install + "bin", + "-nostdinc", + "-U_FORTIFY_SOURCE", + "-fstack-protector", + "-fno-omit-frame-pointer", + "-fcolor-diagnostics", + "-Wall", + "-Wthread-safety", + "-Wself-assign", + "-x c++", + "-lstdc++", + "-lpthread", + ] + + msys_mingw_link_flags = [ + "-l:libstdc++.a", + "-L" + install + "lib", + "-L/usr/lib/gcc/x86_64-w64-mingw32/8.3-w32", + "-v", + "-lm", + "-no-canonical-prefixes", + ] + + default_compile_flags_feature = feature( + name = "default_compile_flags", + enabled = True, + flag_sets = [ + flag_set( + 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_compile, + ACTION_NAMES.cpp_module_codegen, + ACTION_NAMES.lto_backend, + ACTION_NAMES.clif_match, + ], + ), + flag_set( + actions = [ + ACTION_NAMES.linkstamp_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.cpp_header_parsing, + ACTION_NAMES.cpp_module_compile, + ACTION_NAMES.cpp_module_codegen, + ACTION_NAMES.lto_backend, + ACTION_NAMES.clif_match, + ], + flag_groups = ([flag_group(flags = msys_mingw_flags)] if msys_mingw_flags else []), + ), + ], + ) + + compiler_param_file_feature = feature( + name = "compiler_param_file", + ) + + default_link_flags_feature = feature( + name = "default_link_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = ALL_LINK_ACTIONS, + flag_groups = ([flag_group(flags = msys_mingw_link_flags)] if msys_mingw_link_flags else []), + ), + ], + ) + + supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True) + + features = [ + targets_windows_feature, + copy_dynamic_libraries_to_binary_feature, + gcc_env_feature, + default_compile_flags_feature, + compiler_param_file_feature, + default_link_flags_feature, + supports_dynamic_linker_feature, + ] + + cxx_builtin_include_directories = [ + install + "include", + ] + + artifact_name_patterns = [ + artifact_name_pattern( + category_name = "executable", + prefix = "", + extension = ".exe", + ), + ] + + make_variables = [] + tool_paths = [ + tool_path(name = "ld", path = bin_prefix + "ld"), + tool_path(name = "cpp", path = bin_prefix + "cpp"), + tool_path(name = "gcov", path = "/usr/bin/gcov"), + tool_path(name = "nm", path = bin_prefix + "nm"), + tool_path(name = "objcopy", path = bin_prefix + "objcopy"), + tool_path(name = "objdump", path = bin_prefix + "objdump"), + tool_path(name = "strip", path = bin_prefix + "strip"), + tool_path(name = "gcc", path = bin_prefix + "gcc"), + tool_path(name = "ar", path = bin_prefix + "ar"), + ] + + return cc_common.create_cc_toolchain_config_info( + ctx = ctx, + features = features, + action_configs = action_configs, + artifact_name_patterns = artifact_name_patterns, + cxx_builtin_include_directories = cxx_builtin_include_directories, + toolchain_identifier = toolchain_identifier, + host_system_name = host_system_name, + target_system_name = target_system_name, + target_cpu = target_cpu, + target_libc = target_libc, + compiler = compiler, + abi_version = abi_version, + abi_libc_version = abi_libc_version, + tool_paths = tool_paths, + make_variables = make_variables, + builtin_sysroot = builtin_sysroot, + cc_target_os = cc_target_os, + ) + +windows_cc_toolchain_config = rule( + implementation = _impl, + attrs = { + "target": attr.string(mandatory = True), + "stdlib": attr.string(), + }, + provides = [CcToolchainConfigInfo], +) diff --git a/tools/cross-toolchain/configs/versions.bzl b/tools/cross-toolchain/configs/versions.bzl new file mode 100644 index 000000000..061aa29e2 --- /dev/null +++ b/tools/cross-toolchain/configs/versions.bzl @@ -0,0 +1,17 @@ +# Generated file, do not modify by hand +# Generated by 'rbe_ubuntu_gcc_gen' rbe_autoconfig rule +"""Definitions to be used in rbe_repo attr of an rbe_autoconf rule """ +toolchain_config_spec0 = struct(config_repos = ["prysm_toolchains"], create_cc_configs = True, create_java_configs = True, env = {"BAZEL_COMPILER": "clang", "BAZEL_LINKLIBS": "-l%:libstdc++.a", "BAZEL_LINKOPTS": "-lm:-static-libgcc", "BAZEL_USE_LLVM_NATIVE_COVERAGE": "1", "GCOV": "llvm-profdata", "CC": "clang", "CXX": "clang++"}, java_home = "/usr/lib/jvm/java-8-openjdk-amd64", name = "clang") +toolchain_config_spec1 = struct(config_repos = ["prysm_toolchains"], create_cc_configs = True, create_java_configs = True, env = {"BAZEL_COMPILER": "gcc", "BAZEL_LINKLIBS": "-l%:libstdc++.a", "BAZEL_LINKOPTS": "-lm:-static-libgcc", "CC": "gcc", "CXX": "g++"}, java_home = "/usr/lib/jvm/java-8-openjdk-amd64", name = "gcc") +_TOOLCHAIN_CONFIG_SPECS = [toolchain_config_spec0, toolchain_config_spec1] +_BAZEL_TO_CONFIG_SPEC_NAMES = {"2.1.1": ["clang", "gcc"]} +LATEST = "sha256:dd72753a00743d0010ebc9fbcc73061623adc863532b49bb994c6e5c70739e97" +CONTAINER_TO_CONFIG_SPEC_NAMES = {"sha256:dd72753a00743d0010ebc9fbcc73061623adc863532b49bb994c6e5c70739e97": ["clang", "gcc"]} +_DEFAULT_TOOLCHAIN_CONFIG_SPEC = toolchain_config_spec0 +TOOLCHAIN_CONFIG_AUTOGEN_SPEC = struct( + bazel_to_config_spec_names_map = _BAZEL_TO_CONFIG_SPEC_NAMES, + container_to_config_spec_names_map = CONTAINER_TO_CONFIG_SPEC_NAMES, + default_toolchain_config_spec = _DEFAULT_TOOLCHAIN_CONFIG_SPEC, + latest_container = LATEST, + toolchain_config_specs = _TOOLCHAIN_CONFIG_SPECS, +) diff --git a/tools/cross-toolchain/empty.bzl b/tools/cross-toolchain/empty.bzl new file mode 100644 index 000000000..3fc95e435 --- /dev/null +++ b/tools/cross-toolchain/empty.bzl @@ -0,0 +1,18 @@ +_BAZEL_TO_CONFIG_SPEC_NAMES = {} + +# sha256 digest of the latest version of the toolchain container. +LATEST = "" + +_CONTAINER_TO_CONFIG_SPEC_NAMES = {} + +_DEFAULT_TOOLCHAIN_CONFIG_SPEC = "" + +_TOOLCHAIN_CONFIG_SPECS = [] + +TOOLCHAIN_CONFIG_AUTOGEN_SPEC = struct( + bazel_to_config_spec_names_map = _BAZEL_TO_CONFIG_SPEC_NAMES, + container_to_config_spec_names_map = _CONTAINER_TO_CONFIG_SPEC_NAMES, + default_toolchain_config_spec = _DEFAULT_TOOLCHAIN_CONFIG_SPEC, + latest_container = LATEST, + toolchain_config_specs = _TOOLCHAIN_CONFIG_SPECS, +) diff --git a/tools/cross-toolchain/install_clang_cross10.sh b/tools/cross-toolchain/install_clang_cross10.sh new file mode 100755 index 000000000..c418dfd2a --- /dev/null +++ b/tools/cross-toolchain/install_clang_cross10.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +set -eu +curl -L https://github.com/llvm/llvm-project/releases/download/llvmorg-${INSTALL_LLVM_VERSION}/clang+llvm-${INSTALL_LLVM_VERSION}-x86_64-linux-gnu-ubuntu-18.04.tar.xz \ + -o clang+llvm-${INSTALL_LLVM_VERSION}-x86_64-linux-gnu-ubuntu-18.04.tar.xz +tar xf clang+llvm-${INSTALL_LLVM_VERSION}-x86_64-linux-gnu-ubuntu-18.04.tar.xz --strip-components=1 -C /usr +rm -f clang+llvm-${INSTALL_LLVM_VERSION}-x86_64-linux-gnu-ubuntu-18.04.tar.xz +# arm64 +curl -L https://github.com/llvm/llvm-project/releases/download/llvmorg-${INSTALL_LLVM_VERSION}/clang+llvm-${INSTALL_LLVM_VERSION}-aarch64-linux-gnu.tar.xz \ + -o clang+llvm-${INSTALL_LLVM_VERSION}-aarch64-linux-gnu.tar.xz +tar xf clang+llvm-${INSTALL_LLVM_VERSION}-aarch64-linux-gnu.tar.xz +rm -f clang+llvm-${INSTALL_LLVM_VERSION}-aarch64-linux-gnu.tar.xz +mkdir -p /usr/aarch64-linux-gnu/lib/clang/10.0.0 +mkdir -p /usr/aarch64-linux-gnu/include/c++ +mv /clang+llvm-${INSTALL_LLVM_VERSION}-aarch64-linux-gnu/include/c++/v1 /usr/aarch64-linux-gnu/include/c++/ +mv /clang+llvm-${INSTALL_LLVM_VERSION}-aarch64-linux-gnu/lib/clang/10.0.0/include /usr/aarch64-linux-gnu/lib/clang/10.0.0 +mv /clang+llvm-${INSTALL_LLVM_VERSION}-aarch64-linux-gnu/lib/libc++.a /usr/aarch64-linux-gnu/lib/ +mv /clang+llvm-${INSTALL_LLVM_VERSION}-aarch64-linux-gnu/lib/libc++abi.a /usr/aarch64-linux-gnu/lib/ +mv /clang+llvm-${INSTALL_LLVM_VERSION}-aarch64-linux-gnu/lib/libunwind.a /usr/aarch64-linux-gnu/lib/ +mv /clang+llvm-${INSTALL_LLVM_VERSION}-aarch64-linux-gnu/lib/clang/10.0.0/lib/linux/libclang_rt.builtins-aarch64.a /usr/lib/clang/10.0.0/lib/linux/ +mv /clang+llvm-${INSTALL_LLVM_VERSION}-aarch64-linux-gnu/lib/clang/10.0.0/lib/linux/clang_rt.crtbegin-aarch64.o /usr/lib/clang/10.0.0/lib/linux/ +mv /clang+llvm-${INSTALL_LLVM_VERSION}-aarch64-linux-gnu/lib/clang/10.0.0/lib/linux/clang_rt.crtend-aarch64.o /usr/lib/clang/10.0.0/lib/linux/ +rm -rf /clang+llvm-${INSTALL_LLVM_VERSION}-aarch64-linux-gnu diff --git a/tools/cross-toolchain/install_osxcross.sh b/tools/cross-toolchain/install_osxcross.sh new file mode 100755 index 000000000..64ddf3bda --- /dev/null +++ b/tools/cross-toolchain/install_osxcross.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +set -eu + +OSXCROSS_REPO=tpoechtrager/osxcross +OSXCROSS_SHA1=bee9df6 +DARWIN_SDK_URL=https://www.dropbox.com/s/yfbesd249w10lpc/MacOSX10.10.sdk.tar.xz + +# darwin +mkdir -p /usr/x86_64-apple-darwin/osxcross +mkdir -p /tmp/osxcross && cd "/tmp/osxcross" +curl -sLo osxcross.tar.gz "https://codeload.github.com/${OSXCROSS_REPO}/tar.gz/${OSXCROSS_SHA1}" +tar --strip=1 -xzf osxcross.tar.gz +rm -f osxcross.tar.gz +curl -sLo tarballs/MacOSX10.10.sdk.tar.xz "${DARWIN_SDK_URL}" +yes "" | SDK_VERSION=10.10 OSX_VERSION_MIN=10.10 ./build.sh +mv target/* /usr/x86_64-apple-darwin/osxcross/ +mv tools /usr/x86_64-apple-darwin/osxcross/ +cd /usr/x86_64-apple-darwin/osxcross/include +ln -s ../SDK/MacOSX10.10.sdk/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CarbonCore.framework/Versions/A/Headers/ CarbonCore +ln -s ../SDK/MacOSX10.10.sdk/System/Library/Frameworks/CoreFoundation.framework/Versions/A/Headers/ CoreFoundation +ln -s ../SDK/MacOSX10.10.sdk/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/ Frameworks +ln -s ../SDK/MacOSX10.10.sdk/System/Library/Frameworks/Security.framework/Versions/A/Headers/ Security +rm -rf /tmp/osxcross +rm -rf "/usr/x86_64-apple-darwin/osxcross/SDK/MacOSX10.10.sdk/usr/share/man" +# symlink ld64.lld +ln -s /usr/x86_64-apple-darwin/osxcross/bin/x86_64-apple-darwin14-ld /usr/x86_64-apple-darwin/osxcross/bin/ld64.lld +ln -s /usr/x86_64-apple-darwin/osxcross/lib/libxar.so.1 /usr/lib diff --git a/tools/cross-toolchain/prysm_toolchains.bzl b/tools/cross-toolchain/prysm_toolchains.bzl new file mode 100644 index 000000000..7ed39bc3d --- /dev/null +++ b/tools/cross-toolchain/prysm_toolchains.bzl @@ -0,0 +1,40 @@ +def _pryms_toolchains_impl(ctx): + ctx.template( + "BUILD.bazel", + ctx.attr._build_tpl, + ) + ctx.template( + "cc_toolchain_config_linux_arm64.bzl", + ctx.attr._cc_toolchain_config_linux_arm_tpl, + ) + ctx.template( + "cc_toolchain_config_osx.bzl", + ctx.attr._cc_toolchain_config_osx_tpl, + ) + ctx.template( + "cc_toolchain_config_windows.bzl", + ctx.attr._cc_toolchain_config_windows_tpl, + ) + +prysm_toolchains = repository_rule( + implementation = _pryms_toolchains_impl, + attrs = { + "_build_tpl": attr.label( + default = "@prysm//tools/cross-toolchain:cc_toolchain.BUILD.bazel.tpl", + ), + "_cc_toolchain_config_linux_arm_tpl": attr.label( + default = "@prysm//tools/cross-toolchain:cc_toolchain_config_linux_arm64.bzl.tpl", + ), + "_cc_toolchain_config_osx_tpl": attr.label( + default = "@prysm//tools/cross-toolchain:cc_toolchain_config_osx.bzl.tpl", + ), + "_cc_toolchain_config_windows_tpl": attr.label( + default = "@prysm//tools/cross-toolchain:cc_toolchain_config_windows.bzl.tpl", + ), + }, + doc = "Configures Prysm custom toolchains for cross compilation and remote build execution.", +) + +def configure_prysm_toolchains(): + prysm_toolchains(name = "prysm_toolchains") + native.register_toolchains("@prysm_toolchains//:cc-toolchain-multiarch") diff --git a/tools/cross-toolchain/rbe_toolchains_config.bzl b/tools/cross-toolchain/rbe_toolchains_config.bzl new file mode 100644 index 000000000..319429c57 --- /dev/null +++ b/tools/cross-toolchain/rbe_toolchains_config.bzl @@ -0,0 +1,84 @@ +load("@bazel_toolchains//rules:rbe_repo.bzl", "rbe_autoconfig") +load("@prysm//tools/cross-toolchain:configs/versions.bzl", _generated_toolchain_config_suite_autogen_spec = "TOOLCHAIN_CONFIG_AUTOGEN_SPEC") + +_PRYSM_BUILD_IMAGE_REGISTRY = "gcr.io" +_PRYSM_BUILD_IMAGE_REPOSITORY = "prysmaticlabs/rbe-worker" +_PRYSM_BUILD_IMAGE_DIGEST = "sha256:dd72753a00743d0010ebc9fbcc73061623adc863532b49bb994c6e5c70739e97" +_PRYSM_BUILD_IMAGE_JAVA_HOME = "/usr/lib/jvm/java-8-openjdk-amd64" +_CONFIGS_OUTPUT_BASE = "tools/cross-toolchain/configs" + +_CLANG_ENV = { + "BAZEL_COMPILER": "clang", + "BAZEL_LINKLIBS": "-l%:libstdc++.a", + "BAZEL_LINKOPTS": "-lm:-static-libgcc", + "BAZEL_USE_LLVM_NATIVE_COVERAGE": "1", + "GCOV": "llvm-profdata", + "CC": "clang", + "CXX": "clang++", +} + +_GCC_ENV = { + "BAZEL_COMPILER": "gcc", + "BAZEL_LINKLIBS": "-l%:libstdc++.a", + "BAZEL_LINKOPTS": "-lm:-static-libgcc", + "CC": "gcc", + "CXX": "g++", +} + +_TOOLCHAIN_CONFIG_SUITE_SPEC = { + "container_registry": _PRYSM_BUILD_IMAGE_REGISTRY, + "container_repo": _PRYSM_BUILD_IMAGE_REPOSITORY, + "output_base": _CONFIGS_OUTPUT_BASE, + "repo_name": "prysm", + "toolchain_config_suite_autogen_spec": _generated_toolchain_config_suite_autogen_spec, +} + +def _rbe_toolchains_generator(): + rbe_autoconfig( + name = "rbe_ubuntu_clang_gen", + digest = _PRYSM_BUILD_IMAGE_DIGEST, + export_configs = True, + java_home = _PRYSM_BUILD_IMAGE_JAVA_HOME, + registry = _PRYSM_BUILD_IMAGE_REGISTRY, + repository = _PRYSM_BUILD_IMAGE_REPOSITORY, + env = _CLANG_ENV, + toolchain_config_spec_name = "clang", + toolchain_config_suite_spec = _TOOLCHAIN_CONFIG_SUITE_SPEC, + use_checked_in_confs = "False", + config_repos = [ + "prysm_toolchains", + ], + ) + + rbe_autoconfig( + name = "rbe_ubuntu_gcc_gen", + digest = _PRYSM_BUILD_IMAGE_DIGEST, + export_configs = True, + java_home = _PRYSM_BUILD_IMAGE_JAVA_HOME, + registry = _PRYSM_BUILD_IMAGE_REGISTRY, + repository = _PRYSM_BUILD_IMAGE_REPOSITORY, + env = _GCC_ENV, + toolchain_config_spec_name = "gcc", + toolchain_config_suite_spec = _TOOLCHAIN_CONFIG_SUITE_SPEC, + use_checked_in_confs = "False", + config_repos = [ + "prysm_toolchains", + ], + ) + +def _generated_rbe_toolchains(): + rbe_autoconfig( + name = "rbe_ubuntu_clang", + digest = _PRYSM_BUILD_IMAGE_DIGEST, + export_configs = True, + java_home = _PRYSM_BUILD_IMAGE_JAVA_HOME, + registry = _PRYSM_BUILD_IMAGE_REGISTRY, + repository = _PRYSM_BUILD_IMAGE_REPOSITORY, + toolchain_config_spec_name = "clang", + toolchain_config_suite_spec = _TOOLCHAIN_CONFIG_SUITE_SPEC, + use_checked_in_confs = "Force", + ) + +def rbe_toolchains_config(): + _rbe_toolchains_generator() + _generated_rbe_toolchains() diff --git a/tools/cross-toolchain/regenerate.sh b/tools/cross-toolchain/regenerate.sh new file mode 100755 index 000000000..a06ad7b37 --- /dev/null +++ b/tools/cross-toolchain/regenerate.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +set -e + +export RBE_AUTOCONF_ROOT=$(bazel info workspace) + +rm -rf "${RBE_AUTOCONF_ROOT}/tools/cross-toolchain/configs/*" +cp -vf "${RBE_AUTOCONF_ROOT}/tools/cross-toolchain/empty.bzl" "${RBE_AUTOCONF_ROOT}/tools/cross-toolchain/configs/versions.bzl" + +# Bazel query is the right command so bazel won't fail itself. +bazel query "@rbe_ubuntu_clang_gen//..." +bazel query "@rbe_ubuntu_gcc_gen//..." \ No newline at end of file