Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
lts
  • Loading branch information
thesayyn committed Mar 10, 2026
commit 87e6c61ce108f0f172715936b2d27343715ec4d9
2 changes: 0 additions & 2 deletions apt/extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,6 @@ def _distroless_extension(mctx):
arch = arch,
)

print(util.sanitize(package_key))

deb_import(
name = util.sanitize(package_key),
target_name = util.sanitize(package_key),
Expand Down
175 changes: 69 additions & 106 deletions apt/private/deb_import.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ _DEB_IMPORT_BUILD_TMPL = '''
load("@rules_distroless//apt/private:deb_postfix.bzl", "deb_postfix")
load("@rules_distroless//apt/private:deb_export.bzl", "deb_export")
load("@rules_cc//cc/private/rules_impl:cc_import.bzl", "cc_import")
# load("@rules_cc//cc/private:cc_common.bzl", "cc_common")
load("@rules_cc//cc:cc_library.bzl", "cc_library")
load("@bazel_skylib//rules/directory:directory.bzl", "directory")

# print(cc_common.solib_symlink_action)

deb_postfix(
name = "data",
srcs = glob(["data.tar*"]),
Expand Down Expand Up @@ -56,21 +53,13 @@ directory(

_CC_IMPORT_TMPL = """
cc_import(
name = "{name}_imp_",
name = "{name}",
hdrs = {hdrs},
includes = {includes},
linkopts = {linkopts},
shared_library = {shared_lib},
static_library = {static_lib},
)

cc_library(
name = "{name}",
deps = [":{name}_imp_"],
data = {additional_linker_inputs},
additional_compiler_inputs = {additional_compiler_inputs},
additional_linker_inputs = {additional_linker_inputs},
linkopts = {linkopts},
)
"""

_CC_IMPORT_SINGLE_TMPL = """
Expand Down Expand Up @@ -143,10 +132,11 @@ cc_library(
name = "{name}_wodeps",
hdrs = {hdrs},
data = {additional_linker_inputs},
deps = {direct_deps},
linkopts = {linkopts},
additional_compiler_inputs = {additional_compiler_inputs},
additional_linker_inputs = {additional_linker_inputs},
strip_include_prefix = "{strip_include_prefix}",
strip_include_prefix = {strip_include_prefix},
visibility = ["//visibility:public"],
)

Expand Down Expand Up @@ -318,105 +308,68 @@ def _discover_contents(rctx, depends_on, depends_file_map, target_name):
static_lib = None
shared_lib = None

import_targets = []

for pc_file in r_pc_files:
pkgc = pkgconfig(rctx, pc_file)
includes += pkgc.includes
linkopts = pkgc.linkopts
link_paths += pkgc.link_paths

# Look for a static archive
# TODO: static linking is broken for now.
# for ar in a_files:
# if ar.endswith(pkgc.libname + ".a"):
# static_lib = '":%s"' % ar
# break
if not pkgc.libname or pkgc.libname + "_import" in import_targets:
continue

subtarget = pkgc.libname + "_import"
import_targets.append(subtarget)

# Look for a static archive
# for ar in a_files:
# if ar.endswith(pkgc.libname + ".a"):
# static_lib = '":%s"' % ar
# break

# Look for a dynamic library
# for so_lib in so_files:
# if so_lib.endswith(pkgc.libname + ".so"):
# shared_lib = '":%s"' % so_lib
# break
# Look for a dynamic library
for so_lib in so_files:
if pkgc.libname and so_lib.endswith(pkgc.libname + ".so"):
shared_lib = '":%s"' % so_lib
break

build_file_content += _CC_IMPORT_TMPL.format(
name = subtarget,
shared_lib = shared_lib,
static_lib = static_lib,
hdrs = [],
includes = {
"external/.." + include: True
for include in includes + ["/usr/include", "/usr/include/x86_64-linux-gnu"]
}.keys(),
linkopts = pkgc.linkopts,
)

build_file_content += _CC_IMPORT_SINGLE_TMPL.format(
build_file_content += _CC_LIBRARY_TMPL.format(
name = target_name,
hdrs = h_files + hpp_files,
additional_compiler_inputs = hpp_files_woext,
additional_linker_inputs = so_files + o_files + a_files,
shared_lib = '":%s"' % so_files[0],
static_lib = static_lib,
includes = {
"external/.." + include: True
for include in includes
additional_linker_inputs = so_files + o_files,
linkopts = {
opt: True
for opt in [
# Needed for cc_test binaries to locate its dependencies.
"-Wl,-rpath=../{}/{}".format(rctx.attr.name, rpath)
for rp in rpaths
] + [
"-L$(BINDIR)/external/{}/{}".format(rctx.attr.name, lp)
for lp in link_paths
] + [
"-Wl,-rpath=/" + rp
for rp in rpaths
]
}.keys(),
linkopts = linkopts + [
"-Wl,-rpath=/" + rp
for rp in rpaths
] + [
# Needed for cc_test binaries to locate its dependencies.
"-Wl,-rpath=../{}/{}".format(rctx.attr.name, rpath)
for rp in rpaths
] + [
"-L$(BINDIR)/external/{}/{}".format(rctx.attr.name, lp)
for lp in link_paths
],
direct_deps = import_targets,
deps = deps,
strip_include_prefix = None,
)

# elif len(r_pc_files) > 1:
# targets = []
# for pc_file in r_pc_files:
# pkgc = pkgconfig(rctx, pc_file)

# if not pkgc.libname or "_" + pkgc.libname in targets:
# continue

# subtarget = "_" + pkgc.libname

# targets.append(subtarget)

# static_lib = None
# shared_lib = None

# # Look for a static archive
# for ar in a_files:
# if ar.endswith(pkgc.libname + ".a"):
# static_lib = '":%s"' % ar
# break

# # Look for a dynamic library
# for so_lib in so_files:
# if so_lib.endswith(pkgc.libname + ".so"):
# shared_lib = '":%s"' % so_lib
# break

# build_file_content += _CC_IMPORT_TMPL.format(
# name = subtarget,
# hdrs = h_files + hpp_files,
# additional_compiler_inputs = hpp_files_woext,
# additional_linker_inputs = so_files + o_files + a_files,
# shared_lib = shared_lib,
# static_lib = static_lib,
# includes = [
# "external/.." + include
# for include in pkgc.includes
# ],
# linkopts = pkgc.linkopts + [
# "-Wl,-rpath=/" + rp
# for rp in rpaths
# ] + [
# "-L$(BINDIR)/external/{}/{}".format(rctx.attr.name, lp)
# for lp in pkgc.link_paths
# ],
# import_deps = [],
# deps = deps,
# )

# build_file_content += _CC_IMPORT_DENOMITATOR.format(
# name = target_name,
# targets = targets,
# deps = deps,
# )

elif (len(hpp_files) or len(h_files)) and ((target_name.find("libc") != -1 or target_name.find("libstdc") != -1 or target_name.find("libgcc") != -1)):
build_file_content += _CC_LIBRARY_LIBC_TMPL.format(
name = target_name,
Expand All @@ -426,26 +379,36 @@ def _discover_contents(rctx, depends_on, depends_file_map, target_name):
includes = [],
)
else:
extra_linkopts = []
if target_name == "libbsd0":
extra_linkopts = [
"-Wl,--remap-inputs=/usr/lib/x86_64-linux-gnu/libbsd.so.0.11.7=$(BINDIR)/external/{}/usr/lib/x86_64-linux-gnu/libbsd.so.0.11.7".format(rctx.attr.name),
]
build_file_content += _CC_LIBRARY_TMPL.format(
name = target_name,
hdrs = h_files + hpp_files,
deps = deps,
additional_compiler_inputs = hpp_files_woext,
additional_linker_inputs = so_files + a_files + o_files,
additional_linker_inputs = so_files + o_files,
linkopts = [
"-L$(BINDIR)/external/{}/{}".format(rctx.attr.name, rpath)
for rpath in rpaths
] + [
"-Wl,-rpath=/" + rp
# Required for linker to find .so libraries
"-L$(BINDIR)/external/{}/{}".format(rctx.attr.name, rp)
for rp in rpaths
] + [
"-Wl,-rpath=../{}/{}".format(rctx.attr.name, rpath)
# Required for bazel test binary to find its dependencies.
"-Wl,-rpath=../{}/{}".format(rctx.attr.name, rp)
for rp in rpaths
] + [
# Required for ld to validate rpath entries
"-Wl,-rpath-link=$(BINDIR)/external/{}/{}".format(rctx.attr.name, rpath)
for rp in rpaths
],
strip_include_prefix = "usr/include",
] + [
# Required for containers to find the dependencies at runtime.
"-Wl,-rpath=/" + rp
for rp in rpaths
] + extra_linkopts,
strip_include_prefix = '"usr/include"',
direct_deps = [],
)

return (build_file_content, outs, symlinks)
Expand Down
6 changes: 0 additions & 6 deletions apt/private/pkgconfig.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,8 @@ def process_pcconfig(pc):
"-llzma",
]

if directives["Name"] == "icu-uc":
print(pc)

if "Libs" in directives:
libs = _trim(directives["Libs"]).split(" ")

for arg in libs:
if arg in IGNORE:
continue
Expand Down Expand Up @@ -152,8 +148,6 @@ def process_pcconfig(pc):
# Standard include path if the package does not specify includes
"/usr/include",
]
if directives["Name"] == "icu-uc":
print(pc, libname)

return (libname, includedir, libdir, linkopts, link_paths, includes, defines)

Expand Down