Skip to content

Commit c083fa9

Browse files
authored
build krb5 with bazel (#44326)
### What does this PR do? Build krb5 with bazel ### Motivation Migration of our 3rd party dependencies to bazel https://datadoghq.atlassian.net/browse/ABLD-274 ### Describe how you validated your changes Local build for linux x86_64 ### Additional Notes This PR also contains a patch that can be seen as a PR upstream: bazel-contrib/rules_foreign_cc#1451 This will drop all the executables that we currently install: ``` bin/compile_et bin/gss-client bin/k5srvutil bin/kadmin bin/kdestroy bin/kinit bin/klist bin/kpasswd bin/krb5-config bin/ksu bin/kswitch bin/ktutil bin/kvno bin/sclient bin/sim_client bin/uuclient ``` and ``` sbin/gss-server sbin/kadmin.local sbin/kadmind sbin/kdb5_util sbin/kprop sbin/kpropd sbin/kproplog sbin/krb5-send-pr sbin/krb5kdc sbin/sim_server sbin/sserver sbin/uuserver ``` Co-authored-by: hugo.beauzee <[email protected]>
1 parent 7daa6e6 commit c083fa9

File tree

4 files changed

+229
-27
lines changed

4 files changed

+229
-27
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
From af72bc8c79be86e14b3b46bd1207c23365c988d7 Mon Sep 17 00:00:00 2001
2+
From: =?UTF-8?q?Hugo=20Beauz=C3=A9e-Luyssen?= <[email protected]>
3+
Date: Thu, 27 Nov 2025 13:57:04 +0100
4+
Subject: [PATCH] include out_data_dirs to the output groups
5+
6+
---
7+
foreign_cc/private/framework.bzl | 5 ++++-
8+
1 file changed, 4 insertions(+), 1 deletion(-)
9+
10+
diff --git a/foreign_cc/private/framework.bzl b/foreign_cc/private/framework.bzl
11+
index eb7632d..fd354b7 100644
12+
--- a/foreign_cc/private/framework.bzl
13+
+++ b/foreign_cc/private/framework.bzl
14+
@@ -598,7 +598,8 @@ def cc_external_rule_impl(ctx, attrs):
15+
outputs.libraries.static_libraries +
16+
outputs.libraries.shared_libraries +
17+
([outputs.out_include_dir] if outputs.out_include_dir else []) +
18+
- ([outputs.out_pc_dir] if outputs.out_pc_dir else [])
19+
+ ([outputs.out_pc_dir] if outputs.out_pc_dir else []) +
20+
+ (outputs.data_dirs if outputs.data_dirs else [])
21+
)
22+
output_groups = _declare_output_groups(installdir_copy.file, output_groups)
23+
wrapped_files = [
24+
@@ -849,6 +850,7 @@ _Outputs = provider(
25+
out_binary_files = "Binary files, which will be created by the action",
26+
libraries = "Library files, which will be created by the action",
27+
out_pc_dir = "Directory with pkgconfig files (relative to install directory)",
28+
+ data_dirs = "Directory containing additional files generated by the build",
29+
declared_outputs = "All output files and directories of the action",
30+
),
31+
)
32+
@@ -913,6 +915,7 @@ def _define_outputs(ctx, attrs, lib_name):
33+
out_binary_files = out_binary_files,
34+
libraries = libraries,
35+
out_pc_dir = out_pc_dir,
36+
+ data_dirs = out_data_dirs,
37+
declared_outputs = declared_outputs,
38+
)
39+
40+
--
41+
2.43.0
42+

