blob: 33c97d2d98d92998310ff2beebfd91aff2764f3c [file] [log] [blame]
# NOTE: THIS FILE IS EXPERIMENTAL FOR THE BAZEL MIGRATION AND NOT USED FOR
# YOUR BUILDS CURRENTLY.
#
# It is not yet the source of truth for your build. If you're looking to modify
# the build file, modify the Android.bp file instead. Do *not* modify this file
# unless you have coordinated with the team managing the Soong to Bazel
# migration.
package(default_visibility = ["//visibility:public"])
# Toolchain config
filegroup(name = "empty")
load(":cc_toolchain_config.bzl", "android_cc_toolchain", "clang_version")
load(":clang_version.bzl", "DEFAULT_SHORT_VERSION", "DEFAULT_VERSION")
load("@soong_injection//cc_toolchain:constants.bzl", "constants")
# Different clang versions are configured here.
clang_version(
name = "clang",
directory = DEFAULT_VERSION,
includes = [
"lib64/clang/%s/include" % DEFAULT_SHORT_VERSION,
],
)
_LIBCLANG_RT_PREFIX = "%s/lib64/clang/%s/lib/linux" % (DEFAULT_VERSION, DEFAULT_SHORT_VERSION)
_LIBCLANG_RT_PREBUILT_MAP = {
"//build/bazel/platforms/os_arch:android_arm": _LIBCLANG_RT_PREFIX + "/libclang_rt.builtins-arm-android.a",
"//build/bazel/platforms/os_arch:android_arm64": _LIBCLANG_RT_PREFIX + "/libclang_rt.builtins-aarch64-android.a",
"//build/bazel/platforms/os_arch:android_x86": _LIBCLANG_RT_PREFIX + "/libclang_rt.builtins-i686-android.a",
"//build/bazel/platforms/os_arch:android_x86_64": _LIBCLANG_RT_PREFIX + "/libclang_rt.builtins-x86_64-android.a",
"//build/bazel/platforms/os_arch:linux_bionic_x86_64": _LIBCLANG_RT_PREFIX + "/libclang_rt.builtins-x86_64-android.a",
"//build/bazel/platforms/os_arch:linux_glibc_x86": _LIBCLANG_RT_PREFIX + "/libclang_rt.builtins-i386.a",
"//build/bazel/platforms/os_arch:linux_glibc_x86_64": _LIBCLANG_RT_PREFIX + "/libclang_rt.builtins-x86_64.a",
"//conditions:default": None,
}
# x86_64 toolchain definition.
android_cc_toolchain(
name = "cc_toolchain_x86_64",
clang_version = ":clang",
clang_version_directory = DEFAULT_VERSION,
libclang_rt_builtin = _LIBCLANG_RT_PREBUILT_MAP["//build/bazel/platforms/os_arch:android_x86_64"],
target_flags = [
"-m64",
"-march=x86-64",
"--target=x86_64-linux-android10000",
"-mssse3",
"-msse4",
"-msse4.1",
"-msse4.2",
"-mpopcnt",
],
toolchain_identifier = "x86_64-toolchain",
)
toolchain(
name = "cc_toolchain_x86_64_def",
exec_compatible_with = [
"//build/bazel/platforms/arch:x86_64",
"//build/bazel/platforms/os:linux",
],
target_compatible_with = [
"//build/bazel/platforms/arch:x86_64",
"//build/bazel/platforms/os:android",
],
toolchain = ":cc_toolchain_x86_64",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)
# Toolchain to compile for the linux host.
# TODO(b/186628704): automatically generate from Soong.
android_cc_toolchain(
name = "cc_toolchain_x86_64_linux_host",
clang_version = ":clang",
clang_version_directory = DEFAULT_VERSION,
libclang_rt_builtin = _LIBCLANG_RT_PREBUILT_MAP["//build/bazel/platforms/os_arch:linux_glibc_x86_64"],
target_flags = [
"-m64",
"-fdiagnostics-color",
"-Wa,--noexecstack",
"-fPIC",
"-U_FORTIFY_SOURCE",
"-D_FORTIFY_SOURCE=2",
"-fstack-protector",
# Workaround differences in inttypes.h between host and target.
# See bug 12708004.
"-D__STDC_FORMAT_MACROS",
"-D__STDC_CONSTANT_MACROS",
],
linker_flags = [
"-m64",
"-Wl,-z,noexecstack",
"-Wl,-z,relro",
"-Wl,-z,now",
"-Wl,--no-undefined-version",
],
toolchain_identifier = "x86_64-toolchain",
)
# TODO(b/181803350): Fix linux toolchain flag set, as the current flags are for android.
toolchain(
name = "cc_toolchain_x86_64_linux_host_def",
exec_compatible_with = [
"//build/bazel/platforms/arch:x86_64",
"//build/bazel/platforms/os:linux",
],
target_compatible_with = [
"//build/bazel/platforms/arch:x86_64",
"//build/bazel/platforms/os:linux",
],
toolchain = ":cc_toolchain_x86_64_linux_host",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)
# x86 toolchain definition.
android_cc_toolchain(
name = "cc_toolchain_x86",
clang_version = ":clang",
clang_version_directory = DEFAULT_VERSION,
libclang_rt_builtin = _LIBCLANG_RT_PREBUILT_MAP["//build/bazel/platforms/os_arch:android_x86"],
linker_flags = [
"-Wl,-dynamic-linker,/system/bin/linker",
],
target_flags = [
"--target=i686-linux-android10000",
"-m32",
"-march=prescott",
"-msse3",
"-mstackrealign",
],
toolchain_identifier = "x86-toolchain",
)
toolchain(
name = "cc_toolchain_x86_def",
exec_compatible_with = [
"//build/bazel/platforms/arch:x86_64",
"//build/bazel/platforms/os:linux",
],
target_compatible_with = [
"//build/bazel/platforms/arch:x86",
"//build/bazel/platforms/os:android",
],
toolchain = ":cc_toolchain_x86",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)
# arm64 toolchain definition.
android_cc_toolchain(
name = "cc_toolchain_arm64",
clang_version = ":clang",
clang_version_directory = DEFAULT_VERSION,
libclang_rt_builtin = _LIBCLANG_RT_PREBUILT_MAP["//build/bazel/platforms/os_arch:android_arm64"],
linker_flags = [
# Obtained from build/soong/rust/config/arm64_device.go
"-Wl,--icf=safe",
"-Wl,-z,max-page-size=4096",
"-Wl,--execute-only",
"-Wl,-z,separate-code",
],
target_flags = [
"--target=aarch64-linux-android10000",
"-march=armv8-a",
],
toolchain_identifier = "arm64-toolchain",
)
toolchain(
name = "cc_toolchain_arm64_def",
exec_compatible_with = [
"//build/bazel/platforms/arch:x86_64",
"//build/bazel/platforms/os:linux",
],
target_compatible_with = [
"//build/bazel/platforms/arch:arm64",
"//build/bazel/platforms/os:android",
],
toolchain = ":cc_toolchain_arm64",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)
# arm32 toolchain definition.
android_cc_toolchain(
name = "cc_toolchain_arm32",
clang_version = ":clang",
clang_version_directory = DEFAULT_VERSION,
libclang_rt_builtin = _LIBCLANG_RT_PREBUILT_MAP["//build/bazel/platforms/os_arch:android_arm"],
linker_flags = ["-Wl,-dynamic-linker,/system/bin/linker"] + constants.ArmLldflags,
target_flags = ["--target=" + constants.ArmClangTriple + "10000"] +
constants.ArmToolchainClangCflags +
constants.ArmClangArmv7ANeonCflags +
constants.ArmClangThumbCflags +
constants.ArmClangCflags,
toolchain_identifier = "arm-toolchain",
)
toolchain(
name = "cc_toolchain_arm32_def",
exec_compatible_with = [
"//build/bazel/platforms/arch:x86_64",
"//build/bazel/platforms/os:linux",
],
target_compatible_with = [
"//build/bazel/platforms/arch:arm",
"//build/bazel/platforms/os:android",
],
toolchain = ":cc_toolchain_arm32",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)
cc_import(
name = "libclang_rt",
static_library = select(_LIBCLANG_RT_PREBUILT_MAP),
)
[alias(
name = "llvm-%s" % tool,
actual = DEFAULT_VERSION + "/bin/llvm-%s" % tool,
visibility = ["//visibility:public"],
) for tool in ["ar", "readelf", "objcopy", "strip"]]
# Test tools used by Bazel tests.
filegroup(
name = "test_tools",
srcs = [
DEFAULT_VERSION + "/bin/llvm-readelf",
DEFAULT_VERSION + "/bin/llvm-nm",
],
visibility = ["//build/bazel/tests:__subpackages__"]
)