Skip to content

[lld] enable installing lld headers and libraries as part of distribution #127123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 16, 2025

Conversation

makslevental
Copy link
Contributor

@makslevental makslevental commented Feb 13, 2025

This patch allows lld-headers and lld-libraries in LLVM_DISTRIBUTION_COMPONENTS to be specified and thus enable piecewise installation of lld/**/*.h headers and/or lld libraries (both in shared and static builds).
This is similar to use cases such as clang;clang-headers;clang-libraries. Note when lld-libraries is present, llvm-libraries must be present as well because various lld libraries depend on various llvm libraries.

@llvmbot llvmbot added the lld label Feb 13, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 13, 2025

@llvm/pr-subscribers-lld

Author: Maksim Levental (makslevental)

Changes

Currently if one does

set(LLVM_DISTRIBUTION_COMPONENTS
      lld
      lld-cmake-exports)

and then ninja install-distribution one does not get an dist/include/lld folder.

This PR fixes that.


Full diff: https://github.com/llvm/llvm-project/pull/127123.diff

1 Files Affected:

  • (modified) lld/CMakeLists.txt (+10-1)
diff --git a/lld/CMakeLists.txt b/lld/CMakeLists.txt
index 64c9f23805509..7beea1e15296e 100644
--- a/lld/CMakeLists.txt
+++ b/lld/CMakeLists.txt
@@ -180,12 +180,21 @@ include_directories(BEFORE
   ${CMAKE_CURRENT_SOURCE_DIR}/include
   )
 
+add_custom_target(lld-headers)
+set_target_properties(lld-headers PROPERTIES FOLDER "Misc")
 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
