Skip to content

Commit 7dc78cd

Browse files
katrecopybara-github
authored andcommitted
Add explicit execution and target constraints for autodiscovered cc t?
?oolchains. Fixes bazelbuild#8330. Closes bazelbuild#8332. PiperOrigin-RevId: 248383561
1 parent 9cb5c3d commit 7dc78cd

File tree

4 files changed

+52
-38
lines changed

4 files changed

+52
-38
lines changed

src/test/shell/integration/java_integration_test.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,13 @@ constraint_value(
272272
toolchain(
273273
name = 'java_runtime_toolchain',
274274
toolchain = ':runtime',
275-
toolchain_type = '//tools/jdk:runtime_toolchain_type',
275+
toolchain_type = '@bazel_tools//tools/jdk:runtime_toolchain_type',
276276
target_compatible_with = [':constraint'],
277277
)
278278
platform(
279279
name = 'platform',
280-
constraint_values = [":constraint"],
280+
parents = ['@bazel_tools//platforms:host_platform'],
281+
constraint_values = [':constraint'],
281282
)
282283
EOF
283284
else
@@ -294,11 +295,10 @@ toolchain(
294295
)
295296
platform(
296297
name = 'platform',
298+
parents = ['//buildenv/platforms:host_platform'],
297299
constraint_values = [
298-
":constraint",
299-
"//buildenv/platforms/java/constraints:java8",
300-
"//buildenv/platforms:linux",
301-
"//buildenv/platforms:x86_64",
300+
':constraint',
301+
'//buildenv/platforms/java/constraints:java8',
302302
],
303303
)
304304
EOF

tools/cpp/BUILD.tpl

+4-9
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package(default_visibility = ["//visibility:public"])
1818

1919
load(":cc_toolchain_config.bzl", "cc_toolchain_config")
20+
load("@local_config_platform//:constraints.bzl", "HOST_CONSTRAINTS")
2021

2122
licenses(["notice"]) # Apache 2.0
2223

@@ -75,12 +76,8 @@ cc_toolchain_config(
7576

7677
toolchain(
7778
name = "cc-toolchain-%{name}",
78-
exec_compatible_with = [
79-
# TODO(katre): add autodiscovered constraints for host CPU and OS.
80-
],
81-
target_compatible_with = [
82-
# TODO(katre): add autodiscovered constraints for host CPU and OS.
83-
],
79+
exec_compatible_with = HOST_CONSTRAINTS,
80+
target_compatible_with = HOST_CONSTRAINTS,
8481
toolchain = ":cc-compiler-%{name}",
8582
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
8683
)
@@ -109,9 +106,7 @@ cc_toolchain_config(
109106

110107
toolchain(
111108
name = "cc-toolchain-armeabi-v7a",
112-
exec_compatible_with = [
113-
# TODO(katre): add autodiscovered constraints for host CPU and OS.
114-
],
109+
exec_compatible_with = HOST_CONSTRAINTS,
115110
target_compatible_with = [
116111
"@bazel_tools//platforms:arm",
117112
"@bazel_tools//platforms:android",

tools/osx/crosstool/BUILD.tpl

+23-23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package(default_visibility = ["//visibility:public"])
22

3-
load(":osx_archs.bzl", "OSX_TOOLS_ARCHS")
3+
load(":osx_archs.bzl", "OSX_TOOLS_ARCHS", "OSX_TOOLS_CONSTRAINTS")
44
load(":cc_toolchain_config.bzl", "cc_toolchain_config")
55

66
CC_TOOLCHAINS = [(
@@ -10,10 +10,10 @@ CC_TOOLCHAINS = [(
1010
cpu,
1111
":cc-compiler-" + cpu,
1212
) for cpu in OSX_TOOLS_ARCHS] + [
13-
("k8|compiler", ":cc-compiler-darwin_x86_64", ),
14-
("darwin|compiler", ":cc-compiler-darwin_x86_64", ),
15-
("k8", ":cc-compiler-darwin_x86_64", ),
16-
("darwin", ":cc-compiler-darwin_x86_64", ),
13+
("k8|compiler", ":cc-compiler-darwin_x86_64"),
14+
("darwin|compiler", ":cc-compiler-darwin_x86_64"),
15+
("k8", ":cc-compiler-darwin_x86_64"),
16+
("darwin", ":cc-compiler-darwin_x86_64"),
1717
]
1818

1919
cc_library(
@@ -39,13 +39,13 @@ cc_toolchain_suite(
3939
filegroup(
4040
name = "osx_tools_" + arch,
4141
srcs = [
42-
":cc_wrapper",
43-
":libtool",
44-
":make_hashed_objlist.py",
45-
":wrapped_clang",
46-
":wrapped_clang_pp",
47-
":wrapped_ar",
48-
":xcrunwrapper.sh",
42+
":cc_wrapper",
43+
":libtool",
44+
":make_hashed_objlist.py",
45+
":wrapped_ar",
46+
":wrapped_clang",
47+
":wrapped_clang_pp",
48+
":xcrunwrapper.sh",
4949
],
5050
)
5151
for arch in OSX_TOOLS_ARCHS
@@ -54,12 +54,6 @@ cc_toolchain_suite(
5454
[
5555
apple_cc_toolchain(
5656
name = "cc-compiler-" + arch,
57-
toolchain_identifier = (
58-
arch if arch != "armeabi-v7a" else "stub_armeabi-v7a"
59-
),
60-
toolchain_config = ":" + (
61-
arch if arch != "armeabi-v7a" else "stub_armeabi-v7a"
62-
),
6357
all_files = ":osx_tools_" + arch,
6458
ar_files = ":empty",
6559
as_files = ":empty",
@@ -69,15 +63,21 @@ cc_toolchain_suite(
6963
objcopy_files = ":empty",
7064
strip_files = ":osx_tools_" + arch,
7165
supports_param_files = 0,
66+
toolchain_config = ":" + (
67+
arch if arch != "armeabi-v7a" else "stub_armeabi-v7a"
68+
),
69+
toolchain_identifier = (
70+
arch if arch != "armeabi-v7a" else "stub_armeabi-v7a"
71+
),
7272
)
7373
for arch in OSX_TOOLS_ARCHS
7474
]
7575

7676
[
7777
cc_toolchain_config(
7878
name = (arch if arch != "armeabi-v7a" else "stub_armeabi-v7a"),
79-
cpu = arch,
8079
compiler = "compiler",
80+
cpu = arch,
8181
)
8282
for arch in OSX_TOOLS_ARCHS
8383
]
@@ -86,11 +86,11 @@ cc_toolchain_suite(
8686
toolchain(
8787
name = "cc-toolchain-" + arch,
8888
exec_compatible_with = [
89-
# TODO(katre): add autodiscovered constraints for host CPU and OS.
90-
],
91-
target_compatible_with = [
92-
# TODO(katre): add autodiscovered constraints for host CPU and OS.
89+
# These only execute on macOS.
90+
"@bazel_tools//platforms:osx",
91+
"@bazel_tools//platforms:x86_64",
9392
],
93+
target_compatible_with = OSX_TOOLS_CONSTRAINTS[arch],
9494
toolchain = ":cc-compiler-" + arch,
9595
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
9696
)

tools/osx/crosstool/osx_archs.bzl

+19
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,22 @@ OSX_TOOLS_ARCHS = [
3232
"watchos_arm64_32",
3333
"tvos_arm64",
3434
] + OSX_TOOLS_NON_DEVICE_ARCHS
35+
36+
# Target constraints for each arch.
37+
# TODO(apple-rules): Rename osx constraint to macOS.
38+
# TODO(apple-rules): Add constraints for watchos and tvos.
39+
OSX_TOOLS_CONSTRAINTS = {
40+
"darwin_x86_64": ["@bazel_tools//platforms:osx", "@bazel_tools//platforms:x86_64"],
41+
"ios_i386": ["@bazel_tools//platforms:ios", "@bazel_tools//platforms:x86_32"],
42+
"ios_x86_64": ["@bazel_tools//platforms:ios", "@bazel_tools//platforms:x86_64"],
43+
"watchos_i386": ["@bazel_tools//platforms:ios", "@bazel_tools//platforms:x86_32"],
44+
"watchos_x86_64": ["@bazel_tools//platforms:ios", "@bazel_tools//platforms:x86_64"],
45+
"tvos_x86_64": ["@bazel_tools//platforms:ios", "@bazel_tools//platforms:x86_64"],
46+
"armeabi-v7a": ["@bazel_tools//platforms:arm"],
47+
"ios_armv7": ["@bazel_tools//platforms:ios", "@bazel_tools//platforms:arm"],
48+
"ios_arm64": ["@bazel_tools//platforms:ios", "@bazel_tools//platforms:arm"],
49+
"ios_arm64e": ["@bazel_tools//platforms:ios", "@bazel_tools//platforms:arm"],
50+
"watchos_armv7k": ["@bazel_tools//platforms:ios", "@bazel_tools//platforms:arm"],
51+
"watchos_arm64_32": ["@bazel_tools//platforms:ios", "@bazel_tools//platforms:arm"],
52+
"tvos_arm64": ["@bazel_tools//platforms:ios", "@bazel_tools//platforms:arm"],
53+
}

0 commit comments

Comments
 (0)