-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
[vcpkg] Fixup rpath after building dynamic libraries on linux #23035
Merged
+85
−0
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
function(z_vcpkg_fixup_rpath_in_dir) | ||
vcpkg_find_acquire_program(PATCHELF) | ||
|
||
# We need to iterate trough everything because we | ||
# can't predict where an elf file will be located | ||
file(GLOB root_entries LIST_DIRECTORIES TRUE "${CURRENT_PACKAGES_DIR}/*") | ||
|
||
# Skip some folders for better throughput | ||
list(APPEND folders_to_skip "include") | ||
list(JOIN folders_to_skip "|" folders_to_skip_regex) | ||
set(folders_to_skip_regex "^(${folders_to_skip_regex})$") | ||
|
||
foreach(folder IN LISTS root_entries) | ||
if(NOT IS_DIRECTORY "${folder}") | ||
continue() | ||
endif() | ||
|
||
get_filename_component(folder_name "${folder}" NAME) | ||
if(folder_name MATCHES "${folders_to_skip_regex}") | ||
continue() | ||
endif() | ||
|
||
file(GLOB_RECURSE elf_files LIST_DIRECTORIES FALSE "${folder}/*") | ||
foreach(elf_file IN LISTS elf_files) | ||
if(IS_SYMLINK "${elf_file}") | ||
continue() | ||
endif() | ||
|
||
get_filename_component(elf_file_dir "${elf_file}" DIRECTORY) | ||
|
||
set(current_prefix "${CURRENT_PACKAGES_DIR}") | ||
if(elf_file_dir MATCHES "debug/") | ||
set(current_prefix "${CURRENT_PACKAGES_DIR}/debug") | ||
endif() | ||
|
||
# compute path relative to lib | ||
file(RELATIVE_PATH relative_to_lib "${elf_file_dir}" "${current_prefix}/lib") | ||
if(relative_to_lib STREQUAL "") | ||
set(rpath "\$ORIGIN") | ||
else() | ||
set(rpath "\$ORIGIN:\$ORIGIN/${relative_to_lib}") | ||
endif() | ||
|
||
# If this fails, the file is not an elf | ||
execute_process( | ||
COMMAND "${PATCHELF}" --set-rpath "${rpath}" "${elf_file}" | ||
OUTPUT_QUIET | ||
ERROR_VARIABLE set_rpath_error | ||
) | ||
if("${set_rpath_error}" STREQUAL "") | ||
message(STATUS "Fixed rpath: ${elf_file} (${rpath})") | ||
endif() | ||
endforeach() | ||
endforeach() | ||
endfunction() | ||
|
||
z_vcpkg_fixup_rpath_in_dir() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
set(VCPKG_TARGET_ARCHITECTURE x64) | ||
set(VCPKG_CRT_LINKAGE dynamic) | ||
set(VCPKG_LIBRARY_LINKAGE dynamic) | ||
|
||
set(VCPKG_CMAKE_SYSTEM_NAME Linux) | ||
|
||
set(VCPKG_FIXUP_ELF_RPATH ON) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ set(VCPKG_LIBRARY_LINKAGE static) | |
|
||
set(VCPKG_CMAKE_SYSTEM_NAME Linux) | ||
|
||
set(VCPKG_FIXUP_ELF_RPATH ON) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed because some ports have
set(VCPKG_LIBRARY_LINKAGE dynamic)
in their portfiles.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this be automatically
ON
ifVCPKG_LIBRARY_LINKAGE
isdynamic
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how to reliably check for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this effectively changes the produced binaries we want it to be an explicit setting even if it is something that the user would actually want to enable every time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about enabling this on x64-linux (if we do, then the world rebuild is warranted)
@ras0219-msft @BillyONeal thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't mind moving this change to a separate PR, to be able to postpone the changes until a real world rebuild is required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
x64-linux is a static triplet so I don't think we really need to go there but I don't feel strongly about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed that executables work with relocated
installed/
folder and when shared libraries are located side-by-side 🎉There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Osyotr I think we're ready to merge this PR if this change is reverted.
We can always make this on-by-default and enable it in static triplet in a future change if we wanted to.