|
| 1 | +load("@bazel_skylib//rules:write_file.bzl", "write_file") |
| 2 | +load("@rules_cc//cc:cc_binary.bzl", "cc_binary") |
| 3 | +load("@rules_cc//cc:cc_library.bzl", "cc_library") |
| 4 | + |
| 5 | +LINUX_ONLY = select({ |
| 6 | + "@platforms//os:linux": [], |
| 7 | + "//conditions:default": ["@platforms//:incompatible"], |
| 8 | +}) |
| 9 | + |
| 10 | +# Generate config.h |
| 11 | +write_file( |
| 12 | + name = "gen_config_h", |
| 13 | + out = "config.h", |
| 14 | + content = [ |
| 15 | + "/* config.h - Generated by Bazel */", |
| 16 | + "", |
| 17 | + "/* Define to 1 if you have standard C headers */", |
| 18 | + "#define STDC_HEADERS 1", |
| 19 | + "#define HAVE_STDIO_H 1", |
| 20 | + "#define HAVE_STDLIB_H 1", |
| 21 | + "#define HAVE_STRING_H 1", |
| 22 | + "#define HAVE_STRINGS_H 1", |
| 23 | + "#define HAVE_INTTYPES_H 1", |
| 24 | + "#define HAVE_STDINT_H 1", |
| 25 | + "#define HAVE_UNISTD_H 1", |
| 26 | + "#define HAVE_SYS_TYPES_H 1", |
| 27 | + "#define HAVE_SYS_STAT_H 1", |
| 28 | + "", |
| 29 | + "/* TLS support */", |
| 30 | + "#if defined(__GNUC__) || defined(__clang__)", |
| 31 | + "#define TLS __thread", |
| 32 | + "#endif", |
| 33 | + "", |
| 34 | + "/* Symver attribute support */", |
| 35 | + "#if defined(__GNUC__) || defined(__clang__)", |
| 36 | + "#define HAVE_ATTRIBUTE_SYMVER 1", |
| 37 | + "#endif", |
| 38 | + "", |
| 39 | + "/* Package information */", |
| 40 | + "#define PACKAGE \"numactl\"", |
| 41 | + "#define PACKAGE_NAME \"numactl\"", |
| 42 | + "#define PACKAGE_VERSION \"2.0.19\"", |
| 43 | + "#define PACKAGE_STRING \"numactl 2.0.19\"", |
| 44 | + "#define VERSION \"2.0.19\"", |
| 45 | + "", |
| 46 | + ], |
| 47 | + newline = "unix", |
| 48 | +) |
| 49 | + |
| 50 | +# Common compiler flags |
| 51 | +COMMON_COPTS = ["-Wall"] |
| 52 | + |
| 53 | +# Common headers for internal use |
| 54 | +INTERNAL_HDRS = [ |
| 55 | + "numaint.h", |
| 56 | + "util.h", |
| 57 | + "affinity.h", |
| 58 | + "sysfs.h", |
| 59 | + "rtnetlink.h", |
| 60 | + "shm.h", |
| 61 | + "clearcache.h", |
| 62 | + "mt.h", |
| 63 | + "stream_lib.h", |
| 64 | +] |
| 65 | + |
| 66 | +# libnuma: NUMA policy library |
| 67 | +cc_library( |
| 68 | + name = "numa", |
| 69 | + srcs = [ |
| 70 | + "affinity.c", |
| 71 | + "distance.c", |
| 72 | + "libnuma.c", |
| 73 | + "rtnetlink.c", |
| 74 | + "syscall.c", |
| 75 | + "sysfs.c", |
| 76 | + ":gen_config_h", |
| 77 | + ] + INTERNAL_HDRS, |
| 78 | + hdrs = [ |
| 79 | + "numa.h", |
| 80 | + "numacompat1.h", |
| 81 | + "numaif.h", |
| 82 | + ], |
| 83 | + additional_linker_inputs = ["versions.ldscript"], |
| 84 | + copts = COMMON_COPTS, |
| 85 | + includes = ["."], |
| 86 | + linkopts = select({ |
| 87 | + "@platforms//os:linux": [ |
| 88 | + "-Wl,--version-script,$(execpath versions.ldscript)", |
| 89 | + "-Wl,-init,numa_init", |
| 90 | + "-Wl,-fini,numa_fini", |
| 91 | + ], |
| 92 | + "//conditions:default": [], |
| 93 | + }), |
| 94 | + target_compatible_with = LINUX_ONLY, |
| 95 | + visibility = ["//visibility:public"], |
| 96 | + alwayslink = True, |
| 97 | +) |
| 98 | + |
| 99 | +# Utility library for command-line tools and tests |
| 100 | +cc_library( |
| 101 | + name = "util", |
| 102 | + srcs = [ |
| 103 | + "util.c", |
| 104 | + ":gen_config_h", |
| 105 | + ], |
| 106 | + hdrs = ["util.h"], |
| 107 | + copts = COMMON_COPTS, |
| 108 | + includes = ["."], |
| 109 | + target_compatible_with = LINUX_ONLY, |
| 110 | + visibility = ["@numactl_test//:__subpackages__"], |
| 111 | + deps = [":numa"], |
| 112 | +) |
| 113 | + |
| 114 | +# numactl: NUMA policy control |
| 115 | +cc_binary( |
| 116 | + name = "numactl", |
| 117 | + srcs = [ |
| 118 | + "numactl.c", |
| 119 | + "shm.c", |
| 120 | + "shm.h", |
| 121 | + ":gen_config_h", |
| 122 | + ], |
| 123 | + copts = COMMON_COPTS + ["-DVERSION=\\\"2.0.19\\\""], |
| 124 | + target_compatible_with = LINUX_ONLY, |
| 125 | + visibility = ["//visibility:public"], |
| 126 | + deps = [ |
| 127 | + ":numa", |
| 128 | + ":util", |
| 129 | + ], |
| 130 | +) |
| 131 | + |
| 132 | +# numastat: NUMA statistics |
| 133 | +cc_binary( |
| 134 | + name = "numastat", |
| 135 | + srcs = [ |
| 136 | + "numastat.c", |
| 137 | + ":gen_config_h", |
| 138 | + ], |
| 139 | + copts = COMMON_COPTS + [ |
| 140 | + "-std=gnu99", |
| 141 | + "-DVERSION=\\\"2.0.19\\\"", |
| 142 | + ], |
| 143 | + target_compatible_with = LINUX_ONLY, |
| 144 | + visibility = ["//visibility:public"], |
| 145 | +) |
| 146 | + |
| 147 | +# numademo: NUMA demonstration/benchmark |
| 148 | +cc_binary( |
| 149 | + name = "numademo", |
| 150 | + srcs = [ |
| 151 | + "clearcache.c", |
| 152 | + "clearcache.h", |
| 153 | + "mt.c", |
| 154 | + "mt.h", |
| 155 | + "numademo.c", |
| 156 | + "stream_lib.c", |
| 157 | + "stream_lib.h", |
| 158 | + ":gen_config_h", |
| 159 | + ], |
| 160 | + copts = COMMON_COPTS + [ |
| 161 | + "-O3", |
| 162 | + "-ffast-math", |
| 163 | + "-funroll-loops", |
| 164 | + "-DHAVE_STREAM_LIB", |
| 165 | + "-DHAVE_MT", |
| 166 | + "-DHAVE_CLEAR_CACHE", |
| 167 | + ], |
| 168 | + linkopts = ["-lm"], |
| 169 | + target_compatible_with = LINUX_ONLY, |
| 170 | + visibility = ["//visibility:public"], |
| 171 | + deps = [ |
| 172 | + ":numa", |
| 173 | + ":util", |
| 174 | + ], |
| 175 | +) |
| 176 | + |
| 177 | +# migratepages: Migrate pages of a process |
| 178 | +cc_binary( |
| 179 | + name = "migratepages", |
| 180 | + srcs = [ |
| 181 | + "migratepages.c", |
| 182 | + ":gen_config_h", |
| 183 | + ], |
| 184 | + copts = COMMON_COPTS, |
| 185 | + target_compatible_with = LINUX_ONLY, |
| 186 | + visibility = ["//visibility:public"], |
| 187 | + deps = [ |
| 188 | + ":numa", |
| 189 | + ":util", |
| 190 | + ], |
| 191 | +) |
| 192 | + |
| 193 | +# migspeed: Measure migration speed |
| 194 | +cc_binary( |
| 195 | + name = "migspeed", |
| 196 | + srcs = [ |
| 197 | + "migspeed.c", |
| 198 | + ":gen_config_h", |
| 199 | + ], |
| 200 | + copts = COMMON_COPTS, |
| 201 | + target_compatible_with = LINUX_ONLY, |
| 202 | + visibility = ["//visibility:public"], |
| 203 | + deps = [ |
| 204 | + ":numa", |
| 205 | + ":util", |
| 206 | + ], |
| 207 | +) |
| 208 | + |
| 209 | +# memhog: Memory allocation test |
| 210 | +cc_binary( |
| 211 | + name = "memhog", |
| 212 | + srcs = [ |
| 213 | + "memhog.c", |
| 214 | + ":gen_config_h", |
| 215 | + ], |
| 216 | + copts = COMMON_COPTS, |
| 217 | + target_compatible_with = LINUX_ONLY, |
| 218 | + visibility = ["//visibility:public"], |
| 219 | + deps = [ |
| 220 | + ":numa", |
| 221 | + ":util", |
| 222 | + ], |
| 223 | +) |
| 224 | + |
| 225 | +# Convenience alias |
| 226 | +alias( |
| 227 | + name = "libnuma", |
| 228 | + actual = ":numa", |
| 229 | + visibility = ["//visibility:public"], |
| 230 | +) |
0 commit comments