Make '--define=using_cuda_nvcc' temporarily working again until downstream projects have transitioned.

PiperOrigin-RevId: 360675718
Change-Id: Iacf19f732bd49258a1db6467e114effcbcdf6b38
This commit is contained in:
Christian Sigg 2021-03-03 08:29:03 -08:00 committed by TensorFlower Gardener
parent 3f03effd31
commit 44b6753cc2
2 changed files with 35 additions and 6 deletions

View File

@ -96,3 +96,22 @@ def cuda_header_library(
def cuda_library(copts = [], **kwargs):
"""Wrapper over cc_library which adds default CUDA options."""
native.cc_library(copts = cuda_default_copts() + copts, **kwargs)
EnableCudaInfo = provider()
def _enable_cuda_flag_impl(ctx):
value = ctx.build_setting_value
if ctx.attr.enable_override:
print(
"\n\033[1;33mWarning:\033[0m '--define=using_cuda_nvcc' will be " +
"unsupported soon. Use '--@local_config_cuda//:enable_cuda' " +
"instead."
)
value = True
return EnableCudaInfo(value = value)
enable_cuda_flag = rule(
implementation = _enable_cuda_flag_impl,
build_setting = config.bool(flag = True),
attrs = {"enable_override": attr.bool()},
)

View File

@ -1,8 +1,5 @@
load(
"@bazel_skylib//rules:common_settings.bzl",
"bool_flag",
"string_flag",
)
load("@local_config_cuda//cuda:build_defs.bzl", "enable_cuda_flag")
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
package(default_visibility = ["//visibility:public"])
@ -10,9 +7,13 @@ package(default_visibility = ["//visibility:public"])
#
# Enable with '--@local_config_cuda//:enable_cuda', or indirectly with
# ./configure or '--config=cuda'.
bool_flag(
enable_cuda_flag(
name = "enable_cuda",
build_setting_default = False,
enable_override = select({
":define_using_cuda_nvcc": True,
"//conditions:default": False,
}),
)
# Config setting whether CUDA support has been requested.
@ -48,3 +49,12 @@ config_setting(
name = "is_cuda_compiler_nvcc",
flag_values = {":cuda_compiler": "nvcc"},
)
# Config setting to keep `--define=using_cuda_nvcc=true` working.
# TODO(b/174244321): Remove when downstream projects have been fixed, along
# with the enable_cuda_flag rule in cuda:build_defs.bzl.tpl.
config_setting(
name = "define_using_cuda_nvcc",
define_values = {"using_cuda_nvcc": "true"},
visibility = ["//visibility:private"],
)