bazelbuild / bazelbuild/bazel

Allow dynamic linking against multiple versions of a library

Open
#19,261 3 comments 7 reactions 0 assignees View on GitHub
P2 team-Rules-CPP type: feature request
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

### Description of the feature request:

I know that linking multiple versions of a dynamic library is uncommon, but my use case requires this:

My team builds software in Bazel that links against existing dynamic libraries.
This is a requirement, since we want to deploy our software on a target system (Fedora).
One of the libraries (`liba.so`) we are linking against links against two versions of another library (`libb.so.2`, `libb.so.5`). This seems to be uncommon in general, but is a regular practice in Fedora and RHEL based Linux distributions.

Currently, when trying to link against `liba.so`, we encounter the following error:

```
Error in fail: attribute srcs: Trying to link twice a library with the same identifier 'rpm/libvirt-libs/libunistring.so',files: rpm/libvirt-libs/libunistring.so.5 and rpm/libvirt-libs/libunistring.so.2
```

This seems to be a safety check made by Bazel to prevent linking multiple versions of the same shared library.
Could this check be dropped or reworked to allow our use case?

### Which category does this issue belong to?

C++/Objective-C Rules

### What underlying problem are you trying to solve with this feature?

Improve compatibility with existing libraries and build systems. Allow targeting / linking with Fedora / RHEL libraries.

### Which operating system are you running Bazel on?

Fedora Linux

### What is the output of `bazel info release`?

release 6.3.2

### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.

_No response_

### What's the output of `git remote get-url origin; git rev-parse master; git rev-parse HEAD` ?

_No response_

### Have you found anything relevant by searching the web?

Nothing that would help me resolve this. I do find some mentions that this is currently not supported.

### Any other information, logs, or outputs that you want to share?

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with Bazel's C++/Objective-C rules and reproduce the reported duplicate-library error on Fedora using the liba.so, libb.so.2, and libb.so.5 scenario. Investigate the safety check that reports the shared-library identifier collision. Done means Bazel can support this Fedora/RHEL linking case without incorrectly rejecting the two library versions.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, linux
Domain
build-system
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.