Skip to content

Commit c3fb1db

Browse files
hlopkoCopybara-Service
authored andcommitted
Do not use CROSSTOOL to select cc_toolchain
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
1 parent 11642e9 commit c3fb1db

14 files changed

Lines changed: 46 additions & 108 deletions

File tree

‎src/main/java/com/google/devtools/build/lib/rules/cpp/CToolchainSelectionUtils.java‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package com.google.devtools.build.lib.rules.cpp;
1515

1616
import com.google.common.base.Preconditions;
17+
import com.google.common.collect.ImmutableList;
1718
import com.google.devtools.build.lib.analysis.config.InvalidConfigurationException;
1819
import com.google.devtools.build.lib.util.StringUtil;
1920
import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig;
@@ -126,7 +127,12 @@ private static CToolchain getToolchainByIdentifier(
126127
}
127128
if (selectedToolchain == null) {
128129
throw new InvalidConfigurationException(
129-
String.format("Toolchain identifier '%s' was not found", toolchainIdentifier));
130+
String.format(
131+
"Toolchain identifier '%s' was not found, valid identifiers are %s",
132+
toolchainIdentifier,
133+
proto.getToolchainList().stream()
134+
.map(CToolchain::getToolchainIdentifier)
135+
.collect(ImmutableList.toImmutableList())));
130136
}
131137
return selectedToolchain;
132138
}