deps/krb5/krb5.BUILD.bazel

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
load("@@//bazel/rules:so_symlink.bzl", "so_symlink")
2+
load("@rules_license//rules:license.bzl", "license")
3+
load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make")
4+
load("@rules_pkg//pkg:install.bzl", "pkg_install")
5+
load("@rules_pkg//pkg:mappings.bzl", "pkg_files")
6+
load("@rules_pkg//pkg:mappings.bzl", "strip_prefix")
7+
8+
package(default_package_metadata = [":license"])
9+
10+
license(
11+
name = "license",
12+
license_kinds = ["@rules_license//licenses/spdx:BSD-2-Clause"],
13+
license_text = "NOTICE",
14+
visibility = ["//visibility:public"],
15+
)
16+
17+
filegroup(
18+
name = "all_srcs",
19+
srcs = glob(["src/**/*"])
20+
)
21+
22+
SHARED_LIBS = {
23+
'krb5/plugins/tls/k5tls.so': '',
24+
'krb5/plugins/kdb/db2.so': '',
25+
'krb5/plugins/preauth/test.so': '',
26+
'krb5/plugins/preauth/spake.so': '',
27+
'krb5/plugins/preauth/pkinit.so': '',
28+
'krb5/plugins/preauth/otp.so': '',
29+
'libcom_err.so': '3.0',
30+
'libgssapi_krb5.so': '2.2',
31+
'libgssrpc.so': '4.2',
32+
'libk5crypto.so': '3.1',
33+
'libkadm5clnt.so': '',
34+
'libkadm5clnt_mit.so': '12.0',
35+
'libkadm5srv.so': '',
36+
'libkadm5srv_mit.so': '12.0',
37+
'libkdb5.so': '10.0',
38+
'libkrad.so': '0.0',
39+
'libkrb5.so': '3.3',
40+
'libkrb5support.so': '0.1',
41+
'libverto.so': '0.0',
42+
}
43+
44+
configure_make(
45+
name = "krb5",
46+
args = [
47+
"-j 16",
48+
],
49+
autoreconf = True,
50+
configure_in_place = True,
51+
configure_options = [
52+
"--without-keyutils", # this would require additional deps/system deps, disable it
53+
"--without-system-verto", # do not prefer libverto from the system, if installed
54+
"--without-libedit", # we don't want to link with libraries outside of the install dir
55+
"--disable-static",
56+
"--with-crypto-impl=openssl",
57+
"--with-tls-impl=openssl",
58+
"--disable-nls",
59+
],
60+
lib_source = ":all_srcs",
61+
deps = [
62+
"@openssl//:openssl",
63+
],
64+
out_shared_libs = SHARED_LIBS.keys(),
65+
out_data_dirs = ["lib/pkgconfig"],
66+
)
67+
68+
# Unversioned lib handling:
69+
# Create a filegroup refering to configure_make's output_group
70+
# Expose this single file filegroup as a pkg_file target with a common `lib_$foo` name
71+
[
72+
filegroup(
73+
name = "_unversioned_lib_" + libname,
74+
srcs = [":krb5"],
75+
output_group = libname.rpartition('/')[2]
76+
)
77+
for (libname, libversion) in SHARED_LIBS.items() if not libversion
78+
]
79+
80+
[
81+
pkg_files(
82+
name = "_lib_" + libname,
83+
srcs = [":_unversioned_lib_" + libname],
84+
prefix = "lib/" + libname.rpartition('/')[0],
85+
)
86+
for (libname, libversion) in SHARED_LIBS.items() if not libversion
87+
]
88+
89+
# Now the same for versioned libs, except instead of an explicit pkg_file
90+
# we leverage the one created by so_symlink
91+
[
92+
filegroup(
93+
name = "_symlink_src_" + libname,
94+
srcs = [":krb5"],
95+
output_group = libname,
96+
)
97+
for (libname, libversion) in SHARED_LIBS.items() if libversion
98+
]
99+
100+
[
101+
so_symlink(
102+
name = "_lib_" + libname,
103+
src = "_symlink_src_" + libname,
104+
libname = libname.removesuffix(".so"),
105+
version = libversion,
106+
# so_symlink already adds a lib/ folder
107+
prefix = libname.rpartition('/')[0],
108+
)
109+
for (libname, libversion) in SHARED_LIBS.items() if libversion
110+
]
111+
112+
filegroup(
113+
name = "_pc_files",
114+
srcs = [":krb5"],
115+
output_group = "pkgconfig",
116+
)
117+
118+
pkg_files(
119+
name = "pc_files",
120+
srcs = ["_pc_files"],
121+
prefix = "lib/",
122+
)
123+
124+
filegroup(
125+
name = "_headers",
126+
srcs = [":krb5"],
127+
output_group = "include"
128+
)
129+
130+
pkg_files(
131+
name = "hdr_files",
132+
srcs = [":_headers"],
133+
)
134+
135+
pkg_install(
136+
name = "install",
137+
srcs = [
138+
":hdr_files",
139+
":pc_files",
140+
] + [":_lib_" + libname for libname in SHARED_LIBS.keys()],
141+
)

