Skip to content

Commit

Permalink
Do not use CROSSTOOL to select cc_toolchain
Browse files Browse the repository at this point in the history
This is a preparation for flipping
--incompatible_disable_cc_toolchain_label_from_crosstool_proto, which will stop
reading default_toolchain fields from the crosstool and will rely on
cc_toolchain_suite.toolchains containing entries for cpu without compiler.

Migrations docs can be found here:
https://docs.bazel.build/versions/master/skylark/backward-compatibility.html#disallow-using-crosstool-to-select-the-cc_toolchain-label.

RELNOTES: None.
PiperOrigin-RevId: 216470358
  • Loading branch information
hlopko authored and Copybara-Service committed Oct 10, 2018
1 parent 11642e9 commit c3fb1db
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/protobuf/crosstool_config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion src/test/shell/bazel/bazel_sandboxing_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand Down Expand Up @@ -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",
Expand All @@ -86,6 +89,7 @@ cc_toolchain(

cc_toolchain(
name = "cc-compiler-k8",
toolchain_identifier = "local",
all_files = ":empty",
ar_files = ":empty",
as_files = ":empty",
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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" }
Expand Down
24 changes: 16 additions & 8 deletions tools/cpp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -124,6 +124,7 @@ cc_toolchain(
static_runtime_libs = [":empty"],
strip_files = ":empty",
supports_param_files = 1,
toolchain_identifier = "local_linux",
)

toolchain(
Expand All @@ -150,6 +151,7 @@ cc_toolchain(
static_runtime_libs = [":empty"],
strip_files = ":empty",
supports_param_files = 1,
toolchain_identifier = "local_linux",
)

toolchain(
Expand All @@ -176,6 +178,7 @@ cc_toolchain(
static_runtime_libs = [":empty"],
strip_files = ":empty",
supports_param_files = 1,
toolchain_identifier = "local_linux",
)

toolchain(
Expand All @@ -202,6 +205,7 @@ cc_toolchain(
static_runtime_libs = [":empty"],
strip_files = ":empty",
supports_param_files = 1,
toolchain_identifier = "local_linux",
)

toolchain(
Expand Down Expand Up @@ -230,6 +234,7 @@ cc_toolchain(
static_runtime_libs = [":empty"],
strip_files = ":empty",
supports_param_files = 0,
toolchain_identifier = "local_darwin",
)

toolchain(
Expand Down Expand Up @@ -258,6 +263,7 @@ cc_toolchain(
static_runtime_libs = [":empty"],
strip_files = ":empty",
supports_param_files = 0,
toolchain_identifier = "local_freebsd",
)

toolchain(
Expand Down Expand Up @@ -286,6 +292,7 @@ cc_toolchain(
static_runtime_libs = [":empty"],
strip_files = ":empty",
supports_param_files = 0,
toolchain_identifier = "local_windows_msys64",
)

toolchain(
Expand Down Expand Up @@ -314,6 +321,7 @@ cc_toolchain(
static_runtime_libs = [":empty"],
strip_files = ":empty",
supports_param_files = 1,
toolchain_identifier = "vc_14_0_x64",
)

toolchain(
Expand Down
1 change: 1 addition & 0 deletions tools/cpp/BUILD.empty
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ cc_toolchain_suite(

cc_toolchain(
name = "local",
toolchain_identifier = "local",
all_files = ":empty",
compiler_files = ":empty",
cpu = "local",
Expand Down
2 changes: 2 additions & 0 deletions tools/cpp/BUILD.static.freebsd
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
7 changes: 6 additions & 1 deletion tools/cpp/BUILD.static.windows
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions tools/cpp/BUILD.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down Expand Up @@ -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",
Expand Down
52 changes: 0 additions & 52 deletions tools/cpp/CROSSTOOL
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
1 change: 0 additions & 1 deletion tools/cpp/CROSSTOOL.empty
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
major_version: "local"
minor_version: ""
default_target_cpu: "local"

toolchain {
abi_version: "local"
Expand Down
31 changes: 0 additions & 31 deletions tools/cpp/CROSSTOOL.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions tools/osx/crosstool/BUILD.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit c3fb1db

Please sign in to comment.