Skip to content

Commit a1cb406

Browse files
authored
Build util-linux with bazel (#42082)
### What does this PR do? Build the util-linux we care about (`libblkid`) with bazel ### Motivation Migrating our native dependencies build to bazel ### Describe how you validated your changes Local build + CI ### Additional Notes
1 parent 4b25cf2 commit a1cb406

4 files changed

Lines changed: 743 additions & 15 deletions

File tree

deps/repos.MODULE.bazel

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ http_archive(
7272
},
7373
)
7474

75+
http_archive(
76+
name = "util-linux",
77+
build_file = "//deps:util-linux.BUILD.bazel",
78+
url = "https://mirrors.edge.kernel.org/pub/linux/utils/util-linux/v2.39/util-linux-2.39.2.tar.gz",
79+
sha256 = "c8e1a11dd5879a2788973c73589fbcf08606e85aeec095e516162495ead8ba68",
80+
strip_prefix = "util-linux-2.39.2",
81+
files = {
82+
"generated/config.h": "//deps:util-linux/config.h"
83+
}
84+
)
85+
7586
http_archive(
7687
name = "patchelf",
7788
build_file = "//deps:patchelf.BUILD.bazel",

deps/util-linux.BUILD.bazel

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
load("@@//bazel/rules:so_symlink.bzl", "so_symlink")
2+
load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
3+
load("@rules_cc//cc:defs.bzl", "cc_library")
4+
load("@rules_pkg//pkg:install.bzl", "pkg_install")
5+
load("@rules_pkg//pkg:mappings.bzl", "pkg_files")
6+
7+
_VERSION = "2.39.2"
8+
9+
expand_template(
10+
name = "blkid_h",
11+
out = "blkid.h",
12+
template = "libblkid/src/blkid.h.in",
13+
substitutions = {
14+
"@LIBBLKID_DATE@": "REDACTED",
15+
"@LIBBLKID_VERSION@": _VERSION,
16+
},
17+
)
18+
19+
cc_library(
20+
name = "libcommon",
21+
srcs = [
22+
"lib/blkdev.c",
23+
"lib/buffer.c",
24+
"lib/caputils.c",
25+
"lib/canonicalize.c",
26+
"lib/color-names.c",
27+
"lib/cpuset.c",
28+
"lib/crc32.c",
29+
"lib/crc32c.c",
30+
"lib/crc64.c",
31+
"lib/c_strtod.c",
32+
"lib/encode.c",
33+
"lib/env.c",
34+
"lib/fileutils.c",
35+
"lib/idcache.c",
36+
"lib/jsonwrt.c",
37+
"lib/linux_version.c",
38+
"lib/loopdev.c",
39+
"lib/mangle.c",
40+
"lib/match.c",
41+
"lib/mbsalign.c",
42+
"lib/mbsedit.c",
43+
"lib/md5.c",
44+
"lib/path.c",
45+
"lib/procfs.c",
46+
"lib/pwdutils.c",
47+
"lib/randutils.c",
48+
"lib/sha1.c",
49+
"lib/sha256.c",
50+
"lib/signames.c",
51+
"lib/strutils.c",
52+
"lib/strv.c",
53+
"lib/sysfs.c",
54+
"lib/timeutils.c",
55+
"lib/ttyutils.c",
56+
"lib/xxhash.c",
57+
] + ["generated/config.h"],
58+
hdrs = glob(["include/*.h"]),
59+
includes = [
60+
"include",
61+
],
62+
visibility = ["//visibility:private"],
63+
copts = [
64+
"-include generated/config.h",
65+
],
66+
local_defines = [
67+
"_GNU_SOURCE",
68+
],
69+
)
70+
71+
cc_library(
72+
name = "libblkid",
73+
srcs = glob([
74+
"libblkid/src/**/*.c",
75+
"libblkid/src/**/*.h",
76+
]) + ["generated/config.h"],
77+
hdrs = [":blkid_h"],
78+
deps = [":libcommon"],
79+
includes = [
80+
"libblkid/src",
81+
"include",
82+
"generated",
83+
],
84+
copts = [
85+
"-include generated/config.h",
86+
],
87+
local_defines = [
88+
"_GNU_SOURCE",
89+
],
90+
)
91+
92+
cc_shared_library(
93+
name = "blkid",
94+
deps = [":libblkid"],
95+
)
96+
97+
expand_template(
98+
name = "gen_blkid_pkgconfig",
99+
out = "blkid.pc",
100+
substitutions = {
101+
# Prepare the .pc file for our own substitution later
102+
"@prefix@": "##PREFIX##",
103+
"@exec_prefix@": "${prefix}",
104+
"@libdir@": "${prefix}/lib",
105+
"@includedir@": "${prefix}/include",
106+
"@LIBBLKID_VERSION@": _VERSION,
107+
},
108+
template = "libblkid/blkid.pc.in",
109+
)
110+
111+
so_symlink(
112+
name = "libblkid_libfiles",
113+
src = ":blkid",
114+
libname = "libblkid",
115+
version = "1.1.0",
116+
)
117+
118+
pkg_files(
119+
name = "blkid_hdr_files",
120+
srcs = [":blkid_h"],
121+
prefix = "include/blkid",
122+
)
123+
124+
pkg_files(
125+
name = "blkid_pc_file",
126+
srcs = [":gen_blkid_pkgconfig"],
127+
prefix = "lib/pkgconfig",
128+
)
129+
130+
pkg_install(
131+
name = "blkid_install",
132+
srcs = [
133+
":blkid_hdr_files",
134+
":libblkid_libfiles",
135+
":blkid_pc_file",
136+
],
137+
)

0 commit comments

Comments
 (0)