‎src/main/protobuf/crosstool_config.proto‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,8 @@ message CrosstoolRelease {
521521
// not used for that purpose (or anything else) anymore. Please also don't add
522522
// new uses of this field.
523523
optional string default_target_cpu = 3;
524-
// The default toolchain to use for each given cpu.
524+
// Deprecated: The default toolchain to use for each given cpu.
525+
// Use cc_toolchain_suite.toolchains with only cpu specified instead
525526
repeated DefaultCpuToolchain default_toolchain = 4;
526527

527528
// All the toolchains in this release.

‎src/test/shell/bazel/bazel_sandboxing_test.sh‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,9 +657,10 @@ EOF
657657

658658
# Replace the target_root_placeholder with the actual target_root
659659
sed -i "s|target_root_placeholder|$target_root|g" downloaded_toolchain/CROSSTOOL
660+
sed -i "s|name = 'cc-compiler-k8',|name = 'cc-compiler-k8', toolchain_identifier = 'linux_gnu_x86',|g" downloaded_toolchain/BUILD
660661

661662
# Prepare the bazel command flags
662-
flags="--crosstool_top=@x86_64_unknown_linux_gnu//:toolchain --verbose_failures --spawn_strategy=sandboxed"
663+
flags="--crosstool_top=@x86_64_unknown_linux_gnu//:toolchain --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --verbose_failures --spawn_strategy=sandboxed"
663664
flags="${flags} --sandbox_add_mount_pair=${source}:${target}"
664665

665666
# Execute the bazel build command without creating the target. Should fail.

‎src/test/shell/bazel/testdata/bazel_toolchain_test_data/tools/arm_compiler/BUILD.linaro‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ cc_toolchain_suite(
3030
name = "toolchain",
3131
# target_cpu | compiler
3232
toolchains = {
33+
"armeabi-v7a": "cc-compiler-armeabi-v7a",
34+
"k8": "cc-compiler-k8",
3335
"armeabi-v7a|gcc": "cc-compiler-armeabi-v7a",
3436
"k8|compiler": "cc-compiler-k8",
3537
},
@@ -69,6 +71,7 @@ filegroup(
6971

7072
cc_toolchain(
7173
name = "cc-compiler-armeabi-v7a",
74+
toolchain_identifier = "armeabi-v7a",
7275
all_files = ":linaro_linux_all_files",
7376
ar_files = "//tools/arm_compiler/linaro_linux_gcc:ar",
7477
as_files = "//tools/arm_compiler/linaro_linux_gcc:as",
@@ -86,6 +89,7 @@ cc_toolchain(
8689

8790
cc_toolchain(
8891
name = "cc-compiler-k8",
92+
toolchain_identifier = "local",
8993
all_files = ":empty",
9094
ar_files = ":empty",
9195
as_files = ":empty",

‎src/test/shell/bazel/testdata/bazel_toolchain_test_data/tools/arm_compiler/CROSSTOOL‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
major_version: "local"
22
minor_version: ""
3-
default_target_cpu: "armeabi-v7a"
4-
5-
default_toolchain {
6-
cpu: "armeabi-v7a"
7-
toolchain_identifier: "clang_linux_armhf"
8-
}
9-
10-
default_toolchain {
11-
cpu: "k8"
12-
toolchain_identifier: "local"
13-
}
143

154
toolchain {
165
abi_version: "gcc"
@@ -29,7 +18,7 @@ toolchain {
2918
target_libc: "glibc_2.19"
3019
target_cpu: "armeabi-v7a"
3120
target_system_name: "arm_a15"
32-
toolchain_identifier: "clang_linux_armhf"
21+
toolchain_identifier: "armeabi-v7a"
3322

3423
tool_path { name: "ar" path: "linaro_linux_gcc/arm-linux-gnueabihf-ar" }
3524
tool_path { name: "compat-ld" path: "linaro_linux_gcc/arm-linux-gnueabihf-ld" }

‎tools/cpp/BUILD‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,17 @@ cc_toolchain_suite(
9393
"armeabi-v7a|compiler": ":cc-compiler-armeabi-v7a",
9494
"darwin|compiler": ":cc-compiler-darwin",
9595
"freebsd|compiler": ":cc-compiler-freebsd",
96-
"local|compiler": ":cc-compiler-local",
96+
"local|compiler": ":cc-compiler-local-local",
9797
"x64_windows|compiler": ":cc-compiler-x64_windows",
9898
"x64_windows_msvc|compiler": ":cc-compiler-x64_windows_msvc",
9999
"ppc|compiler": ":cc-compiler-ppc",
100-
"k8": ":cc-compiler-local",
101-
"piii": ":cc-compiler-local",
102-
"arm": ":cc-compiler-local",
103-
"aarch64": ":cc-compiler-local",
104-
"s390x": ":cc-compiler-local",
105-
"ppc": ":cc-compiler-local",
106-
"ppc64": ":cc-compiler-local",
100+
"k8": ":cc-compiler-local-k8",
101+
"piii": ":cc-compiler-local-piii",
102+
"arm": ":cc-compiler-local-arm",
103+
"aarch64": ":cc-compiler-local-aarch64",
104+
"s390x": ":cc-compiler-local-s390x",
105+
"ppc": ":cc-compiler-local-ppc",
106+
"ppc64": ":cc-compiler-local-ppc64",
107107
"darwin": ":cc-compiler-darwin",
108108
"freebsd": ":cc-compiler-freebsd",
109109
"armeabi-v7a": ":cc-compiler-armeabi-v7a",
@@ -124,6 +124,7 @@ cc_toolchain(
124124
static_runtime_libs = [":empty"],
125125
strip_files = ":empty",
126126
supports_param_files = 1,
127+
toolchain_identifier = "local_linux",
127128
)
128129

129130
toolchain(
@@ -150,6 +151,7 @@ cc_toolchain(
150151
static_runtime_libs = [":empty"],
151152
strip_files = ":empty",
152153
supports_param_files = 1,
154+
toolchain_identifier = "local_linux",
153155
)
154156

155157
toolchain(
@@ -176,6 +178,7 @@ cc_toolchain(
176178
static_runtime_libs = [":empty"],
177179
strip_files = ":empty",
178180
supports_param_files = 1,
181+
toolchain_identifier = "local_linux",
179182
)
180183

181184
toolchain(
@@ -202,6 +205,7 @@ cc_toolchain(
202205
static_runtime_libs = [":empty"],
203206
strip_files = ":empty",
204207
supports_param_files = 1,
208+
toolchain_identifier = "local_linux",
205209
)
206210

207211
toolchain(
@@ -230,6 +234,7 @@ cc_toolchain(
230234
static_runtime_libs = [":empty"],
231235
strip_files = ":empty",
232236
supports_param_files = 0,
237+
toolchain_identifier = "local_darwin",
233238
)
234239

235240
toolchain(
@@ -258,6 +263,7 @@ cc_toolchain(
258263
static_runtime_libs = [":empty"],
259264
strip_files = ":empty",
260265
supports_param_files = 0,
266+
toolchain_identifier = "local_freebsd",
261267
)
262268

263269
toolchain(
@@ -286,6 +292,7 @@ cc_toolchain(
286292
static_runtime_libs = [":empty"],
287293
strip_files = ":empty",
288294
supports_param_files = 0,
295+
toolchain_identifier = "local_windows_msys64",
289296
)
290297

291298
toolchain(
@@ -314,6 +321,7 @@ cc_toolchain(
314321
static_runtime_libs = [":empty"],
315322
strip_files = ":empty",
316323
supports_param_files = 1,
324+
toolchain_identifier = "vc_14_0_x64",
317325
)
318326

319327
toolchain(

‎tools/cpp/BUILD.empty‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ cc_toolchain_suite(
3737

3838
cc_toolchain(
3939
name = "local",
40+
toolchain_identifier = "local",
4041
all_files = ":empty",
4142
compiler_files = ":empty",
4243
cpu = "local",

‎tools/cpp/BUILD.static.freebsd‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ cc_toolchain_suite(
4242

4343
cc_toolchain(
4444
name = "cc-compiler-freebsd",
45+
toolchain_identifier = "local_freebsd",
4546
all_files = ":empty",
4647
compiler_files = ":empty",
4748
cpu = "local",
@@ -70,6 +71,7 @@ toolchain(
7071

7172
cc_toolchain(
7273
name = "cc-compiler-armeabi-v7a",
74+
toolchain_identifier = "stub_armeabi-v7a",
7375
all_files = ":empty",
7476
compiler_files = ":empty",
7577
cpu = "local",

‎tools/cpp/BUILD.static.windows‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@ cc_toolchain_suite(
3737
"x64_windows|msvc-cl": ":cc-compiler-x64_windows",
3838
"x64_windows|msys-gcc": ":cc-compiler-x64_windows_msys",
3939
"x64_windows|mingw-gcc": ":cc-compiler-x64_windows_mingw",
40-
"x64_windows": ":cc-compiler-x64_windows_msys",
40+
"x64_windows_msys": ":cc-compiler-x64_windows_msys",
41+
"x64_windows": ":cc-compiler-x64_windows",
4142
"armeabi-v7a": ":cc-compiler-armeabi-v7a",
4243
},
4344
)
4445

4546
cc_toolchain(
4647
name = "cc-compiler-x64_windows_msys",
48+
toolchain_identifier = "msys_x64",
4749
all_files = ":empty",
4850
compiler_files = ":empty",
4951
cpu = "local",
@@ -73,6 +75,7 @@ toolchain(
7375

7476
cc_toolchain(
7577
name = "cc-compiler-x64_windows_mingw",
78+
toolchain_identifier = "msys_x64_mingw",
7679
all_files = ":empty",
7780
compiler_files = ":empty",
7881
cpu = "x64_windows",
@@ -102,6 +105,7 @@ toolchain(
102105

103106
cc_toolchain(
104107
name = "cc-compiler-x64_windows",
108+
toolchain_identifier = "msvc_x64",
105109
all_files = ":empty",
106110
compiler_files = ":empty",
107111
cpu = "x64_windows",
@@ -130,6 +134,7 @@ toolchain(
130134

131135
cc_toolchain(
132136
name = "cc-compiler-armeabi-v7a",
137+
toolchain_identifier = "stub_armeabi-v7a",
133138
all_files = ":empty",
134139
compiler_files = ":empty",
135140
cpu = "local",

‎tools/cpp/BUILD.tpl‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ cc_toolchain_suite(
5656

5757
cc_toolchain(
5858
name = "cc-compiler-%{name}",
59+
toolchain_identifier = "local",
5960
all_files = ":compiler_deps",
6061
compiler_files = ":compiler_deps",
6162
cpu = "%{name}",
@@ -85,6 +86,7 @@ toolchain(
8586
# Android tooling requires a default toolchain for the armeabi-v7a cpu.
8687
cc_toolchain(
8788
name = "cc-compiler-armeabi-v7a",
89+
toolchain_identifier = "stub_armeabi-v7a",
8890
all_files = ":empty",
8991
compiler_files = ":empty",
9092
cpu = "local",

0 commit comments

Comments
 (0)