-  install(DIRECTORY include/
+  install(DIRECTORY include/lld
     DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
+    COMPONENT lld-headers
     FILES_MATCHING
     PATTERN "*.h"
     )
+
+  if (NOT LLVM_ENABLE_IDE)
+    add_llvm_install_targets(install-lld-headers
+                             DEPENDS lld-headers
+                             COMPONENT lld-headers)
+  endif()
 endif()
 
 add_subdirectory(Common)

@makslevental
Copy link
Contributor Author

Turns out libaries don't get installed either...

@MaskRay
Copy link
Member

MaskRay commented Feb 15, 2025

Description:

set(LLVM_DISTRIBUTION_COMPONENTS lld lld-cmake-exports)
and then ninja install-distribution one does not get an dist/include/lld folder.

I am not familiar with LLVM_DISTRIBUTION_COMPONENTS but this appears to be the intended behavior.
With LLVM_DISTRIBUTION_COMPONENTS=clang;lld, ninja install-distribution installs bin/{clang,lld} and a few symlinks. There is no header.

LLVM_DISTRIBUTION_COMPONENTS=clang;clang-headers;lld installs clang headers. This PR makes lld-headers installs lld headers.

Copy link
Member

@MaskRay MaskRay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

@makslevental
Copy link
Contributor Author

makslevental commented Feb 15, 2025

LLVM_DISTRIBUTION_COMPONENTS=clang;clang-headers;lld installs clang headers. This PR makes lld-headers installs lld headers.

Sorry I don't understand This PR makes lld-headers installs lld headers..

Do you mean that LLVM_DISTRIBUTION_COMPONENTS=clang;clang-headers;lld shouldn't install lld-headers? That's fine I can fix that (I'm just trying to understand what exactly the change requested is).

@MaskRay
Copy link
Member

MaskRay commented Feb 16, 2025

LLVM_DISTRIBUTION_COMPONENTS=clang;clang-headers;lld installs clang headers. This PR makes lld-headers installs lld headers.

Sorry I don't understand This PR makes lld-headers installs lld headers..

Do you mean that LLVM_DISTRIBUTION_COMPONENTS=clang;clang-headers;lld shouldn't install lld-headers?

Right. lld headers should only be installed when lld-headers is present.

That's fine I can fix that (I'm just trying to understand what exactly the change requested is).

@MaskRay
Copy link
Member

MaskRay commented Feb 16, 2025

lld;lld-headers;lld-libraries;clang;clang-libraries;clang-headers;llvm-libraries installs lib/libLLD* and lib/libclang*.
(It seems that llvm-libraries must be present when clang-libraries or lld-libraries is present)

@makslevental
Copy link
Contributor Author

makslevental commented Feb 16, 2025

LLVM_DISTRIBUTION_COMPONENTS=clang;clang-headers;lld installs clang headers. This PR makes lld-headers installs lld headers.

Sorry are you sure this is true? I just double checked:

(base) mlevental@maksims-MacBook-Pro llvm-project % git rev-parse HEAD
fafbf216156043d1874cb339e44f57bb1e8dd4b6
(base) mlevental@maksims-MacBook-Pro llvm-project % rm -rf build llvm-install-release
(base) mlevental@maksims-MacBook-Pro llvm-project % cmake -B build -S llvm -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS=lld -DLLVM_DISTRIBUTION_COMPONENTS=lld -DCMAKE_INSTALL_PREFIX=llvm-install-release
-- The C compiler identification is AppleClang 16.0.0.16000026
-- The CXX compiler identification is AppleClang 16.0.0.16000026
...
-- Build files have been written to: /Users/mlevental/dev_projects/llvm-project/build
(base) mlevental@maksims-MacBook-Pro llvm-project % cmake --build build --target install-distribution
...
(base) mlevental@maksims-MacBook-Pro llvm-project % ls llvm-install-release
bin
(base) mlevental@maksims-MacBook-Pro llvm-project % ls llvm-install-release/bin
ld.lld		ld64.lld	lld		lld-link	wasm-ld

@MaskRay
Copy link
Member

MaskRay commented Feb 16, 2025

Sorry are you sure this is true? I just double checked:

I am sure. The clang behavior looks reasonable. The executable clang and headers are separate. Clang headers are only useful for projects that use Clang API. Similarly, lld headers are often unneeded.

Can you clarify things in the PR description? State the behavior of lld;lld-headers;lld-libraries respectively when they are used in LLVM_DISTRIBUTION_COMPONENTS.

@makslevental
Copy link
Contributor Author

makslevental commented Feb 16, 2025

I am sure.

I'm not saying I disagree with the clang behavior, I'm saying that the behavior I'm seeing is exactly what you expect i.e. -DLLVM_DISTRIBUTION_COMPONENTS=lld only installs lld itself and not the headers.

State the behavior of lld;lld-headers;lld-libraries respectively when they are used in LLVM_DISTRIBUTION_COMPONENTS.

It is exactly what you expect and what this PR implements:

DLLVM_DISTRIBUTION_COMPONENTS=lld-headers

(base) mlevental@maksims-MacBook-Pro llvm-project % rm -rf llvm-install-release                                                                                                                                                                             
(base) mlevental@maksims-MacBook-Pro llvm-project % cmake -GNinja -B build -S llvm -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS=lld -DLLVM_TARGETS_TO_BUILD=host -DLLVM_DISTRIBUTION_COMPONENTS=lld-headers -DCMAKE_INSTALL_PREFIX=llvm-install-release
...
(base) mlevental@maksims-MacBook-Pro llvm-project % cmake --build build --target install-distribution
...
(base) mlevental@maksims-MacBook-Pro llvm-project % ls llvm-install-release                                                                                                                                                                             
include
(base) mlevental@maksims-MacBook-Pro llvm-project % ls llvm-install-release/include                                                                                                                                                                         
lld

DLLVM_DISTRIBUTION_COMPONENTS=lld-libraries

(base) mlevental@maksims-MacBook-Pro llvm-project % rm -rf llvm-install-release                                                                                                                                                                             
(base) mlevental@maksims-MacBook-Pro llvm-project % cmake -GNinja -B build -S llvm -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS=lld -DLLVM_TARGETS_TO_BUILD=host -DLLVM_DISTRIBUTION_COMPONENTS=llvm-libraries;lld-headers -DCMAKE_INSTALL_PREFIX=llvm-install-release
...
(base) mlevental@maksims-MacBook-Pro llvm-project % cmake --build build --target install-distribution
...
(base) mlevental@maksims-MacBook-Pro llvm-project % ls llvm-install-release                     
include	lib
(base) mlevental@maksims-MacBook-Pro llvm-project % ls llvm-install-release/include             
llvm-c
(base) mlevental@maksims-MacBook-Pro llvm-project % ls llvm-install-release/lib | grep "liblld*"
liblldCOFF.a
liblldCommon.a
liblldELF.a
liblldMachO.a
liblldMinGW.a
liblldWasm.a

Can you please try a fresh/clean build on this commit to confirm. If you're not able to I can setup a test/demo/repro repo.

@MaskRay
Copy link
Member

MaskRay commented Feb 16, 2025

I am still confused. You mentioned the following in the description

and then ninja install-distribution one does not get an dist/include/lld folder. This PR fixes that.

I stated that this is the intended behavior: lld in LLVM_DISTRIBUTION_COMPONENTS should not install include/lld headers. This PR doesn't fix a bug. It introduces a new feature (IIUC) related to lld-headers;lld-libraries.

Can you clarify this in the PR description? Suggested description (please confirm the behavior):

This patch allows lld-headers and lld-libraries in LLVM_DISTRIBUTION_COMPONENTS to specify ......
This is similar to clang;clang-headers;clang-libraries. When clang-libraries or lld-libraries is present, llvm-libraries must be present as well.

@makslevental
Copy link
Contributor Author

Sorry sorry it wasn't clear to me what your were asking. I've now adjusted the PR description. Thank you for the suggested description.

@makslevental makslevental changed the title [lld] enable installing lld headers as part of distribution [lld] enable installing lld headers and libraries as part of distribution Feb 16, 2025
@makslevental makslevental merged commit 6273877 into llvm:main Feb 16, 2025
8 checks passed
@makslevental makslevental deleted the makslevental/lld-headers branch February 16, 2025 20:18
MaskRay pushed a commit that referenced this pull request Feb 21, 2025
…tains lld-headers (#127946)

Without this inc file `getLLDVersion` cannot be called; see
https://github.com/llvm/llvm-project/blob/main/lld/include/lld/Common/Version.h#L16.

Fixes incomplete solution introduced by
#127123.
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Feb 21, 2025
…PONENTS contains lld-headers (#127946)

Without this inc file `getLLDVersion` cannot be called; see
https://github.com/llvm/llvm-project/blob/main/lld/include/lld/Common/Version.h#L16.

Fixes incomplete solution introduced by
llvm/llvm-project#127123.
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Feb 24, 2025
…tion (llvm#127123)

This patch allows `lld-headers` and `lld-libraries` in
`LLVM_DISTRIBUTION_COMPONENTS` to be specified and thus enable piecewise
installation of `lld/**/*.h` headers and/or lld libraries (both in
shared and static builds).
This is similar to use cases such as
`clang;clang-headers;clang-libraries`. Note when `lld-libraries` is
present, `llvm-libraries` must be present as well because various lld
libraries depend on various llvm libraries.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants