This is an archive of the discontinued LLVM Phabricator instance.

[libunwind] Provide a way to conveniently install libunwind headers
ClosedPublic

Authored by rZhBoYao on Dec 10 2021, 9:14 AM.

Details

Summary

This adds a CMake option (defaults to OFF to not be intrusive) to activate 2 new targets install-unwind-headers and install-unwind-headers-stripped.
So, for example:

cmake -S runtimes -B build -G Ninja \
-DLLVM_ENABLE_RUNTIMES='libunwind' \
-DLIBUNWIND_INSTALL_HEADERS=ON

And then, ninja -C build install-unwind would install headers in addition to good ol' dylibs and archives, i.e., targets install-unwind* DEPENDS on install-unwind-headers*
On the other hand, ninja -C build install-unwind-headers gives you headers only.

Diff Detail

Event Timeline

rZhBoYao created this revision.Dec 10 2021, 9:14 AM
Herald added a reviewer: Restricted Project. · View Herald TranscriptDec 10 2021, 9:14 AM
rZhBoYao requested review of this revision.Dec 10 2021, 9:14 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 10 2021, 9:14 AM
ldionne requested changes to this revision.Dec 13 2021, 6:54 AM

I believe unwind should be made to depend on unwind-header, and install-unwind on install-unwind-headers.

Also, instead of include_directories(include) in libunwind/CMakeLists.txt, we should be able to target_link_libraries(unwind_shared PRIVATE unwind-headers) (and similarly for the static library). That will require adding target_include_directories(unwind-headers INTERFACE <path-to-libunwind-include>).

libunwind/include/CMakeLists.txt
18

Why do we have that check?

This revision now requires changes to proceed.Dec 13 2021, 6:54 AM
rZhBoYao updated this revision to Diff 394193.Dec 14 2021, 2:43 AM
rZhBoYao edited the summary of this revision. (Show Details)

All points addressed. I also updated the summary accordingly. Tested on macOS 12.1 and Ubuntu 20.04.2 LTS.

rZhBoYao added inline comments.Dec 14 2021, 2:51 AM
libunwind/include/CMakeLists.txt
18

Should've been NOT CMAKE_CONFIGURATION_TYPES AND LIBUNWIND_INSTALL_HEADERS. That must've slipped in when I cargo-culted it from other cmake file. I believe NOT CMAKE_CONFIGURATION_TYPES is meant to hide install-* targets from IDEs, since CMAKE_CONFIGURATION_TYPES is set only if the generator is an IDE say -GXcode and not -GNinja.

ldionne added inline comments.Dec 14 2021, 8:10 AM
libunwind/include/CMakeLists.txt
19–23

Instead, why don't we simply do

set(files
    __libunwind_config.h
    libunwind.h
    mach-o/compact_unwind_encoding.h
    unwind_arm_ehabi.h
    unwind_itanium.h
    unwind.h
    )

above and always include that header?

rZhBoYao added inline comments.Dec 15 2021, 12:21 PM
libunwind/include/CMakeLists.txt
19–23

At first, I actually tried that, only to find out mach-o/compact_unwind_encoding.h would then be installed as <CMAKE_INSTALL_PREFIX>/include/compact_unwind_encoding.h instead of <CMAKE_INSTALL_PREFIX>/include/mach-o/compact_unwind_encoding.h, which I think is undesirable.

ldionne added inline comments.Dec 15 2021, 2:01 PM
libunwind/include/CMakeLists.txt
19–23

I would replace it with this:

foreach(file ${files})
    get_filename_component(dir ${file} DIRECTORY)
    install(FILES ${file}
      DESTINATION "include/${dir}"
      COMPONENT unwind-headers
      PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
    )
endforeach()

That's what we do for libc++. That way, we don't have platform specific logic and it should work without modification if new headers are added in the future.

rZhBoYao updated this revision to Diff 394667.Dec 15 2021, 3:06 PM
rZhBoYao edited the summary of this revision. (Show Details)

Address inline comment.

ldionne accepted this revision.Dec 16 2021, 9:15 AM

Thank you!

This revision is now accepted and ready to land.Dec 16 2021, 9:15 AM

Can you commit this for me? My name and email: PoYao Chang <rZhBoYao@gmail.com>.
And thank you for your time!

Can you commit this for me? My name and email: PoYao Chang <rZhBoYao@gmail.com>.
And thank you for your time!

Thanks for the patch!

Ping @thakis in case you want to make a matching change to the gn build (sorry if not and this is just spamming you).