xref: /aosp_15_r20/external/pytorch/tools/bazel.bzl (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1*da0073e9SAndroid Build Coastguard Workerload("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
2*da0073e9SAndroid Build Coastguard Workerload("@rules_cuda//cuda:defs.bzl", "cuda_library", "requires_cuda_enabled")
3*da0073e9SAndroid Build Coastguard Workerload("@rules_python//python:defs.bzl", "py_binary", "py_library")
4*da0073e9SAndroid Build Coastguard Workerload("@pip_deps//:requirements.bzl", "requirement")
5*da0073e9SAndroid Build Coastguard Workerload("@pytorch//c10/macros:cmake_configure_file.bzl", "cmake_configure_file")
6*da0073e9SAndroid Build Coastguard Workerload("@pytorch//tools/config:defs.bzl", "if_cuda")
7*da0073e9SAndroid Build Coastguard Worker
8*da0073e9SAndroid Build Coastguard Workerdef _genrule(**kwds):
9*da0073e9SAndroid Build Coastguard Worker    if _enabled(**kwds):
10*da0073e9SAndroid Build Coastguard Worker        native.genrule(**kwds)
11*da0073e9SAndroid Build Coastguard Worker
12*da0073e9SAndroid Build Coastguard Workerdef _is_cpu_static_dispatch_build():
13*da0073e9SAndroid Build Coastguard Worker    return False
14*da0073e9SAndroid Build Coastguard Worker
15*da0073e9SAndroid Build Coastguard Worker# Rules implementation for the Bazel build system. Since the common
16*da0073e9SAndroid Build Coastguard Worker# build structure aims to replicate Bazel as much as possible, most of
17*da0073e9SAndroid Build Coastguard Worker# the rules simply forward to the Bazel definitions.
18*da0073e9SAndroid Build Coastguard Workerrules = struct(
19*da0073e9SAndroid Build Coastguard Worker    cc_binary = cc_binary,
20*da0073e9SAndroid Build Coastguard Worker    cc_library = cc_library,
21*da0073e9SAndroid Build Coastguard Worker    cc_test = cc_test,
22*da0073e9SAndroid Build Coastguard Worker    cmake_configure_file = cmake_configure_file,
23*da0073e9SAndroid Build Coastguard Worker    cuda_library = cuda_library,
24*da0073e9SAndroid Build Coastguard Worker    filegroup = native.filegroup,
25*da0073e9SAndroid Build Coastguard Worker    genrule = _genrule,
26*da0073e9SAndroid Build Coastguard Worker    glob = native.glob,
27*da0073e9SAndroid Build Coastguard Worker    if_cuda = if_cuda,
28*da0073e9SAndroid Build Coastguard Worker    is_cpu_static_dispatch_build = _is_cpu_static_dispatch_build,
29*da0073e9SAndroid Build Coastguard Worker    py_binary = py_binary,
30*da0073e9SAndroid Build Coastguard Worker    py_library = py_library,
31*da0073e9SAndroid Build Coastguard Worker    requirement = requirement,
32*da0073e9SAndroid Build Coastguard Worker    requires_cuda_enabled = requires_cuda_enabled,
33*da0073e9SAndroid Build Coastguard Worker    select = select,
34*da0073e9SAndroid Build Coastguard Worker    test_suite = native.test_suite,
35*da0073e9SAndroid Build Coastguard Worker)
36*da0073e9SAndroid Build Coastguard Worker
37*da0073e9SAndroid Build Coastguard Workerdef _enabled(tags = [], **_kwds):
38*da0073e9SAndroid Build Coastguard Worker    """Determines if the target is enabled."""
39*da0073e9SAndroid Build Coastguard Worker    return "-bazel" not in tags
40