llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.61k stars 11.35k forks source link

request lldb cmake config for static build #98754

Open curu opened 1 month ago

curu commented 1 month ago

can anyone please add output static library option for lldb build? it's hard coded to be shared in lldb/source/API/CMakeLists.txt :

add_lldb_library(liblldb SHARED ${option_framework}

and it would be better to generate a lldb cmake package file so that other tool which requires lldb can work smoothly. that is, when install , create a file like <PREFIX>lib/cmake/clang/LLDBConfig.cmake

vortex73 commented 1 month ago

I could work on this if maintainers assign?

llvmbot commented 1 month ago

@llvm/issue-subscribers-lldb

Author: Curu Wong (curu)

can anyone please add output static library option for lldb build? it's hard coded to be `shared` in `lldb/source/API/CMakeLists.txt` : ``` add_lldb_library(liblldb SHARED ${option_framework} ``` and it would be better to generate a lldb cmake package file so that other tool which requires lldb can work smoothly. that is, when install , create a file like `<PREFIX>lib/cmake/clang/LLDBConfig.cmake`
vortex73 commented 1 month ago

@curu I'm pretty much done but what must the install dedstination of the config package be?

curu commented 1 month ago

@curu I'm pretty much done but what must the install dedstination of the config package be?

maybe under CMAKE_INSTALL_PREFIX ? eg, if CMAKE_INSTALL_PREFIX is /usr/local, then the config pkg should be under /usr/local/lib/cmake/lldb/LLDBConfig.cmake

it would be better if you add an option to enable/disable static library build of LLDB.

In fact, I tried to do a static build of bpftrace, which requires LLDB, if there's a LLDB config pkg, then a simple find_package(LLDB) would populate the required library link option for lldb, then

target_link_libraries(runtime LLDB)

would get the correct link flag from lldb cmake pkg.

if we got just a partial liblldb.a(missing other symbol it links to like what in libCore.a), then compilation would fail.

vortex73 commented 1 month ago

@curu I'm pretty much done but what must the install dedstination of the config package be?

maybe under CMAKE_INSTALL_PREFIX ? eg, if CMAKE_INSTALL_PREFIX is /usr/local, then the config pkg should be under /usr/local/lib/cmake/lldb/LLDBConfig.cmake

it would be better if you add an option to enable/disable static library build of LLDB.

In fact, I tried to do a static build of bpftrace, which requires LLDB, if there's a LLDB config pkg, then a simple find_package(LLDB) would populate the required library link option for lldb, then

target_link_libraries(runtime LLDB)

would get the correct link flag from lldb cmake pkg.

if we got just a partial liblldb.a(missing other symbol it links to like what in libCore.a), then compilation would fail.

Sure I'll put a PR and you can let me know if you meant something else.

jimingham commented 1 month ago

So long as people aren't led to assume that anything outside the lldb: namespace is a stable API, this is fine. I wouldn't want to appear to be making false promises, and we have no intention of supporting the lldb_private API's as stable API's.

bulbazord commented 1 month ago

@curu Can you give some more context behind your request? I assume you want to statically link liblldb into another program?

curu commented 1 month ago

@curu Can you give some more context behind your request? I assume you want to statically link liblldb into another program?

it's bpftrace that requires lldb, and I want to build a static version of bpftrace. you may check this at https://github.com/bpftrace/bpftrace/blob/master/CMakeLists.txt

bulbazord commented 1 month ago

@curu Can you give some more context behind your request? I assume you want to statically link liblldb into another program?

it's bpftrace that requires lldb, and I want to build a static version of bpftrace. you may check this at https://github.com/bpftrace/bpftrace/blob/master/CMakeLists.txt

bpftrace calls find_package(lldb), but we don't currently produce a CMake package like LLVM and Clang do. How does this work today? Do they create their own package? LLDB vending a package would certainly make this easier, but I'd like to know what they're doing now to better inform a solution. I'd prefer not to break them downstream (unless it makes sense to from our perspective).

chenhengqi commented 1 month ago

cc @ajor @danobi

ajor commented 1 month ago

bpftrace calls find_package(lldb), but we don't currently produce a CMake package like LLVM and Clang do. How does this work today?

bpftrace uses this FindLLDB.cmake file which just looks for LLDB libraries and headers in the standard locations: https://github.com/bpftrace/bpftrace/blob/master/cmake/FindLLDB.cmake

We'd definitely appreciate a static liblldb as we do support building bpftrace as a statically linked executable. LLDB is treated as an optional dependency, so right now, without a static liblldb, static bpftrace is missing DWARF support.

curu commented 1 month ago

bpftrace uses this FindLLDB.cmake file which just looks for LLDB libraries and headers in the standard locations: https://github.com/bpftrace/bpftrace/blob/master/cmake/FindLLDB.cmake

and it would be better if the static version of liblldb and its dependency contain only necessary public symbol to reduce the final static binary object size.