deps/repos.MODULE.bazel

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ single_version_override(
5757
patch_strip = 1,
5858
patches = [
5959
"//bazel/patches:rules_foreign_cc/0000-expose-pc-files.patch",
60+
"//bazel/patches:rules_foreign_cc/0001-include-out_data_dirs-to-the-output-groups.patch",
6061
],
6162
)
6263

@@ -315,3 +316,13 @@ http_archive(
315316
},
316317
)
317318

319+
http_archive(
320+
name = "krb5",
321+
url = "https://kerberos.org/dist/krb5/1.21/krb5-1.21.3.tar.gz",
322+
sha256 = "b7a4cd5ead67fb08b980b21abd150ff7217e85ea320c9ed0c6dadd304840ad35",
323+
strip_prefix = "krb5-1.21.3",
324+
files = {
325+
"BUILD.bazel": "//deps:krb5/krb5.BUILD.bazel",
326+
},
327+
)
328+

omnibus/config/software/libkrb5.rb

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,41 @@
11
name "libkrb5"
22
default_version "1.21.3"
33

4-
dependency "openssl3"
5-
6-
version "1.21.3" do
7-
source url: "https://kerberos.org/dist/krb5/1.21/krb5-1.21.3.tar.gz"
8-
source sha256: "b7a4cd5ead67fb08b980b21abd150ff7217e85ea320c9ed0c6dadd304840ad35"
9-
end
10-
11-
relative_path "krb5-#{version}/src"
12-
13-
reconf_env = { "PATH" => "#{install_dir}/embedded/bin:#{ENV["PATH"]}" }
14-
154
build do
16-
license "BSD-style"
17-
license_file "https://raw.githubusercontent.com/krb5/krb5/master/NOTICE"
18-
19-
configure_options = ["--without-keyutils", # this would require additional deps/system deps, disable it
20-
"--without-system-verto", # do not prefer libverto from the system, if installed
21-
"--without-libedit", # we don't want to link with libraries outside of the install dir
22-
"--disable-static"
5+
pc_files = [
6+
'gssrpc.pc',
7+
'kadm-client.pc',
8+
'kadm-server.pc',
9+
'kdb.pc',
10+
'krb5-gssapi.pc',
11+
'krb5.pc',
12+
'mit-krb5-gssapi.pc',
13+
'mit-krb5.pc',
2314
]
24-
env = with_standard_compiler_flags(with_embedded_path)
25-
configure(*configure_options, :env => env)
26-
command "make -j #{workers}", :env => { "LD_RUN_PATH" => "#{install_dir}/embedded/lib" }
27-
command "make install", :env => { "LD_RUN_PATH" => "#{install_dir}/embedded/lib" }
28-
29-
# FIXME: CONDA libs appear to confuse the health checker - manually checked file
30-
# are properly linked. Must whitelist for build to succeed.
31-
whitelist_file "#{install_dir}/embedded/lib/krb5/plugins/tls/k5tls.so"
32-
whitelist_file "#{install_dir}/embedded/lib/krb5/plugins/preauth/pkinit.so"
15+
lib_files = [
16+
'krb5/plugins/tls/k5tls.so',
17+
'krb5/plugins/kdb/db2.so',
18+
'krb5/plugins/preauth/test.so',
19+
'krb5/plugins/preauth/spake.so',
20+
'krb5/plugins/preauth/pkinit.so',
21+
'krb5/plugins/preauth/otp.so',
22+
'libkadm5clnt_mit.so',
23+
'libkrad.so',
24+
'libverto.so',
25+
'libk5crypto.so',
26+
'libcom_err.so',
27+
'libkadm5srv.so',
28+
'libkrb5support.so',
29+
'libgssrpc.so',
30+
'libkrb5.so',
31+
'libkadm5srv_mit.so',
32+
'libkdb5.so',
33+
'libgssapi_krb5.so',
34+
'libkadm5clnt.so',
35+
]
36+
command_on_repo_root "bazelisk run -- @krb5//:install --destdir='#{install_dir}/embedded'"
37+
command_on_repo_root "bazelisk run -- //bazel/rules:replace_prefix --prefix '#{install_dir}/embedded' " \
38+
+ lib_files.map{ |l| "#{install_dir}/embedded/lib/#{l}" }.join(' ') \
39+
+ " " \
40+
+ pc_files.map{ |pc| "#{install_dir}/embedded/lib/pkgconfig/#{pc}" }.join(' ')
3341
end

0 commit comments

Comments
 (0)