Issue 87260
Summary lldb Python bindings build creates symlink to `liblldb.so`, instead of (versioned) runtime library
Labels new issue
Assignees
Reporter ferdnyc
    Seemingly similar to #86183, when the SWIG Python bindings for lldb are built, the liblldb library is symlinked into the Python package directory as `_lldb.so`. (This is done from the `CMakeLists.txt` for the Python bindings directory:)

https://github.com/llvm/llvm-project/blob/1351d17826e1efa3da3b29b6e345d44cb0ce3bc9/lldb/bindings/python/CMakeLists.txt#L134-L141

By constructing this symlink target as `"${LLVM_SHLIB_OUTPUT_INTDIR}/liblldb${CMAKE_SHARED_LIBRARY_SUFFIX}"`, the _unversioned_ `liblldb.so` library symlink will be the target of the symlink.

When packaged by distributions, the `liblldb.so` symlink is typically packaged into a separate `-devel`/`-dev` package, typically needed only when building dependent code against the library in question. For runtime use, the versioned library file (`liblldb.so.X.Y.Z`) or the SONAMEd library symlink (`liblldb.so.17`) would instead be used.

This has caused difficulties when packaging `python3-lldb` in Fedora, for example — see [bz2260611](https://bugzilla.redhat.com/show_bug.cgi?id=2260611). (Where the decision was made to move `liblldb.so` into the non-devel package, as a special case to work around this issue.)

### Linking to the runtime library

The lldb Python bindings should be able to symlink to the correct runtime library. `create_relative_symlink()` is a CMake function implemented using `add_custom_command()`, which [accepts generator expressions](https://cmake.org/cmake/help/latest/command/add_custom_command.html#generating-files) in its `COMMAND` arguments.

The full versioned library filename of the `liblldb` CMake target is easily retrieved with the generator _expression_ [`$<TARGET_FILE_NAME:liblldb>`](https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html#genex:TARGET_FILE_NAME), and the SONAMEd symlink filename using the _expression_ [`$<TARGET_SONAME_FILE_NAME:liblldb>`](https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html#genex:TARGET_SONAME_FILE_NAME).

Code similar to this should symlink the `_lldb.so` Python module library to the fully-versioned `liblldb` library file, rather than `liblldb.so`, allowing the bindings to depend only on the `liblldb` package instead of requiring the `liblldb-devel` package to be installed:

```cmake
if(LLDB_BUILD_FRAMEWORK)
  set(LIBLLDB_SYMLINK_DEST
    "${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/LLDB")
else()
  set(LIBLLDB_SYMLINK_DEST
    "${LLVM_SHLIB_OUTPUT_INTDIR}/$<TARGET_FILE_NAME:liblldb>")
endif()
set(LIBLLDB_SYMLINK_OUTPUT_FILE
  "_lldb${LLDB_PYTHON_EXT_SUFFIX}")
create_relative_symlink(
  ${swig_target}
  ${LIBLLDB_SYMLINK_DEST}
  ${lldb_python_target_dir}
  ${LIBLLDB_SYMLINK_OUTPUT_FILE}
)
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to