diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CToolchainSelectionUtils.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CToolchainSelectionUtils.java index 7090fab25decf1..4ed99f7ad17844 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CToolchainSelectionUtils.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CToolchainSelectionUtils.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.rules.cpp; import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; import com.google.devtools.build.lib.analysis.config.InvalidConfigurationException; import com.google.devtools.build.lib.util.StringUtil; import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig; @@ -126,7 +127,12 @@ private static CToolchain getToolchainByIdentifier( } if (selectedToolchain == null) { throw new InvalidConfigurationException( - String.format("Toolchain identifier '%s' was not found", toolchainIdentifier)); + String.format( + "Toolchain identifier '%s' was not found, valid identifiers are %s", + toolchainIdentifier, + proto.getToolchainList().stream() + .map(CToolchain::getToolchainIdentifier) + .collect(ImmutableList.toImmutableList()))); } return selectedToolchain; } diff --git a/src/main/protobuf/crosstool_config.proto b/src/main/protobuf/crosstool_config.proto index abc5d089cdb8a4..01fdb54a43def8 100644 --- a/src/main/protobuf/crosstool_config.proto +++ b/src/main/protobuf/crosstool_config.proto @@ -521,7 +521,8 @@ message CrosstoolRelease { // not used for that purpose (or anything else) anymore. Please also don't add // new uses of this field. optional string default_target_cpu = 3; - // The default toolchain to use for each given cpu. + // Deprecated: The default toolchain to use for each given cpu. + // Use cc_toolchain_suite.toolchains with only cpu specified instead repeated DefaultCpuToolchain default_toolchain = 4; // All the toolchains in this release. diff --git a/src/test/shell/bazel/bazel_sandboxing_test.sh b/src/test/shell/bazel/bazel_sandboxing_test.sh index aa9815faec6e43..0a45df94352564 100755 --- a/src/test/shell/bazel/bazel_sandboxing_test.sh +++ b/src/test/shell/bazel/bazel_sandboxing_test.sh @@ -657,9 +657,10 @@ EOF # Replace the target_root_placeholder with the actual target_root sed -i "s|target_root_placeholder|$target_root|g" downloaded_toolchain/CROSSTOOL + sed -i "s|name = 'cc-compiler-k8',|name = 'cc-compiler-k8', toolchain_identifier = 'linux_gnu_x86',|g" downloaded_toolchain/BUILD # Prepare the bazel command flags - flags="--crosstool_top=@x86_64_unknown_linux_gnu//:toolchain --verbose_failures --spawn_strategy=sandboxed" + flags="--crosstool_top=@x86_64_unknown_linux_gnu//:toolchain --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --verbose_failures --spawn_strategy=sandboxed" flags="${flags} --sandbox_add_mount_pair=${source}:${target}" # Execute the bazel build command without creating the target. Should fail. diff --git a/src/test/shell/bazel/testdata/bazel_toolchain_test_data/tools/arm_compiler/BUILD.linaro b/src/test/shell/bazel/testdata/bazel_toolchain_test_data/tools/arm_compiler/BUILD.linaro index bdbd57f3ea4d66..9db59dce83b227 100644 --- a/src/test/shell/bazel/testdata/bazel_toolchain_test_data/tools/arm_compiler/BUILD.linaro +++ b/src/test/shell/bazel/testdata/bazel_toolchain_test_data/tools/arm_compiler/BUILD.linaro @@ -30,6 +30,8 @@ cc_toolchain_suite( name = "toolchain", # target_cpu | compiler toolchains = { + "armeabi-v7a": "cc-compiler-armeabi-v7a", + "k8": "cc-compiler-k8", "armeabi-v7a|gcc": "cc-compiler-armeabi-v7a", "k8|compiler": "cc-compiler-k8", }, @@ -69,6 +71,7 @@ filegroup( cc_toolchain( name = "cc-compiler-armeabi-v7a", + toolchain_identifier = "armeabi-v7a", all_files = ":linaro_linux_all_files", ar_files = "//tools/arm_compiler/linaro_linux_gcc:ar", as_files = "//tools/arm_compiler/linaro_linux_gcc:as", @@ -86,6 +89,7 @@ cc_toolchain( cc_toolchain( name = "cc-compiler-k8", + toolchain_identifier = "local", all_files = ":empty", ar_files = ":empty", as_files = ":empty", diff --git a/src/test/shell/bazel/testdata/bazel_toolchain_test_data/tools/arm_compiler/CROSSTOOL b/src/test/shell/bazel/testdata/bazel_toolchain_test_data/tools/arm_compiler/CROSSTOOL index 090cf594ad1acd..d9e45a4e01d109 100644 --- a/src/test/shell/bazel/testdata/bazel_toolchain_test_data/tools/arm_compiler/CROSSTOOL +++ b/src/test/shell/bazel/testdata/bazel_toolchain_test_data/tools/arm_compiler/CROSSTOOL @@ -1,16 +1,5 @@ major_version: "local" minor_version: "" -default_target_cpu: "armeabi-v7a" - -default_toolchain { - cpu: "armeabi-v7a" - toolchain_identifier: "clang_linux_armhf" -} - -default_toolchain { - cpu: "k8" - toolchain_identifier: "local" -} toolchain { abi_version: "gcc" @@ -29,7 +18,7 @@ toolchain { target_libc: "glibc_2.19" target_cpu: "armeabi-v7a" target_system_name: "arm_a15" - toolchain_identifier: "clang_linux_armhf" + toolchain_identifier: "armeabi-v7a" tool_path { name: "ar" path: "linaro_linux_gcc/arm-linux-gnueabihf-ar" } tool_path { name: "compat-ld" path: "linaro_linux_gcc/arm-linux-gnueabihf-ld" } diff --git a/tools/cpp/BUILD b/tools/cpp/BUILD index 7e271fa2748bc9..ee8f1d2252b493 100644 --- a/tools/cpp/BUILD +++ b/tools/cpp/BUILD @@ -93,17 +93,17 @@ cc_toolchain_suite( "armeabi-v7a|compiler": ":cc-compiler-armeabi-v7a", "darwin|compiler": ":cc-compiler-darwin", "freebsd|compiler": ":cc-compiler-freebsd", - "local|compiler": ":cc-compiler-local", + "local|compiler": ":cc-compiler-local-local", "x64_windows|compiler": ":cc-compiler-x64_windows", "x64_windows_msvc|compiler": ":cc-compiler-x64_windows_msvc", "ppc|compiler": ":cc-compiler-ppc", - "k8": ":cc-compiler-local", - "piii": ":cc-compiler-local", - "arm": ":cc-compiler-local", - "aarch64": ":cc-compiler-local", - "s390x": ":cc-compiler-local", - "ppc": ":cc-compiler-local", - "ppc64": ":cc-compiler-local", + "k8": ":cc-compiler-local-k8", + "piii": ":cc-compiler-local-piii", + "arm": ":cc-compiler-local-arm", + "aarch64": ":cc-compiler-local-aarch64", + "s390x": ":cc-compiler-local-s390x", + "ppc": ":cc-compiler-local-ppc", + "ppc64": ":cc-compiler-local-ppc64", "darwin": ":cc-compiler-darwin", "freebsd": ":cc-compiler-freebsd", "armeabi-v7a": ":cc-compiler-armeabi-v7a", @@ -124,6 +124,7 @@ cc_toolchain( static_runtime_libs = [":empty"], strip_files = ":empty", supports_param_files = 1, + toolchain_identifier = "local_linux", ) toolchain( @@ -150,6 +151,7 @@ cc_toolchain( static_runtime_libs = [":empty"], strip_files = ":empty", supports_param_files = 1, + toolchain_identifier = "local_linux", ) toolchain( @@ -176,6 +178,7 @@ cc_toolchain( static_runtime_libs = [":empty"], strip_files = ":empty", supports_param_files = 1, + toolchain_identifier = "local_linux", ) toolchain( @@ -202,6 +205,7 @@ cc_toolchain( static_runtime_libs = [":empty"], strip_files = ":empty", supports_param_files = 1, + toolchain_identifier = "local_linux", ) toolchain( @@ -230,6 +234,7 @@ cc_toolchain( static_runtime_libs = [":empty"], strip_files = ":empty", supports_param_files = 0, + toolchain_identifier = "local_darwin", ) toolchain( @@ -258,6 +263,7 @@ cc_toolchain( static_runtime_libs = [":empty"], strip_files = ":empty", supports_param_files = 0, + toolchain_identifier = "local_freebsd", ) toolchain( @@ -286,6 +292,7 @@ cc_toolchain( static_runtime_libs = [":empty"], strip_files = ":empty", supports_param_files = 0, + toolchain_identifier = "local_windows_msys64", ) toolchain( @@ -314,6 +321,7 @@ cc_toolchain( static_runtime_libs = [":empty"], strip_files = ":empty", supports_param_files = 1, + toolchain_identifier = "vc_14_0_x64", ) toolchain( diff --git a/tools/cpp/BUILD.empty b/tools/cpp/BUILD.empty index a3c591e96d0bd3..f503345d9a4770 100644 --- a/tools/cpp/BUILD.empty +++ b/tools/cpp/BUILD.empty @@ -37,6 +37,7 @@ cc_toolchain_suite( cc_toolchain( name = "local", + toolchain_identifier = "local", all_files = ":empty", compiler_files = ":empty", cpu = "local", diff --git a/tools/cpp/BUILD.static.freebsd b/tools/cpp/BUILD.static.freebsd index c27ae4ea882580..7fed316ade2c92 100644 --- a/tools/cpp/BUILD.static.freebsd +++ b/tools/cpp/BUILD.static.freebsd @@ -42,6 +42,7 @@ cc_toolchain_suite( cc_toolchain( name = "cc-compiler-freebsd", + toolchain_identifier = "local_freebsd", all_files = ":empty", compiler_files = ":empty", cpu = "local", @@ -70,6 +71,7 @@ toolchain( cc_toolchain( name = "cc-compiler-armeabi-v7a", + toolchain_identifier = "stub_armeabi-v7a", all_files = ":empty", compiler_files = ":empty", cpu = "local", diff --git a/tools/cpp/BUILD.static.windows b/tools/cpp/BUILD.static.windows index 37bb810ff0f4d5..88ed029a9eb3e2 100644 --- a/tools/cpp/BUILD.static.windows +++ b/tools/cpp/BUILD.static.windows @@ -37,13 +37,15 @@ cc_toolchain_suite( "x64_windows|msvc-cl": ":cc-compiler-x64_windows", "x64_windows|msys-gcc": ":cc-compiler-x64_windows_msys", "x64_windows|mingw-gcc": ":cc-compiler-x64_windows_mingw", - "x64_windows": ":cc-compiler-x64_windows_msys", + "x64_windows_msys": ":cc-compiler-x64_windows_msys", + "x64_windows": ":cc-compiler-x64_windows", "armeabi-v7a": ":cc-compiler-armeabi-v7a", }, ) cc_toolchain( name = "cc-compiler-x64_windows_msys", + toolchain_identifier = "msys_x64", all_files = ":empty", compiler_files = ":empty", cpu = "local", @@ -73,6 +75,7 @@ toolchain( cc_toolchain( name = "cc-compiler-x64_windows_mingw", + toolchain_identifier = "msys_x64_mingw", all_files = ":empty", compiler_files = ":empty", cpu = "x64_windows", @@ -102,6 +105,7 @@ toolchain( cc_toolchain( name = "cc-compiler-x64_windows", + toolchain_identifier = "msvc_x64", all_files = ":empty", compiler_files = ":empty", cpu = "x64_windows", @@ -130,6 +134,7 @@ toolchain( cc_toolchain( name = "cc-compiler-armeabi-v7a", + toolchain_identifier = "stub_armeabi-v7a", all_files = ":empty", compiler_files = ":empty", cpu = "local", diff --git a/tools/cpp/BUILD.tpl b/tools/cpp/BUILD.tpl index a7657fef61656a..b68c00fe22fa82 100644 --- a/tools/cpp/BUILD.tpl +++ b/tools/cpp/BUILD.tpl @@ -56,6 +56,7 @@ cc_toolchain_suite( cc_toolchain( name = "cc-compiler-%{name}", + toolchain_identifier = "local", all_files = ":compiler_deps", compiler_files = ":compiler_deps", cpu = "%{name}", @@ -85,6 +86,7 @@ toolchain( # Android tooling requires a default toolchain for the armeabi-v7a cpu. cc_toolchain( name = "cc-compiler-armeabi-v7a", + toolchain_identifier = "stub_armeabi-v7a", all_files = ":empty", compiler_files = ":empty", cpu = "local", diff --git a/tools/cpp/CROSSTOOL b/tools/cpp/CROSSTOOL index a3dfc3121f7ed6..a41b8822a964a4 100644 --- a/tools/cpp/CROSSTOOL +++ b/tools/cpp/CROSSTOOL @@ -1,57 +1,5 @@ major_version: "local" minor_version: "" -default_target_cpu: "same_as_host" - -default_toolchain { - cpu: "k8" - toolchain_identifier: "local_linux" -} -default_toolchain { - cpu: "piii" - toolchain_identifier: "local_linux" -} -default_toolchain { - cpu: "darwin" - toolchain_identifier: "local_darwin" -} -default_toolchain { - cpu: "freebsd" - toolchain_identifier: "local_freebsd" -} -default_toolchain { - cpu: "armeabi-v7a" - toolchain_identifier: "stub_armeabi-v7a" -} -default_toolchain { - cpu: "arm" - toolchain_identifier: "local_linux" -} -default_toolchain { - cpu: "aarch64" - toolchain_identifier: "local_linux" -} -default_toolchain { - cpu: "x64_windows" - toolchain_identifier: "local_windows_msys64" -} -default_toolchain { - cpu: "x64_windows_msvc" - toolchain_identifier: "vc_14_0_x64" -} -default_toolchain { - cpu: "s390x" - toolchain_identifier: "local_linux" -} - -default_toolchain { - cpu: "ppc" - toolchain_identifier: "local_linux" -} - -default_toolchain { - cpu: "ppc64" - toolchain_identifier: "local_linux" -} toolchain { abi_version: "armeabi-v7a" diff --git a/tools/cpp/CROSSTOOL.empty b/tools/cpp/CROSSTOOL.empty index 945d98785d2b72..f1ecf9bf83e682 100644 --- a/tools/cpp/CROSSTOOL.empty +++ b/tools/cpp/CROSSTOOL.empty @@ -1,6 +1,5 @@ major_version: "local" minor_version: "" -default_target_cpu: "local" toolchain { abi_version: "local" diff --git a/tools/cpp/CROSSTOOL.tpl b/tools/cpp/CROSSTOOL.tpl index 5f09aef56554fc..1f788f5d4d8387 100644 --- a/tools/cpp/CROSSTOOL.tpl +++ b/tools/cpp/CROSSTOOL.tpl @@ -14,37 +14,6 @@ major_version: "local" minor_version: "" -default_target_cpu: "same_as_host" - -default_toolchain { - cpu: "%{cpu}" - toolchain_identifier: "%{default_toolchain_name}" -} - -default_toolchain { - cpu: "armeabi-v7a" - toolchain_identifier: "stub_armeabi-v7a" -} - -default_toolchain { - cpu: "x64_windows" - toolchain_identifier: "msvc_x64" -} - -default_toolchain { - cpu: "x64_windows_msvc" - toolchain_identifier: "msvc_x64" -} - -default_toolchain { - cpu: "x64_windows_msys" - toolchain_identifier: "msys_x64" -} - -default_toolchain { - cpu: "s390x" - toolchain_identifier: "%{toolchain_name}" -} # Android tooling requires a default toolchain for the armeabi-v7a cpu. toolchain { diff --git a/tools/osx/crosstool/BUILD.tpl b/tools/osx/crosstool/BUILD.tpl index 83f40b471dee94..6310cb55a4711d 100644 --- a/tools/osx/crosstool/BUILD.tpl +++ b/tools/osx/crosstool/BUILD.tpl @@ -57,6 +57,9 @@ cc_toolchain_suite( [ apple_cc_toolchain( name = "cc-compiler-" + arch, + toolchain_identifier = ( + arch if arch != "armeabi-v7a" else "stub_armeabi-v7a" + ), all_files = ":osx_tools_" + arch, compiler_files = ":osx_tools_" + arch, cpu = arch,