| # 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. |
| |
| """ |
| Toolchain config |
| """ |
| |
| load("@bazel_skylib//rules:common_settings.bzl", "bool_flag") |
| load("@env//:env.bzl", "env") |
| load( |
| ":cc_toolchain_config.bzl", |
| "android_cc_toolchain", |
| "clang_version", |
| "expand_feature_flags", |
| "toolchain_definition", |
| ) |
| load( |
| ":cc_toolchain_constants.bzl", |
| "arch_to_variants", |
| "arches", |
| "device_compatibility_flags_non_darwin", |
| "device_compatibility_flags_non_windows", |
| "generated_config_constants", |
| "libclang_rt_prebuilt_map", |
| "libclang_ubsan_minimal_rt_prebuilt_map", |
| "variant_name", |
| "x86_64_host_toolchains", |
| "x86_64_musl_host_toolchains", |
| "x86_host_toolchains", |
| "x86_musl_host_toolchains", |
| _bionic_crt = "bionic_crt", |
| _musl_crt = "musl_crt", |
| ) |
| load( |
| ":cc_toolchain_features_cfi_test.bzl", |
| "cc_toolchain_features_cfi_test_suite", |
| ) |
| load( |
| ":cc_toolchain_features_pack_relocation_test.bzl", |
| "cc_toolchain_features_pack_relocation_test_suite", |
| ) |
| load( |
| ":cc_toolchain_features_thinlto_test.bzl", |
| "cc_toolchain_features_lto_test_suite", |
| ) |
| load( |
| ":cc_toolchain_features_ubsan_test.bzl", |
| "cc_toolchain_features_ubsan_test_suite", |
| ) |
| load( |
| ":cc_toolchain_features_env_based_flags_test.bzl", |
| "cc_toolchain_features_env_based_flags_test_suite", |
| ) |
| load( |
| ":cc_toolchain_features_flag_order_test.bzl", |
| "cc_toolchain_features_flag_order_test_suite", |
| ) |
| load( |
| ":cc_toolchain_features_linker_alignment_test.bzl", |
| "cc_toolchain_features_linker_alignment_test_suite", |
| ) |
| load("//build/bazel/flags:common.bzl", "is_env_true") |
| load("//build/bazel/platforms/arch/variants:constants.bzl", _arch_constants = "constants") |
| |
| filegroup(name = "empty") |
| |
| # Different clang versions are configured here. |
| clang_version( |
| name = "clang", |
| directory = generated_config_constants.ClangVersion, |
| includes = [ |
| "lib/clang/%s/include" % generated_config_constants.ClangShortVersion, |
| ], |
| ) |
| |
| # x86_64 toolchain definitions |
| [ |
| android_cc_toolchain( |
| name = "cc_toolchain_x86_64" + variant_name(variant), |
| clang_version = ":clang", |
| clang_version_directory = generated_config_constants.ClangVersion, |
| compiler_flags = generated_config_constants.X86_64ToolchainCflags + |
| generated_config_constants.X86_64ArchVariantCflags[variant.arch_variant] + |
| expand_feature_flags( |
| variant.arch_variant, |
| _arch_constants.AndroidArchToVariantToFeatures[arches.X86_64], |
| generated_config_constants.X86_64ArchFeatureCflags, |
| ) + generated_config_constants.X86_64Cflags, |
| crt = _bionic_crt, |
| libclang_rt_builtin = libclang_rt_prebuilt_map["//build/bazel/platforms/os_arch:android_x86_64"], |
| libclang_rt_ubsan_minimal = libclang_ubsan_minimal_rt_prebuilt_map["//build/bazel/platforms/os_arch:android_x86_64"], |
| linker_flags = generated_config_constants.X86_64ToolchainLdflags + generated_config_constants.X86_64Lldflags, |
| target_arch = arches.X86_64, |
| target_os = "android", |
| toolchain_identifier = "x86_64-toolchain", |
| ) |
| for variant in arch_to_variants[arches.X86_64] |
| ] |
| |
| # x86 toolchain definitions. |
| [ |
| android_cc_toolchain( |
| name = "cc_toolchain_x86" + variant_name(variant), |
| clang_version = ":clang", |
| clang_version_directory = generated_config_constants.ClangVersion, |
| compiler_flags = generated_config_constants.X86ToolchainCflags + |
| generated_config_constants.X86ArchVariantCflags[variant.arch_variant] + |
| expand_feature_flags( |
| variant.arch_variant, |
| _arch_constants.AndroidArchToVariantToFeatures[arches.X86], |
| generated_config_constants.X86ArchFeatureCflags, |
| ) + generated_config_constants.X86Cflags, |
| crt = _bionic_crt, |
| libclang_rt_builtin = libclang_rt_prebuilt_map["//build/bazel/platforms/os_arch:android_x86"], |
| libclang_rt_ubsan_minimal = libclang_ubsan_minimal_rt_prebuilt_map["//build/bazel/platforms/os_arch:android_x86"], |
| linker_flags = generated_config_constants.X86ToolchainLdflags + generated_config_constants.X86Lldflags, |
| target_arch = arches.X86, |
| target_os = "android", |
| toolchain_identifier = "x86-toolchain", |
| ) |
| for variant in arch_to_variants[arches.X86] |
| ] |
| |
| # arm64 toolchain definitions. |
| [ |
| android_cc_toolchain( |
| name = "cc_toolchain_arm64" + variant_name(variant), |
| clang_version = ":clang", |
| clang_version_directory = generated_config_constants.ClangVersion, |
| compiler_flags = generated_config_constants.Arm64Cflags + |
| generated_config_constants.Arm64ArchVariantCflags[variant.arch_variant] + |
| generated_config_constants.Arm64CpuVariantCflags.get( |
| variant.cpu_variant, |
| [], |
| ), |
| crt = _bionic_crt, |
| libclang_rt_builtin = libclang_rt_prebuilt_map["//build/bazel/platforms/os_arch:android_arm64"], |
| libclang_rt_ubsan_minimal = libclang_ubsan_minimal_rt_prebuilt_map["//build/bazel/platforms/os_arch:android_arm64"], |
| linker_flags = generated_config_constants.Arm64CpuVariantLdflags.get( |
| variant.cpu_variant, |
| [], |
| ) + generated_config_constants.Arm64Lldflags, |
| target_arch = arches.Arm64, |
| target_os = "android", |
| toolchain_identifier = "arm64-toolchain", |
| ) |
| for variant in arch_to_variants[arches.Arm64] |
| ] |
| |
| # arm32 toolchain definitions. |
| [ |
| android_cc_toolchain( |
| name = "cc_toolchain_arm" + variant_name(variant), |
| clang_version = ":clang", |
| clang_version_directory = generated_config_constants.ClangVersion, |
| compiler_flags = generated_config_constants.ArmCflags + |
| generated_config_constants.ArmToolchainCflags + |
| generated_config_constants.ArmArchVariantCflags[variant.arch_variant] + |
| generated_config_constants.ArmCpuVariantCflags.get( |
| variant.cpu_variant, |
| [], |
| ), |
| crt = _bionic_crt, |
| libclang_rt_builtin = libclang_rt_prebuilt_map["//build/bazel/platforms/os_arch:android_arm"], |
| libclang_rt_ubsan_minimal = libclang_ubsan_minimal_rt_prebuilt_map["//build/bazel/platforms/os_arch:android_arm"], |
| # do not pass "ld"-only flags as Bazel is only using lld. Ensure that all flags are lld-compatible. |
| linker_flags = generated_config_constants.ArmLldflags, |
| target_arch = arches.Arm, |
| target_os = "android", |
| toolchain_identifier = "arm-toolchain", |
| ) |
| for variant in arch_to_variants[arches.Arm] |
| ] |
| |
| # 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 = generated_config_constants.ClangVersion, |
| compiler_flags = generated_config_constants.LinuxCflags + |
| generated_config_constants.LinuxGlibcCflags + |
| generated_config_constants.LinuxX8664Cflags + |
| # Added by stl.go for non-bionic toolchains. |
| [ |
| "-nostdinc++", |
| ], |
| crt = False, |
| gcc_toolchain = generated_config_constants.LinuxGccRoot, |
| libclang_rt_builtin = libclang_rt_prebuilt_map["//build/bazel/platforms/os_arch:linux_glibc_x86_64"], |
| libclang_rt_ubsan_minimal = libclang_ubsan_minimal_rt_prebuilt_map["//build/bazel/platforms/os_arch:linux_glibc_x86_64"], |
| linker_flags = generated_config_constants.LinuxGlibcLdflags + |
| generated_config_constants.LinuxLdflags + |
| generated_config_constants.LinuxX8664Ldflags + |
| device_compatibility_flags_non_windows + |
| device_compatibility_flags_non_darwin, |
| rtti_toggle = False, |
| target_arch = "x86_64", |
| target_flags = ["--target=x86_64-linux-gnu"], |
| target_os = "linux_glibc", |
| toolchain_identifier = "x86_64-toolchain", |
| ) |
| |
| # Toolchain to compile for the linux x86 target. |
| android_cc_toolchain( |
| name = "cc_toolchain_x86_linux_host", |
| clang_version = ":clang", |
| clang_version_directory = generated_config_constants.ClangVersion, |
| compiler_flags = generated_config_constants.LinuxCflags + |
| generated_config_constants.LinuxGlibcCflags + |
| generated_config_constants.LinuxX86Cflags + |
| # Added by stl.go for non-bionic toolchains. |
| [ |
| "-nostdinc++", |
| ], |
| crt = False, |
| gcc_toolchain = generated_config_constants.LinuxGccRoot, |
| libclang_rt_builtin = libclang_rt_prebuilt_map["//build/bazel/platforms/os_arch:linux_glibc_x86"], |
| libclang_rt_ubsan_minimal = libclang_ubsan_minimal_rt_prebuilt_map["//build/bazel/platforms/os_arch:linux_glibc_x86"], |
| linker_flags = generated_config_constants.LinuxGlibcLdflags + |
| generated_config_constants.LinuxLdflags + |
| generated_config_constants.LinuxX86Ldflags + |
| device_compatibility_flags_non_windows + |
| device_compatibility_flags_non_darwin, |
| rtti_toggle = False, |
| target_arch = "x86", |
| target_flags = ["--target=i686-linux-gnu"], |
| target_os = "linux_glibc", |
| toolchain_identifier = "x86-toolchain", |
| ) |
| |
| # Toolchain to compile for the linux host with musl libc. |
| android_cc_toolchain( |
| name = "cc_toolchain_x86_64_linux_musl_host", |
| clang_version = ":clang", |
| clang_version_directory = generated_config_constants.ClangVersion, |
| compiler_flags = generated_config_constants.LinuxCflags + |
| generated_config_constants.LinuxMuslCflags + |
| generated_config_constants.LinuxX8664Cflags + |
| # Added by stl.go for non-bionic toolchains. |
| [ |
| "-nostdinc++", |
| ], |
| crt = _musl_crt, |
| gcc_toolchain = generated_config_constants.LinuxGccRoot, |
| libclang_rt_builtin = libclang_rt_prebuilt_map["//build/bazel/platforms/os_arch:linux_musl_x86_64"], |
| libclang_rt_ubsan_minimal = libclang_ubsan_minimal_rt_prebuilt_map["//build/bazel/platforms/os_arch:linux_musl_x86_64"], |
| linker_flags = generated_config_constants.LinuxMuslLdflags + |
| generated_config_constants.LinuxLdflags + |
| generated_config_constants.LinuxX8664Ldflags, |
| rtti_toggle = False, |
| target_arch = "x86_64", |
| target_flags = ["--target=x86_64-linux-musl"], |
| target_os = "linux_musl", |
| toolchain_identifier = "x86_64-toolchain", |
| ) |
| |
| # Toolchain to compile for the linux x86 host with musl libc. |
| android_cc_toolchain( |
| name = "cc_toolchain_x86_linux_musl_host", |
| clang_version = ":clang", |
| clang_version_directory = generated_config_constants.ClangVersion, |
| compiler_flags = generated_config_constants.LinuxCflags + |
| generated_config_constants.LinuxMuslCflags + |
| generated_config_constants.LinuxX86Cflags + |
| # Added by stl.go for non-bionic toolchains. |
| [ |
| "-nostdinc++", |
| ], |
| crt = _musl_crt, |
| gcc_toolchain = generated_config_constants.LinuxGccRoot, |
| libclang_rt_builtin = libclang_rt_prebuilt_map["//build/bazel/platforms/os_arch:linux_musl_x86"], |
| libclang_rt_ubsan_minimal = libclang_ubsan_minimal_rt_prebuilt_map["//build/bazel/platforms/os_arch:linux_musl_x86"], |
| linker_flags = generated_config_constants.LinuxMuslLdflags + |
| generated_config_constants.LinuxLdflags + |
| generated_config_constants.LinuxX86Ldflags, |
| rtti_toggle = False, |
| target_arch = "x86", |
| target_flags = ["--target=i686-linux-musl"], |
| target_os = "linux_musl", |
| toolchain_identifier = "x86-toolchain", |
| ) |
| |
| toolchain_type(name = "nocrt_toolchain") |
| |
| # Device toolchains |
| [ |
| [ |
| [ |
| toolchain_definition(arch, variant, nocrt) |
| for nocrt in [ |
| True, |
| False, |
| ] |
| ] |
| for variant in variants |
| ] |
| for arch, variants in arch_to_variants.items() |
| ] |
| |
| # Toolchains for linux host (x86_64) archs |
| [ |
| toolchain( |
| name = "%s_def" % toolchain_name, |
| exec_compatible_with = [ |
| "//build/bazel/platforms/arch:x86_64", |
| "//build/bazel/platforms/os:linux_glibc", |
| ], |
| target_compatible_with = [ |
| "//build/bazel/platforms/arch:x86_64", |
| "//build/bazel/platforms/os:linux_glibc", |
| ], |
| toolchain = toolchain_name, |
| toolchain_type = toolchain_type, |
| ) |
| for (toolchain_name, toolchain_type) in x86_64_host_toolchains |
| ] |
| |
| # Toolchains for linux target (non-host) x86 arch |
| [ |
| toolchain( |
| name = "%s_def" % toolchain_name, |
| exec_compatible_with = [ |
| "//build/bazel/platforms/arch:x86_64", |
| "//build/bazel/platforms/os:linux_glibc", |
| ], |
| target_compatible_with = [ |
| "//build/bazel/platforms/arch:x86", |
| "//build/bazel/platforms/os:linux_glibc", |
| ], |
| toolchain = toolchain_name, |
| toolchain_type = toolchain_type, |
| ) |
| for (toolchain_name, toolchain_type) in x86_host_toolchains |
| ] |
| |
| # Toolchains for linux musl host (x86_64) archs |
| [ |
| toolchain( |
| name = "%s_def" % toolchain_name, |
| exec_compatible_with = [ |
| "//build/bazel/platforms/arch:x86_64", |
| "//build/bazel/platforms/os:linux_musl", |
| ], |
| target_compatible_with = [ |
| "//build/bazel/platforms/arch:x86_64", |
| "//build/bazel/platforms/os:linux_musl", |
| ], |
| toolchain = toolchain_name, |
| toolchain_type = toolchain_type, |
| ) |
| for (toolchain_name, toolchain_type) in x86_64_musl_host_toolchains |
| ] |
| |
| # Toolchains for linux musl target (non-host) x86 arch |
| [ |
| toolchain( |
| name = "%s_def" % toolchain_name, |
| exec_compatible_with = [ |
| "//build/bazel/platforms/arch:x86_64", |
| "//build/bazel/platforms/os:linux_musl", |
| ], |
| target_compatible_with = [ |
| "//build/bazel/platforms/arch:x86", |
| "//build/bazel/platforms/os:linux_musl", |
| ], |
| toolchain = toolchain_name, |
| toolchain_type = toolchain_type, |
| ) |
| for (toolchain_name, toolchain_type) in x86_musl_host_toolchains |
| ] |
| |
| cc_import( |
| name = "libclang_rt", |
| static_library = select(libclang_rt_prebuilt_map), |
| ) |
| |
| [alias( |
| name = "llvm-%s" % tool, |
| actual = generated_config_constants.ClangVersion + "/bin/llvm-%s" % tool, |
| visibility = ["//visibility:public"], |
| ) for tool in [ |
| "ar", |
| "readelf", |
| "objcopy", |
| "strip", |
| ]] |
| |
| [alias( |
| name = tool, |
| actual = generated_config_constants.ClangVersion + "/bin/" + tool, |
| visibility = ["//visibility:public"], |
| ) for tool in [ |
| "clang-tidy", |
| "clang-tidy.sh", |
| "clang-tidy.real", |
| ]] |
| |
| # Test tools used by Bazel tests. |
| filegroup( |
| name = "test_tools", |
| srcs = [ |
| generated_config_constants.ClangVersion + "/bin/llvm-readelf", |
| generated_config_constants.ClangVersion + "/bin/llvm-nm", |
| ], |
| visibility = ["//build/bazel/tests:__subpackages__"], |
| ) |
| |
| cc_toolchain_features_cfi_test_suite( |
| name = "cc_toolchain_features_cfi_tests", |
| ) |
| |
| cc_toolchain_features_pack_relocation_test_suite( |
| name = "cc_toolchain_features_pack_relocation_tests", |
| ) |
| |
| cc_toolchain_features_lto_test_suite( |
| name = "cc_toolchain_features_thinlto_tests", |
| ) |
| |
| cc_toolchain_features_ubsan_test_suite( |
| name = "cc_toolchain_features_ubsan_tests", |
| ) |
| |
| cc_toolchain_features_env_based_flags_test_suite( |
| name = "cc_toolchain_features_env_based_flags_tests", |
| ) |
| |
| cc_toolchain_features_flag_order_test_suite( |
| name = "cc_toolchain_features_flag_order_tests", |
| ) |
| |
| cc_toolchain_features_linker_alignment_test_suite( |
| name = "cc_toolchain_features_linker_alignment_tests", |
| ) |
| |
| bool_flag( |
| name = "auto_zero_initialize_env", |
| build_setting_default = is_env_true(env.get("AUTO_ZERO_INITIALIZE")), |
| ) |
| |
| bool_flag( |
| name = "auto_pattern_initialize_env", |
| build_setting_default = is_env_true(env.get("AUTO_PATTERN_INITIALIZE")), |
| ) |
| |
| bool_flag( |
| name = "auto_uninitialize_env", |
| build_setting_default = is_env_true(env.get("AUTO_UNINITIALIZE")), |
| ) |
| |
| bool_flag( |
| name = "use_ccache_env", |
| build_setting_default = is_env_true(env.get("USE_CCACHE")), |
| ) |
| |
| bool_flag( |
| name = "llvm_next_env", |
| build_setting_default = is_env_true(env.get("LLVM_NEXT")), |
| ) |
| |
| bool_flag( |
| name = "allow_unknown_warning_option_env", |
| build_setting_default = is_env_true(env.get("ALLOW_UNKNOWN_WARNING_OPTION")), |
| ) |