Conflict between static cc_library dependencies with the same target name
Nobody has claimed this yet.
- Dominant language
- Starlark
- Stars
- 279
- Forks
- 93
- Avg merge
- 13d 11h
- Merged PRs (30d)
- 3
Description
Describe the bug
When a Haskell library, say //:hslib, depends on two statically linked cc_library targets with the same target name, say //liba:cbits and //libb:cbits, then their names will clash in the extra-libraries entry of the Haskell library's package configuration file. I.e. it will contain only a single cbits entry. When a Haskell binary depends on //:hslib, then only one of //liba:cbits and //libb:cbits will be linked, which can cause missing symbol errors.
To Reproduce
- Checkout a4de7dbd241b510e9e0e30b24ba26352dac4d1e0
- Execute
bazel test //tests/library-cbits-name-clash - Observe linker error, e.g.
error: undefined reference to 'two'.
See azure, circleci.
Expected behavior
Linking should succeed and the test-case should pass.
Environment
- OS name + version: openSUSE Tumbleweed 20190428
- Bazel version: 0.24.0- (@non-git) (rules_haskell
shell.nix) - Version of the rules: adc3503
Additional context
Ultimately the issue is that Bazel treats dynamic and static C libraries differently, in that it only name mangles dynamic libraries, but preserves static library names. If a C library target has both a static and a dynamic library, then rules_haskell will create a symlink for the static library to match its name with the mangled dynamic library. This is so that the corresponding extra-libraries entry in the package configuration file works for both linking modes. However, if no dynamic library is present, then rules_haskell does not name mangle the static library. One solution to this issue would be to implement fall-back name mangling for static only C library dependencies.
I encountered this issue when trying to patch Hazel to create shorter, generic target names, such as :lib for a Haskell library component and :cbits for the corresponding cc_library cbits target. This fails on Windows with missing symbols, because Hazel does not produce dynamic C libraries on Windows.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running bazel test //tests/library-cbits-name-clash at the reported revision and inspect the test target's rules_haskell inputs. Trace how static-only cc_library dependencies are named in the generated package configuration, comparing them with dependencies that also provide dynamic libraries. Done means the regression test passes and both same-named static libraries are linked without missing symbols.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100