xref: /aosp_15_r20/external/pytorch/c10/cuda/build.bzl (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1def define_targets(rules, extra_defines=[]):
2    rules.cc_library(
3        name = "cuda",
4        srcs = rules.glob(
5            [
6                "*.cpp",
7                "impl/*.cpp",
8            ],
9            exclude = [
10                "test/**/*.cpp",
11            ],
12        ),
13        hdrs = rules.glob(
14            [
15                "*.h",
16                "impl/*.h",
17            ],
18            exclude = [
19                "CUDAMacros.h",
20            ],
21        ),
22        defines = ["USE_CUDA"] + extra_defines,
23        linkstatic = True,
24        local_defines = ["C10_BUILD_MAIN_LIB"],
25        target_compatible_with = rules.requires_cuda_enabled(),
26        visibility = ["//visibility:public"],
27        deps = [
28            ":Macros",
29            "//c10/core:base",
30            "//c10/macros",
31            "//c10/util:base",
32            "@cuda",
33        ],
34        # This library uses registration. Don't let registered
35        # entities be removed.
36        alwayslink = True,
37    )
38
39    rules.cc_library(
40        name = "Macros",
41        srcs = [":cuda_cmake_macros"],
42        hdrs = ["CUDAMacros.h"],
43        linkstatic = True,
44        local_defines = ["C10_BUILD_MAIN_LIB"],
45        visibility = ["//visibility:public"],
46    )
47
48    rules.cmake_configure_file(
49        name = "cuda_cmake_macros",
50        src = "impl/cuda_cmake_macros.h.in",
51        out = "impl/cuda_cmake_macros.h",
52        definitions = [],
53    )
54
55    rules.filegroup(
56        name = "headers",
57        srcs = rules.glob(
58            [
59                "*.h",
60                "impl/*.h",
61            ],
62            exclude = [
63            ],
64        ),
65        visibility = ["//c10:__pkg__"],
66    )
67