load("@bazel_skylib//rules:write_file.bzl", "write_file") load("@rules_cc//cc:cc_binary.bzl", "cc_binary") load("@rules_cc//cc:cc_library.bzl", "cc_library") LINUX_ONLY = select({ "@platforms//os:linux": [], "//conditions:default": ["@platforms//:incompatible"], }) # Generate config.h write_file( name = "gen_config_h", out = "config.h", content = [ "/* config.h - Generated by Bazel */", "", "/* Define to 1 if you have standard C headers */", "#define STDC_HEADERS 1", "#define HAVE_STDIO_H 1", "#define HAVE_STDLIB_H 1", "#define HAVE_STRING_H 1", "#define HAVE_STRINGS_H 1", "#define HAVE_INTTYPES_H 1", "#define HAVE_STDINT_H 1", "#define HAVE_UNISTD_H 1", "#define HAVE_SYS_TYPES_H 1", "#define HAVE_SYS_STAT_H 1", "", "/* TLS support */", "#if defined(__GNUC__) || defined(__clang__)", "#define TLS __thread", "#endif", "", "/* Symver attribute support - disabled for Bazel builds */", "/* #undef HAVE_ATTRIBUTE_SYMVER */", "", "/* Package information */", "#define PACKAGE \"numactl\"", "#define PACKAGE_NAME \"numactl\"", "#define PACKAGE_VERSION \"2.0.19\"", "#define PACKAGE_STRING \"numactl 2.0.19\"", "#define VERSION \"2.0.19\"", "", ], newline = "unix", ) # Common compiler flags COMMON_COPTS = ["-w"] # Common headers for internal use INTERNAL_HDRS = [ "numaint.h", "util.h", "affinity.h", "sysfs.h", "rtnetlink.h", "shm.h", "clearcache.h", "mt.h", "stream_lib.h", ] # libnuma: NUMA policy library cc_library( name = "numa", srcs = [ "affinity.c", "distance.c", "libnuma.c", "rtnetlink.c", "syscall.c", "sysfs.c", ":gen_config_h", ] + INTERNAL_HDRS, hdrs = [ "numa.h", "numacompat1.h", "numaif.h", ], additional_linker_inputs = ["versions.ldscript"], copts = COMMON_COPTS, includes = ["."], linkopts = [ "-Wl,--version-script=$(location versions.ldscript)", "-Wl,-init,numa_init", "-Wl,-fini,numa_fini", ], target_compatible_with = LINUX_ONLY, visibility = ["//visibility:public"], alwayslink = True, ) # Utility library for command-line tools and tests cc_library( name = "util", srcs = [ "util.c", ":gen_config_h", ], hdrs = ["util.h"], copts = COMMON_COPTS, includes = ["."], linkstatic = True, target_compatible_with = LINUX_ONLY, visibility = ["//visibility:public"], deps = [":numa"], alwayslink = True, ) # numactl: NUMA policy control cc_binary( name = "numactl", srcs = [ "numactl.c", "shm.c", "shm.h", ":gen_config_h", ], copts = COMMON_COPTS + ["-DVERSION=\\\"2.0.19\\\""], linkstatic = True, target_compatible_with = LINUX_ONLY, visibility = ["//visibility:public"], deps = [ ":numa", ":util", ], ) # numastat: NUMA statistics cc_binary( name = "numastat", srcs = [ "numastat.c", ":gen_config_h", ], copts = COMMON_COPTS + [ "-std=gnu99", "-DVERSION=\\\"2.0.19\\\"", ], target_compatible_with = LINUX_ONLY, visibility = ["//visibility:public"], ) # numademo: NUMA demonstration/benchmark cc_binary( name = "numademo", srcs = [ "clearcache.c", "clearcache.h", "mt.c", "mt.h", "numademo.c", "stream_lib.c", "stream_lib.h", ":gen_config_h", ], copts = COMMON_COPTS + [ "-O3", "-ffast-math", "-funroll-loops", "-DHAVE_STREAM_LIB", "-DHAVE_MT", "-DHAVE_CLEAR_CACHE", ], linkopts = ["-lm"], linkstatic = True, target_compatible_with = LINUX_ONLY, visibility = ["//visibility:public"], deps = [ ":numa", ":util", ], ) # migratepages: Migrate pages of a process cc_binary( name = "migratepages", srcs = [ "migratepages.c", ":gen_config_h", ], copts = COMMON_COPTS, linkstatic = True, target_compatible_with = LINUX_ONLY, visibility = ["//visibility:public"], deps = [ ":numa", ":util", ], ) # migspeed: Measure migration speed cc_binary( name = "migspeed", srcs = [ "migspeed.c", ":gen_config_h", ], copts = COMMON_COPTS, linkstatic = True, target_compatible_with = LINUX_ONLY, visibility = ["//visibility:public"], deps = [ ":numa", ":util", ], ) # memhog: Memory allocation test cc_binary( name = "memhog", srcs = [ "memhog.c", ":gen_config_h", ], copts = COMMON_COPTS, linkstatic = True, target_compatible_with = LINUX_ONLY, visibility = ["//visibility:public"], deps = [ ":numa", ":util", ], ) # Convenience alias alias( name = "libnuma", actual = ":numa", visibility = ["//visibility:public"], )