Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR: some library packages rely on postint for proper dynamic resolution #76

Open
lazcamus opened this issue Aug 17, 2024 · 4 comments
Open
Labels
feature request New feature or request

Comments

@lazcamus
Copy link
Contributor

Title is generic as I think other libs may do this too?

The specific example I'm dealing with today are packages libblas3 and liblapack3 that install their shared libraries into a subdirectory of the dynamic library path (e.x. /usr/lib/x86_64-linux-gnu/blas/libblas.so.3), then in post install run update-alternatives to make the symlinks in the library directory.

Postint:

% cat libblas3.postinst.in
#!/bin/sh

set -e

update-alternatives --install /usr/lib/@DEB_HOST_MULTIARCH@/libblas.so.3 \
                    libblas.so.3-@DEB_HOST_MULTIARCH@ /usr/lib/@DEB_HOST_MULTIARCH@/blas/libblas.so.3 10

#DEBHELPER#

exit 0

The binaries that try to load them fail. My testcase is installing gdal-bin and running ogr2ogr --version, which will cry:

root@d876f2ae9478:~# ogr2ogr --version                                                                                                                          
ogr2ogr: error while loading shared libraries: libblas.so.3: cannot open shared object file: No such file or directory

I'm currently hacking around it with symlinks:

# This is to hack around the fact that liblas3 and liblapack3 run a postinst to
# `update-alternates` and install their libraries in /usr/lib/$(uname -m)-linux-gnu/
#
# We don't run the postist, so just symlink the libraries to where they need to be
genrule(
    name = "libblas.symlinks_mtree",
    outs = ["libblas.symlinks.mtree"],
    # double $$ to pass through the bazel make rule expansion
    cmd = """
    for lib in libblas.so.3 liblapack.so.3; do
        DEB_HOST_MULTIARCH="$$(uname -m)-linux-gnu";
        LIBNAME="$${lib%%.so.*}"; LIBNAME="$${LIBNAME#lib}";
        echo "usr/lib/$$DEB_HOST_MULTIARCH/$$lib uid=0 gid=0 time=0 type=link link=/usr/lib/$$DEB_HOST_MULTIARCH/$$LIBNAME/$$lib"
    done > $@
    """,
)

tar(
    name = "libblas.symlinks",
    mtree = ":libblas.symlinks_mtree",
)

Filing the issue as an errata I guess, as I have a workaround in hand. Does this seem like a "best practice" for something like this? I don't really expect rules_distroless to handle this out of the box unless it was a common library pattern (and it doesn't seem to be).

@thesayyn
Copy link
Collaborator

thesayyn commented Sep 6, 2024

We currently don't support running any lifecycle scripts as usually they require a running container, technically we could support lifecycle hooks that does basic things like these but i don't have the time do it myself, happy to review a PR

@thesayyn thesayyn added the feature request New feature or request label Sep 6, 2024
@thesayyn thesayyn changed the title some library packages rely on postint for proper dynamic resolution FR: some library packages rely on postint for proper dynamic resolution Dec 4, 2024
@thesayyn
Copy link
Collaborator

thesayyn commented Dec 9, 2024

I have looked into this briefly, good news is that as we always install from scratch, we are not concerned with most of the lifecycle commands we might get away with only running post* hooks, and the bad news is that only way to know if a package has hooks is to inspect the control layer which only downloaded when requested by a target.

@lazcamus
Copy link
Contributor Author

It's a hard thing to support generically for sure.

I'm just spitballing, but maybe there's a class of postinst_ functions that'll accept control files to process, and output a weird compat tarball?

For this update-alternatives use case:

postinst_update_alternatives(
    name = "update_alternatives",
    srcs = ["@noble//libblas3/arm64:control"]
)

# then include ":update_alternatives" in your `tars`

The rule could grab the postinst out of each of the sources, look for dh_installalternatives signature in postinst and spit out compatibility symlinks?

Kind elaborate ... but it's more generic than the ca-certificates munging.

@thesayyn
Copy link
Collaborator

update_alternatives is definitely something we can support, looks like its interface is well defined and something we can mimic.

I'd be happy review a PR and debate more on the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants