Skip to content

Commit

Permalink
Add explicit execution and target constraints for autodiscovered cc t?
Browse files Browse the repository at this point in the history
?oolchains.

Fixes #8330.

Closes #8332.

PiperOrigin-RevId: 248383561
  • Loading branch information
katre authored and aehlig committed May 23, 2019
1 parent a9e5caf commit 1641492
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 38 deletions.
12 changes: 6 additions & 6 deletions src/test/shell/integration/java_integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,13 @@ constraint_value(
toolchain(
name = 'java_runtime_toolchain',
toolchain = ':runtime',
toolchain_type = '//tools/jdk:runtime_toolchain_type',
toolchain_type = '@bazel_tools//tools/jdk:runtime_toolchain_type',
target_compatible_with = [':constraint'],
)
platform(
name = 'platform',
constraint_values = [":constraint"],
parents = ['@bazel_tools//platforms:host_platform'],
constraint_values = [':constraint'],
)
EOF
else
Expand All @@ -294,11 +295,10 @@ toolchain(
)
platform(
name = 'platform',
parents = ['//buildenv/platforms:host_platform'],
constraint_values = [
":constraint",
"//buildenv/platforms/java/constraints:java8",
"//buildenv/platforms:linux",
"//buildenv/platforms:x86_64",
':constraint',
'//buildenv/platforms/java/constraints:java8',
],
)
EOF
Expand Down
13 changes: 4 additions & 9 deletions tools/cpp/BUILD.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package(default_visibility = ["//visibility:public"])

load(":cc_toolchain_config.bzl", "cc_toolchain_config")
load("@local_config_platform//:constraints.bzl", "HOST_CONSTRAINTS")

licenses(["notice"]) # Apache 2.0

Expand Down Expand Up @@ -75,12 +76,8 @@ cc_toolchain_config(

toolchain(
name = "cc-toolchain-%{name}",
exec_compatible_with = [
# TODO(katre): add autodiscovered constraints for host CPU and OS.
],
target_compatible_with = [
# TODO(katre): add autodiscovered constraints for host CPU and OS.
],
exec_compatible_with = HOST_CONSTRAINTS,
target_compatible_with = HOST_CONSTRAINTS,
toolchain = ":cc-compiler-%{name}",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)
Expand Down Expand Up @@ -109,9 +106,7 @@ cc_toolchain_config(

toolchain(
name = "cc-toolchain-armeabi-v7a",
exec_compatible_with = [
# TODO(katre): add autodiscovered constraints for host CPU and OS.
],
exec_compatible_with = HOST_CONSTRAINTS,
target_compatible_with = [
"@bazel_tools//platforms:arm",
"@bazel_tools//platforms:android",
Expand Down
46 changes: 23 additions & 23 deletions tools/osx/crosstool/BUILD.tpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package(default_visibility = ["//visibility:public"])

load(":osx_archs.bzl", "OSX_TOOLS_ARCHS")
load(":osx_archs.bzl", "OSX_TOOLS_ARCHS", "OSX_TOOLS_CONSTRAINTS")
load(":cc_toolchain_config.bzl", "cc_toolchain_config")

CC_TOOLCHAINS = [(
Expand All @@ -10,10 +10,10 @@ CC_TOOLCHAINS = [(
cpu,
":cc-compiler-" + cpu,
) for cpu in OSX_TOOLS_ARCHS] + [
("k8|compiler", ":cc-compiler-darwin_x86_64", ),
("darwin|compiler", ":cc-compiler-darwin_x86_64", ),
("k8", ":cc-compiler-darwin_x86_64", ),
("darwin", ":cc-compiler-darwin_x86_64", ),
("k8|compiler", ":cc-compiler-darwin_x86_64"),
("darwin|compiler", ":cc-compiler-darwin_x86_64"),
("k8", ":cc-compiler-darwin_x86_64"),
("darwin", ":cc-compiler-darwin_x86_64"),
]

cc_library(
Expand All @@ -39,13 +39,13 @@ cc_toolchain_suite(
filegroup(
name = "osx_tools_" + arch,
srcs = [
":cc_wrapper",
":libtool",
":make_hashed_objlist.py",
":wrapped_clang",
":wrapped_clang_pp",
":wrapped_ar",
":xcrunwrapper.sh",
":cc_wrapper",
":libtool",
":make_hashed_objlist.py",
":wrapped_ar",
":wrapped_clang",
":wrapped_clang_pp",
":xcrunwrapper.sh",
],
)
for arch in OSX_TOOLS_ARCHS
Expand All @@ -54,12 +54,6 @@ cc_toolchain_suite(
[
apple_cc_toolchain(
name = "cc-compiler-" + arch,
toolchain_identifier = (
arch if arch != "armeabi-v7a" else "stub_armeabi-v7a"
),
toolchain_config = ":" + (
arch if arch != "armeabi-v7a" else "stub_armeabi-v7a"
),
all_files = ":osx_tools_" + arch,
ar_files = ":empty",
as_files = ":empty",
Expand All @@ -69,15 +63,21 @@ cc_toolchain_suite(
objcopy_files = ":empty",
strip_files = ":osx_tools_" + arch,
supports_param_files = 0,
toolchain_config = ":" + (
arch if arch != "armeabi-v7a" else "stub_armeabi-v7a"
),
toolchain_identifier = (
arch if arch != "armeabi-v7a" else "stub_armeabi-v7a"
),
)
for arch in OSX_TOOLS_ARCHS
]

[
cc_toolchain_config(
name = (arch if arch != "armeabi-v7a" else "stub_armeabi-v7a"),
cpu = arch,
compiler = "compiler",
cpu = arch,
)
for arch in OSX_TOOLS_ARCHS
]
Expand All @@ -86,11 +86,11 @@ cc_toolchain_suite(
toolchain(
name = "cc-toolchain-" + arch,
exec_compatible_with = [
# TODO(katre): add autodiscovered constraints for host CPU and OS.
],
target_compatible_with = [
# TODO(katre): add autodiscovered constraints for host CPU and OS.
# These only execute on macOS.
"@bazel_tools//platforms:osx",
"@bazel_tools//platforms:x86_64",
],
target_compatible_with = OSX_TOOLS_CONSTRAINTS[arch],
toolchain = ":cc-compiler-" + arch,
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)
Expand Down
19 changes: 19 additions & 0 deletions tools/osx/crosstool/osx_archs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,22 @@ OSX_TOOLS_ARCHS = [
"watchos_arm64_32",
"tvos_arm64",
] + OSX_TOOLS_NON_DEVICE_ARCHS

# Target constraints for each arch.
# TODO(apple-rules): Rename osx constraint to macOS.
# TODO(apple-rules): Add constraints for watchos and tvos.
OSX_TOOLS_CONSTRAINTS = {
"darwin_x86_64": ["@bazel_tools//platforms:osx", "@bazel_tools//platforms:x86_64"],
"ios_i386": ["@bazel_tools//platforms:ios", "@bazel_tools//platforms:x86_32"],
"ios_x86_64": ["@bazel_tools//platforms:ios", "@bazel_tools//platforms:x86_64"],
"watchos_i386": ["@bazel_tools//platforms:ios", "@bazel_tools//platforms:x86_32"],
"watchos_x86_64": ["@bazel_tools//platforms:ios", "@bazel_tools//platforms:x86_64"],
"tvos_x86_64": ["@bazel_tools//platforms:ios", "@bazel_tools//platforms:x86_64"],
"armeabi-v7a": ["@bazel_tools//platforms:arm"],
"ios_armv7": ["@bazel_tools//platforms:ios", "@bazel_tools//platforms:arm"],
"ios_arm64": ["@bazel_tools//platforms:ios", "@bazel_tools//platforms:arm"],
"ios_arm64e": ["@bazel_tools//platforms:ios", "@bazel_tools//platforms:arm"],
"watchos_armv7k": ["@bazel_tools//platforms:ios", "@bazel_tools//platforms:arm"],
"watchos_arm64_32": ["@bazel_tools//platforms:ios", "@bazel_tools//platforms:arm"],
"tvos_arm64": ["@bazel_tools//platforms:ios", "@bazel_tools//platforms:arm"],
}

0 comments on commit 1641492

Please sign in to comment.