<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/87260>87260</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
lldb Python bindings build creates symlink to `liblldb.so`, instead of (versioned) runtime library
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ferdnyc
</td>
</tr>
</table>
<pre>
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}
)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMV11z4jrS_jXiRhWXLYODL7iAAGeoIclUIO_MvDcu2WpsbWSJI8lhOL9-S_IH5GNnd8_VVlEzwbQe9cfTT7epMbyUADM0WaDJckQbWyk9O4Bm8lyMcsXOsx1AzWUpztjwmguqsVUYkXiaRNMYkTt8qkBiWwHefd_8gb-dbaUkzrlkXJYGH5TGQrAcUw04b7iw7owzFzz3Pwiea6rPmBtszrXg8gUY5tIqb9XhHWnxQkvAjGsorNJnTA1GSZg5iMAolIQBRmS6r7hxSExJwAetag-CkvDunr7AlhtrAvvLoiT0nl3dMHg8XIHiOSIpCpconLf_VtYejX-8RmRdcls1eVCoGpG1EK_9fzdHrf4BhUVknQuVI7KO4knEotspSSCCA40ZjXOS5gnE4wkbj4s8LCDOi9QDMHei9waR9dH7h8j6XQgk3kbx-GYbjaNrHxdnXChprG4Ky2WJbXVJLLZUl2C73CFCEBmj28V2-3_32e7LdrPIHp_335732eZhv9w8odul86itU2t6dz__usp2X-ZPq2W23Sye5k8_s93zer354a2J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