Skip to content

Commit fe454cb

Browse files
committed
numactl: Allow the build of shared lirary
Currently it only creates a static library. Signed-off-by: Jonh Wendell <[email protected]>
1 parent d8e74a2 commit fe454cb

File tree

9 files changed

+397
-1
lines changed

9 files changed

+397
-1
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""https://github.com/numactl/numactl"""
2+
3+
module(
4+
name = "numactl",
5+
version = "2.0.19.bcr.1",
6+
bazel_compatibility = [">=7.2.1"],
7+
)
8+
9+
bazel_dep(name = "rules_cc", version = "0.2.4")
10+
bazel_dep(name = "platforms", version = "1.0.0")
11+
bazel_dep(name = "bazel_skylib", version = "1.8.2")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test
Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
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 - disabled for Bazel builds */",
35+
"/* #undef HAVE_ATTRIBUTE_SYMVER */",
36+
"",
37+
"/* Package information */",
38+
"#define PACKAGE \"numactl\"",
39+
"#define PACKAGE_NAME \"numactl\"",
40+
"#define PACKAGE_VERSION \"2.0.19\"",
41+
"#define PACKAGE_STRING \"numactl 2.0.19\"",
42+
"#define VERSION \"2.0.19\"",
43+
"",
44+
],
45+
newline = "unix",
46+
)
47+
48+
# Common compiler flags
49+
COMMON_COPTS = ["-w"]
50+
51+
# Common headers for internal use
52+
INTERNAL_HDRS = [
53+
"numaint.h",
54+
"util.h",
55+
"affinity.h",
56+
"sysfs.h",
57+
"rtnetlink.h",
58+
"shm.h",
59+
"clearcache.h",
60+
"mt.h",
61+
"stream_lib.h",
62+
]
63+
64+
# libnuma: NUMA policy library
65+
cc_library(
66+
name = "numa",
67+
srcs = [
68+
"affinity.c",
69+
"distance.c",
70+
"libnuma.c",
71+
"rtnetlink.c",
72+
"syscall.c",
73+
"sysfs.c",
74+
":gen_config_h",
75+
] + INTERNAL_HDRS,
76+
hdrs = [
77+
"numa.h",
78+
"numacompat1.h",
79+
"numaif.h",
80+
],
81+
additional_linker_inputs = ["versions.ldscript"],
82+
copts = COMMON_COPTS,
83+
includes = ["."],
84+
linkopts = [
85+
"-Wl,--version-script=$(location versions.ldscript)",
86+
"-Wl,-init,numa_init",
87+
"-Wl,-fini,numa_fini",
88+
],
89+
target_compatible_with = LINUX_ONLY,
90+
visibility = ["//visibility:public"],
91+
alwayslink = True,
92+
)
93+
94+
# Utility library for command-line tools and tests
95+
cc_library(
96+
name = "util",
97+
srcs = [
98+
"util.c",
99+
":gen_config_h",
100+
],
101+
hdrs = ["util.h"],
102+
copts = COMMON_COPTS,
103+
includes = ["."],
104+
linkstatic = True,
105+
target_compatible_with = LINUX_ONLY,
106+
visibility = ["//visibility:public"],
107+
deps = [":numa"],
108+
alwayslink = True,
109+
)
110+
111+
# numactl: NUMA policy control
112+
cc_binary(
113+
name = "numactl",
114+
srcs = [
115+
"numactl.c",
116+
"shm.c",
117+
"shm.h",
118+
":gen_config_h",
119+
],
120+
copts = COMMON_COPTS + ["-DVERSION=\\\"2.0.19\\\""],
121+
linkstatic = True,
122+
target_compatible_with = LINUX_ONLY,
123+
visibility = ["//visibility:public"],
124+
deps = [
125+
":numa",
126+
":util",
127+
],
128+
)
129+
130+
# numastat: NUMA statistics
131+
cc_binary(
132+
name = "numastat",
133+
srcs = [
134+
"numastat.c",
135+
":gen_config_h",
136+
],
137+
copts = COMMON_COPTS + [
138+
"-std=gnu99",
139+
"-DVERSION=\\\"2.0.19\\\"",
140+
],
141+
target_compatible_with = LINUX_ONLY,
142+
visibility = ["//visibility:public"],
143+
)
144+
145+
# numademo: NUMA demonstration/benchmark
146+
cc_binary(
147+
name = "numademo",
148+
srcs = [
149+
"clearcache.c",
150+
"clearcache.h",
151+
"mt.c",
152+
"mt.h",
153+
"numademo.c",
154+
"stream_lib.c",
155+
"stream_lib.h",
156+
":gen_config_h",
157+
],
158+
copts = COMMON_COPTS + [
159+
"-O3",
160+
"-ffast-math",
161+
"-funroll-loops",
162+
"-DHAVE_STREAM_LIB",
163+
"-DHAVE_MT",
164+
"-DHAVE_CLEAR_CACHE",
165+
],
166+
linkopts = ["-lm"],
167+
linkstatic = True,
168+
target_compatible_with = LINUX_ONLY,
169+
visibility = ["//visibility:public"],
170+
deps = [
171+
":numa",
172+
":util",
173+
],
174+
)
175+
176+
# migratepages: Migrate pages of a process
177+
cc_binary(
178+
name = "migratepages",
179+
srcs = [
180+
"migratepages.c",
181+
":gen_config_h",
182+
],
183+
copts = COMMON_COPTS,
184+
linkstatic = True,
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+
linkstatic = True,
202+
target_compatible_with = LINUX_ONLY,
203+
visibility = ["//visibility:public"],
204+
deps = [
205+
":numa",
206+
":util",
207+
],
208+
)
209+
210+
# memhog: Memory allocation test
211+
cc_binary(
212+
name = "memhog",
213+
srcs = [
214+
"memhog.c",
215+
":gen_config_h",
216+
],
217+
copts = COMMON_COPTS,
218+
linkstatic = True,
219+
target_compatible_with = LINUX_ONLY,
220+
visibility = ["//visibility:public"],
221+
deps = [
222+
":numa",
223+
":util",
224+
],
225+
)
226+
227+
# Convenience alias
228+
alias(
229+
name = "libnuma",
230+
actual = ":numa",
231+
visibility = ["//visibility:public"],
232+
)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""https://github.com/numactl/numactl"""
2+
3+
module(
4+
name = "numactl",
5+
version = "2.0.19",
6+
bazel_compatibility = [">=7.2.1"],
7+
)
8+
9+
bazel_dep(name = "rules_cc", version = "0.2.4")
10+
bazel_dep(name = "platforms", version = "1.0.0")
11+
bazel_dep(name = "bazel_skylib", version = "1.8.2")
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
load("@rules_cc//cc:cc_test.bzl", "cc_test")
2+
3+
# Common configuration for all tests
4+
COMMON_COPTS = ["-Wall"]
5+
6+
# Linux-only constraint - all numactl tests require Linux
7+
LINUX_ONLY = select({
8+
"@platforms//os:linux": [],
9+
"//conditions:default": ["@platforms//:incompatible"],
10+
})
11+
12+
# Test programs from Makefile.am
13+
# All tests are Linux-specific
14+
# Tests that work without NUMA hardware
15+
TEST_CASES = {
16+
"ftok": ["ftok.c"],
17+
"mynode": ["mynode.c"],
18+
"pagesize": ["pagesize.c"],
19+
}
20+
21+
# Tests that require NUMA hardware/kernel support (tagged as manual)
22+
MANUAL_TEST_CASES = {
23+
"distance": ["distance.c"],
24+
"mbind_mig_pages": ["mbind_mig_pages.c"],
25+
"migrate_pages": ["migrate_pages.c"],
26+
"move_pages": ["move_pages.c"],
27+
"nodemap": ["nodemap.c"],
28+
"realloc_test": ["realloc_test.c"],
29+
"tshared": ["tshared.c"],
30+
}
31+
32+
# Generate basic tests
33+
[cc_test(
34+
name = name,
35+
srcs = srcs,
36+
copts = COMMON_COPTS,
37+
linkstatic = True,
38+
target_compatible_with = LINUX_ONLY,
39+
deps = ["@numactl//:numa"],
40+
) for name, srcs in TEST_CASES.items()]
41+
42+
# Generate manual tests (require NUMA hardware)
43+
[cc_test(
44+
name = name,
45+
srcs = srcs,
46+
copts = COMMON_COPTS,
47+
linkstatic = True,
48+
tags = ["manual"],
49+
target_compatible_with = LINUX_ONLY,
50+
deps = ["@numactl//:numa"],
51+
) for name, srcs in MANUAL_TEST_CASES.items()]
52+
53+
# Tests that also need util library
54+
cc_test(
55+
name = "node-parse",
56+
srcs = ["node-parse.c"],
57+
copts = COMMON_COPTS,
58+
linkstatic = True,
59+
target_compatible_with = LINUX_ONLY,
60+
deps = [
61+
"@numactl//:numa",
62+
"@numactl//:util",
63+
],
64+
)
65+
66+
cc_test(
67+
name = "prefered",
68+
srcs = ["prefered.c"],
69+
copts = COMMON_COPTS,
70+
linkstatic = True,
71+
tags = ["manual"], # Requires NUMA hardware
72+
target_compatible_with = LINUX_ONLY,
73+
deps = [
74+
"@numactl//:numa",
75+
"@numactl//:util",
76+
],
77+
)
78+
79+
cc_test(
80+
name = "tbitmap",
81+
srcs = ["tbitmap.c"],
82+
copts = COMMON_COPTS,
83+
linkstatic = True,
84+
target_compatible_with = LINUX_ONLY,
85+
deps = [
86+
"@numactl//:numa",
87+
"@numactl//:util",
88+
],
89+
)
90+
91+
# Test that is known to be broken (per Makefile.am comment)
92+
cc_test(
93+
name = "randmap",
94+
srcs = ["randmap.c"],
95+
copts = COMMON_COPTS,
96+
linkstatic = True,
97+
tags = ["manual"],
98+
target_compatible_with = LINUX_ONLY,
99+
deps = ["@numactl//:numa"],
100+
)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module(
2+
name = "numactl_test",
3+
version = "0.0.0",
4+
)
5+
6+
bazel_dep(name = "numactl", version = "0.0.0")
7+
local_path_override(
8+
module_name = "numactl",
9+
path = "../",
10+
)
11+
12+
bazel_dep(name = "platforms", version = "1.0.0")
13+
bazel_dep(name = "rules_cc", version = "0.2.4")
14+
bazel_dep(name = "bazel_skylib", version = "1.8.2")
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
bcr_test_module:
2+
module_path: "test"
3+
matrix:
4+
platform: ["rockylinux8", "ubuntu2004", "ubuntu2004_arm64"]
5+
bazel: ["7.x", "8.x", "rolling"]
6+
tasks:
7+
verify_targets:
8+
name: "Run test module"
9+
platform: ${{ platform }}
10+
bazel: ${{ bazel }}
11+
build_targets:
12+
- "@numactl//..."
13+
test_targets:
14+
- "//..."

0 commit comments

Comments
 (0)