xref: /aosp_15_r20/external/pytorch/c10/util/build.bzl (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1def define_targets(rules):
2    rules.cc_library(
3        name = "TypeCast",
4        srcs = ["TypeCast.cpp"],
5        hdrs = ["TypeCast.h"],
6        linkstatic = True,
7        local_defines = ["C10_BUILD_MAIN_LIB"],
8        visibility = ["//visibility:public"],
9        deps = [
10            ":base",
11            "//c10/core:ScalarType",
12            "//c10/macros",
13        ],
14    )
15
16    rules.cc_library(
17        name = "base",
18        srcs = rules.glob(
19            ["*.cpp"],
20            exclude = [
21                "TypeCast.cpp",
22                "typeid.cpp",
23            ],
24        ),
25        hdrs = rules.glob(
26            ["*.h"],
27            exclude = [
28                "TypeCast.h",
29                "typeid.h",
30            ],
31        ),
32        linkstatic = True,
33        local_defines = ["C10_BUILD_MAIN_LIB"],
34        visibility = ["//visibility:public"],
35        deps = [
36            ":bit_cast",
37            "//c10/macros",
38            "@fmt",
39        ] + rules.select({
40            "//c10:using_gflags": ["@com_github_gflags_gflags//:gflags"],
41            "//conditions:default": [],
42        }) + rules.select({
43            "//c10:using_glog": ["@com_github_glog//:glog"],
44            "//conditions:default": [],
45        }),
46        # This library uses flags and registration. Do not let the
47        # linker remove them.
48        alwayslink = True,
49    )
50
51    rules.cc_library(
52        name = "bit_cast",
53        hdrs = ["bit_cast.h"],
54        visibility = ["//:__subpackages__"],
55    )
56
57    rules.cc_library(
58        name = "ssize",
59        hdrs = ["ssize.h"],
60        linkstatic = True,
61        visibility = ["//:__subpackages__"],
62        deps = [":base"],
63    )
64
65    rules.cc_library(
66        name = "typeid",
67        srcs = ["typeid.cpp"],
68        hdrs = ["typeid.h"],
69        linkstatic = True,
70        local_defines = ["C10_BUILD_MAIN_LIB"],
71        visibility = ["//visibility:public"],
72        deps = [
73            ":base",
74            "//c10/core:ScalarType",
75            "//c10/macros",
76        ],
77    )
78
79    rules.filegroup(
80        name = "headers",
81        srcs = rules.glob(
82            ["*.h"],
83            exclude = [
84                "bit_cast.h",
85                "ssize.h",
86            ],
87        ),
88        visibility = [
89            "//:__pkg__",
90            "//c10:__pkg__",
91        ],
92    )
93