xref: /aosp_15_r20/external/pytorch/third_party/glog.buck.bzl (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1GLOG_CONFIG_HEADERS = [
2    "vlog_is_on.h",
3    "stl_logging.h",
4    "raw_logging.h",
5    "logging.h",
6]
7
8GLOG_SED_COMMAND = " ".join([
9    "sed",
10    "-e 's/@ac_cv_cxx_using_operator@/1/g'",
11    "-e 's/@ac_cv_have_unistd_h@/1/g'",
12    "-e 's/@ac_cv_have_stdint_h@/1/g'",
13    "-e 's/@ac_cv_have_systypes_h@/1/g'",
14    "-e 's/@ac_cv_have_libgflags@/0/g'",
15    "-e 's/@ac_cv_have_uint16_t@/1/g'",
16    "-e 's/@ac_cv_have___builtin_expect@/1/g'",
17    "-e 's/@ac_cv_have_.*@/0/g'",
18    "-e 's/@ac_google_start_namespace@/namespace google {/g'",
19    "-e 's/@ac_google_end_namespace@/}/g'",
20    "-e 's/@ac_google_namespace@/google/g'",
21    "-e 's/@ac_cv___attribute___noinline@/__attribute__((noinline))/g'",
22    "-e 's/@ac_cv___attribute___noreturn@/__attribute__((noreturn))/g'",
23    "-e 's/@ac_cv___attribute___printf_4_5@/__attribute__((__format__ (__printf__, 4, 5)))/g'",
24])
25
26def define_glog():
27    cxx_library(
28        name = "glog",
29        srcs = [
30            "glog/src/demangle.cc",
31            "glog/src/vlog_is_on.cc",
32            "glog/src/symbolize.cc",
33            "glog/src/raw_logging.cc",
34            "glog/src/logging.cc",
35            "glog/src/signalhandler.cc",
36            "glog/src/utilities.cc",
37        ],
38        exported_headers = [":glog_{}".format(header) for header in GLOG_CONFIG_HEADERS],
39        header_namespace = "glog",
40        compiler_flags = [
41            "-Wno-sign-compare",
42            "-Wno-unused-function",
43            "-Wno-unused-local-typedefs",
44            "-Wno-unused-variable",
45            "-Wno-deprecated-declarations",
46        ],
47        preferred_linkage = "static",
48        exported_linker_flags = [],
49        exported_preprocessor_flags = [
50            "-DGLOG_NO_ABBREVIATED_SEVERITIES",
51            "-DGLOG_STL_LOGGING_FOR_UNORDERED",
52            "-DGOOGLE_GLOG_DLL_DECL=",
53            "-DGOOGLE_NAMESPACE=google",
54            # this is required for buck build
55            "-DGLOG_BAZEL_BUILD",
56            "-DHAVE_PTHREAD",
57            # Allows src/logging.cc to determine the host name.
58            "-DHAVE_SYS_UTSNAME_H",
59            # For src/utilities.cc.
60            "-DHAVE_SYS_SYSCALL_H",
61            "-DHAVE_SYS_TIME_H",
62            "-DHAVE_STDINT_H",
63            "-DHAVE_STRING_H",
64            # Enable dumping stacktrace upon sigaction.
65            "-DHAVE_SIGACTION",
66            # For logging.cc.
67            "-DHAVE_PREAD",
68            "-DHAVE___ATTRIBUTE__",
69        ],
70        deps = [":glog_config"],
71        soname = "libglog.$(ext)",
72        visibility = ["PUBLIC"],
73    )
74
75    cxx_library(
76        name = "glog_config",
77        header_namespace = "",
78        exported_headers = {
79            "config.h": ":glog_config.h",
80            "glog/log_severity.h": "glog/src/glog/log_severity.h",
81        },
82    )
83
84    genrule(
85        name = "glog_config.h",
86        srcs = ["glog/src/config.h.cmake.in"],
87        out = "config.h",
88        cmd = "awk '{ gsub(/^#cmakedefine/, \"//cmakedefine\"); print; }' $SRCS > $OUT",
89    )
90
91    for header in GLOG_CONFIG_HEADERS:
92        genrule(
93            name = "glog_{}".format(header),
94            out = header,
95            srcs = ["glog/src/glog/{}.in".format(header)],
96            cmd = "{} $SRCS > $OUT".format(GLOG_SED_COMMAND),
97        )
98